chore: migrate unit tests from Karma/Jasmine to Vitest - #5
Open
JeevanMahesha wants to merge 1 commit into
Open
Conversation
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).
Collaborator
|
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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.