Skip to content

test(test): Migrate specs and helpers from Jasmine API to Vitest API - #5300

Open
thomas-lebeau wants to merge 5 commits into
mainfrom
thomas.lebeau/vitest-run-codemod
Open

thomas-lebeau wants to merge 5 commits into
mainfrom
thomas.lebeau/vitest-run-codemod

Conversation

@thomas-lebeau

@thomas-lebeau thomas-lebeau commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Last step before removing the Jasmine compatibility shim: migrate every spec file and test helper from the Jasmine API to the Vitest API. Stacked on #5144, which adds the codemod and the migration guard.

Changes

Review commit by commit:

  1. Hand-converted test helpers: mockClock (Vitest fake timers), collectAsyncCalls, mockRequestIdleCallback, mockDisplay. These are the helpers the codemod can't convert.
  2. Raw codemod output: node scripts/test/jasmine-to-vitest.ts run on the other test helpers and on every spec in packages and developer-extension. Not edited by hand.
  3. Hand fixes:
    • The 22 constructs the codemod reports as unsupported: toThrowMatching, toHaveBeenCalledBefore, toBeRejected, arrayWithExactContents, calls.all(), jasmine.Expected, a custom asymmetric matcher, and pending() in test helpers.
    • Behaviour that differs under Vitest in ways the codemod can't detect without types:
      • stringMatching rejects numbers.
      • Number comparisons no longer coerce strings.
      • A spy on window.onunhandledrejection is never called.
      • A negative clock tick throws.
    • The type errors left in the codemod output, mostly from Vitest's stricter mock types.
    • collectAsyncCalls() resolves with spy.mock.calls, and a new observation of a spy replaces the previous one, as the Jasmine version did.
    • mockClock().tick() keeps sub-millisecond durations in the mocked performance.now(), as the Jasmine clock did.
    • The migration guard (VITEST_API_SPEC_FILES) now covers every spec file and test helper, so the Jasmine API can't come back.

The test count is unchanged (5443). The shim, the Jasmine dependencies and the docs are cleaned up in the next PR of the stack.

These changes were AI-assisted. The feature-detection skips (pending() → context.skip() / describe.skipIf) deserve a careful look. Some conditions are now evaluated when the tests are collected instead of in each test, with the same conditions.

Test instructions

  • yarn test:unit (passes on 3 random seeds, no unhandled errors)
  • yarn typecheck
  • yarn lint

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

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Nov 19, 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-prod-us1-4

datadog-prod-us1-4 Bot commented Nov 19, 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: ba554ce | Docs | View more details | Give us feedback!

@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-run-codemod branch 2 times, most recently from 0f0ff90 to 96ae3b8 Compare November 19, 2026 12:54
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-run-codemod branch from 96ae3b8 to e718283 Compare November 19, 2026 13:53
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-run-codemod branch 2 times, most recently from 0f5ff42 to 2a83a13 Compare November 23, 2026 11:26
@thomas-lebeau thomas-lebeau changed the title ✅ Migrate every spec and test helper from the Jasmine API to the Vitest API test(test): Migrate specs and helpers from Jasmine API to Vitest API Nov 24, 2026
@thomas-lebeau
thomas-lebeau marked this pull request as ready for review November 25, 2026 08:47
@thomas-lebeau
thomas-lebeau requested review from a team as code owners November 25, 2026 08:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 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-25T09:33:39.255192Z ba554ce New commits
🔒 Security Review ✅ Completed 2026-11-25T09:34:23.217981Z ba554ce 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: 2a83a13c06

ℹ️ 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 +21 to 22
expect.unreachable(message)
reject(new Error(message))

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 failure recording for unexpected monitored calls

issue: If an observed spy receives an extra call inside monitor/callMonitored after the collection promise has resolved, expect.unreachable() throws an assertion error that the SDK monitor catches and suppresses. Unlike the previous fail() shim in test/unit-vitest/vitest.setup.ts, this does not record a failure for the end-of-test check, and rejecting an already-resolved promise cannot fail the test either. This weakens callers such as the startView tests in rumPublicApi.spec.ts, which inspect only the first collected call and rely on this helper to reject extras. Record the failure independently of exception propagation, or assert the final call count during test cleanup.

Useful? React with 👍 / 👎.

@datadog-prod-us1-4 datadog-prod-us1-4 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

Replacing the shim’s fail() with native expect.unreachable() loses failure recording when exceptions are caught. Extra-call guards and the stream-rejection check can consequently pass despite the incorrect behavior they should detect.

Open Bits AI session

🤖 Bits Code Review · Commit 2a83a13

} else if (spy.mock.calls.length > expectedCallsCount) {
const message = `Unexpected extra call for spec '${currentSpec.fullName}'`
fail(message)
expect.unreachable(message)

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 failure recording for guarded test helpers

When an extra spy call occurs after this promise resolves inside monitored SDK code, expect.unreachable() throws an exception that monitorError can swallow without recording a test failure. Tests such as the valid-configuration case in preStartLogs.spec.ts can therefore accept duplicate starts. The previous shim's fail() recorded failures independently of thrown exceptions. Persist guard failures on the Vitest task or report them during cleanup; the migrated schema assertion in formatValidation.ts needs equivalent handling.

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 30 to 35
try {
await readBytesFromStream(stream)
fail('Should have thrown an error')
expect.unreachable('Should have thrown an error')
} catch (error) {
expect(error).toEqual(jasmine.any(Error))
expect(error).toEqual(expect.any(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 Keep the rejection assertion outside its own catch

If readBytesFromStream() incorrectly resolves, expect.unreachable() throws an AssertionError that the following catch accepts as an Error, so the rejection test passes. A focused reproduction with a resolving implementation confirmed this false positive. The previous shim's fail() separately recorded the failure even when caught. Use an awaited rejection matcher outside the catch.

Suggested change
try {
await readBytesFromStream(stream)
fail('Should have thrown an error')
expect.unreachable('Should have thrown an error')
} catch (error) {
expect(error).toEqual(jasmine.any(Error))
expect(error).toEqual(expect.any(Error))
}
await expect(readBytesFromStream(stream)).rejects.toEqual(expect.any(Error))

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

Base automatically changed from thomas.lebeau/vitest-codemod to main November 25, 2026 09:14
- collectAsyncCalls: observe calls through `mock.calls` instead of wrapping
  the spy implementation, so `vi.spyOn()` spies keep calling through, and
  resolve with `mock.calls`
- mockClock: Vitest fake timers, faking the same APIs as Jasmine's clock
- mockRequestIdleCallback: read return values from `mock.results`
- mockDisplay: an object of `vi.fn()`
…c file

Output of `node scripts/test/jasmine-to-vitest.ts <test helpers> packages developer-extension`,
unchanged. The constructs it can't convert are fixed in the next commit.
- Convert the constructs the codemod reports as unsupported: `toThrowMatching`,
  `toHaveBeenCalledBefore`, `toBeRejected`, `arrayWithExactContents`, `calls.all()`,
  `jasmine.Expected`, a custom asymmetric matcher, and `pending()` in test helpers.
- Fix the assertions whose semantics differ between Jasmine and Vitest in ways the codemod can't
  detect (`stringMatching` on numbers, number comparisons on strings, spying on
  `window.onunhandledrejection`, a negative clock tick).
- Use the array returned by `collectAsyncCalls()`, and let a new observation of a spy replace the
  previous one, as the Jasmine version did.
- Keep the sub-millisecond part of `mockClock().tick()` in the mocked `performance.now()`.
- Fix the type errors of the codemod output.
- Turn the migration guard on for every spec file and test helper.

@datadog-prod-us1-4 datadog-prod-us1-4 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

Catchable assertions can let tests pass incorrectly where Jasmine previously recorded failures. Fractional fake-clock ticks can also make callback timestamps move backward.

Open Bits AI session

🤖 Bits Code Review · Commit 2a83a13

} else if (spy.mock.calls.length > expectedCallsCount) {
const message = `Unexpected extra call for spec '${currentSpec.fullName}'`
fail(message)
expect.unreachable(message)

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 failure recording when replacing fail()

If monitored SDK code makes an extra spy call after this promise resolves, callMonitored can swallow the error thrown by expect.unreachable(), allowing the test to pass. The previous fail() shim recorded failures for an end-of-test check even when caught. The same replacement in readBytesFromStream.spec.ts lets its catch block accept the assertion error when reading unexpectedly succeeds. Preserve failure recording in the helper and assert stream rejection directly.

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

tick: (ms: number) => jasmine.clock().tick(ms),
setDate: (date: Date) => jasmine.clock().mockDate(date),
tick: (ms: number) => {
tickedDuration += ms

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 fractional clock readings monotonic during callbacks

The reviewer reproduced tick(0.9), scheduling a zero-delay timer, then tick(0.2): the callback observes performance.now() approximately 0.1 ms above the initial reading after it already reached 0.9 ms. Jasmine remained monotonic. Updating tickedDuration before executing timers combines the final fractional remainder with the callback's earlier Date.now(), potentially producing negative elapsed durations. Derive fractional time from the fake clock's current execution position instead.

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

…main

Output of `node scripts/test/jasmine-to-vitest.ts packages developer-extension` after rebasing on main, followed by `eslint --fix`.
@thomas-lebeau
thomas-lebeau force-pushed the thomas.lebeau/vitest-run-codemod branch from 2a83a13 to ba554ce Compare November 25, 2026 09:31

@datadog-prod-us1-4 datadog-prod-us1-4 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 can silently accept extra spy calls and a stream read that resolves when rejection is required. The mock clock also exposes the final fractional offset to earlier timer callbacks, changing duration measurements.

Open Bits AI session

🤖 Bits Code Review · Commit ba554ce

} else if (spy.mock.calls.length > expectedCallsCount) {
const message = `Unexpected extra call for spec '${currentSpec.fullName}'`
fail(message)
expect.unreachable(message)

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 Record extra-call failures even when the caller catches them

After the collection promise resolves, an extra spy call inside callMonitored throws an assertion that monitoring catches, allowing the test to pass. A focused in-memory check confirmed zero recorded failures. The previous fail() recorded the failure independently of propagation; use a soft assertion to preserve that protection.

Suggested change
expect.unreachable(message)
expect.soft(spy.mock.calls, message).toHaveLength(expectedCallsCount)

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

tick: (ms: number) => jasmine.clock().tick(ms),
setDate: (date: Date) => jasmine.clock().mockDate(date),
tick: (ms: number) => {
tickedDuration += ms

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 Align fractional clock offsets with timer execution

tickedDuration includes the entire advance before intermediate timer callbacks execute. A focused check scheduling a 1 ms timeout and calling clock.tick(1.5) confirmed that the callback observes 1.5 ms elapsed instead of 1 ms. This changes timer-driven duration measurements. Fractional time must follow the clock's current position during callbacks.

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 30 to 35
try {
await readBytesFromStream(stream)
fail('Should have thrown an error')
expect.unreachable('Should have thrown an error')
} catch (error) {
expect(error).toEqual(jasmine.any(Error))
expect(error).toEqual(expect.any(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 Assert stream rejection outside the surrounding catch

If readBytesFromStream incorrectly resolves, expect.unreachable() throws an AssertionError that the surrounding catch accepts as expect.any(Error). Replacing the awaited operation with a resolved promise reproduced the false positive. The previous fail() recorded failure independently, so this migration removes the test's rejection protection. Assert rejection directly.

Suggested change
try {
await readBytesFromStream(stream)
fail('Should have thrown an error')
expect.unreachable('Should have thrown an error')
} catch (error) {
expect(error).toEqual(jasmine.any(Error))
expect(error).toEqual(expect.any(Error))
}
await expect(readBytesFromStream(stream)).rejects.toEqual(expect.any(Error))

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant