-
fix(vite): improve vitest 4 migration to better handle vitest workspace config (#35940)
发布于
2026-06-10 23:13:52 +00:00 Current Behavior
The
migrate-to-vitest-4migration defersvitest.workspace.*handling
entirely to the AI step, which inlines the project globs verbatim into a
rootvitest.config.*undertest.projects. After the upgrade,
packages that run tests through a package.jsonvitestscript without a
local config fail with "No projects were found": Vitest 4 discovers the
new root config by walking up from the package directory and resolves
thetest.projectsglobs relative to that directory. Workspaces
migrated without the AI step get no workspace-file handling at all.
Reported while testing the Nx 23 betas; reproduction:
https://github.com/juristr/nx23-vitest-issue-repro.Expected Behavior
The migration handles workspace files deterministically and produces a
working setup on its own:- Static
vitest.workspace.*files (the Nx-generated shape) are inlined
into the rootvitest.config.*undertest.projectsand deleted. Only
dynamic shapes are forwarded to the AI step. - Packages that run vitest via a package.json script and have no local
config get a minimalvitest.config.*generated, so their tests keep
running from the package directory and@nx/vitestinfers their test
target. - When the inlined globs match both a
vite.config.*and a
vitest.config.*in the same directory resolving to the same project
name, thevite.config.*file is excluded with a negative glob. This
matches vitest's own vitest-over-vite preference and avoids the "Project
name ... is not unique" startup error that the copied globs previously
produced on root-level runs. Cases that can't be determined statically
are forwarded to the AI step as advisories.
Anything the migration cannot do safely (dynamic workspace files,
configs it can't merge into) is still deferred to the AI step with
accurate context, and the instructions teach the agent the same rules
for the files it inlines itself.
Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
下载附件
- Static