From cdd202fe98897158c7114e10551b897bc77c45e7 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Wed, 19 Feb 2025 09:12:31 +0100 Subject: [PATCH] config validation --- packages/playwright/src/common/configLoader.ts | 5 +++++ tests/playwright-test/resolver.spec.ts | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/playwright/src/common/configLoader.ts b/packages/playwright/src/common/configLoader.ts index 440bf083fb..8e960d692f 100644 --- a/packages/playwright/src/common/configLoader.ts +++ b/packages/playwright/src/common/configLoader.ts @@ -254,6 +254,11 @@ function validateConfig(file: string, config: Config) { else if (typeof config.workers === 'string' && !config.workers.endsWith('%')) throw errorWithFile(file, `config.workers must be a number or percentage`); } + + if ('tsconfig' in config && config.tsconfig !== undefined) { + if (typeof config.tsconfig !== 'string') + throw errorWithFile(file, `config.tsconfig must be a string`); + } } function validateProject(file: string, project: Project, title: string) { diff --git a/tests/playwright-test/resolver.spec.ts b/tests/playwright-test/resolver.spec.ts index d4dec96495..fe85aab11f 100644 --- a/tests/playwright-test/resolver.spec.ts +++ b/tests/playwright-test/resolver.spec.ts @@ -734,6 +734,19 @@ 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 = {