Skip to content

Commit

Permalink
fix(test runner): improve error message when not able to parse tsconf…
Browse files Browse the repository at this point in the history
…ig (#32526)
  • Loading branch information
dgozman committed Sep 9, 2024
1 parent e6c5b60 commit 6bb005d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/playwright/src/third_party/tsconfig-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ export interface LoadedTsConfig {
}

export function loadTsConfig(configPath: string): LoadedTsConfig[] {
const references: LoadedTsConfig[] = [];
const config = innerLoadTsConfig(configPath, references);
return [config, ...references];
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) {
Expand Down
18 changes: 18 additions & 0 deletions tests/playwright-test/resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down

0 comments on commit 6bb005d

Please sign in to comment.