fix(playwright): reset cleanup state at start of _afterSuite to prevent worker crashes#5552
Merged
DavertMik merged 1 commit intocodeceptjs:4.xfrom May 8, 2026
Conversation
…nt worker crashes When a test fails and its screenshot also fails (timeout, closed page, etc.), `saveScreenshot()` sets `hasCleanupError = true` and pushes to `testFailures[]`. These flags are reset per-test in `_beforeTest()` (line 567-568), but NOT at the start of `_afterSuite()`. So when the last test in a suite has a screenshot failure, the stale error state carries over into `_afterSuite`. At the end of `_afterSuite` (line 841-844), the method checks `if (this.hasCleanupError && this.testFailures.length > 0)` and throws — even if the suite's own cleanup completed successfully. This throw is fatal in a `run-workers` context: it kills the worker thread and silently drops all remaining test files assigned to that worker. Observed impact: in a 4-worker parallel run (133 scenarios), Worker 01 crashed at minute 1 due to this bug. Its remaining ~21 tests were never executed and never reported — a silent 16% test loss with no indication in the CI summary. The fix resets `hasCleanupError` and `testFailures` at the top of `_afterSuite` so the guard clause only evaluates errors from the suite teardown itself, not leftover test-level errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
DavertMik
approved these changes
May 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When running tests with
run-workers, workers can crash silently due to stale cleanup state leaking from test-level hooks into_afterSuite().Root cause
screenshotplugin callssaveScreenshot()saveScreenshot()setsthis.hasCleanupError = trueand pushes tothis.testFailures[](Playwright.js L2991-2992)hasCleanupError/testFailuresare reset per-test in_beforeTest()(L567-568), but not at the start of_afterSuite()_afterSuite()_afterSuite(), the guard clauseif (this.hasCleanupError && this.testFailures.length > 0)evaluates totrueand throws (L841-844) — even if the suite's own cleanup completed successfullyrun-workerscontext, this throw kills the worker thread. All remaining test files assigned to that worker are silently dropped — they never execute and never appear in the resultsFix
Reset
hasCleanupErrorandtestFailuresat the top of_afterSuite(), before any suite-level cleanup runs. This ensures the guard clause at L841 only evaluates errors from_afterSuite's own cleanup operations, not leftover test-level errors.async _afterSuite() { + // Reset leftover test-level cleanup state (e.g. screenshot failures) + // so only errors from this suite teardown are evaluated below. + this.hasCleanupError = false + this.testFailures = [] + // Stop browser after suite completes