add skipAfterAnyFailure option (default: true) (#1)

This commit is contained in:
Alex Schwartz 2025-02-21 18:35:29 -05:00 committed by GitHub
parent 6486ac006e
commit a417629b2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View file

@ -88,6 +88,7 @@ export class FullConfigInternal {
userConfig.metadata = userConfig.metadata || {}; userConfig.metadata = userConfig.metadata || {};
this.config = { this.config = {
skipAfterAnyFailure: userConfig.skipAfterAnyFailure ?? true,
configFile: resolvedConfigFile, configFile: resolvedConfigFile,
rootDir: pathResolve(configDir, userConfig.testDir) || configDir, rootDir: pathResolve(configDir, userConfig.testDir) || configDir,
forbidOnly: takeFirst(configCLIOverrides.forbidOnly, userConfig.forbidOnly, false), forbidOnly: takeFirst(configCLIOverrides.forbidOnly, userConfig.forbidOnly, false),

View file

@ -393,6 +393,9 @@ export class WorkerMain extends ProcessRunner {
// After hooks get an additional timeout. // After hooks get an additional timeout.
const afterHooksTimeout = calculateMaxTimeout(this._project.project.timeout, testInfo.timeout); const afterHooksTimeout = calculateMaxTimeout(this._project.project.timeout, testInfo.timeout);
const afterHooksSlot = { timeout: afterHooksTimeout, elapsed: 0 }; 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 () => { await testInfo._runAsStage({ title: 'After Hooks', stepInfo: { category: 'hook' } }, async () => {
let firstAfterHooksError: Error | undefined; 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 // In case of failure the worker will be stopped and we have to make sure that afterAll
// hooks run before worker fixtures teardown. // hooks run before worker fixtures teardown.
for (const suite of reversedSuites) { for (const suite of reversedSuites) {
if (!nextSuites.has(suite) || testInfo._isFailure()) { if (!nextSuites.has(suite) || FAILURE_AND_SkIP_NOW) {
try { try {
await this._runAfterAllHooksForSuite(suite, testInfo); await this._runAfterAllHooksForSuite(suite, testInfo);
} catch (error) { } catch (error) {
@ -440,7 +443,7 @@ export class WorkerMain extends ProcessRunner {
checkForFloatingPromises('afterAll/afterEach hooks'); checkForFloatingPromises('afterAll/afterEach hooks');
if (testInfo._isFailure()) if (FAILURE_AND_SkIP_NOW)
this._isStopped = true; this._isStopped = true;
if (this._isStopped) { if (this._isStopped) {

View file

@ -792,6 +792,8 @@ type LiteralUnion<T extends U, U = string> = T | (U & { zz_IGNORE_ME?: never });
* *
*/ */
interface TestConfig<TestArgs = {}, WorkerArgs = {}> { interface TestConfig<TestArgs = {}, WorkerArgs = {}> {
skipAfterAnyFailure: boolean;
/** /**
* Playwright Test supports running multiple test projects at the same time. See * Playwright Test supports running multiple test projects at the same time. See
* [TestProject](https://playwright.dev/docs/api/class-testproject) for more information. * [TestProject](https://playwright.dev/docs/api/class-testproject) for more information.