|
1 | | -import { assert, beforeEach, afterEach, describe, it } from 'vitest' |
| 1 | +import { afterEach, describe, test, vi, expect } from 'vitest' |
2 | 2 | import { getLocale } from '../src/i18n' |
3 | 3 |
|
4 | | -let ORG_ENV = {} |
5 | | - |
6 | | -beforeEach(function () { |
7 | | - ORG_ENV = process.env |
8 | | - process.env = {} |
9 | | -}) |
10 | | - |
11 | | -afterEach(function () { |
12 | | - process.env = ORG_ENV |
| 4 | +afterEach(() => { |
| 5 | + vi.resetAllMocks() |
13 | 6 | }) |
14 | 7 |
|
15 | | -describe('getLocale', function () { |
16 | | - it('default', function () { |
17 | | - assert.equal(getLocale(), 'en-US') |
18 | | - }) |
19 | | - |
20 | | - it('LC_ALL', function () { |
21 | | - process.env['LC_ALL'] = 'ja_JP' |
22 | | - assert.equal(getLocale(), 'ja-JP') |
23 | | - }) |
24 | | - |
25 | | - it('LC_MESSAGES', function () { |
26 | | - process.env['LC_MESSAGES'] = 'ja_JP' |
27 | | - assert.equal(getLocale(), 'ja-JP') |
28 | | - }) |
29 | | - |
30 | | - it('LANG', function () { |
31 | | - process.env['LANG'] = 'ja_JP' |
32 | | - assert.equal(getLocale(), 'ja-JP') |
33 | | - }) |
34 | | - |
35 | | - it('LANGUAGE', function () { |
36 | | - process.env['LANGUAGE'] = 'ja_JP' |
37 | | - assert.equal(getLocale(), 'ja-JP') |
| 8 | +describe('getLocale', () => { |
| 9 | + test('default value', () => { |
| 10 | + vi.spyOn(process, 'env', 'get').mockReturnValue({}) |
| 11 | + expect(getLocale()).toBe('en-US') |
38 | 12 | }) |
39 | 13 |
|
40 | | - it('BCP-47', function () { |
41 | | - process.env['LC_ALL'] = 'ja-JP' |
42 | | - assert.equal(getLocale(), 'ja-JP') |
| 14 | + test('basic', () => { |
| 15 | + vi.spyOn(process, 'env', 'get').mockReturnValue({ |
| 16 | + LC_ALL: 'en-GB', |
| 17 | + LC_MESSAGES: 'en-US', |
| 18 | + LANG: 'ja-JP', |
| 19 | + LANGUAGE: 'en' |
| 20 | + }) |
| 21 | + expect(getLocale()).toBe('en-GB') |
43 | 22 | }) |
44 | 23 | }) |
0 commit comments