Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(test runner): show deep strack traces during imports (#20305)

Dmitry Gozmanb971dd341762
diff --git a/packages/playwright-test/src/transform.ts b/packages/playwright-test/src/transform.ts
index fa97cd353d..9f13ea5975 100644
--- a/packages/playwright-test/src/transform.ts
+++ b/packages/playwright-test/src/transform.ts
@@ -38,8 +38,7 @@ type ParsedTsConfigData = {
};
const cachedTSConfigs = new Map<string, ParsedTsConfigData | undefined>();
-const kStackTraceLimit = 15;
-Error.stackTraceLimit = kStackTraceLimit;
+Error.stackTraceLimit = 200;
sourceMapSupport.install({
environment: 'node',
@@ -270,11 +269,12 @@ export function wrapFunctionWithLocation<A extends any[], R>(func: (location: Lo
column: frame.getColumnNumber(),
};
};
+ const oldStackTraceLimit = Error.stackTraceLimit;
Error.stackTraceLimit = 2;
const obj: { stack: Location } = {} as any;
Error.captureStackTrace(obj);
const location = obj.stack;
- Error.stackTraceLimit = kStackTraceLimit;
+ Error.stackTraceLimit = oldStackTraceLimit;
Error.prepareStackTrace = oldPrepareStackTrace;
return func(location, ...args);
};
diff --git a/tests/playwright-test/loader.spec.ts b/tests/playwright-test/loader.spec.ts
index a254a99dad..53f5e0524b 100644
--- a/tests/playwright-test/loader.spec.ts
+++ b/tests/playwright-test/loader.spec.ts
@@ -32,6 +32,42 @@ test('should return the location of a syntax error', async ({ runInlineTest }) =
expect(result.output).toContain('(6:18)');
});
+test('should return the location of a syntax error with deep stack', async ({ runInlineTest }) => {
+ const result = await runInlineTest({
+ 'error.ts': `
+ const x = {
+ foo: 'bar';
+ };
+ `,
+ 'qux.ts': `
+ import { error } from './error';
+ export function qux() { error() }
+ `,
+ 'baz.ts': `
+ import { qux } from './qux';
+ export function baz() { qux() }
+ `,
+ 'bar.ts': `
+ import { baz } from './baz';
+ export function bar() { baz() }
+ `,
+ 'foo.ts': `
+ import { bar } from './bar';
+ export function foo() { bar() }
+ `,
+ 'test.spec.ts': `
+ import { foo } from './foo';
+ foo();
+ `,
+ });
+ expect(result.exitCode).toBe(1);
+ expect(result.output).toContain('qux.ts:4:7');
+ expect(result.output).toContain('baz.ts:4:7');
+ expect(result.output).toContain('bar.ts:4:7');
+ expect(result.output).toContain('foo.ts:4:7');
+ expect(result.output).toContain('test.spec.ts:5:7');
+});
+
test('should print an improper error', async ({ runInlineTest }) => {
const result = await runInlineTest({
'error.spec.js': `