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

Fixes #20239.
This commit is contained in:
Dmitry Gozman 2023-01-24 08:49:06 -08:00 committed by GitHub
parent 2c52d5be59
commit b971dd3417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 3 deletions

View File

@ -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);
};

View File

@ -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': `