From fdc71cd53a9b4b3075aca69d422e6a7b366f235d Mon Sep 17 00:00:00 2001 From: 3y3 <3y3@ya.ru> Date: Tue, 12 Nov 2024 12:39:35 +0300 Subject: [PATCH] fix: Fix translation tests --- src/commands/translate/__tests__/index.ts | 4 ++-- src/commands/translate/index.spec.ts | 12 +++++++++--- src/commands/translate/utils/config.ts | 1 + 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/commands/translate/__tests__/index.ts b/src/commands/translate/__tests__/index.ts index e034314d..fbabca44 100644 --- a/src/commands/translate/__tests__/index.ts +++ b/src/commands/translate/__tests__/index.ts @@ -44,6 +44,7 @@ export function testConfig(defaultArgs: string) { config: DeepPartial, result: Error | string, ): void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any function _testConfig(name: string, args: string, config: any, result?: any): void { it(name, async () => { if (!result) { @@ -59,9 +60,8 @@ export function testConfig(defaultArgs: string) { }); if (result instanceof Error || typeof result === 'string') { - const message = result.message || result; await expect(async () => runTranslate(defaultArgs + ' ' + args)).rejects.toThrow( - message, + result, ); } else { const instance = await runTranslate(defaultArgs + ' ' + args); diff --git a/src/commands/translate/index.spec.ts b/src/commands/translate/index.spec.ts index 6281e743..024bf4ac 100644 --- a/src/commands/translate/index.spec.ts +++ b/src/commands/translate/index.spec.ts @@ -99,7 +99,7 @@ describe('Translate command', () => { ); test( - 'should handle args with priority', + 'should handle args with priority', '--source ru', { // @ts-ignore @@ -312,8 +312,14 @@ describe('Translate command', () => { }); it('should call provider translate with config', async () => { - const instance = await run('-o output --folder 1'); + const instance = await run('-o output --folder 1 --source ru --target en --auth y0_1'); - expect(instance.provider?.translate).toBeCalledWith(expect.objectContaining({})); + expect(instance.provider?.translate).toBeCalledWith( + expect.anything(), + expect.objectContaining({ + input: expect.stringMatching(/^(\/|[A-Z]:\\).*?/), + output: expect.stringMatching(/^(\/|[A-Z]:\\).*?/), + }), + ); }); }); diff --git a/src/commands/translate/utils/config.ts b/src/commands/translate/utils/config.ts index c34deacf..6073d663 100644 --- a/src/commands/translate/utils/config.ts +++ b/src/commands/translate/utils/config.ts @@ -120,6 +120,7 @@ export function resolveFiles( result = glob.sync(extmatch, { cwd: input, nodir: true, + ignore: ['node_modules/**', '*/node_modules/**'], }); if (exclude.length) {