From 1bb79d6cdaa4003ae9c2953e9a41e007eb6f7cd1 Mon Sep 17 00:00:00 2001 From: shaharkazaz Date: Fri, 14 Jun 2024 16:39:04 +0300 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=92=8D=20split=20test=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/resolveConfig/resolveConfig.spec.ts | 30 ++++++++----------- __tests__/resolveConfig/src/folder/2.html | 10 +++++++ 2 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 __tests__/resolveConfig/src/folder/2.html diff --git a/__tests__/resolveConfig/resolveConfig.spec.ts b/__tests__/resolveConfig/resolveConfig.spec.ts index 2d318df..0cce814 100644 --- a/__tests__/resolveConfig/resolveConfig.spec.ts +++ b/__tests__/resolveConfig/resolveConfig.spec.ts @@ -38,27 +38,22 @@ describe('resolveConfig', () => { outputFormat: 'pot', }; let spies: SpyInstance[]; - let processExitSpy: SpyInstance; - let consoleLogSpy: SpyInstance; - let defaultConfig = _defaultConfig(); + const defaultConfig = _defaultConfig(); beforeAll(() => { mockedGloblConfig = {}; - processExitSpy = spyOnProcess('exit'); - consoleLogSpy = spyOnConsole('log'); - spies = [processExitSpy, consoleLogSpy]; + spies = [spyOnProcess('exit'), spyOnConsole('log')]; }); afterAll(() => { - processExitSpy.mockRestore(); - consoleLogSpy.mockRestore(); + spies.forEach((s) => s.mockRestore()); }); function resolvePath(configPath: string[]): string[]; function resolvePath(configPath: string): string; function resolvePath(configPath: string, asArray: true): string[]; function resolvePath(configPath: string | string[], asArray = false) { - const resolve = (p) => path.resolve(process.cwd(), sourceRoot, p); + const resolve = (p: string) => path.resolve(process.cwd(), sourceRoot, p); if (Array.isArray(configPath)) { return configPath.map(resolve); } @@ -66,7 +61,7 @@ describe('resolveConfig', () => { return asArray ? [resolve(configPath)] : resolve(configPath); } - function assertConfig(expected, inline = {}) { + function assertConfig(expected: T, inline = {}) { const { scopes, ...config } = resolveConfig(inline); expect(config).toEqual(expected); expect(scopes).toBeDefined(); @@ -142,6 +137,7 @@ describe('resolveConfig', () => { describe('validate directories', () => { function shouldFail(prop: string, msg: 'pathDoesntExist' | 'pathIsNotDir') { + const [processExitSpy, consoleLogSpy] = spies; expect(processExitSpy).toHaveBeenCalled(); expect(consoleLogSpy).toHaveBeenCalledWith( chalk.bgRed.black(`${prop} ${messages[msg]}`), @@ -150,9 +146,7 @@ describe('resolveConfig', () => { } function shouldPass() { - [processExitSpy, consoleLogSpy].forEach((s) => - expect(s).not.toHaveBeenCalled(), - ); + spies.forEach((s) => expect(s).not.toHaveBeenCalled()); clearSpies(); } @@ -169,8 +163,7 @@ describe('resolveConfig', () => { shouldFail('Input', 'pathIsNotDir'); }); - it('should fail on invalid translations path', () => { - /* should only fail translation path when in find mode */ + it('should pass on invalid translations path in extract mode', () => { resolveConfig({ input: ['src/folder'], translationsPath: 'noFolder', @@ -183,6 +176,9 @@ describe('resolveConfig', () => { command: 'extract', }); shouldPass(); + }); + + it('should fail on invalid translations path in find mode', () => { resolveConfig({ input: ['src/folder'], translationsPath: 'noFolder', @@ -201,12 +197,12 @@ describe('resolveConfig', () => { describe('resolveConfigPaths', () => { it('should prefix all the paths in the config with the process cwd', () => { const config = resolveConfig({ input: ['folder'] }); - const assertPath = (p) => + const assertPath = (p: string) => expect(p.startsWith(path.resolve(process.cwd(), sourceRoot))).toBe( true, ); config.input.forEach(assertPath); - ['output', 'translationsPath'].forEach((prop) => + (['output', 'translationsPath'] as const).forEach((prop) => assertPath(config[prop]), ); }); diff --git a/__tests__/resolveConfig/src/folder/2.html b/__tests__/resolveConfig/src/folder/2.html new file mode 100644 index 0000000..e149a39 --- /dev/null +++ b/__tests__/resolveConfig/src/folder/2.html @@ -0,0 +1,10 @@ + + + + + Title + + + + +