From 4fb068e6aeab8f5ffb40104ec758b36fbb2b5ae6 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 19 Feb 2025 09:27:12 +0100 Subject: [PATCH] check file existance --- .../playwright/src/common/configLoader.ts | 2 ++ tests/playwright-test/config.spec.ts | 32 +++++++++++++++++++ tests/playwright-test/resolver.spec.ts | 13 -------- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/packages/playwright/src/common/configLoader.ts b/packages/playwright/src/common/configLoader.ts index 8e960d692f..32783e3a98 100644 --- a/packages/playwright/src/common/configLoader.ts +++ b/packages/playwright/src/common/configLoader.ts @@ -258,6 +258,8 @@ function validateConfig(file: string, config: Config) { if ('tsconfig' in config && config.tsconfig !== undefined) { if (typeof config.tsconfig !== 'string') throw errorWithFile(file, `config.tsconfig must be a string`); + if (!fs.existsSync(path.resolve(file, '..', config.tsconfig))) + throw errorWithFile(file, `config.tsconfig does not exist`); } } diff --git a/tests/playwright-test/config.spec.ts b/tests/playwright-test/config.spec.ts index 518bf33839..a2c61d62dd 100644 --- a/tests/playwright-test/config.spec.ts +++ b/tests/playwright-test/config.spec.ts @@ -698,3 +698,35 @@ test('should merge ct configs', async ({ runInlineTest }) => { }); expect(result.exitCode).toBe(0); }); + +test('should throw on invalid config.tsconfig option', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'playwright.config.ts': ` + export default { + tsconfig: true, + }; + `, + }); + + expect(result.exitCode).toBe(1); + expect(result.output).toContain(`config.tsconfig must be a string`); +}); + +test('should throw on nonexistant config.tsconfig', async ({ runInlineTest }) => { + const result = await runInlineTest({ + 'playwright.config.ts': ` + export default { + tsconfig: './does-not-exist.json', + }; + `, + 'tests/a.test.ts': ` + import { test, expect } from '@playwright/test'; + test('test', ({}) => { + expect(1).toBe(1); + }); + `, + }); + + expect(result.exitCode).toBe(1); + expect(result.output).toContain(`config.tsconfig does not exist`); +}); diff --git a/tests/playwright-test/resolver.spec.ts b/tests/playwright-test/resolver.spec.ts index fe85aab11f..d4dec96495 100644 --- a/tests/playwright-test/resolver.spec.ts +++ b/tests/playwright-test/resolver.spec.ts @@ -734,19 +734,6 @@ test('should respect config.tsconfig option', async ({ runInlineTest }) => { expect(result.output).not.toContain(`Could not`); }); -test('should throw on invalid config.tsconfig option', async ({ runInlineTest }) => { - const result = await runInlineTest({ - 'playwright.config.ts': ` - export default { - tsconfig: true, - }; - `, - }); - - expect(result.exitCode).toBe(1); - expect(result.output).toContain(`config.tsconfig must be a string`); -}); - test.describe('directory imports', () => { test('should resolve index.js without path mapping in CJS', async ({ runInlineTest, runTSC }) => { const files = {