Skip to content

✅ Add a Jasmine to Vitest codemod and a migration guard - #5144

Draft
thomas-lebeau wants to merge 1 commit into
thomas.lebeau/remove-karmafrom
thomas.lebeau/vitest-codemod
Draft

thomas-lebeau wants to merge 1 commit into
thomas.lebeau/remove-karmafrom
thomas.lebeau/vitest-codemod

Conversation

@thomas-lebeau

@thomas-lebeau thomas-lebeau commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

With Karma gone (#5142), specs still use the Jasmine API through a compatibility shim. This PR adds the groundwork to migrate them to the native Vitest API in small, independent PRs (one per helper or directory) without blocking other contributors: unmigrated specs keep working through the shim, and a file using import { describe, it, expect, vi } from 'vitest' gets the real Vitest functions (imports shadow the shim globals). Stacked on #5142.

Changes

Codemod — node scripts/test/jasmine-to-vitest.ts <files or directories> (scripts/test/lib/jasmineToVitest.ts)

  • TypeScript-AST based, editing the source text in place (formatting and comments preserved), then Prettier.
  • Converts: imports (describe, it, expect, hooks, vi, Mock/Mocked types), jasmine.createSpy → vi.fn, spyOn/spyOnProperty → vi.spyOn (bare spies are stubbed like Jasmine does: .mockReturnValue(undefined as never); .and.callThrough() dropped), .and.* strategies, .calls.* (count, argsFor, allArgs, reset, mostRecent().args, first().args, optional chaining kept), matchers (toHaveBeenCalledOnceWith → toHaveBeenCalledExactlyOnceWith, toBeTrue/False, toHaveSize → toHaveLength, withContext), asymmetric matchers, expectAsync resolves/rejects, done callbacks → Promise, pending() → ctx.skip(), fail() → expect.unreachable(), fit/fdescribe/xit/xdescribe, jasmine.Spy/SpyObj/Func types.
  • Anything it can't convert safely (e.g. jasmine.createSpyObj, spy.calls.all(), jasmine.clock(), custom asymmetric matchers) is left untouched and reported with file:line.
  • Deterministic: on a merge conflict, take the file from main and re-run it.
  • Unit tests: scripts/test/lib/jasmineToVitest.spec.ts (40 cases, run by yarn test:script).

Migration guard — VITEST_API_SPEC_FILES in eslint.config.ts: migrated paths are added there, which forbids Jasmine globals (jasmine, spyOn, fail, pending, …) and requires importing test functions from 'vitest'. Empty for now.

Other

  • vitest declared as a devDependency of every workspace with specs (needed by import-x/no-extraneous-dependencies once specs import it).
  • AGENTS.md: write new specs with the Vitest API.
  • Removed the unused mockContextManager test helper.

No spec is converted in this PR. Trial run: on browser-rum-slim, browser-worker, browser-plugin-wasm and js-core (16 specs), 15 pass right after the codemod; the last one uses the reported jasmine.createSpyObj. On browser-logs, failures come from helpers still returning Jasmine spies (replaceMockableWithSpy), to be migrated together with their consumers.

Next PRs: shared helpers (mockClock, then each spy-returning helper with its consumers), then codemod sweeps per directory.

⚠️ Written with an AI agent (Claude Code).

Test instructions

yarn
node --test scripts/test/lib/jasmineToVitest.spec.ts
# trial conversion (don't commit):
node scripts/test/jasmine-to-vitest.ts packages/js-core && yarn test:unit packages/js-core
git checkout -- packages

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

@thomas-lebeau
thomas-lebeau added this pull request to stack #5137 October 15, 2026 07:13
@thomas-lebeau thomas-lebeau changed the title ✅ add a Jasmine to Vitest codemod and a migration guard ✅ Add a Jasmine to Vitest codemod and a migration guard Oct 15, 2026
@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Bundles Sizes Evolution

📦 Bundle Name Base Size Local Size 𝚫 𝚫% Status
Rum Salesforce N/A 188.06 KiB N/A N/A N/A
Rum 188.04 KiB 188.04 KiB 0 B 0.00% ✅
Rum-salesforce Profiler N/A 8.35 KiB N/A N/A N/A
Rum Profiler 8.35 KiB 8.35 KiB 0 B 0.00% ✅
Rum-salesforce Recorder N/A 32.04 KiB N/A N/A N/A
Rum Recorder 32.04 KiB 32.04 KiB 0 B 0.00% ✅
Logs 59.44 KiB 59.44 KiB 0 B 0.00% ✅
Rum Slim 145.83 KiB 145.83 KiB 0 B 0.00% ✅
Worker 22.96 KiB 22.96 KiB 0 B 0.00% ✅
Rum Shopify N/A 218.48 KiB N/A N/A N/A
Rum-shopify Profiler N/A 8.35 KiB N/A N/A N/A
Rum-shopify Recorder N/A 4.85 KiB N/A N/A N/A

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Tests

✅ All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 78.23% (-0.03%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 55599fd | Docs | View more details | Give us feedback!

@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-codemod branch from e6f4f3c to 6c51bca Compare October 15, 2026 14:37
Groundwork to migrate specs from the Jasmine API to the Vitest API in small
PRs, without blocking other work (unmigrated specs keep running through the
Jasmine compatibility shim).

- scripts/test/jasmine-to-vitest.ts: deterministic codemod (TypeScript AST,
  in-place text edits, Prettier) converting spies, spy strategies, calls,
  matchers, asymmetric matchers, done callbacks, pending(), fail(), focus/
  skip and types; constructs it can't convert safely are reported. On a
  conflict, take the file from main and re-run it.
- eslint.config.ts: VITEST_API_SPEC_FILES, where Jasmine globals are
  forbidden and test functions must be imported from 'vitest'
- vitest declared as a devDependency of every workspace with specs
- AGENTS.md: write new specs with the Vitest API
- remove the unused mockContextManager helper
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-codemod branch from 6c51bca to 55599fd Compare October 15, 2026 15:55

This branch has not been deployed

No deployments
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.

1 participant