Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(runner): validate `config.tsconfig` (#34849)
Simon Knottaca3fb275b5a
diff --git a/packages/playwright/src/common/configLoader.ts b/packages/playwright/src/common/configLoader.tsindex 371a59d086..ef8f1683fa 100644--- a/packages/playwright/src/common/configLoader.ts+++ b/packages/playwright/src/common/configLoader.ts@@ -254,6 +254,13 @@ 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`);+ if (!fs.existsSync(path.resolve(file, '..', config.tsconfig)))+ throw errorWithFile(file, `config.tsconfig does not exist`);+ }}function validateProject(file: string, project: Project, title: string) {diff --git a/packages/playwright/src/program.ts b/packages/playwright/src/program.tsindex cb62f28f68..bc899b48c6 100644--- a/packages/playwright/src/program.ts+++ b/packages/playwright/src/program.ts@@ -337,6 +337,9 @@ function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverridoverrides.use = overrides.use || {};overrides.use.trace = options.trace;}+ if (overrides.tsconfig && !fs.existsSync(overrides.tsconfig))+ throw new Error(`--tsconfig "${options.tsconfig}" does not exist`);+return overrides;}diff --git a/tests/playwright-test/config.spec.ts b/tests/playwright-test/config.spec.tsindex 518bf33839..77e5fb23f6 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',+ };+ `,+ });++ expect(result.exitCode).toBe(1);+ expect(result.output).toContain(`config.tsconfig does not exist`);+});++test('should throw on invalid --tsconfig', async ({ runInlineTest }) => {+ const result = await runInlineTest({}, { 'tsconfig': 'does-not-exist.json' });+ expect(result.exitCode).toBe(1);+ expect(result.output).toContain(`--tsconfig "does-not-exist.json" does not exist`);+});