check file existance

This commit is contained in:
Simon Knott 2025-02-19 09:27:12 +01:00
parent cdd202fe98
commit 4fb068e6ae
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
3 changed files with 34 additions and 13 deletions

View file

@ -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`);
}
}

View file

@ -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`);
});

View file

@ -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 = {