Skip to content

Commit 9bbe782

Browse files
committed
fix(@angular/build): prevent unit-test vitest runner from hanging after 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 #32832
1 parent 8358805 commit 9bbe782

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

  • packages/angular/build/src/builders/unit-test/runners/vitest

packages/angular/build/src/builders/unit-test/runners/vitest/executor.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,16 @@ export class VitestExecutor implements TestExecutor {
205205

206206
async [Symbol.asyncDispose](): Promise<void> {
207207
this.debugLog(DebugLogLevel.Info, 'Disposing VitestExecutor: Closing Vitest instance.');
208-
await this.vitest?.close();
208+
if (this.vitest && !this.options.watch) {
209+
// In run (non-watch) mode, mirror the `vitest run` CLI by using `exit()`, which arms an
210+
// unref'd `teardownTimeout` safety net (`process.exit()`) before closing. `close()` alone
211+
// can wait indefinitely when a worker or service keeps the event loop alive, leaving the
212+
// process hanging after all tests have completed.
213+
// See https://github.com/angular/angular-cli/issues/32832
214+
await this.vitest.exit();
215+
} else {
216+
await this.vitest?.close();
217+
}
209218
this.debugLog(DebugLogLevel.Info, 'Vitest instance closed.');
210219
}
211220

0 commit comments

Comments
 (0)