From a417629b2cb9f55097db64fa6026b8b903c35c0f Mon Sep 17 00:00:00 2001 From: Alex Schwartz Date: Fri, 21 Feb 2025 18:35:29 -0500 Subject: [PATCH] add `skipAfterAnyFailure` option (default: true) (#1) --- packages/playwright/src/common/config.ts | 1 + packages/playwright/src/worker/workerMain.ts | 7 +++++-- packages/playwright/types/test.d.ts | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/playwright/src/common/config.ts b/packages/playwright/src/common/config.ts index 4578c3771a..07eddc1591 100644 --- a/packages/playwright/src/common/config.ts +++ b/packages/playwright/src/common/config.ts @@ -88,6 +88,7 @@ export class FullConfigInternal { userConfig.metadata = userConfig.metadata || {}; this.config = { + skipAfterAnyFailure: userConfig.skipAfterAnyFailure ?? true, configFile: resolvedConfigFile, rootDir: pathResolve(configDir, userConfig.testDir) || configDir, forbidOnly: takeFirst(configCLIOverrides.forbidOnly, userConfig.forbidOnly, false), diff --git a/packages/playwright/src/worker/workerMain.ts b/packages/playwright/src/worker/workerMain.ts index 8ff6d31fd0..7c89ac8526 100644 --- a/packages/playwright/src/worker/workerMain.ts +++ b/packages/playwright/src/worker/workerMain.ts @@ -393,6 +393,9 @@ export class WorkerMain extends ProcessRunner { // After hooks get an additional timeout. const afterHooksTimeout = calculateMaxTimeout(this._project.project.timeout, testInfo.timeout); const afterHooksSlot = { timeout: afterHooksTimeout, elapsed: 0 }; + + const FAILURE_AND_SkIP_NOW = testInfo._isFailure() && this._config.config.skipAfterAnyFailure; + await testInfo._runAsStage({ title: 'After Hooks', stepInfo: { category: 'hook' } }, async () => { let firstAfterHooksError: Error | undefined; @@ -425,7 +428,7 @@ export class WorkerMain extends ProcessRunner { // In case of failure the worker will be stopped and we have to make sure that afterAll // hooks run before worker fixtures teardown. for (const suite of reversedSuites) { - if (!nextSuites.has(suite) || testInfo._isFailure()) { + if (!nextSuites.has(suite) || FAILURE_AND_SkIP_NOW) { try { await this._runAfterAllHooksForSuite(suite, testInfo); } catch (error) { @@ -440,7 +443,7 @@ export class WorkerMain extends ProcessRunner { checkForFloatingPromises('afterAll/afterEach hooks'); - if (testInfo._isFailure()) + if (FAILURE_AND_SkIP_NOW) this._isStopped = true; if (this._isStopped) { diff --git a/packages/playwright/types/test.d.ts b/packages/playwright/types/test.d.ts index 4c2766232d..c527d0b680 100644 --- a/packages/playwright/types/test.d.ts +++ b/packages/playwright/types/test.d.ts @@ -792,6 +792,8 @@ type LiteralUnion = T | (U & { zz_IGNORE_ME?: never }); * */ interface TestConfig { + skipAfterAnyFailure: boolean; + /** * Playwright Test supports running multiple test projects at the same time. See * [TestProject](https://playwright.dev/docs/api/class-testproject) for more information.