fix(runner): validate `config.tsconfig` (#34849)
This commit is contained in:
parent
d5adeb3cf4
commit
aca3fb275b
|
@ -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) {
|
||||
|
|
|
@ -337,6 +337,9 @@ function overridesFromOptions(options: { [key: string]: any }): ConfigCLIOverrid
|
|||
overrides.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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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`);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue