fix(test runner): do not swallow afterAll failure (#8099)

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

View File

@ -144,6 +144,12 @@ export class Dispatcher {
failedTestIds.add(test._id);
first = false;
}
if (first) {
// We had a fatal error after all tests have passed - most likely in the afterAll hook.
// Let's just fail the test run.
this._hasWorkerErrors = true;
this._reporter.onError?.(params.fatalError);
}
// Since we pretend that all remaining tests failed, there is nothing else to run,
// except for possible retries.
remaining = [];

View File

@ -242,3 +242,19 @@ test('beforeAll hook should get retry index of the first test', async ({ runInli
'%%test-retry-1',
]);
});
test('afterAll exception should fail the run', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.js': `
const { test } = pwt;
test.afterAll(() => {
throw new Error('From the afterAll');
});
test('passed', () => {
});
`,
});
expect(result.exitCode).toBe(1);
expect(result.passed).toBe(1);
expect(result.output).toContain('From the afterAll');
});