fix(test-runner): do not override error with unhandled error (#7507)

This commit is contained in:
Max Schmitt 2021-07-08 18:24:07 +02:00 committed by GitHub
parent 1cc2a2dc59
commit ae489b1c43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View file

@ -72,6 +72,8 @@ export class WorkerRunner extends EventEmitter {
if (this._isStopped)
return;
if (this._currentTest) {
if (this._currentTest.testInfo.error)
return;
this._currentTest.testInfo.status = 'failed';
this._currentTest.testInfo.error = serializeError(error);
this._failedTestId = this._currentTest.testId;

View file

@ -110,3 +110,32 @@ test('sigint should stop workers', async ({ runInlineTest }) => {
expect(result.output).not.toContain('%%skipped1');
expect(result.output).not.toContain('%%skipped2');
});
test('should use the first occurring error when an unhandled exception was thrown', async ({ runInlineTest }) => {
const result = await runInlineTest({
'unhandled-exception.spec.js': `
const test = pwt.test.extend({
context: async ({}, test) => {
await test(123)
let errorWasThrownPromiseResolve = () => {}
const errorWasThrownPromise = new Promise(resolve => errorWasThrownPromiseResolve = resolve);
setTimeout(() => {
errorWasThrownPromiseResolve();
throw new Error('second error');
}, 0)
await errorWasThrownPromise;
},
page: async ({ context}, test) => {
throw new Error('first error');
await test(123)
},
});
test('my-test', async ({ page }) => { });
`
});
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');
});