chore: do not lose error name for js errors (#28177)
This commit is contained in:
		
							parent
							
								
									4575c9a182
								
							
						
					
					
						commit
						25b9c4eb4a
					
				|  | @ -32,11 +32,11 @@ const PLAYWRIGHT_CORE_PATH = path.dirname(require.resolve('playwright-core/packa | |||
| 
 | ||||
| export 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')}` | ||||
|   }; | ||||
| } | ||||
|  |  | |||
|  | @ -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); | ||||
| }); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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.'), | ||||
|     } | ||||
|   }); | ||||
|  |  | |||
|  | @ -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', | ||||
|  |  | |||
|  | @ -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 }) => { | ||||
|  |  | |||
|  | @ -236,7 +236,7 @@ test('should use the first occurring error when an unhandled exception was throw | |||
|   expect(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 }) => { | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -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.' | ||||
|   ]); | ||||
| }); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue