Repository navigation
test(test): Migrate specs and helpers from Jasmine API to Vitest API - #5300
thomas-lebeau wants to merge 5 commits into
Conversation
Bundles Sizes Evolution
|
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: ba554ce | Docs | View more details | Give us feedback! |
0f0ff90 to
96ae3b8
Compare
96ae3b8 to
e718283
Compare
0f5ff42 to
2a83a13
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: 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".
| expect.unreachable(message) | ||
| reject(new Error(message)) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
🤖 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) |
There was a problem hiding this comment.
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
| 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)) | ||
| } |
There was a problem hiding this comment.
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.
| 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
- 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.
There was a problem hiding this comment.
Catchable assertions can let tests pass incorrectly where Jasmine previously recorded failures. Fractional fake-clock ticks can also make callback timestamps move backward.
🤖 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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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`.
…ray.prototype.push
2a83a13 to
ba554ce
Compare
There was a problem hiding this comment.
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.
🤖 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) |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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
| 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)) | ||
| } |
There was a problem hiding this comment.
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.
| 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
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:
mockClock(Vitest fake timers),collectAsyncCalls,mockRequestIdleCallback,mockDisplay. These are the helpers the codemod can't convert.node scripts/test/jasmine-to-vitest.tsrun on the other test helpers and on every spec inpackagesanddeveloper-extension. Not edited by hand.toThrowMatching,toHaveBeenCalledBefore,toBeRejected,arrayWithExactContents,calls.all(),jasmine.Expected, a custom asymmetric matcher, andpending()in test helpers.stringMatchingrejects numbers.window.onunhandledrejectionis never called.collectAsyncCalls()resolves withspy.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 mockedperformance.now(), as the Jasmine clock did.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 typecheckyarn lintChecklist