fix(@angular/build): prevent unit-test vitest runner from hanging after tests complete#33319
fix(@angular/build): prevent unit-test vitest runner from hanging after tests complete#33319hebus wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the VitestExecutor disposal logic to call vitest.exit() instead of vitest.close() in non-watch mode, preventing hanging processes. The review feedback recommends adding a defensive check to verify that vitest.exit is a function before calling it, and warns that calling exit() could prematurely terminate the host process when executed programmatically.
…er tests complete In non-watch mode, the vitest executor disposed the Vitest instance with `close()`, which can wait indefinitely when a worker or service keeps the event loop alive. The process then never exits even though all tests have completed and their results were reported. Use `exit()` instead when not in watch mode, mirroring the `vitest run` CLI behavior: `exit()` arms an unref'd `teardownTimeout` safety net that force-exits the process if teardown does not settle in time, while still performing a normal `close()` when teardown succeeds. Watch mode behavior is unchanged. Fixes angular#32832
9bbe782 to
9535a75
Compare
PR Checklist
PR Type
What is the current behavior?
In non-watch mode,
ng testwith the vitest runner hangs indefinitely after all testscomplete and results are printed. The executor disposes the Vitest instance with
close(), which has no teardown timeout. Whether the hang occurs depends on the sizeof the TypeScript program of the spec tsconfig (full analysis in the linked issue) —
freshly generated projects exit cleanly while larger real-world projects hang on every
run, leaving orphaned node/esbuild processes in CI.
Issue Number: #32832 (likely also #33317)
What is the new behavior?
When not in watch mode, the executor calls
vitest.exit()instead ofvitest.close(),mirroring what the
vitest runCLI does:exit()arms an unref'dteardownTimeoutsafety net (
process.exit()after 10s by default) before closing. When teardowncompletes normally nothing changes; when something keeps the event loop alive, vitest
reports it and force-exits:
Watch mode still uses
close()and is unaffected.Validated on a project that reproduces the hang on 100% of runs (315 tests, 19 spec files):
Does this PR introduce a breaking change?
Other information
No test added: asserting "the process exits" requires a real hanging handle, which the
builder test harness does not reproduce (small programs tear down cleanly — that is the
bug's timing dependency). Happy to add one if there is a suitable seam.