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 lose error name for js errors (#28177)
Pavel Feldman25b9c4eb4ae7
diff --git a/packages/playwright/src/util.ts b/packages/playwright/src/util.tsindex f4c2da22db..1e1acc62ba 100644--- a/packages/playwright/src/util.ts+++ b/packages/playwright/src/util.ts@@ -32,11 +32,11 @@ const PLAYWRIGHT_CORE_PATH = path.dirname(require.resolve('playwright-core/packaexport function filterStackTrace(e: Error): { message: string, stack: string } {if (process.env.PWDEBUGIMPL)- return { message: e.message, stack: e.stack || '' };+ return { message: e.name + ': ' + e.message, stack: e.stack || '' };const stackLines = stringifyStackFrames(filteredStackTrace(e.stack?.split('\n') || []));return {- message: e.message,+ message: e.name + ': ' + e.message,stack: `${e.name}: ${e.message}\n${stackLines.join('\n')}`};}diff --git a/tests/playwright-test/fixture-errors.spec.ts b/tests/playwright-test/fixture-errors.spec.tsindex f776ae48c8..f1813ab26c 100644--- a/tests/playwright-test/fixture-errors.spec.ts+++ b/tests/playwright-test/fixture-errors.spec.ts@@ -349,7 +349,7 @@ test('should throw when calling runTest twice', async ({ runInlineTest }) => {test('works', async ({foo}) => {});`,});- expect(result.results[0].error.message).toBe('Cannot provide fixture value for the second time');+ expect(result.results[0].error.message).toBe('Error: Cannot provide fixture value for the second time');expect(result.exitCode).toBe(1);});diff --git a/tests/playwright-test/list-files.spec.ts b/tests/playwright-test/list-files.spec.tsindex 263d11a226..25058eabeb 100644--- a/tests/playwright-test/list-files.spec.ts+++ b/tests/playwright-test/list-files.spec.ts@@ -94,7 +94,7 @@ test('should report error', async ({ runListFiles }) => {line: 3,column: 8,},- message: 'Assignment to constant variable.',+ message: 'TypeError: Assignment to constant variable.',stack: expect.stringContaining('TypeError: Assignment to constant variable.'),}});diff --git a/tests/playwright-test/playwright.trace.spec.ts b/tests/playwright-test/playwright.trace.spec.tsindex 5ac1c1fb31..ec75ae0ef6 100644--- a/tests/playwright-test/playwright.trace.spec.ts+++ b/tests/playwright-test/playwright.trace.spec.ts@@ -668,7 +668,7 @@ test('should show non-expect error in trace', async ({ runInlineTest }, testInfo' fixture: page',' browserContext.newPage','expect.toBe',- 'undefinedVariable1 is not defined',+ 'ReferenceError: undefinedVariable1 is not defined','After Hooks',' fixture: page',' fixture: context',diff --git a/tests/playwright-test/reporter.spec.ts b/tests/playwright-test/reporter.spec.tsindex 08a200623b..d98b580c2e 100644--- a/tests/playwright-test/reporter.spec.ts+++ b/tests/playwright-test/reporter.spec.ts@@ -454,7 +454,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {`begin {\"title\":\"page.setContent\",\"category\":\"pw:api\"}`,`end {\"title\":\"page.setContent\",\"category\":\"pw:api\"}`,`begin {\"title\":\"page.click(input)\",\"category\":\"pw:api\"}`,- `end {\"title\":\"page.click(input)\",\"category\":\"pw:api\",\"error\":{\"message\":\"page.click: Timeout 1ms exceeded.\\nCall log:\\n \\u001b[2m- waiting for locator('input')\\u001b[22m\\n\",\"stack\":\"<stack>\",\"location\":\"<location>\",\"snippet\":\"<snippet>\"}}`,+ `end {\"title\":\"page.click(input)\",\"category\":\"pw:api\",\"error\":{\"message\":\"Error: page.click: Timeout 1ms exceeded.\\nCall log:\\n \\u001b[2m- waiting for locator('input')\\u001b[22m\\n\",\"stack\":\"<stack>\",\"location\":\"<location>\",\"snippet\":\"<snippet>\"}}`,`begin {\"title\":\"After Hooks\",\"category\":\"hook\"}`,`begin {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,`end {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,@@ -567,7 +567,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {}, { 'reporter': '' });expect(result.exitCode).toBe(1);- expect(result.output).toContain(`%%got error: No tests found`);+ expect(result.output).toContain(`%%got error: Error: No tests found`);});test('should report require error to reporter', async ({ runInlineTest }) => {@@ -584,7 +584,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {}, { 'reporter': '' });expect(result.exitCode).toBe(1);- expect(result.output).toContain(`%%got error: Oh my!`);+ expect(result.output).toContain(`%%got error: Error: Oh my!`);});test('should report global setup error to reporter', async ({ runInlineTest }) => {@@ -608,7 +608,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {}, { 'reporter': '' });expect(result.exitCode).toBe(1);- expect(result.output).toContain(`%%got error: Oh my!`);+ expect(result.output).toContain(`%%got error: Error: Oh my!`);});test('should report correct tests/suites when using grep', async ({ runInlineTest }) => {diff --git a/tests/playwright-test/runner.spec.ts b/tests/playwright-test/runner.spec.tsindex ceb03251c7..088a73ead1 100644--- a/tests/playwright-test/runner.spec.ts+++ b/tests/playwright-test/runner.spec.ts@@ -236,7 +236,7 @@ test('should use the first occurring error when an unhandled exception was throwexpect(result.exitCode).toBe(1);expect(result.passed).toBe(0);expect(result.failed).toBe(1);- expect(result.report.suites[0].specs[0].tests[0].results[0].error!.message).toBe('first error');+ expect(result.report.suites[0].specs[0].tests[0].results[0].error!.message).toBe('Error: first error');});test('worker interrupt should report errors', async ({ interactWithTestRunner }) => {diff --git a/tests/playwright-test/test-output-dir.spec.ts b/tests/playwright-test/test-output-dir.spec.tsindex 07a5f5be15..6d74551303 100644--- a/tests/playwright-test/test-output-dir.spec.ts+++ b/tests/playwright-test/test-output-dir.spec.ts@@ -51,12 +51,12 @@ test('should work and remove non-failures', async ({ runInlineTest }, testInfo)expect(result.results[0].status).toBe('failed');expect(result.results[0].retry).toBe(0);// Should only fail the last retry check.- expect(result.results[0].error.message).toBe('Give me retries');+ expect(result.results[0].error.message).toBe('Error: Give me retries');expect(result.results[1].status).toBe('failed');expect(result.results[1].retry).toBe(1);// Should only fail the last retry check.- expect(result.results[1].error.message).toBe('Give me retries');+ expect(result.results[1].error.message).toBe('Error: Give me retries');expect(result.results[2].status).toBe('passed');expect(result.results[2].retry).toBe(2);diff --git a/tests/playwright-test/ui-mode-test-source.spec.ts b/tests/playwright-test/ui-mode-test-source.spec.tsindex 8e7a35f5db..5d2973a8cf 100644--- a/tests/playwright-test/ui-mode-test-source.spec.ts+++ b/tests/playwright-test/ui-mode-test-source.spec.ts@@ -97,7 +97,7 @@ test('should show top-level errors in file', async ({ runUITest }) => {page.locator('.CodeMirror-linewidget')).toHaveText([' ',- 'Assignment to constant variable.'+ 'TypeError: Assignment to constant variable.']);});