Skip to content

chore: cxspa-13736 - migrate 14 remaining libs from karma to vitest - #21847

Open
SouhaibKhadraoui wants to merge 26 commits into
developfrom
chore/CXSPA-13736
Open

chore: cxspa-13736 - migrate 14 remaining libs from karma to vitest#21847
SouhaibKhadraoui wants to merge 26 commits into
developfrom
chore/CXSPA-13736

Conversation

@SouhaibKhadraoui

Copy link
Copy Markdown
Contributor

Vitest Migration Report — CXSPA-13736

Branch: chore/CXSPA-13736 vs develop

Scope

15 libraries migrated from Karma/Jasmine to Vitest across 638 spec files and 85 config/infrastructure files.

Library Spec files migrated
core-libs/core 239
feature-libs/organization 131
feature-libs/product-configurator 91
feature-libs/user 48
feature-libs/quote 25
feature-libs/pickup-in-store 24
feature-libs/storefinder 20
feature-libs/subscription-billing 18
feature-libs/product 16
feature-libs/requested-delivery-date 6
feature-libs/pdf-invoices 5
feature-libs/smartedit 5
feature-libs/tracking 4
feature-libs/product-multi-dimensional 4
feature-libs/qualtrics 2
Total 638

Infrastructure Changes

Files added (per library)

  • vitest.config.ts — 15 new configs (one per library)

Files deleted (per library)

  • karma.conf.js — 15 removed
  • test.ts (Karma entry point) — 14 removed (all feature-libs; core-libs/core did not have one)

Config pattern (vitest.config.ts)

All configs follow a consistent shape:

export default defineConfig({
  root: import.meta.dirname,
  plugins: [angular(), nxViteTsPaths()],
  resolve: { alias: { /* path aliases for non-resolvable monorepo imports */ } },
  test: {
    pool: 'forks',
    watch: false,
    globals: true,
    environment: 'jsdom',
    setupFiles: ['../../testing/setup-vitest.ts'],
    include: ['**/*.spec.ts'],
    coverage: { provider: 'v8', reporter: ['lcov'], thresholds: { statements: 90, lines: 90, branches: 80, functions: 90 } },
    reporters: ['default', ['junit', { outputFile: '../../unit-tests-reports/unit-test-<lib>.xml' }]],
  },
})

core-libs/core uses the base config (no resolve.alias block needed). Feature-libs that reference non-barrel monorepo paths add explicit resolve.alias entries to work around Vite's module resolution.

project.json changes (per library)

The test target (Karma executor) was renamed to test-vitest and switched to nx:run-commands:

- "test": {
-   "executor": "@angular-devkit/build-angular:karma",
-   "options": { "main": "...", "tsConfig": "...", "karmaConfig": "..." }
- }
+ "test-vitest": {
+   "executor": "nx:run-commands",
+   "options": { "command": "npx vitest run --config vitest.config.ts", "cwd": "{projectRoot}" }
+ }

ci-scripts/unit-tests.sh

Two new shell functions added:

run_vitest_migrated_tests   # npx nx run-many --all --target=test-vitest
run_vitest_affected_tests   # npx nx affected --target=test-vitest

Both run_all_unit_tests and run_affected_unit_tests now call the corresponding Vitest function after their Jasmine/Jest steps.


Spec File Fixes Applied

# Pattern (removed → added) Occurrences Description
1 jasmine.createSpy() / jasmine.createSpyObj()vi.fn() ~349 removed / ~857 vi.fn() lines added Jasmine spy factories replaced with Vitest mock functions
2 .and.returnValue() / .and.callFake() / .and.callThrough().mockReturnValue() / .mockImplementation() ~2 574 removed / ~1 836 added Jasmine spy chaining replaced with Vitest mock API
3 import createSpy = jasmine.createSpyimport { vi } from 'vitest' 189 import aliases removed / 564 vitest imports added Removed Jasmine namespace imports; added Vitest imports
4 spyOnProperty(obj, 'prop')vi.spyOn(obj, 'prop', 'get') ~123 removed / ~69 vi.spyOn(...'get') added spyOnProperty is Jasmine-only; replaced with Vitest accessor spy
5 .toBeTrue() / .toBeFalse().toBe(true) / .toBe(false) 76 removed / 102 added Jasmine-only matchers replaced with standard Jest/Vitest equivalents
6 jasmine.objectContaining({})expect.objectContaining({}) 59 removed / 59 added Jasmine asymmetric matcher replaced with Vitest/Jest equivalent
7 jasmine.any(Type)expect.any(Type) 31 removed / 34 added Jasmine asymmetric matcher replaced with Vitest/Jest equivalent
8 .nativeElement.innerText.nativeElement.textContent 75 removed / 77 added innerText is not implemented in jsdom; textContent (with optional .trim()) used instead
9 Missing vi.useFakeTimers() / vi.useRealTimers() brackets 44 useFakeTimers / 44 useRealTimers calls added Tests using vi.advanceTimersByTimeAsync require explicit fake timer setup/teardown
10 jasmine.SpyObj<T> type annotation → removed / retyped 53 occurrences removed Jasmine type annotations removed; replaced with plain types or ReturnType<typeof vi.spyOn> where needed

No residual jasmine.* references remain in any added lines — the migration is clean with respect to Jasmine API surface.


Vitest Config Notes

  • pool: 'forks' — uses child processes instead of threads, required for Angular's zone.js compatibility under jsdom.
  • globals: true — exposes describe, it, expect, beforeEach, afterEach etc. globally so spec files do not need explicit imports for those.
  • setupFiles: ['../../testing/setup-vitest.ts'] — shared setup file (pre-existing from earlier migrations) configures jsdom globals, zone.js, and Angular TestBed teardown.
  • resolve.alias — feature-libs with deep cross-lib imports (e.g. organization) map non-resolvable paths to their .ts source files directly. core-libs/core does not need this.

Summary

Metric Count
Libraries migrated 15
Spec files updated 638
karma.conf.js deleted 15
test.ts entry points deleted 14
vitest.config.ts added 15
project.json targets updated 15
Jasmine spy calls replaced ~2 900+
Vitest vi.* calls introduced ~2 700+

SouhaibKhadraoui and others added 6 commits August 4, 2026 13:33
…ng libs : organization, pdf-invoices, pickup-in-store, product, product-configurator, product-multi-dimensional, qualtrics, quote, requested-delivery-date, smartedit, storefinder, subscription-billing, tracking, user
…. gitignore updated to exclude workflow files
…iles - still some minor failures to tackle, but mostly done
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@SouhaibKhadraoui
SouhaibKhadraoui requested review from a team as code owners August 5, 2026 20:56
@github-actions
github-actions Bot marked this pull request as draft August 5, 2026 20:57
Comment thread feature-libs/cart/base/core/facade/active-cart.service.spec.ts Outdated
@SouhaibKhadraoui
SouhaibKhadraoui marked this pull request as ready for review August 24, 2026 15:30
@cypress

cypress Bot commented Aug 24, 2026

Copy link
Copy Markdown

spartacus    Run #54641

Run Properties:  status check passed Passed #54641  •  git commit 5b361a82af ℹ️: Merge 24ac1a3fe559ea61019170bb447d5385f5e11d70 into 21f8ac4e24716545c9ff0759590f...
Project spartacus
Branch Review chore/CXSPA-13736
Run status status check passed Passed #54641
Run duration 05m 27s
Commit git commit 5b361a82af ℹ️: Merge 24ac1a3fe559ea61019170bb447d5385f5e11d70 into 21f8ac4e24716545c9ff0759590f...
Committer SouhaibKhadraoui
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 4
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 103
View all changes introduced in this branch ↗︎

@github-actions
github-actions Bot marked this pull request as draft August 24, 2026 15:55
@SouhaibKhadraoui
SouhaibKhadraoui marked this pull request as ready for review August 24, 2026 16:10
@github-actions
github-actions Bot marked this pull request as draft August 24, 2026 17:32
@SouhaibKhadraoui
SouhaibKhadraoui marked this pull request as ready for review August 24, 2026 17:54
@github-actions
github-actions Bot marked this pull request as draft August 24, 2026 18:43
@SouhaibKhadraoui
SouhaibKhadraoui marked this pull request as ready for review August 24, 2026 20:35
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.

3 participants