Repository navigation
✅ Add a Jasmine to Vitest codemod and a migration guard - #5144
Draft
thomas-lebeau wants to merge 1 commit into
Draft
thomas-lebeau wants to merge 1 commit into
thomas-lebeau wants to merge 1 commit into
Conversation
thomas-lebeau
added this pull request to stack #5137
October 15, 2026 07:13
Bundles Sizes Evolution
|
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 55599fd | Docs | View more details | Give us feedback! |
thomas-lebeau
force-pushed
the
thomas.lebeau/vitest-codemod
branch
from
October 15, 2026 14:37
e6f4f3c to
6c51bca
Compare
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
force-pushed
the
thomas.lebeau/vitest-codemod
branch
from
October 15, 2026 15:55
6c51bca to
55599fd
Compare
This branch has not been deployed
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.
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)describe,it,expect, hooks,vi,Mock/Mockedtypes),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,expectAsyncresolves/rejects,donecallbacks → Promise,pending()→ctx.skip(),fail()→expect.unreachable(),fit/fdescribe/xit/xdescribe,jasmine.Spy/SpyObj/Functypes.jasmine.createSpyObj,spy.calls.all(),jasmine.clock(), custom asymmetric matchers) is left untouched and reported withfile:line.mainand re-run it.scripts/test/lib/jasmineToVitest.spec.ts(40 cases, run byyarn test:script).Migration guard —
VITEST_API_SPEC_FILESineslint.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
vitestdeclared as a devDependency of every workspace with specs (needed byimport-x/no-extraneous-dependenciesonce specs import it).mockContextManagertest helper.No spec is converted in this PR. Trial run: on
browser-rum-slim,browser-worker,browser-plugin-wasmandjs-core(16 specs), 15 pass right after the codemod; the last one uses the reportedjasmine.createSpyObj. Onbrowser-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.Test instructions
Checklist