From 6bb005db85c047f1a3708c4ec0f10659e7ae0046 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 9 Sep 2024 14:01:02 -0700 Subject: [PATCH] fix(test runner): improve error message when not able to parse tsconfig (#32526) --- .../src/third_party/tsconfig-loader.ts | 10 +++++++--- tests/playwright-test/resolver.spec.ts | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/playwright/src/third_party/tsconfig-loader.ts b/packages/playwright/src/third_party/tsconfig-loader.ts index 61ad11a3bdd94..b654a3b963925 100644 --- a/packages/playwright/src/third_party/tsconfig-loader.ts +++ b/packages/playwright/src/third_party/tsconfig-loader.ts @@ -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) { diff --git a/tests/playwright-test/resolver.spec.ts b/tests/playwright-test/resolver.spec.ts index 5a0e91b099412..e06959558c8a2 100644 --- a/tests/playwright-test/resolver.spec.ts +++ b/tests/playwright-test/resolver.spec.ts @@ -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' });