chore: migrate unit tests from Karma/Jasmine to Vitest - #5
Conversation
|
Thank you! The current goal for a v1 release of this library is no changes beyond what's necessary to publish to npm. But feel free to keep this up for v2! |
|
v1 is released. Can you bring your branch up to date with I'd like to get this in before moving onto the angular 22 PR. |
Angular 21 made Vitest the stable, primary test runner. Switches the existing @angular/build:unit-test builder to the vitest runner, drops Karma/Jasmine tooling, and updates the demo app's spec file via the official refactor-jasmine-vitest codemod (with manual fixes for await-ordering bugs it introduced in a few async tests).
2e200ec to
de813a3
Compare
|
Done! Rebased onto |
There was a problem hiding this comment.
Pull request overview
Migrates the repo’s unit-test tooling from Karma/Jasmine to Vitest (now the primary Angular 21 test runner), updating configuration, dependencies, and the existing spec file accordingly.
Changes:
- Switched Angular test runner configuration to Vitest and set new-project defaults to generate Vitest tests.
- Updated the existing Jasmine-style specs to Vitest-friendly async patterns and timer APIs.
- Replaced Karma/Jasmine dependencies and CI test flags with Vitest + jsdom equivalents; updated TS spec types.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.spec.json | Swaps Jasmine global types for Vitest globals in spec compilation. |
| src/app/toasts.spec.ts | Converts specs from done callbacks / jasmine.clock() to async/await and vi timers. |
| package.json | Removes Karma/Jasmine deps, adds Vitest tooling, and drops Karma-specific CI browser flag. |
| karma.conf.js | Removes obsolete Karma configuration. |
| angular.json | Sets Vitest as the test runner and configures coverage reporters under the unit-test builder. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Description
Angular 21 made Vitest the stable, primary test runner, superseding Karma. This PR migrates the
project's unit tests off Karma/Jasmine and onto Vitest:
@angular/build:unit-testbuilder fromrunner: "karma"torunner: "vitest"inangular.json, mapping the oldkarma.conf.jscoverage reporters(
html,text-summary,lcovonly) onto the builder's nativecoverageReportersoption, anddeletes
karma.conf.js.@schematics/angular:application/:librarydefaults totestRunner: "vitest"sofuture generated code follows suit.
vitest,@vitest/coverage-v8,jsdomas devDependencies; removeskarma,karma-chrome-launcher,karma-coverage,karma-jasmine,karma-jasmine-html-reporter,karma-coverage-istanbul-reporter,jasmine-core, and@types/jasmine.tsconfig.spec.json'stypes: ["jasmine"]for["vitest/globals"].--browsers=ChromeHeadlessCustomflag from thetest:ciscript —Vitest runs headlessly against jsdom by default, no browser launcher needed.
ng g @schematics/angular:refactor-jasmine-vitestcodemod againstsrc/app/toasts.spec.ts, then manually fixes ordering bugs it introduced: in theonTap,onAction, andShould close last toasttests, the codemod movedawaitbefore thesynchronous call that triggers the awaited event (
tapToast(),action(),clearLastToast()), which would have made those tests hang/timeout. Restored the correctsubscribe → trigger → await ordering and reformatted to match the repo's Prettier config.
Related issues
Fixes #4
Type of change
Breaking changes
None. This only affects internal dev tooling (test runner); no changes to the published
@openng/ngx-toastrpackage's public API or runtime behavior.Test plan
npm run buildnpm testnpm run lintAll 15 existing specs in
src/app/toasts.spec.tspass under Vitest (previously passing underKarma/Jasmine), including coverage reporting via
@vitest/coverage-v8.npm run test:ciandnpx prettier --checkwere also run and pass.Checklist
Additional context
No
vitest.config.tswas added — coverage, reporters, include/exclude globs, etc. are allexpressed directly via the
@angular/build:unit-testbuilder options inangular.json, which isnow the single source of truth for both build and test configuration. The
ngx-toastrlibraryproject itself has no test target (specs run against the demo app), so no changes were needed
there.