From a85c15b19cc176daa126ecceea2ded336365680d Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 23 Jan 2023 15:26:40 -0800 Subject: [PATCH] fix(test runner): show deep strack traces during imports --- packages/playwright-test/src/transform.ts | 6 ++-- tests/playwright-test/loader.spec.ts | 36 +++++++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/packages/playwright-test/src/transform.ts b/packages/playwright-test/src/transform.ts index fa97cd353dd48..9f13ea5975968 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(); -const kStackTraceLimit = 15; -Error.stackTraceLimit = kStackTraceLimit; +Error.stackTraceLimit = 200; sourceMapSupport.install({ environment: 'node', @@ -270,11 +269,12 @@ export function wrapFunctionWithLocation(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 a254a99dad8ee..53f5e0524bccd 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': `