test: migrate unit tests from Karma to Vitest#66
Conversation
Replace the Karma/Jasmine unit-test stack with Angular's first-party Vitest runner (@angular/build:unit-test). - Switch build/serve/extract-i18n to the @angular/build:* builders, which the unit-test builder requires for correct test-environment wiring. - Use the 'zone.js' polyfill package entry so the runner statically imports 'zone.js/testing' (avoids an unsupported top-level await in the test build). - Replace the legacy waitForAsync() beforeEach wrapper with async/await; zone.js does not patch Vitest, so there is no per-test ProxyZone. - Bump rxjs to 7.x: rxjs 6 lacks ESM exports and breaks Vitest resolution, and Angular 22 requires rxjs 7 anyway. - Point tsconfig.spec types at vitest/globals and widen typeRoots so they resolve outside @types. - Drop --browsers=ChromeHeadless from CI; the runner uses jsdom by default. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe project's test stack is migrated from Karma/Jasmine to Vitest. All Angular builders are updated from ChangesKarma → Vitest Migration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
package.json (1)
38-40: These deprecated tooling dependencies are still actively used and cannot be safely removed without broader refactoring.
protractoris actively configured inangular.json(builder) and referenced in e2e test files (e2e/src/app.po.ts,e2e/src/app.e2e-spec.ts).tslinthas a configuration file in place andcodelyzeris referenced within it. Removing them frompackage.jsonnow would break the e2e test setup and linting. Consider removing these as part of a larger migration effort (e.g., migrating e2e tests away from protractor and switching to ESLint), but not in isolation.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@package.json` around lines 38 - 40, The deprecated packages protractor, ts-node, and tslint are still actively used in the project and should not be removed from package.json in isolation. Keep these dependencies in place as they are actively referenced in angular.json builder configuration and e2e test files (e2e/src/app.po.ts and e2e/src/app.e2e-spec.ts), and tslint is still configured for linting. Plan to remove these packages only as part of a larger migration effort that includes migrating e2e tests away from protractor, updating the angular.json builder configuration, and switching from tslint to ESLint for linting.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@package.json`:
- Around line 38-40: The deprecated packages protractor, ts-node, and tslint are
still actively used in the project and should not be removed from package.json
in isolation. Keep these dependencies in place as they are actively referenced
in angular.json builder configuration and e2e test files (e2e/src/app.po.ts and
e2e/src/app.e2e-spec.ts), and tslint is still configured for linting. Plan to
remove these packages only as part of a larger migration effort that includes
migrating e2e tests away from protractor, updating the angular.json builder
configuration, and switching from tslint to ESLint for linting.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3a5be516-2e9e-4511-867e-3a456d0b927e
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (10)
.github/workflows/tests.ymlangular.jsonkarma.conf.jspackage.jsonsrc/app/app.component.spec.tssrc/app/app.service.spec.tssrc/polyfills.tssrc/test.tstsconfig.app.jsontsconfig.spec.json
💤 Files with no reviewable changes (3)
- src/polyfills.ts
- src/test.ts
- karma.conf.js
What
Migrates the unit test setup from Karma + Jasmine to Angular's first-party experimental Vitest runner (
@angular/build:unit-test), running in jsdom.Why
Karma is deprecated and is no longer the default test runner in modern Angular. Vitest is faster, has no browser/ChromeHeadless dependency in CI, and is the path Angular is steering projects toward.
Changes
testtarget now uses@angular/build:unit-testwithrunner: vitest. Build/serve/extract-i18n switched to the@angular/build:*builders, which the unit-test builder needs for correct test-environment wiring.polyfillsnow lists thezone.jspackage entry so the runner statically importszone.js/testinginstead of emitting a top-levelawait import()that the test build rejects.src/polyfills.tsandsrc/test.tsare removed (the builder provides the TestBed init).waitForAsync(() => …)wrapper inbeforeEachis replaced with plainasync/awaitoncompileComponents(). zone.js does not patch Vitest, so there is no per-test ProxyZone; this is also the modern recommended pattern. NofakeAsync/tickis used anywhere.exportsand breaks Vitest's resolver (rxjs/operatorsdirectory import). Angular 22 requires rxjs 7 regardless, so this also fixes a latent mismatch.typesset tovitest/globals;typeRootswidened so they resolve outside@types(the base config restrictstypeRootstonode_modules/@types).vitestandjsdom.npx ng test --watch=false(dropped--browsers=ChromeHeadless; the runner uses jsdom).Verification
npx ng test --watch=false→ 2 files, 4 tests passing.npx ng build --configuration productionsucceeds.🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Dependencies
Chores