Skip to content

Commit 25b9c4e

Browse files
authored
chore: do not lose error name for js errors (#28177)
1 parent 4575c9a commit 25b9c4e

File tree

8 files changed

+13
-13
lines changed

8 files changed

+13
-13
lines changed

packages/playwright/src/util.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ const PLAYWRIGHT_CORE_PATH = path.dirname(require.resolve('playwright-core/packa
3232

3333
export function filterStackTrace(e: Error): { message: string, stack: string } {
3434
if (process.env.PWDEBUGIMPL)
35-
return { message: e.message, stack: e.stack || '' };
35+
return { message: e.name + ': ' + e.message, stack: e.stack || '' };
3636

3737
const stackLines = stringifyStackFrames(filteredStackTrace(e.stack?.split('\n') || []));
3838
return {
39-
message: e.message,
39+
message: e.name + ': ' + e.message,
4040
stack: `${e.name}: ${e.message}\n${stackLines.join('\n')}`
4141
};
4242
}

tests/playwright-test/fixture-errors.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ test('should throw when calling runTest twice', async ({ runInlineTest }) => {
349349
test('works', async ({foo}) => {});
350350
`,
351351
});
352-
expect(result.results[0].error.message).toBe('Cannot provide fixture value for the second time');
352+
expect(result.results[0].error.message).toBe('Error: Cannot provide fixture value for the second time');
353353
expect(result.exitCode).toBe(1);
354354
});
355355

tests/playwright-test/list-files.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ test('should report error', async ({ runListFiles }) => {
9494
line: 3,
9595
column: 8,
9696
},
97-
message: 'Assignment to constant variable.',
97+
message: 'TypeError: Assignment to constant variable.',
9898
stack: expect.stringContaining('TypeError: Assignment to constant variable.'),
9999
}
100100
});

tests/playwright-test/playwright.trace.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ test('should show non-expect error in trace', async ({ runInlineTest }, testInfo
668668
' fixture: page',
669669
' browserContext.newPage',
670670
'expect.toBe',
671-
'undefinedVariable1 is not defined',
671+
'ReferenceError: undefinedVariable1 is not defined',
672672
'After Hooks',
673673
' fixture: page',
674674
' fixture: context',

tests/playwright-test/reporter.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
454454
`begin {\"title\":\"page.setContent\",\"category\":\"pw:api\"}`,
455455
`end {\"title\":\"page.setContent\",\"category\":\"pw:api\"}`,
456456
`begin {\"title\":\"page.click(input)\",\"category\":\"pw:api\"}`,
457-
`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>\"}}`,
457+
`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>\"}}`,
458458
`begin {\"title\":\"After Hooks\",\"category\":\"hook\"}`,
459459
`begin {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,
460460
`end {\"title\":\"fixture: page\",\"category\":\"fixture\"}`,
@@ -567,7 +567,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
567567
}, { 'reporter': '' });
568568

569569
expect(result.exitCode).toBe(1);
570-
expect(result.output).toContain(`%%got error: No tests found`);
570+
expect(result.output).toContain(`%%got error: Error: No tests found`);
571571
});
572572

573573
test('should report require error to reporter', async ({ runInlineTest }) => {
@@ -584,7 +584,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
584584
}, { 'reporter': '' });
585585

586586
expect(result.exitCode).toBe(1);
587-
expect(result.output).toContain(`%%got error: Oh my!`);
587+
expect(result.output).toContain(`%%got error: Error: Oh my!`);
588588
});
589589

590590
test('should report global setup error to reporter', async ({ runInlineTest }) => {
@@ -608,7 +608,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
608608
}, { 'reporter': '' });
609609

610610
expect(result.exitCode).toBe(1);
611-
expect(result.output).toContain(`%%got error: Oh my!`);
611+
expect(result.output).toContain(`%%got error: Error: Oh my!`);
612612
});
613613

614614
test('should report correct tests/suites when using grep', async ({ runInlineTest }) => {

tests/playwright-test/runner.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ test('should use the first occurring error when an unhandled exception was throw
236236
expect(result.exitCode).toBe(1);
237237
expect(result.passed).toBe(0);
238238
expect(result.failed).toBe(1);
239-
expect(result.report.suites[0].specs[0].tests[0].results[0].error!.message).toBe('first error');
239+
expect(result.report.suites[0].specs[0].tests[0].results[0].error!.message).toBe('Error: first error');
240240
});
241241

242242
test('worker interrupt should report errors', async ({ interactWithTestRunner }) => {

tests/playwright-test/test-output-dir.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ test('should work and remove non-failures', async ({ runInlineTest }, testInfo)
5151
expect(result.results[0].status).toBe('failed');
5252
expect(result.results[0].retry).toBe(0);
5353
// Should only fail the last retry check.
54-
expect(result.results[0].error.message).toBe('Give me retries');
54+
expect(result.results[0].error.message).toBe('Error: Give me retries');
5555

5656
expect(result.results[1].status).toBe('failed');
5757
expect(result.results[1].retry).toBe(1);
5858
// Should only fail the last retry check.
59-
expect(result.results[1].error.message).toBe('Give me retries');
59+
expect(result.results[1].error.message).toBe('Error: Give me retries');
6060

6161
expect(result.results[2].status).toBe('passed');
6262
expect(result.results[2].retry).toBe(2);

tests/playwright-test/ui-mode-test-source.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ test('should show top-level errors in file', async ({ runUITest }) => {
9797
page.locator('.CodeMirror-linewidget')
9898
).toHaveText([
9999
'            ',
100-
'Assignment to constant variable.'
100+
'TypeError: Assignment to constant variable.'
101101
]);
102102
});
103103

0 commit comments

Comments
 (0)