fix(test runner): afterAll error should not mask beforeAll error (#8358)

This commit is contained in:
Dmitry Gozman 2021-08-23 09:21:40 -07:00 committed by GitHub
parent d3a703478b
commit f9b87268a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 2 deletions

View File

@ -162,7 +162,8 @@ export class WorkerRunner extends EventEmitter {
// TODO: separate timeout for beforeAll modifiers?
const result = await raceAgainstDeadline(this._fixtureRunner.resolveParametersAndRunHookOrTest(beforeAllModifier.fn, this._workerInfo, undefined), this._deadline());
if (result.timedOut) {
this._fatalError = serializeError(new Error(`Timeout of ${this._project.config.timeout}ms exceeded while running ${beforeAllModifier.type} modifier`));
if (!this._fatalError)
this._fatalError = serializeError(new Error(`Timeout of ${this._project.config.timeout}ms exceeded while running ${beforeAllModifier.type} modifier`));
this.stop();
}
if (!!result.result)
@ -375,7 +376,7 @@ export class WorkerRunner extends EventEmitter {
if (testInfo.status !== 'passed' && testInfo.status !== 'skipped') {
if (test._type === 'test')
this._failedTestId = testId;
else
else if (!this._fatalError)
this._fatalError = testInfo.error;
this.stop();
}

View File

@ -401,3 +401,22 @@ test('afterEach failure should not prevent afterAll', async ({ runInlineTest })
'%%afterAll',
]);
});
test('afterAll error should not mask beforeAll', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test.beforeAll(() => {
throw new Error('from beforeAll');
});
test.afterAll(() => {
throw new Error('from afterAll');
})
test('test', () => {
});
`,
});
expect(result.exitCode).toBe(1);
expect(result.failed).toBe(1);
expect(result.output).toContain('from beforeAll');
});