Skip to content

Commit

Permalink
fix(test runner): show deep strack traces during imports (microsoft#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
dgozman authored Jan 24, 2023
1 parent 2c52d5b commit b971dd3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/playwright-test/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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);
};
Expand Down
36 changes: 36 additions & 0 deletions tests/playwright-test/loader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': `
Expand Down

0 comments on commit b971dd3

Please sign in to comment.