fix(vitest): handle zoneless Angular apps in vitest configuration generator#34700
fix(vitest): handle zoneless Angular apps in vitest configuration generator#34700leosvelperez merged 1 commit intomasterfrom
Conversation
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 1bbf497
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
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:
These changes update the test snapshots to align with the new Angular 21+ vitest configuration behavior introduced in the PR. The generator now defaults to Angular 21+ when no version is specified, using setup-snapshots and setupTestBed() instead of the legacy Angular 20 APIs. We've updated the snapshots to expect the new format and removed an extra blank line in the Angular 19 test to match actual generator output.
Warning
❌ We could not verify this fix.
Suggested Fix changes
diff --git a/packages/vite/src/generators/vitest/__snapshots__/vitest.spec.ts.snap b/packages/vite/src/generators/vitest/__snapshots__/vitest.spec.ts.snap
index 1124ae79ca..a1d15f014e 100644
--- a/packages/vite/src/generators/vitest/__snapshots__/vitest.spec.ts.snap
+++ b/packages/vite/src/generators/vitest/__snapshots__/vitest.spec.ts.snap
@@ -2,18 +2,10 @@
exports[`vitest generator angular should generate src/test-setup.ts 1`] = `
"import '@angular/compiler';
-import '@analogjs/vitest-angular/setup-zone';
+import '@analogjs/vitest-angular/setup-snapshots';
+import { setupTestBed } from '@analogjs/vitest-angular/setup-testbed';
-import {
- BrowserTestingModule,
- platformBrowserTesting,
-} from '@angular/platform-browser/testing';
-import { getTestBed } from '@angular/core/testing';
-
-getTestBed().initTestEnvironment(
- BrowserTestingModule,
- platformBrowserTesting(),
-);
+setupTestBed({ zoneless: false });
"
`;
diff --git a/packages/vite/src/generators/vitest/vitest.spec.ts b/packages/vite/src/generators/vitest/vitest.spec.ts
index 43e3b2ce75..2fa6cc58a6 100644
--- a/packages/vite/src/generators/vitest/vitest.spec.ts
+++ b/packages/vite/src/generators/vitest/vitest.spec.ts
@@ -235,7 +235,6 @@ describe('vitest generator', () => {
expect(tree.read('apps/my-test-angular-app/src/test-setup.ts', 'utf-8'))
.toMatchInlineSnapshot(`
"import '@analogjs/vitest-angular/setup-zone';
-
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
✅ The fix was applied locally; push changes to this branch.
View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
…erator Add `zoneless` option to vitest configuration schema with auto-detection from project config. Generate appropriate setup file based on Angular version and zoneless status: use `setup-snapshots` for zoneless apps instead of `setup-zone`, and use `setupTestBed()` for Angular 21+. Remove duplicated `createAnalogSetupFile` from `addVitestAnalog` and pass `zoneless` through to the vitest configuration generator instead.
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
When running
@nx/vitest:configurationon an Angular project, the generator always generatesimport '@analogjs/vitest-angular/setup-zone'regardless of whether the app is zoneless. Additionally, the setup file generation logic for Angular 21+ (which usessetupTestBed()) only exists inpackages/angular/src/generators/utils/add-vitest.ts(createAnalogSetupFile), making the vitest generator not self-contained.Expected Behavior
The vitest configuration generator should:
setup-snapshotsinstead ofsetup-zonefor zoneless projectssetupTestBed()setup directly, without requiring a separate function in the angular packagezonelessoption to override auto-detectionRelated Issue(s)
Fixes #33983