Skip to content

chore: migrate unit tests from Karma/Jasmine to Vitest - #5

Open
JeevanMahesha wants to merge 1 commit into
openng-org:mainfrom
JeevanMahesha:chore/migrate-karma-to-vitest
Open

chore: migrate unit tests from Karma/Jasmine to Vitest#5
JeevanMahesha wants to merge 1 commit into
openng-org:mainfrom
JeevanMahesha:chore/migrate-karma-to-vitest

Conversation

@JeevanMahesha

Copy link
Copy Markdown

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:

  • Switches the existing @angular/build:unit-test builder from runner: "karma" to
    runner: "vitest" in angular.json, mapping the old karma.conf.js coverage reporters
    (html, text-summary, lcovonly) onto the builder's native coverageReporters option, and
    deletes karma.conf.js.
  • Updates the @schematics/angular:application/:library defaults to testRunner: "vitest" so
    future generated code follows suit.
  • Adds vitest, @vitest/coverage-v8, jsdom as devDependencies; removes karma,
    karma-chrome-launcher, karma-coverage, karma-jasmine, karma-jasmine-html-reporter,
    karma-coverage-istanbul-reporter, jasmine-core, and @types/jasmine.
  • Swaps tsconfig.spec.json's types: ["jasmine"] for ["vitest/globals"].
  • Drops the Karma-specific --browsers=ChromeHeadlessCustom flag from the test:ci script —
    Vitest runs headlessly against jsdom by default, no browser launcher needed.
  • Runs the official ng g @schematics/angular:refactor-jasmine-vitest codemod against
    src/app/toasts.spec.ts, then manually fixes ordering bugs it introduced: in the onTap,
    onAction, and Should close last toast tests, the codemod moved await before the
    synchronous call that triggers the awaited event (tapToast(), action(),
    clearLastToast()), which would have made those tests hang/timeout. Restored the correct
    subscribe → trigger → await ordering and reformatted to match the repo's Prettier config.

Related issues

Fixes #4

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes the public API)
  • Documentation only
  • Refactor, test, or chore (no user-facing change)

Breaking changes

None. This only affects internal dev tooling (test runner); no changes to the published
@openng/ngx-toastr package's public API or runtime behavior.

Test plan

  • npm run build
  • npm test
  • npm run lint
  • Verified in the demo app (if applicable)

All 15 existing specs in src/app/toasts.spec.ts pass under Vitest (previously passing under
Karma/Jasmine), including coverage reporting via @vitest/coverage-v8. npm run test:ci and
npx prettier --check were also run and pass.

Checklist

  • Issue discussed or bug clearly described (link issue when applicable)
  • Tests added or updated for behavioral changes
  • Documentation updated (README, JSDoc, migration notes as needed)
  • Public API changes documented; breaking changes called out
  • CHANGELOG updated (if the repository maintains one and the change is user-facing)
  • Commit messages follow Conventional Commits
  • I agree to follow the OpenNG Foundation Code of Conduct

Additional context

No vitest.config.ts was added — coverage, reporters, include/exclude globs, etc. are all
expressed directly via the @angular/build:unit-test builder options in angular.json, which is
now the single source of truth for both build and test configuration. The ngx-toastr library
project itself has no test target (specs run against the demo app), so no changes were needed
there.

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).
@JasonWeinzierl

Copy link
Copy Markdown
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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

migrate unit test runner from Karma/Jasmine to Vitest

2 participants