mirror of
https://github.com/microsoft/playwright.git
synced 2024-10-27 21:58:52 +03:00
chore: do not point to node_modules in code frames (#18358)
Fixes https://github.com/microsoft/playwright/issues/18330
This commit is contained in:
parent
1505a952fe
commit
db456a020c
@ -439,6 +439,8 @@ export function prepareErrorStack(stack: string): {
|
||||
const { frame: parsed, fileName: resolvedFile } = parseStackTraceLine(line);
|
||||
if (!parsed || !resolvedFile)
|
||||
continue;
|
||||
if (belongsToNodeModules(resolvedFile))
|
||||
continue;
|
||||
location = { file: resolvedFile, column: parsed.column || 0, line: parsed.line || 0 };
|
||||
break;
|
||||
}
|
||||
@ -481,3 +483,7 @@ function fitToWidth(line: string, width: number, prefix?: string): string {
|
||||
}
|
||||
return taken.reverse().join('');
|
||||
}
|
||||
|
||||
function belongsToNodeModules(file: string) {
|
||||
return file.includes(`${path.sep}node_modules${path.sep}`);
|
||||
}
|
||||
|
@ -85,6 +85,35 @@ test('should print an error in a codeframe', async ({ runInlineTest }) => {
|
||||
expect(result.output).toContain(`> 7 | const error = new Error('my-message');`);
|
||||
});
|
||||
|
||||
test('should filter out node_modules error in a codeframe', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'node_modules/utils/utils.js': `
|
||||
function assert(value) {
|
||||
if (!value)
|
||||
throw new Error('Assertion error');
|
||||
}
|
||||
module.exports = { assert };
|
||||
`,
|
||||
'a.spec.ts': `
|
||||
const { test } = pwt;
|
||||
const { assert } = require('utils/utils.js');
|
||||
test('fail', async ({}) => {
|
||||
assert(false);
|
||||
});
|
||||
`
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.failed).toBe(1);
|
||||
const output = stripAnsi(result.output);
|
||||
expect(output).toContain('Error: Assertion error');
|
||||
expect(output).toContain('a.spec.ts:7:7 › fail');
|
||||
expect(output).toContain(` 7 | test('fail', async ({}) => {`);
|
||||
expect(output).toContain(`> 8 | assert(false);`);
|
||||
expect(output).toContain(` | ^`);
|
||||
expect(output).toContain(`utils.js:6`);
|
||||
expect(output).toContain(`a.spec.ts:8:9`);
|
||||
});
|
||||
|
||||
test('should print codeframe from a helper', async ({ runInlineTest }) => {
|
||||
const result = await runInlineTest({
|
||||
'helper.ts': `
|
||||
|
Loading…
Reference in New Issue
Block a user