From f9b87268a738e1e2f4cd0f18290c98b9d9c585e8 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 23 Aug 2021 09:21:40 -0700 Subject: [PATCH] fix(test runner): afterAll error should not mask beforeAll error (#8358) --- src/test/workerRunner.ts | 5 +++-- tests/playwright-test/hooks.spec.ts | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/test/workerRunner.ts b/src/test/workerRunner.ts index cb10388e6a..ad3edbba59 100644 --- a/src/test/workerRunner.ts +++ b/src/test/workerRunner.ts @@ -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(); } diff --git a/tests/playwright-test/hooks.spec.ts b/tests/playwright-test/hooks.spec.ts index e9a17c20b7..e47121fcc1 100644 --- a/tests/playwright-test/hooks.spec.ts +++ b/tests/playwright-test/hooks.spec.ts @@ -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'); +});