From c9021b0e39f6ad1e162c721dddee2960642932bc Mon Sep 17 00:00:00 2001 From: Paul Bohm <29411+enki@users.noreply.github.com> Date: Mon, 9 Jun 2025 05:50:04 -0400 Subject: [PATCH] =?UTF-8?q?fix(vite):=20NxReporter=20compatible=20with=20V?= =?UTF-8?q?itest=20=E2=89=A50.29=20(#31425)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Current Behavior Running `nx test … --reporter=verbose` (or any additional Vitest reporter) on projects that use **Vitest ≥ 0.29** hangs indefinitely at the end of the run. `vitest` itself finishes, but the Nx task-runner never receives the *done* signal because **`NxReporter` only implements the legacy `onFinished()` hook**. When multiple reporters are configured, Vitest now emits `onTestRunEnd()` instead of `onFinished()`, so the promise in `NxReporter` remains unresolved and the worker process stays alive forever. ## Expected Behavior `nx test` (and affected `nx run-many --target=test`) exits cleanly on **all** Vitest versions, regardless of how many reporters are passed. * `NxReporter` resolves its internal promise via **either** `onTestRunEnd` (Vitest ≥ 0.29) **or** `onFinished` (Vitest ≤ 0.28). * No functional change in watch-mode. * No extra timers or fallbacks – just one shared helper. ## Implementation Notes * Added `onTestRunEnd` method that delegates to a private `_handleFinished`. * Re-implemented `onFinished` as a thin delegate to the same helper. * Original error-detection logic is untouched. ## Related Issue(s) Closes nrwl/nx# Co-authored-by: Paul Bohm <{{GITHUB_NOREPLY_EMAIL}}> --- packages/vite/src/executors/test/lib/nx-reporter.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/vite/src/executors/test/lib/nx-reporter.ts b/packages/vite/src/executors/test/lib/nx-reporter.ts index e38631e106..e994f14b0d 100644 --- a/packages/vite/src/executors/test/lib/nx-reporter.ts +++ b/packages/vite/src/executors/test/lib/nx-reporter.ts @@ -28,7 +28,17 @@ export class NxReporter implements Reporter { }; } + /** Vitest ≥ 0.29 */ + onTestRunEnd(files: any[], errors?: any) { + this._handleFinished(files, errors); + } + /** Vitest ≤ 0.28 */ onFinished(files: File[], errors?: unknown[]) { + this._handleFinished(files, errors); + } + + // --- private ---------------------------------------------------------- + private _handleFinished(files: any[], errors?: any) { const hasErrors = files.some((f) => f.result?.state === 'fail') || errors?.length > 0; this.deferred.resolve(hasErrors);