Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: do not point to node_modules in code frames (#18358)
Pavel Feldmandb456a020c14
diff --git a/packages/playwright-test/src/reporters/base.ts b/packages/playwright-test/src/reporters/base.tsindex c71cc919e2..e74e06194e 100644--- a/packages/playwright-test/src/reporters/base.ts+++ b/packages/playwright-test/src/reporters/base.ts@@ -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}`);+}diff --git a/tests/playwright-test/reporter-base.spec.ts b/tests/playwright-test/reporter-base.spec.tsindex d044c1a8a2..3377a6ffa2 100644--- a/tests/playwright-test/reporter-base.spec.ts+++ b/tests/playwright-test/reporter-base.spec.ts@@ -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': `