Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Dmitry Gozmanf9b87268a738
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');
+});