fix(test runner): improve error message when not able to parse tsconfig (#32526)

This commit is contained in:
Dmitry Gozman 2024-09-09 14:01:02 -07:00 committed by GitHub
parent e6c5b6054d
commit 6bb005db85
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 25 additions and 3 deletions

View file

@ -53,9 +53,13 @@ export interface LoadedTsConfig {
}
export function loadTsConfig(configPath: string): LoadedTsConfig[] {
try {
const references: LoadedTsConfig[] = [];
const config = innerLoadTsConfig(configPath, references);
return [config, ...references];
} catch (e) {
throw new Error(`Failed to load tsconfig file at ${configPath}:\n${e.message}`);
}
}
function resolveConfigFile(baseConfigFile: string, referencedConfigFile: string) {

View file

@ -16,6 +16,24 @@
import { test, expect } from './playwright-test-fixtures';
test('should print tsconfig parsing error', async ({ runInlineTest }) => {
const files = {
'a.spec.ts': `
import { test } from '@playwright/test';
test('pass', async () => {});
`,
'tsconfig.json': `
"foo": "bar"
`,
};
const result = await runInlineTest(files);
expect(result.exitCode).toBe(1);
expect(result.output).toContain(`Failed to load tsconfig file at`);
expect(result.output).toContain(`tsconfig.json`);
expect(result.output).toContain(`JSON5: invalid character ':' at 2:12`);
});
test('should respect path resolver', async ({ runInlineTest }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/11656' });