|
| 1 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
| 2 | +import { vol } from 'memfs' |
| 3 | + |
| 4 | +beforeEach(() => { |
| 5 | + vi.resetModules() |
| 6 | +}) |
| 7 | + |
| 8 | +describe('isTranslationTaskNeeded', () => { |
| 9 | + const mockExit = vi.spyOn(process, 'exit').mockImplementation(vi.fn()) |
| 10 | + vi.mock('child_process', () => ({ |
| 11 | + exec: vi.fn((cmd, cb) => cb(null, 'mocked stdout', '')), |
| 12 | + })) |
| 13 | + |
| 14 | + it('should return exit code 1 because temp.json has more keys than en-US.json', async () => { |
| 15 | + vol.fromJSON({ |
| 16 | + '__mocks__/locales/temp.json': JSON.stringify({ a: 'foo', b: 'bar' }), |
| 17 | + '__mocks__/locales/en-US.json': JSON.stringify({ a: 'foo' }), |
| 18 | + }) |
| 19 | + await import('./check.mjs') |
| 20 | + expect(mockExit).toHaveBeenCalledWith(1) |
| 21 | + }) |
| 22 | + |
| 23 | + it('should return exit code 0 because temp.json and en-US.json have the same keys', async () => { |
| 24 | + vol.fromJSON({ |
| 25 | + '__mocks__/locales/temp.json': JSON.stringify({ a: 'foo', b: 'bar' }), |
| 26 | + '__mocks__/locales/en-US.json': JSON.stringify({ a: 'foo', b: 'bar' }), |
| 27 | + }) |
| 28 | + await import('./check.mjs') |
| 29 | + expect(mockExit).toHaveBeenCalledWith(0) |
| 30 | + }) |
| 31 | + |
| 32 | + it('should return exit code 1 because temp.json has less keys than en-US.json', async () => { |
| 33 | + vol.fromJSON({ |
| 34 | + '__mocks__/locales/temp.json': JSON.stringify({ a: 'foo' }), |
| 35 | + '__mocks__/locales/en-US.json': JSON.stringify({ a: 'foo', b: 'bar' }), |
| 36 | + }) |
| 37 | + await import('./check.mjs') |
| 38 | + expect(mockExit).toHaveBeenCalledWith(1) |
| 39 | + }) |
| 40 | +}) |
0 commit comments