Skip to content

feat(testing): offer vitest consistently across generators with a unitTestRunner option - #36715

Open
jaysoo wants to merge 12 commits into
masterfrom
NXC-4780
Open

feat(testing): offer vitest consistently across generators with a unitTestRunner option#36715
jaysoo wants to merge 12 commits into
masterfrom
NXC-4780

Conversation

@jaysoo

@jaysoo jaysoo commented Aug 19, 2026

Copy link
Copy Markdown
Member

Current Behavior

@nx/next:application only allows jest/none while @nx/next:library allows vitest. @nx/react host/remote/federate-module schema enums block vitest even though the underlying application generator supports it. create-nx-workspace hides the vitest choice for Next.js presets and the node stack.

Expected Behavior

vitest is selectable everywhere the underlying generator supports it: @nx/next:application (standalone vitest.config.mts, specs/ include, spec types in tsconfig.json), @nx/react host/remote/federate-module, and the CNW prompts for Next.js and node stacks. react-native/expo (jest-only upstream), angular MF (vitest-angular needs esbuild), and nuxt/vue (vitest-only) are intentionally unchanged.

Related Issue(s)

NXC-4780


View Polygraph session ↗

…tTestRunner option

## Current Behavior
- @nx/next:application only allows jest/none while @nx/next:library allows vitest
- @nx/react host/remote/federate-module schema enums block vitest even though the underlying application generator supports it
- create-nx-workspace hides the vitest choice for Next.js presets and the node stack, though node/express/nest generators accept it

## Expected Behavior
- @nx/next:application accepts --unitTestRunner=vitest (standalone vitest.config.mts, specs/ include, spec types in tsconfig.json)
- @nx/react host/remote/federate-module accept vitest and pass it through
- create-nx-workspace prompts include vitest for Next.js and node stacks; react-native/expo still exclude it (jest-only upstream)
- @nx/vite createOrEditViteConfig accepts testInclude for projects whose specs live outside src/

## Related Issue(s)
Fixes NXC-4780
@jaysoo jaysoo added the polygraph label Aug 19, 2026 — with Polygraph App
@netlify

netlify Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 5362548
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/6a88db733abc7f0008cb3456
😎 Deploy Preview https://deploy-preview-36715--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify

netlify Bot commented Aug 19, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 5362548
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/6a88db73b577db0008cd31e7
😎 Deploy Preview https://deploy-preview-36715--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud

nx-cloud Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 5362548

Command Status Duration Result
nx affected --targets=lint,oxlint,test,build,e2... ✅ Succeeded 34m 52s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 4s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 1m View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 19s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-21 23:52:34 UTC

jaysoo added 5 commits August 19, 2026 13:55
…t vitest apps

## Current Behavior
Generated vitest.config.mts imports @nx/vite/plugins/* but @nx/vite never lands in the user's package.json (skipViteConfig bypasses the generator that adds it), so nx test fails at config load in non-ts-solution workspaces. Specs colocated under src/ are silently skipped.

## Expected Behavior
@nx/vite added as devDependency when the config references it. Vitest include covers {src,specs}.

## Related Issue(s)
NXC-4780
…or next apps

## Current Behavior
Next vitest wiring goes through @nx/vite createOrEditViteConfig, and the generated config pulls in the deprecated nxViteTsPaths/nxCopyAssetsPlugin helpers (plus an @nx/vite dep).

## Expected Behavior
@nx/vitest exports its own createOrEditViteConfig (testInclude added there, @nx/vite untouched). Next configs skip the deprecated helper plugins via skipNxPlugins, so no @nx/vite dep is generated or needed.

## Related Issue(s)
NXC-4780
## Current Behavior
No e2e exercises the next generators with vitest.

## Expected Behavior
e2e-next covers app generation with vitest (generated specs/ test plus a colocated src/ spec) and lib generation with vitest.

## Related Issue(s)
NXC-4780
…ocated spec in e2e

## Current Behavior
Vitest include misses colocated specs in root app/ or pages/ when --no-src is used. The e2e colocated-spec assertion passes even if colocation regresses.

## Expected Behavior
Include covers {src,app,pages,specs}. e2e asserts both spec files actually ran.

## Related Issue(s)
NXC-4780
## Current Behavior
Comment restates why an ignored dependency is listed.

## Expected Behavior
List entry only, like its siblings.

## Related Issue(s)
NXC-4780
@jaysoo
jaysoo marked this pull request as ready for review August 19, 2026 22:21
@jaysoo
jaysoo requested a review from a team as a code owner August 19, 2026 22:21
@jaysoo
jaysoo requested a review from AgentEnder August 19, 2026 22:21
jaysoo added 3 commits August 20, 2026 09:25
## Current Behavior
A spec importing via the @/* alias fails to resolve under vitest: the alias lives in the app tsconfig.json, tsconfig.spec.json extends tsconfig.base.json without it, and neither vite-tsconfig-paths nor vite 8's native resolve.tsconfigPaths applies on vitest's transform path.

## Expected Behavior
Generated config mirrors the app tsconfig paths as explicit resolve.alias entries (new resolveAlias option on @nx/vitest createOrEditViteConfig); tsconfig.spec.json gets the paths copied for typechecking. testInclude values escape single quotes. e2e app test imports via @/ to prove it. Assertion-narrating comments dropped.

## Related Issue(s)
NXC-4780
## Current Behavior
No coverage for @/* -> ./* (--no-src) alias derivation.

## Expected Behavior
Unit test pins the emitted alias and tsconfig.spec.json paths for --no-src apps. Runtime resolution with the trailing-slash root verified against a live workspace.

## Related Issue(s)
NXC-4780
…s support

## Current Behavior
Legacy workspaces cannot resolve root tsconfig aliases in next vitest specs. Generated specs/ sits outside tsconfig.spec.json include in ts-solution setups. testInclude backslashes and alias apostrophes can corrupt emitted configs; URL .pathname percent-encodes spaces. resolveAlias silently dropped for existing configs.

## Expected Behavior
Root tsconfig paths mirrored as offset aliases in non-ts-solution workspaces (wildcard and exact entries). tsconfig.spec.json include covers specs/. Literals fully escaped (backslash + quote); aliases emitted via join(import.meta.dirname, ...). Existing-config path warns when resolveAlias cannot be applied.

## Related Issue(s)
NXC-4780

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

We updated the create-nx-workspace unit test to align with the PR's intentional change: the node stack now offers vitest as a valid unit test runner, so asserting it is excluded was incorrect. Clearing excluded for the node stack entry removes it from the "should not offer excluded runner" assertion, fixing the test failure without reverting any feature work.

Warning

We could not verify this fix.

diff --git a/packages/create-nx-workspace/bin/create-nx-workspace.spec.ts b/packages/create-nx-workspace/bin/create-nx-workspace.spec.ts
index 0a9a3592..3fed541c 100644
--- a/packages/create-nx-workspace/bin/create-nx-workspace.spec.ts
+++ b/packages/create-nx-workspace/bin/create-nx-workspace.spec.ts
@@ -547,7 +547,7 @@ describe('determineUnitTestRunner', () => {
         workspaceType: 'integrated',
       },
       expected: 'jest',
-      excluded: 'vitest',
+      excluded: '',
     },
   };
 

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally vwfu-OzrC

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

jaysoo added 3 commits August 21, 2026 10:55
…ases

## Current Behavior
--js apps leave the generated spec outside typed projects (no allowJs). Root tsconfig paths with a non-root baseUrl map to the wrong directory. CR/LF in emitted literals breaks the config. resolveAlias leaks an unused join import into existing configs.

## Expected Behavior
allowJs set in tsconfig.spec.json for --js apps. Root path mappings resolve against baseUrl. Line terminators escaped. join import only emitted for new config files.

## Related Issue(s)
NXC-4780
…ock node vitest fixture

## Current Behavior
createOrEditViteConfig exported from @nx/vitest/generators without an API contract. New CNW prompt spec from master still expects node to exclude vitest.

## Expected Behavior
Helper moves to @nx/vitest/internal (first-party surface). Node stack fixture no longer expects an exclusion.

## Related Issue(s)
NXC-4780
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant