Skip to content

Migrate Jest to vitest#1921

Open
mm-kevcenteno wants to merge 7 commits into
mainfrom
jest-to-vitest
Open

Migrate Jest to vitest#1921
mm-kevcenteno wants to merge 7 commits into
mainfrom
jest-to-vitest

Conversation

@mm-kevcenteno

@mm-kevcenteno mm-kevcenteno commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

migrates jest to vitest

Summary by CodeRabbit

  • Testing
    • Migrated automated and end-to-end test execution to Vitest.
    • Added comprehensive coverage for request construction, validation, location, shipping, billing, and transaction reporting.
    • Strengthened coverage reporting with complete branch, function, and line coverage requirements.
    • Expanded error-handling checks, including invalid responses and rejected network requests.
  • Documentation
    • Updated testing guidance and project documentation to reflect the current test workflow.

Replace jest, ts-jest, and @types/jest with vitest and
@vitest/coverage-v8. Specs now import test APIs explicitly from
'vitest' instead of relying on injected globals.

The v8 coverage provider surfaced gaps the previous setup missed (CI
never passed --coverage through npm). Add tests for the legacy numeric
timeout argument, non-Error fetch rejections, orders without a referrer
URI, and transaction reports with no identifier fields. Annotate two
defensive email-normalization branches that validation makes
unreachable.
Spec files were excluded from tsc and ts-jest ran in transpile-only
mode, so they were never type-checked. Run tsc against
tsconfig.test.json in the lint script and fix the errors it surfaced:
the specs referenced RequestInfo, which @types/node does not declare
globally.
npm swallowed the --coverage flag in 'npm test --coverage', so the
coverage thresholds were never checked in CI. Use the test:coverage
script, which runs Vitest with coverage enabled.
Both e2e packages now use Vitest, which handles TypeScript directly, so
the ts package drops ts-jest and @types/jest. Each package gets a local
vitest.config to anchor its test root; otherwise Vitest walks up and
uses the repository config. The CI steps no longer need the
experimental-vm-modules flag, and the Jest globals carve-out is removed
from the ESLint config.
The assertions were weakened because Jest's --experimental-vm-modules
created errors in a different realm, breaking instanceof. Vitest runs
native ESM without VM sandboxing, so the workaround is no longer
needed.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mm-kevcenteno, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d2c2fee2-2c7f-4f0a-8b0b-9048760965c5

📥 Commits

Reviewing files that changed from the base of the PR and between 436fc9b and 34069f7.

📒 Files selected for processing (1)
  • src/request/email.ts
📝 Walkthrough

Walkthrough

The project’s test tooling, CI workflow, documentation, end-to-end tests, and source specs migrate from Jest to Vitest. Coverage configuration is added, and several constructor and WebServiceClient behaviors receive additional test coverage.

Changes

Vitest migration

Layer / File(s) Summary
Runner and coverage configuration
.github/workflows/test.yml, package.json, vitest.config.ts, tsconfig.test.json, eslint.config.mjs, CLAUDE.md
Project scripts, CI commands, coverage thresholds, compiler settings, lint configuration, and testing guidance are updated for Vitest.
End-to-end test setup
e2e/js/*, e2e/ts/*
End-to-end packages replace Jest dependencies and configuration with Vitest setup and test files.
Source spec migration and validation coverage
src/**/*.spec.ts, src/request/email.ts
Source specs import Vitest APIs, replace Jest mocking, add constructor validation cases, and annotate branches excluded from coverage.
WebServiceClient test updates
src/webServiceClient.spec.ts
Tests update fetch parameter typing, legacy timeout coverage, error-cause assertions, and non-Error rejection handling.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

Suggested reviewers: kevcenteno, oschwald

Poem

I’m a rabbit with tests in my paws,
Vitest now hops where Jest once was.
Coverage blooms, configs align,
Errors reveal their causes fine.
CI runs bright through every lane—
Hop, hop, green checks again!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing Jest with Vitest across tests, config, and CI.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jest-to-vitest

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/request/email.ts`:
- Around line 385-387: Update both V8 ignore sites in the email validation logic
around localPart to use the exact directive form `/* v8 ignore else -- `@preserve`
*/`, preserving the existing branch exclusions through esbuild.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: dbe23dda-26ad-4163-9c6c-8eeffc51d528

📥 Commits

Reviewing files that changed from the base of the PR and between 028bea5 and 436fc9b.

⛔ Files ignored due to path filters (3)
  • e2e/js/package-lock.json is excluded by !**/package-lock.json
  • e2e/ts/package-lock.json is excluded by !**/package-lock.json
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (34)
  • .github/workflows/test.yml
  • CLAUDE.md
  • e2e/js/index.spec.js
  • e2e/js/package.json
  • e2e/js/vitest.config.js
  • e2e/ts/index.spec.ts
  • e2e/ts/jest.config.js
  • e2e/ts/package.json
  • e2e/ts/tsconfig.json
  • e2e/ts/vitest.config.ts
  • eslint.config.mjs
  • jest.config.js
  • package.json
  • src/errors.spec.ts
  • src/request/account.spec.ts
  • src/request/billing.spec.ts
  • src/request/credit-card.spec.ts
  • src/request/custom-input.spec.ts
  • src/request/device.spec.ts
  • src/request/email.spec.ts
  • src/request/email.ts
  • src/request/event.spec.ts
  • src/request/location.spec.ts
  • src/request/order.spec.ts
  • src/request/payment.spec.ts
  • src/request/shipping.spec.ts
  • src/request/shopping-cart-item.spec.ts
  • src/request/transaction-report.spec.ts
  • src/request/transaction.spec.ts
  • src/response/models/insights.spec.ts
  • src/utils.spec.ts
  • src/webServiceClient.spec.ts
  • tsconfig.test.json
  • vitest.config.ts
💤 Files with no reviewable changes (2)
  • jest.config.js
  • e2e/ts/jest.config.js

Comment thread src/request/email.ts
The Vitest docs recommend this form so the hints survive transforms
that strip comments. The current Oxc-based transform keeps them either
way, but the documented behavior is comment stripping, so a future
toolchain change could silently invalidate plain hints.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants