Repository navigation
test(test): Add a Jasmine to Vitest codemod and migration guard - #5144
Conversation
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 7fd2849 | Docs | View more details | Give us feedback! |
e6f4f3c to
6c51bca
Compare
6c51bca to
55599fd
Compare
b8dee2c to
3158a41
Compare
05271ab to
6b75c84
Compare
ef306be to
311628f
Compare
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| case 'fail': | ||
| replaceNode(callee, 'expect.unreachable') | ||
| usedVitestValues.add('expect') |
There was a problem hiding this comment.
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 👍 / 👎.
| case 'returnValues': | ||
| replacement = args.map((arg) => `.mockReturnValueOnce(${arg})`).join('') |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit 311628f
| "next": "16.4.5", | ||
| "react": "19.3.1", | ||
| "react-dom": "19.3.1" | ||
| "react-dom": "19.3.0", |
There was a problem hiding this comment.
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
| 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 | ||
| } |
There was a problem hiding this comment.
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.
| 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
| if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) { | ||
| report(node, `no Vitest equivalent for ${name}()`) | ||
| } |
There was a problem hiding this comment.
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.
| 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('') |
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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
| ) | ||
| 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) |
There was a problem hiding this comment.
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.
| 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
| report(node, 'pending() in a test callback that already has parameters') | ||
| return | ||
| } | ||
| addEdit(callback.parameters.pos, callback.parameters.pos, 'ctx') |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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}]` |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
💡 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".
| replacement = `.mockImplementation(() => {\n throw new Error(${error.getText()})\n})` | ||
| } else if (error && ts.isNewExpression(error)) { | ||
| replacement = `.mockImplementation(() => {\n throw ${error.getText()}\n})` |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit 9d207ec
| const isDoneFn = isDoneFnType(parameter.type) | ||
| if (!isDoneFn && (parameter.name.text !== 'done' || !isTestCallback(node, CALLBACK_FUNCTIONS))) { | ||
| return | ||
| } |
There was a problem hiding this comment.
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.
| 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 && |
There was a problem hiding this comment.
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
| if (!isDoneFn && (parameter.name.text !== 'done' || !isTestCallback(node, CALLBACK_FUNCTIONS))) { | ||
| return | ||
| } |
There was a problem hiding this comment.
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.
| 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
There was a problem hiding this comment.
💡 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', |
There was a problem hiding this comment.
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 👍 / 👎.
| const properties = methods.elements.map((element) => { | ||
| const name = (element as ts.StringLiteral).text | ||
| return `${name}: vi.fn${type ? `<${type}['${name}']>` : ''}()` | ||
| }) | ||
| replaceNode(node, `({ ${properties.join(', ')} })`) |
There was a problem hiding this comment.
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}]` |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
🤖 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] |
There was a problem hiding this comment.
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.
| 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
| const name = (element as ts.StringLiteral).text | ||
| return `${name}: vi.fn${type ? `<${type}['${name}']>` : ''}()` |
There was a problem hiding this comment.
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.
| 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) { |
There was a problem hiding this comment.
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 || |
There was a problem hiding this comment.
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.
| !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, '') |
There was a problem hiding this comment.
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')) { |
There was a problem hiding this comment.
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.
| 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]) { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
c899903 to
7bc7a4a
Compare
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit 7bc7a4a
| "next": "16.4.5", | ||
| "react": "19.3.1", | ||
| "react-dom": "19.3.1" | ||
| "react-dom": "19.3.0", |
There was a problem hiding this comment.
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
| if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) { | ||
| report(node, `no Vitest equivalent for ${name}()`) | ||
| } |
There was a problem hiding this comment.
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.
| 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('') |
There was a problem hiding this comment.
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
| 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 | ||
| } |
There was a problem hiding this comment.
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.
| 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
| const next = argsAccess.parent | ||
| return ts.isElementAccessExpression(next) && next.expression === argsAccess ? '?.' : '' |
There was a problem hiding this comment.
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.
| 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') |
There was a problem hiding this comment.
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')) { |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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
7bc7a4a to
4636bc1
Compare
There was a problem hiding this comment.
💡 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".
| if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) { | ||
| report(node, `no Vitest equivalent for ${name}()`) | ||
| } | ||
| return false |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit 4636bc1
| transformSpyOn(node, callee) | ||
| return false | ||
| case 'fail': | ||
| replaceNode(callee, 'expect.unreachable') |
There was a problem hiding this comment.
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('') |
There was a problem hiding this comment.
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
| function transformCreateSpyObj(node: ts.CallExpression): boolean { | ||
| const methods = node.arguments[1] |
There was a problem hiding this comment.
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.
| 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) |
There was a problem hiding this comment.
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.
| 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
| const next = argsAccess.parent | ||
| return ts.isElementAccessExpression(next) && next.expression === argsAccess ? '?.' : '' |
There was a problem hiding this comment.
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.
| 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
| const name = (element as ts.StringLiteral).text | ||
| return `${name}: vi.fn${type ? `<${type}['${name}']>` : ''}()` |
There was a problem hiding this comment.
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.
| 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)) { |
There was a problem hiding this comment.
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.
| 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)) { |
There was a problem hiding this comment.
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() : '') |
There was a problem hiding this comment.
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.
| 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})` |
There was a problem hiding this comment.
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
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
4636bc1 to
7fd2849
Compare
There was a problem hiding this comment.
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.
🤖 Bits Code Review · Commit 7fd2849
| report(node, `unsupported async matcher ${name}()`) | ||
| return false | ||
| } | ||
| if (['toThrowMatching', 'toHaveBeenCalledBefore', 'toHaveBeenCalledAfter'].includes(name)) { |
There was a problem hiding this comment.
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.
| 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('') |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
| 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
| if ( | ||
| !methods || | ||
| !ts.isArrayLiteralExpression(methods) || | ||
| !methods.elements.every((element) => ts.isStringLiteral(element)) | ||
| ) { | ||
| report(node, 'jasmine.createSpyObj() without a list of method names') | ||
| return true | ||
| } |
There was a problem hiding this comment.
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.
| 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
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)eslint --fixon the converted files (removes unnecessaryas neverassertions; type-aware, so a full run needsNODE_OPTIONS='--max-old-space-size=8192').describe,it,expect, hooks,vi,Mock/Mockedtypes),jasmine.createSpy→vi.fn(vi.fn(fn)with.and.callThrough()),jasmine.createSpyObjwith method names → object of typedvi.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→toContainEqualon arrays and objects,toMatchwith a regular expression string →new RegExp()), asymmetric matchers,expectAsyncresolves/rejects,donecallbacks (andDoneFncallbacks built by a factory) → Promise,pending()in tests andbeforeEach→ test contextskip(),jasmine.clock()install/tick/uninstall→vifake timers, adescribetimeout set withjasmine.DEFAULT_TIMEOUT_INTERVALinbeforeAll/afterAll→describe(name, { timeout }, fn),fail()→expect.unreachable(),fit/fdescribe/xit/xdescribe,jasmine.Spy/SpyObj/Functypes.toThrowMatching,arrayWithExactContents,spy.calls.all(),toBeRejected, custom asymmetric matchers,pending()in helpers) is left untouched and reported withfile: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).mainand re-run it.scripts/test/lib/jasmineToVitest.spec.ts(58 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
Refs: RUM-19779