Repository navigation
test: keep running deferred cleanup and afterEach hooks when one throws or hangs - #54995
Merged
Conversation
vitest runs a test's afterEach hooks one at a time and stops at the first one that throws, skipping the rest of that suite's hooks and every enclosing suite's. The spec runner adds defer()-ed cleanup as the first afterEach hook of every suite, so a single failing cleanup also skipped hooks such as protocol.unhandle() and closeWindow(). The handler and the window then leaked, and on CI the next try failed in beforeEach with "Failed to register protocol: no-cors". The runner now catches what each afterEach hook throws, defer()-ed cleanup included, lets the remaining hooks run, and rethrows the errors from an onTestFinished callback once all of them have finished. The test still fails, and vitest reports each error separately. The order of hooks and cleanups is unchanged. A new spec covers failing hooks and cleanups in nested suites. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-authored-by: Charles Kerr <[email protected]>
defer()-ed cleanup has had no timeout since the move to vitest (#54264). The mocha shim registered it with vitest's hook timeout set to 0, which vitest treats as no timeout, and the runner from #54439 puts it into each suite's afterEach hooks directly, not through afterEach(). So a cleanup that never settles, such as a closeWindow() whose window never emits 'closed', hangs the spec file until the CI job times out instead of failing one test. Each defer()-ed cleanup now gets the hook timeout, as an afterEach hook would. A cleanup that times out fails the test with an error whose stack points at its defer() call, and the cleanups registered before it and the remaining afterEach hooks still run. The timeout is read when the cleanup runs, so vi.setConfig() applies; the new spec uses that to keep its slow-cleanup case fast. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-authored-by: Charles Kerr <[email protected]>
4 tasks done
MarshallOfSound
approved these changes
Oct 15, 2026
MarshallOfSound
enabled auto-merge (squash)
October 15, 2026 07:05
MarshallOfSound
deleted the
trop/43-x-y-bp-test-keep-running-deferred-cleanup-and-aftereach-hooks-when-one-throws-or-hangs-1792044962940
branch
October 15, 2026 14:47
|
No Release Notes |
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.
Backport of #54950
See that PR for details.
Notes: none