发布

  • fix(vite): improve vitest 4 migration to better handle vitest workspace config (#35940)

    frostbyte_neo 发布于 2026-06-10 23:13:52 +00:00

    Current Behavior

    The migrate-to-vitest-4 migration defers vitest.workspace.* handling
    entirely to the AI step, which inlines the project globs verbatim into a
    root vitest.config.* under test.projects. After the upgrade,
    packages that run tests through a package.json vitest script 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
    the test.projects globs 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 root vitest.config.* under test.projects and 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 minimal vitest.config.* generated, so their tests keep
      running from the package directory and @nx/vitest infers 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, the vite.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.


    View session information


    Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>

    下载附件