Skip to content

test(test): Add a Jasmine to Vitest codemod and migration guard - #5144

Merged
thomas-lebeau merged 4 commits into
mainfrom
thomas.lebeau/vitest-codemod
Nov 25, 2026
Merged

thomas-lebeau merged 4 commits into
mainfrom
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.

Closes RUM-19779

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 and eslint --fix on the converted files (removes unnecessary as never assertions; type-aware, so a full run needs NODE_OPTIONS='--max-old-space-size=8192').
  • Converts: imports (describe, it, expect, hooks, vi, Mock/Mocked types), jasmine.createSpy → vi.fn (vi.fn(fn) with .and.callThrough()), jasmine.createSpyObj with method names → object of typed 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, toContain → toContainEqual on arrays and objects, toMatch with a regular expression string → new RegExp()), asymmetric matchers, expectAsync resolves/rejects, done callbacks (and DoneFn callbacks built by a factory) → Promise, pending() in tests and beforeEach → test context skip(), jasmine.clock() install/tick/uninstall → vi fake timers, a describe timeout set with jasmine.DEFAULT_TIMEOUT_INTERVAL in beforeAll/afterAll → describe(name, { timeout }, fn), fail() → expect.unreachable(), fit/fdescribe/xit/xdescribe, jasmine.Spy/SpyObj/Func types.
  • Anything it can't convert safely (e.g. toThrowMatching, arrayWithExactContents, spy.calls.all(), toBeRejected, custom asymmetric matchers, pending() in helpers) is left untouched and reported with file:line. On the whole repo: 22 constructs to convert by hand (see test(test): Migrate specs and helpers from Jasmine API to Vitest API #5300).
  • Deterministic: on a merge conflict, take the file from main and re-run it.
  • Unit tests: scripts/test/lib/jasmineToVitest.spec.ts (58 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

Refs: RUM-19779

@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 194.51 KiB 194.51 KiB 0 B 0.00% ✅
Rum 194.48 KiB 194.48 KiB 0 B 0.00% ✅
Rum Salesforce Profiler 8.10 KiB 8.10 KiB 0 B 0.00% ✅
Rum Profiler 8.10 KiB 8.10 KiB 0 B 0.00% ✅
Rum Salesforce Recorder 32.80 KiB 32.80 KiB 0 B 0.00% ✅
Rum Recorder 32.80 KiB 32.80 KiB 0 B 0.00% ✅
Logs 60.25 KiB 60.25 KiB 0 B 0.00% ✅
Rum Slim 149.87 KiB 149.87 KiB 0 B 0.00% ✅
Worker 24.23 KiB 24.23 KiB 0 B 0.00% ✅
Rum Shopify 226.03 KiB 226.03 KiB 0 B 0.00% ✅
Rum Shopify Profiler 8.10 KiB 8.10 KiB 0 B 0.00% ✅
Rum Shopify Recorder 4.85 KiB 4.85 KiB 0 B 0.00% ✅
Early Collection 309 B 309 B 0 B 0.00% ✅

@datadog-datadog-us1-prod

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

Copy link
Copy Markdown

Pipelines  Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 78.07% (+0.00%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7fd2849 | 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
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-codemod branch from 6c51bca to 55599fd Compare October 15, 2026 15:55
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-codemod branch 16 times, most recently from b8dee2c to 3158a41 Compare November 5, 2026 11:59
@thomas-lebeau thomas-lebeau changed the title ✅ Add a Jasmine to Vitest codemod and a migration guard ✅ [RUM-19779] Add a Jasmine to Vitest codemod and a migration guard Nov 5, 2026
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-codemod branch 5 times, most recently from 05271ab to 6b75c84 Compare November 12, 2026 06:03
Base automatically changed from thomas.lebeau/remove-karma to main November 19, 2026 11:11
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-codemod branch from ef306be to 311628f Compare November 19, 2026 11:11
@thomas-lebeau
thomas-lebeau marked this pull request as ready for review November 19, 2026 11:11
@thomas-lebeau
thomas-lebeau requested review from a team as code owners November 19, 2026 11:11
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T08:56:02.122939Z 7fd2849 New commits
🔒 Security Review ✅ Completed 2026-11-25T08:57:31.498401Z 7fd2849 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 311628f5f9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +133 to +135
case 'fail':
replaceNode(callee, 'expect.unreachable')
usedVitestValues.add('expect')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve recorded failures when converting fail()

issue: When fail() is inside a try block, replacing it with expect.unreachable() can silently turn a failing test green. The existing Jasmine shim records the failure before throwing and checks recorded failures at test completion; native expect.unreachable() only throws, so the surrounding catch can swallow it. This affects the existing rejection test in packages/browser-core/src/tools/readBytesFromStream.spec.ts: after conversion, an unexpectedly successful read reaches expect.unreachable(), whose error satisfies the catch block's expect.any(Error) assertion. Rewrite this pattern safely or report it for manual conversion instead of returning no unsupported constructs.

Useful? React with 👍 / 👎.

Comment on lines +357 to +358
case 'returnValues':
replacement = args.map((arg) => `.mockReturnValueOnce(${arg})`).join('')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the fallback behavior of returnValues spies

issue: For spyOn(object, 'method').and.returnValues(1, 2), this emits vi.spyOn(object, 'method').mockReturnValueOnce(1).mockReturnValueOnce(2) without a default stub, because transformSpyOn sees an explicit strategy. After the second call, Jasmine returns undefined, whereas the generated Vitest spy calls the real method. Likewise, applying returnValues to a spy previously configured with returnValue leaves that old default active in Vitest. Set an undefined fallback when converting this strategy so exhausting the supplied values does not change test behavior or invoke real browser operations.

Useful? React with 👍 / 👎.

const ASYNC_MATCHERS: Record<string, string> = {
toBeResolvedTo: 'resolves.toEqual',
toBeRejectedWith: 'rejects.toEqual',
toBeRejectedWithError: 'rejects.toThrow',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve exact error-message matching for async assertions

issue: When toBeRejectedWithError receives a string, Jasmine requires the complete error message to equal that string, but Vitest's rejects.toThrow(string) accepts a substring. Thus a rejection with new Error('not boom') starts passing an assertion originally written as toBeRejectedWithError('boom'). Existing assertions in packages/browser-core/src/tools/thenable.spec.ts use this string form, and the conversion reports it as fully supported. Preserve exact message matching for string arguments, or report these cases for manual conversion.

Useful? React with 👍 / 👎.

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The most critical production-affecting issue is the react/react-dom version mismatch in packages/browser-rum-nextjs/package.json, which causes an immediate "Incompatible React versions" exception at runtime. The jasmineToVitest.ts migration script has several correctness bugs — including duplicated context parameters from multiple pending() calls, broken optional-chain preservation, and import-alias stripping — that will silently produce invalid or semantically weakened converted specs.

Open Bits AI session

🤖 Bits Code Review · Commit 311628f

"next": "16.4.5",
"react": "19.3.1",
"react-dom": "19.3.1"
"react-dom": "19.3.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Keep React DOM aligned with React

This downgrades React DOM to 19.3.0 while React remains 19.3.1. Loading react-dom/client from this workspace reproduced an “Incompatible React versions” exception, preventing use of the renderer. Restore matching versions in both the manifest and yarn.lock.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment thread scripts/test/lib/jasmineToVitest.ts Outdated
Comment on lines +408 to +414
if (node.parameters.length !== 1 || !isTestCallback(node, CALLBACK_FUNCTIONS)) {
return
}
const parameter = node.parameters[0]
if (!ts.isIdentifier(parameter.name) || parameter.name.text !== 'done') {
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Report helper-returned done callbacks

Converting domMutationObservable.spec.ts leaves the helper-returned (done: DoneFn) callback unchanged while importing native Vitest it, with no unsupported warning. Native Vitest supplies a test context rather than a completion function, so asynchronous assertions can run after completion and done() fails. Convert these callbacks or report them for manual migration.

Suggested change
if (node.parameters.length !== 1 || !isTestCallback(node, CALLBACK_FUNCTIONS)) {
return
}
const parameter = node.parameters[0]
if (!ts.isIdentifier(parameter.name) || parameter.name.text !== 'done') {
return
}
if (node.parameters.length !== 1) {
return
}
const parameter = node.parameters[0]
if (!ts.isIdentifier(parameter.name) || parameter.name.text !== 'done') {
return
}
if (!isTestCallback(node, CALLBACK_FUNCTIONS)) {
report(node, 'done callback outside a direct test/hook call: convert it manually')
return
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +272 to +274
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
report(node, `no Vitest equivalent for ${name}()`)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Convert or report two-argument toThrowError assertions

The existing two-argument toThrowError assertion in expression.spec.ts remains unchanged without a warning. Vitest accepts only one matcher argument; a focused runtime check confirmed that an incorrect ReferenceError message passes because the second argument is ignored. Convert the overload or flag it for manual migration.

Suggested change
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
report(node, `no Vitest equivalent for ${name}()`)
}
if (name === 'toThrowError' && node.arguments.length > 1) {
report(node, 'two-argument toThrowError(): convert the error type and message checks manually')
return false
}
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
report(node, `no Vitest equivalent for ${name}()`)
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session


switch (name) {
case 'returnValues':
replacement = args.map((arg) => `.mockReturnValueOnce(${arg})`).join('')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Stub the fallback when converting returnValues

Converting spyOn(obj, 'method').and.returnValues(1) emits only mockReturnValueOnce(1). A focused execution returned 1 once, then invoked the real method; Jasmine instead returns undefined after exhausting its values. Reset the fallback to an undefined-returning stub and update the corresponding expected-output assertion.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

}
if (isExpectAsync(expectCall)) {
if (name in ASYNC_MATCHERS && (name !== 'toBeRejectedWithError' || node.arguments.length <= 1)) {
replaceNode(callee.name, ASYNC_MATCHERS[name])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve exact messages in async error assertions

Jasmine matches string error messages exactly, while the generated rejects.toThrow(string) uses substring matching. A focused comparison rejected Error('wrong boom suffix') under Jasmine but accepted it under the converted matcher expecting 'boom'. This silently weakens assertions such as those in thenable.spec.ts. Preserve exact-message semantics or report unsupported cases, and update the conversion expectation.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +560 to +817
)
if (existing?.importClause?.namedBindings && ts.isNamedImports(existing.importClause.namedBindings)) {
for (const element of existing.importClause.namedBindings.elements) {
values.add(element.isTypeOnly ? `type ${element.name.text}` : element.name.text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve aliases when merging Vitest imports

A focused conversion of a file containing import { expect as check } from 'vitest' and a global it produced import { check, it } from 'vitest'. Vitest does not export check, so the migrated spec cannot load. Preserve complete existing import specifiers when merging imports.

Suggested change
values.add(element.isTypeOnly ? `type ${element.name.text}` : element.name.text)
values.add(element.getText())

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment thread scripts/test/lib/jasmineToVitest.ts Outdated
report(node, 'pending() in a test callback that already has parameters')
return
}
addEdit(callback.parameters.pos, callback.parameters.pos, 'ctx')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Insert the skip context once per callback

Each pending() inserts another context parameter because traversal uses the unchanged AST. Converting the existing trackMutation.spec.ts test about a link moved with moveBefore() reproduced async (ctxctx), while its body references ctx.skip(). The converted spec therefore has an undeclared identifier. Insert the context only once per callback.

Suggested change
addEdit(callback.parameters.pos, callback.parameters.pos, 'ctx')
if (!edits.some((edit) => edit.start === callback.parameters.pos && edit.end === edit.start && edit.text === 'ctx')) {
addEdit(callback.parameters.pos, callback.parameters.pos, 'ctx')
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

node.name &&
ts.isIdentifier(node.name)
) {
names.add(node.name.text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Resolve shadowed names within their lexical scopes

Collecting declarations from all nested scopes makes a helper parameter named expect suppress the Vitest expect import for unrelated tests. Those tests can have their spies converted to Vitest mocks while retaining Jasmine's global expect, causing spy assertions to fail. Resolve whether each reference is shadowed within its lexical scope.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

replacement = '.mock.calls.length'
break
case 'argsFor':
replacement = `.mock.calls[${call.arguments[0]?.getText() ?? 0}]`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve the empty-array fallback of argsFor

Jasmine's calls.argsFor(index) returns an empty array when that invocation does not exist; mock.calls[index] returns undefined. Consequently, a valid spy.calls.argsFor(0)[0] now throws before the first call, and empty-array assertions fail. Preserve the fallback with appropriate parentheses and update the existing conversion expectation.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

]
const RENAMED_MATCHERS: Record<string, string> = {
toHaveBeenCalledOnceWith: 'toHaveBeenCalledExactlyOnceWith',
toHaveSize: 'toHaveLength',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve object-key semantics when converting toHaveSize

The Jasmine implementation used by the shim counts enumerable keys for plain objects, whereas Vitest's toHaveLength requires a length-bearing value or supported collection. Thus expect({ a: 1 }).toHaveSize(1) passes before conversion but fails afterward. Handle object-size assertions separately or report cases that cannot safely be renamed.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d207ecd00

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +382 to +384
replacement = `.mockImplementation(() => {\n throw new Error(${error.getText()})\n})`
} else if (error && ts.isNewExpression(error)) {
replacement = `.mockImplementation(() => {\n throw ${error.getText()}\n})`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Evaluate throwError arguments once when configuring the spy

issue: For spy.and.throwError(new Error(...)) or a template-string message, the generated closure evaluates the original argument on every spy invocation instead of once during setup. Consequently, repeated calls throw different Error objects, and template expressions or constructor arguments read state after it may have changed. Jasmine configures a single error and rethrows that same object. Capture the error at configuration time, or report these cases for manual conversion instead of silently changing their behavior.

Useful? React with 👍 / 👎.

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

Two correctness bugs stand out in the DoneFn and containment conversions: helper functions that accept a DoneFn parameter are incorrectly rewritten, leaving tests pending, and Set receivers are blindly converted to toContainEqual, silently flipping reference-identity checks to deep-equality checks. A third distinct issue is that the failure-path conversion always emits a hardcoded reject binding, producing unparseable new Promise((reject, reject) => …) output when the original parameter is also named reject.

Open Bits AI session

🤖 Bits Code Review · Commit 9d207ec

Comment on lines +429 to +432
const isDoneFn = isDoneFnType(parameter.type)
if (!isDoneFn && (parameter.name.text !== 'done' || !isTestCallback(node, CALLBACK_FUNCTIONS))) {
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve helpers that consume an existing DoneFn

The new DoneFn check also converts helpers that consume an existing completion callback. For const complete = (done: DoneFn) => { done() }; it('x', (done) => complete(done)), a focused comparison confirmed that the previous conversion resolves, while the new conversion leaves the test Promise pending: complete ignores the supplied callback and resolves its own Promise instead. Restrict automatic conversion to test callbacks or callback factories, and report other uses for manual review.

Suggested change
const isDoneFn = isDoneFnType(parameter.type)
if (!isDoneFn && (parameter.name.text !== 'done' || !isTestCallback(node, CALLBACK_FUNCTIONS))) {
return
}
const isDoneFn = isDoneFnType(parameter.type)
const isCallback = isTestCallback(node, CALLBACK_FUNCTIONS)
if (isDoneFn && !isCallback && !ts.isReturnStatement(node.parent)) {
report(node, 'DoneFn helper outside a returned test callback: review manually')
return
}
if (!isDoneFn && (parameter.name.text !== 'done' || !isCallback)) {
return
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

return true
}
return (
expected !== undefined &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve Set identity semantics in containment conversions

Jasmine uses Set.has for Set containment, preserving object identity. The reproduced assertion expect(new Set([{ id: 1 }])).not.toContain({ id: 1 }) passes before this commit but fails after conversion to toContainEqual. Determine the actual collection type before choosing deep containment, or report ambiguous cases; existing expectations for unknown collections also need adjustment.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +430 to +432
if (!isDoneFn && (parameter.name.text !== 'done' || !isTestCallback(node, CALLBACK_FUNCTIONS))) {
return
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Avoid duplicate rejection parameters in typed callbacks

Typed callbacks now accept any parameter name, but failure conversion always introduces a rejection parameter named reject. Converting a factory returning (reject: DoneFn) => { reject.fail('failure') } reproduced new Promise((reject, reject) => ...), which fails parsing. Allocate a distinct rejection binding throughout the conversion or report this form as unsupported.

Suggested change
if (!isDoneFn && (parameter.name.text !== 'done' || !isTestCallback(node, CALLBACK_FUNCTIONS))) {
return
}
if (!isDoneFn && (parameter.name.text !== 'done' || !isTestCallback(node, CALLBACK_FUNCTIONS))) {
return
}
if (parameter.name.text === 'reject' && findDoneFailCalls(node.body, parameter.name.text).length) {
report(node, 'DoneFn callback named reject with fail(): rename the parameter before converting')
return
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c89990375c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

]
const RENAMED_MATCHERS: Record<string, string> = {
toHaveBeenCalledOnceWith: 'toHaveBeenCalledExactlyOnceWith',
toHaveSize: 'toHaveLength',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve size assertions for Maps, Sets, and objects

issue: When toHaveSize is used with a Map, Set, or plain object, renaming it to toHaveLength changes a valid Jasmine assertion into a failing Vitest assertion because those values have no length property. For example, expect(new Set([1])).toHaveSize(1) is reported as fully supported but becomes expect(new Set([1])).toHaveLength(1). Preserve the appropriate size/key-count check, or report cases that cannot safely be converted instead of unconditionally renaming this matcher.

Useful? React with 👍 / 👎.

Comment on lines +224 to +228
const properties = methods.elements.map((element) => {
const name = (element as ts.StringLiteral).text
return `${name}: vi.fn${type ? `<${type}['${name}']>` : ''}()`
})
replaceNode(node, `({ ${properties.join(', ')} })`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve or report createSpyObj property arguments

issue: When jasmine.createSpyObj receives its supported third argument containing property names or values, this conversion accepts the method-name array but replaces the entire call with only method mocks, silently discarding every property. For example, jasmine.createSpyObj('service', ['run'], { enabled: true }) becomes an object without enabled, changing any tested branch that reads it while returning no unsupported constructs. Convert these property definitions too, or report calls with a third argument for manual conversion.

Useful? React with 👍 / 👎.

replacement = '.mock.calls.length'
break
case 'argsFor':
replacement = `.mock.calls[${call.arguments[0]?.getText() ?? 0}]`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the empty-array fallback of calls.argsFor

issue: When the requested call has not occurred, Jasmine's spy.calls.argsFor(index) returns an empty array, whereas indexing Vitest's spy.mock.calls returns undefined. Consequently, a passing assertion such as const spy = jasmine.createSpy(); expect(spy.calls.argsFor(0)).toEqual([]) becomes a failing assertion after conversion, with no unsupported construct reported. Preserve the empty-array fallback, including parentheses where needed for subsequent property access, rather than replacing this API with a bare array lookup.

Useful? React with 👍 / 👎.

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The migration tool has several silent correctness bugs: it discards createSpyObj property arguments, emits unquoted method names that produce invalid TypeScript, throws primitives instead of Error-wrapped strings for non-literal throwError arguments, lifts timeout expressions out of their declaring scope, fails to recursively convert Jasmine constructs inside retained expressions, misidentifies renamed DoneFn parameters as Vitest context objects, and corrupts aliased or namespace Vitest import bindings during import merging.

Open Bits AI session

🤖 Bits Code Review · Commit c899903


// jasmine.createSpyObj<T>('name', ['a', 'b']) -> ({ a: vi.fn<T['a']>(), b: vi.fn<T['b']>() })
function transformCreateSpyObj(node: ts.CallExpression): boolean {
const methods = node.arguments[1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Report unsupported spy-object property specifications

The conversion ignores createSpyObj's optional property specifications. A focused execution confirmed that jasmine.createSpyObj('service', ['run'], { ready: true }) becomes an object containing only run: ready changes from true to undefined without a warning. Convert property specifications or report these calls as unsupported.

Suggested change
const methods = node.arguments[1]
const methods = node.arguments[1]
if (node.arguments.length > 2) {
report(node, 'jasmine.createSpyObj() property specifications require manual conversion')
return true
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +225 to +226
const name = (element as ts.StringLiteral).text
return `${name}: vi.fn${type ? `<${type}['${name}']>` : ''}()`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Quote method names when generating spy objects

Method names are emitted as unquoted source text. Converting jasmine.createSpyObj('service', ['do-work']) reproduced invalid TypeScript, ({ do-work: vi.fn() }), without an unsupported warning. Formatting then aborts the migration. Escape property names and their corresponding indexed-access type keys.

Suggested change
const name = (element as ts.StringLiteral).text
return `${name}: vi.fn${type ? `<${type}['${name}']>` : ''}()`
const name = (element as ts.StringLiteral).text
const isIdentifier = /^[a-z_$][\w$]*$/i.test(name)
const key = isIdentifier ? name : JSON.stringify(name)
const typeKey = isIdentifier ? `'${name}'` : JSON.stringify(name)
return `${key}: vi.fn${type ? `<${type}[${typeKey}]>` : ''}()`

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

(ts.isStringLiteral(error) || ts.isNoSubstitutionTemplateLiteral(error) || ts.isTemplateExpression(error))
) {
replacement = `.mockImplementation(() => {\n throw new Error(${error.getText()})\n})`
} else if (error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve Error wrapping for nonliteral strings

Nonliteral arguments can contain strings. A focused comparison confirmed that const message = 'boom'; spy.and.throwError(message) throws an Error under Jasmine but a primitive string after conversion, losing its message property and stack without a warning. Preserve Jasmine's runtime string wrapping or retain the unsupported report, and update the new conversion expectation.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

getHookStatements(beforeAll).length !== 2 ||
otherRestores.length ||
!savedName ||
!timeout ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Keep timeout expressions within their valid scope

Moving the timeout expression into describe's arguments can move it outside its scope. A suite declaring const timeout = 10000 inside its callback reproduced describe('a', { timeout: timeout }, ...), which throws “timeout is not defined” during collection without a warning. Only move expressions proven safe outside the callback; otherwise retain manual-conversion reporting.

Suggested change
!timeout ||
!timeout ||
!ts.isNumericLiteral(timeout) ||

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

if (strategy?.name === 'callThrough') {
// jasmine.createSpy(name, fn).and.callThrough() -> vi.fn(fn)
addEdit(node.arguments.pos, node.arguments.end, implementation ? implementation.getText() : '')
addEdit(node.end, strategy.call.end, '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Recursively convert expressions retained by whole-call rewrites

Both new handlers copy retained expressions without visiting their AST. Call-through implementations can retain Jasmine-only toBeTrue() calls after expect becomes Vitest's import; clock.tick(spy.calls.count()) retains .calls after spy conversion. These migrated tests throw. Recursively convert retained implementations and clock arguments, including their import requirements.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

return
}
const parameter = callback.parameters[0]
if (parameter && (!ts.isIdentifier(parameter.name) || parameter.name.text === 'done')) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Recognize DoneFn parameters before using them as contexts

A completion parameter typed DoneFn can have a name other than done. Converting it('a', (next: DoneFn) => { pending('skip') }) reproduced a Promise executor calling next.skip(), where next is its resolver. It fails with “next.skip is not a function” instead of skipping, without a warning. Check the DoneFn type before treating a parameter as a Vitest context.

Suggested change
if (parameter && (!ts.isIdentifier(parameter.name) || parameter.name.text === 'done')) {
if (
parameter &&
(!ts.isIdentifier(parameter.name) || parameter.name.text === 'done' || isDoneFnType(parameter.type))
) {

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

statement.declarationList.declarations[0].name.text === savedName.text &&
!statement.declarationList.declarations[0].initializer
)
for (const statement of [declaration, beforeAll, afterAll]) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve timeout snapshots that remain referenced

The saved timeout variable may also be read by a test or another hook. This removes its declaration and initialization while leaving those references, producing an undeclared identifier without warning. Analyze remaining references before removal, preserving the snapshot and its initialization or reporting the suite as unsupported.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

)
if (existing?.importClause?.namedBindings && ts.isNamedImports(existing.importClause.namedBindings)) {
for (const element of existing.importClause.namedBindings.elements) {
values.add(element.isTypeOnly ? `type ${element.name.text}` : element.name.text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve existing Vitest import bindings

Aliased and namespace imports remain broken after the new CLI lint pass: expect as check becomes an import of the nonexistent export check, and namespace bindings are removed while references remain. Duplicate type imports are now repaired by CLI linting. Import merging still needs to preserve aliases and namespace bindings.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The most critical production issue is the react/react-dom version mismatch in packages/browser-rum-nextjs/package.json, which causes an "Incompatible React versions" exception at render time. The remaining findings are all in the Jasmine-to-Vitest codemod (jasmineToVitest.ts) and cover a range of silent semantic regressions — including broken optional chaining, lost import aliases, dropped spy property definitions, and incorrect matcher conversions — that can cause converted test suites to fail or silently weaken assertions.

Open Bits AI session

🤖 Bits Code Review · Commit 7bc7a4a

"next": "16.4.5",
"react": "19.3.1",
"react-dom": "19.3.1"
"react-dom": "19.3.0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Keep React DOM aligned with React

React remains at 19.3.1 while this change downgrades React DOM to 19.3.0. Requiring react-dom/server from this workspace reproduced an “Incompatible React versions” exception, preventing server rendering. Keep the versions aligned in both the manifest and lockfile.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +480 to +482
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
report(node, `no Vitest equivalent for ${name}()`)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Report the two-argument toThrowError overload

The codemod silently preserves Jasmine’s toThrowError(ErrorType, message) overload, already used in expression.spec.ts. A focused execution confirmed that Vitest accepts a ReferenceError with the wrong message because it ignores the second argument. Report this overload for manual migration or convert both checks to avoid silently weakening assertions.

Suggested change
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
report(node, `no Vitest equivalent for ${name}()`)
}
if (name === 'toThrowError' && node.arguments.length > 1) {
report(node, 'two-argument toThrowError(): check both the error type and message manually')
return false
}
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
report(node, `no Vitest equivalent for ${name}()`)
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session


switch (name) {
case 'returnValues':
replacement = args.map((arg) => `.mockReturnValueOnce(${arg})`).join('')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve stubbing after returnValues is exhausted

For spyOn(obj, 'method').and.returnValues(1, 2), the generated spy calls the original method after exhausting its queued values. A focused reproduction returned [1, 2, 99] and invoked the original method; Jasmine would return undefined on the third call. Preserve an undefined default implementation when converting this strategy, including on existing spies, and update its expected-output coverage.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +214 to +222
const methods = node.arguments[1]
if (
!methods ||
!ts.isArrayLiteralExpression(methods) ||
!methods.elements.every((element) => ts.isStringLiteral(element))
) {
report(node, 'jasmine.createSpyObj() without a list of method names')
return true
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Reject unhandled createSpyObj property arguments

A valid call such as jasmine.createSpyObj('obj', ['run'], { enabled: true }) passes this check, but conversion silently drops the property spies. Reading enabled then returns undefined instead of true. Convert the third argument or leave this form untouched with an unsupported warning.

Suggested change
const methods = node.arguments[1]
if (
!methods ||
!ts.isArrayLiteralExpression(methods) ||
!methods.elements.every((element) => ts.isStringLiteral(element))
) {
report(node, 'jasmine.createSpyObj() without a list of method names')
return true
}
const methods = node.arguments[1]
if (
node.arguments.length > 2 ||
!methods ||
!ts.isArrayLiteralExpression(methods) ||
!methods.elements.every((element) => ts.isStringLiteral(element))
) {
report(node, 'jasmine.createSpyObj() with unsupported method or property arguments')
return true
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +687 to +688
const next = argsAccess.parent
return ts.isElementAccessExpression(next) && next.expression === argsAccess ? '?.' : ''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve optional chaining after spy arguments

A focused reproduction converted spy.calls.mostRecent()?.args.length into spy.mock.lastCall.length, which throws when the spy has not been called. It also converted spy.calls.mostRecent()?.args?.[0] into invalid syntax, spy.mock.lastCall?.?.[0]. Preserve optionality for following property accesses and avoid duplicating an existing optional token.

Suggested change
const next = argsAccess.parent
return ts.isElementAccessExpression(next) && next.expression === argsAccess ? '?.' : ''
const next = argsAccess.parent
if (
(ts.isElementAccessExpression(next) || ts.isPropertyAccessExpression(next)) &&
next.expression === argsAccess &&
!next.questionDotToken
) {
return ts.isElementAccessExpression(next) ? '?.' : '?'
}
return ''

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

return true
}
if (name === 'Func') {
replaceNode(node, '(...args: any[]) => any')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Parenthesize replacement function types

Replacing jasmine.Func without parentheses changes enclosing type syntax. For example, jasmine.Func[] becomes (...args: any[]) => any[], a function returning an array instead of an array of functions. Parenthesize the replacement so arrays, intersections, and type operators retain their grouping, and update the conversion expectations.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

return
}
const parameter = callback.parameters[0]
if (parameter && (!ts.isIdentifier(parameter.name) || parameter.name.text === 'done')) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Recognize typed done parameters when converting pending

For it('a', (complete: DoneFn) => { pending(); complete() }), transformDoneCallback makes complete the Promise resolver, but this check treats it as a Vitest context and emits complete.skip(). The test throws instead of skipping, without a warning. Recognize typed DoneFn parameters regardless of their name.

Suggested change
if (parameter && (!ts.isIdentifier(parameter.name) || parameter.name.text === 'done')) {
if (
parameter &&
(!ts.isIdentifier(parameter.name) || parameter.name.text === 'done' || isDoneFnType(parameter.type))
) {

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

}
const done = parameter.name.text
const failCalls = findDoneFailCalls(node.body, done)
const executorParameters = failCalls.length ? `${done}, reject` : done

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Choose a fresh Promise rejection-callback name

When a done callback uses done.fail and declares const reject, conversion introduces a reject executor parameter in the same scope, producing a SyntaxError. It can also shadow an outer reject reference and change behavior. Choose a fresh rejection-callback binding and use it consistently in the executor and rewritten done.fail accesses.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

addEdit(node.arguments.pos, node.arguments.end, '')
}
usedVitestValues.add('vi')
return true

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Convert retained createSpy implementations and type arguments

Returning here skips retained implementations and type arguments. A createSpy implementation containing expect(true).toBeTrue() therefore keeps that matcher without a warning. If another expectation imports Vitest's expect, invoking the spy fails on toBeTrue. Traverse retained content and compose its edits with the call rewrite so nested conversions are preserved.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

]
const RENAMED_MATCHERS: Record<string, string> = {
toHaveBeenCalledOnceWith: 'toHaveBeenCalledExactlyOnceWith',
toHaveSize: 'toHaveLength',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve non-array semantics when converting toHaveSize

Jasmine's toHaveSize counts plain-object keys and Map/Set entries as well as array lengths. For example, expect({ a: 1 }).toHaveSize(1) passes before conversion but fails as toHaveLength(1). Handle the appropriate size operation or report uncertain inputs instead of unconditionally renaming this matcher.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-codemod branch from 7bc7a4a to 4636bc1 Compare November 23, 2026 11:26

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4636bc127d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +480 to +483
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
report(node, `no Vitest equivalent for ${name}()`)
}
return false

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve exact messages in synchronous toThrowError assertions

issue: When a synchronous Jasmine assertion uses toThrowError('boom'), importing Vitest's expect while leaving the matcher unchanged weakens exact message equality to substring matching. For example, expect(() => { throw new Error('not boom') }).toThrowError('boom') becomes a passing assertion, and the transformer reports no unsupported constructs. Existing string-form assertions in packages/browser-core/src/tools/serialisation/sanitize.spec.ts and packages/browser-rum/src/domain/segmentCollection/segment.spec.ts are affected. Convert string arguments to an exact-message check, or report this synchronous matcher form for manual conversion.

Useful? React with 👍 / 👎.

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The codemod has several correctness gaps where converted tests silently change behavior: the two most critical are the loss of createSpyObj property-definition arguments (making converted objects return undefined for previously defined properties) and the corruption of aliased Vitest imports (producing unresolvable import bindings that prevent converted specs from loading). Additional issues include weakened error-message assertions, incorrect returnValues exhaustion behavior, duplicated optional-chain tokens producing unparseable output, and unconverted Jasmine calls inside retained spy implementations.

Open Bits AI session

🤖 Bits Code Review · Commit 4636bc1

transformSpyOn(node, callee)
return false
case 'fail':
replaceNode(callee, 'expect.unreachable')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve failures when fail() exceptions are caught

Replacing a caught fail() with expect.unreachable() can silently remove a test failure. The compatibility shim records failures before throwing; Vitest's exception can simply be caught. The rejection test in packages/browser-core/src/tools/readBytesFromStream.spec.ts catches any Error, so after conversion it passes if the operation unexpectedly succeeds. Preserve that failure recording or report caught fail() calls for manual conversion.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session


switch (name) {
case 'returnValues':
replacement = args.map((arg) => `.mockReturnValueOnce(${arg})`).join('')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Stub spies after returnValues exhausts its values

For spyOn(obj, 'method').and.returnValues(1, 2), no default stub is installed because an explicit strategy exists. Reproduction returns [1, 2, undefined] with Jasmine but calls the original method on the third invocation after conversion. Install an undefined fallback alongside the queued values, including for previously configured spies, and update the codemod expectations.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +213 to +214
function transformCreateSpyObj(node: ts.CallExpression): boolean {
const methods = node.arguments[1]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Retain or report createSpyObj property arguments

A focused conversion of jasmine.createSpyObj('obj', ['method'], { enabled: true }) produced only the method mock, silently dropping enabled without an unsupported warning. The third argument is a valid Jasmine property-spy argument, so migrated tests receive a different object. Preserve those properties or leave the call untouched and report it.

Suggested change
function transformCreateSpyObj(node: ts.CallExpression): boolean {
const methods = node.arguments[1]
function transformCreateSpyObj(node: ts.CallExpression): boolean {
if (node.arguments.length > 2) {
report(node, 'jasmine.createSpyObj() with property spies')
return true
}
const methods = node.arguments[1]

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

)
if (existing?.importClause?.namedBindings && ts.isNamedImports(existing.importClause.namedBindings)) {
for (const element of existing.importClause.namedBindings.elements) {
values.add(element.isTypeOnly ? `type ${element.name.text}` : element.name.text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Preserve aliases when merging Vitest imports

When merging an existing aliased import, only its local name survives. Reproduction converts import { expect as check } from 'vitest' into import { check, it } from 'vitest'. Vitest exports no check, so the converted spec cannot load. Preserve the complete import specifier, including its alias and type modifier.

Suggested change
values.add(element.isTypeOnly ? `type ${element.name.text}` : element.name.text)
values.add(element.getText())

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +687 to +688
const next = argsAccess.parent
return ts.isElementAccessExpression(next) && next.expression === argsAccess ? '?.' : ''

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Avoid duplicating optional-chain tokens

Focused conversion of spy.calls.mostRecent()?.args?.[0] produced spy.mock.lastCall?.?.[0], which TypeScript cannot parse. first() has the same failure. The existing optional element-access token must be preserved without inserting another; otherwise valid input stops migration during formatting.

Suggested change
const next = argsAccess.parent
return ts.isElementAccessExpression(next) && next.expression === argsAccess ? '?.' : ''
const next = argsAccess.parent
return ts.isElementAccessExpression(next) && next.expression === argsAccess && !next.questionDotToken
? '?.'
: ''

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +225 to +226
const name = (element as ts.StringLiteral).text
return `${name}: vi.fn${type ? `<${type}['${name}']>` : ''}()`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Quote generated createSpyObj method names

Focused conversion of jasmine.createSpyObj('obj', ['some-method']) produced the invalid property some-method: vi.fn(), without an unsupported warning. Jasmine permits arbitrary string method names. Preserve quoting and escaping in generated property names and type indexes so these inputs remain valid and the CLI can format them.

Suggested change
const name = (element as ts.StringLiteral).text
return `${name}: vi.fn${type ? `<${type}['${name}']>` : ''}()`
const name = element.getText()
const property = /^[A-Za-z_$][\w$]*$/.test((element as ts.StringLiteral).text)
? (element as ts.StringLiteral).text
: name
return `${property}: vi.fn${type ? `<${type}[${name}]>` : ''}()`

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

report(node, `unsupported async matcher ${name}()`)
return false
}
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Handle the two-argument toThrowError overload

The two-argument toThrowError(ReferenceError, 'foo is not defined') used in expression.spec.ts survives conversion without a warning, but Vitest ignores its second argument. Focused execution confirmed that the wrong message fails before conversion and passes afterward. Preserve both constraints or report the overload for manual migration.

Suggested change
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
if (name === 'toThrowError' && node.arguments.length > 1) {
report(node, 'unsupported two-argument toThrowError(): preserve both the error type and message')
}
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

return true
}
if (isExpectAsync(expectCall)) {
if (name in ASYNC_MATCHERS && (name !== 'toBeRejectedWithError' || node.arguments.length <= 1)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve exact messages in async error assertions

Jasmine's toBeRejectedWithError('oops') requires an exact message; the generated rejects.toThrow('oops') accepts substrings. Reproduction with new Error('not oops at all') fails before conversion and passes afterward. This weakens assertions such as those in the thenable and Shopify specs. Preserve exact matching for strings and string-valued expressions, and update the codemod's expected output.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

const implementation = node.arguments[1]
if (strategy?.name === 'callThrough') {
// jasmine.createSpy(name, fn).and.callThrough() -> vi.fn(fn)
addEdit(node.arguments.pos, node.arguments.end, implementation ? implementation.getText() : '')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Convert Jasmine calls inside retained spy implementations

The retained call-through implementation is copied without visiting its contents. Reproduction converts jasmine.createSpy('x', () => jasmine.createSpy()).and.callThrough() into vi.fn(() => jasmine.createSpy()) without warning. The returned spy remains a Jasmine spy, and native Vitest spy assertions reject it. Visit the retained implementation while preserving nonoverlapping edits.

Suggested change
addEdit(node.arguments.pos, node.arguments.end, implementation ? implementation.getText() : '')
if (implementation) {
addEdit(node.arguments.pos, implementation.getStart(), '')
visit(implementation)
} else {
addEdit(node.arguments.pos, node.arguments.end, '')
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

replacement = `.mockImplementation(() => {\n throw new Error(${error.getText()})\n})`
} else if (error) {
// Jasmine throws non-string values as is, assume a value that isn't a string literal is an error
replacement = `.mockImplementation(() => {\n throw ${error.getText()}\n})`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Evaluate throwError arguments during configuration

Moving .and.throwError(makeError()) into the mock implementation changes evaluation timing and error identity. Reproduction evaluates the factory once during Jasmine configuration, but twice across two converted spy calls, throwing different objects. Capture the configured error once, including string-to-Error conversion, then install the throwing implementation and update the codemod expectations.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

@thomas-lebeau thomas-lebeau changed the title ✅ [RUM-19779] Add a Jasmine to Vitest codemod and a migration guard test(test): Add a Jasmine to Vitest codemod and migration guard Nov 24, 2026
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
- `DoneFn` callbacks built by a factory
- `toContain` with an array, an object or an asymmetric matcher: `toContainEqual`
- `toMatch` with a string containing regular expression syntax: `new RegExp()`
- `pending()` in `beforeEach`, and several `pending()` in the same callback
- `jasmine.createSpy(name, fn).and.callThrough()`, `jasmine.createSpyObj()` with method names
- `and.throwError()` with any value
- `jasmine.clock()` `install()`, `tick()` and `uninstall()`
- a `describe` timeout set with `jasmine.DEFAULT_TIMEOUT_INTERVAL` in `beforeAll` and restored in
  `afterAll`
- `done` arrow functions become `() => new Promise(...)`, without a block that only returns
- the test context parameter avoids the names declared in the file
- the CLI runs `eslint --fix` on the converted files, to remove unnecessary `as never` assertions
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-codemod branch from 4636bc1 to 7fd2849 Compare November 25, 2026 08:54

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

Converting Jasmine’s two-argument toThrowError assertions silently drops message validation. Other confirmed conversions change spy behavior, remove object properties, and produce invalid aliased imports.

Open Bits AI session

🤖 Bits Code Review · Commit 7fd2849

report(node, `unsupported async matcher ${name}()`)
return false
}
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Preserve message validation in two-argument toThrowError assertions

Two-argument assertions such as the existing toThrowError(ReferenceError, 'foo is not defined') in expression.spec.ts are converted without warning. A focused reproduction confirmed that Vitest passes the assertion with the wrong message because it ignores the second argument. Convert this overload or report it for manual migration so message validation is preserved.

Suggested change
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {
if (name === 'toThrowError' && node.arguments.length > 1) {
report(node, 'two-argument toThrowError(): migrate the error type and message checks manually')
}
if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) {

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session


switch (name) {
case 'returnValues':
replacement = args.map((arg) => `.mockReturnValueOnce(${arg})`).join('')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Clear the fallback implementation when converting returnValues

Converting spyOn(object, 'method').and.returnValues(1, 2) retains the original implementation after the queued values are exhausted. A reproduction returned [1, 2, 99] instead of Jasmine's [1, 2, undefined], allowing unexpected calls to execute real behavior. Replace the fallback implementation with an undefined-returning stub and update the existing conversion test expectation.

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

)
if (existing?.importClause?.namedBindings && ts.isNamedImports(existing.importClause.namedBindings)) {
for (const element of existing.importClause.namedBindings.elements) {
values.add(element.isTypeOnly ? `type ${element.name.text}` : element.name.text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Preserve aliases when merging existing Vitest imports

When a partially migrated file has an aliased Vitest import and conversion adds another import, the exported name is discarded. A focused conversion changed import { expect as vitestExpect } into import { it, vitestExpect }; Vitest exports no vitestExpect, so the resulting spec cannot load. Preserve the complete import specifier when merging.

Suggested change
values.add(element.isTypeOnly ? `type ${element.name.text}` : element.name.text)
values.add(element.getText())

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

Comment on lines +215 to +222
if (
!methods ||
!ts.isArrayLiteralExpression(methods) ||
!methods.elements.every((element) => ts.isStringLiteral(element))
) {
report(node, 'jasmine.createSpyObj() without a list of method names')
return true
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Report createSpyObj calls that also define properties

A focused conversion of jasmine.createSpyObj('object', ['method'], { enabled: true }) produced only the method mock and reported no unsupported construct. Jasmine provides enabled as true, but the converted object lacks that property, changing consumer behavior. Preserve the third argument's properties or report this overload for manual migration.

Suggested change
if (
!methods ||
!ts.isArrayLiteralExpression(methods) ||
!methods.elements.every((element) => ts.isStringLiteral(element))
) {
report(node, 'jasmine.createSpyObj() without a list of method names')
return true
}
if (
node.arguments.length > 2 ||
!methods ||
!ts.isArrayLiteralExpression(methods) ||
!methods.elements.every((element) => ts.isStringLiteral(element))
) {
report(node, 'jasmine.createSpyObj() with properties or without a list of method names')
return true
}

React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it

What each reaction means
  • 👍 Useful: correct, and you're fixing it or will.
  • 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
  • 😕 Unclear: you can't tell what it means or why it matters.
  • 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.

🤖 Bits Code Review · Open Bits AI session

@thomas-lebeau
thomas-lebeau merged commit 6b0a092 into main Nov 25, 2026
32 checks passed
@thomas-lebeau
thomas-lebeau deleted the thomas.lebeau/vitest-codemod branch November 25, 2026 09:14
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants