Skip to content

Migrate Jest to vitest#1745

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

Migrate Jest to vitest#1745
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 unit and end-to-end test execution from Jest to Vitest, with Vitest-based coverage and watch flows.
    • Added dedicated coverage command with enforced thresholds and improved test discovery.
    • Updated test files to use Vitest helpers explicitly and tightened TypeScript test typing.
    • Adjusted coverage handling for unreachable code paths and strengthened API client assertions (omitted fields, invalid JSON error causes).
  • Documentation
    • Updated repository testing guidance and commands to reflect Vitest.
  • Quality/Tooling
    • Updated linting configuration to remove Jest-specific globals.

Vitest is ESM-native and transforms TypeScript itself, removing the need
for ts-jest and the --experimental-vm-modules workaround. Spec files now
import the test API explicitly. A new test:coverage script runs coverage
with the thresholds carried over from the Jest config; CI uses it
instead of "npm test --coverage", which never actually forwarded the
flag to Jest.
The v8 provider counts branches that Jest's istanbul instrumentation did
not (and the old CI invocation never enforced the thresholds). Add a
test for Insights responses without an anonymizer record, and mark two
defensive branches unreachable from the public API with v8 ignore
hints.
Each suite gets a minimal local Vitest config; without one, Vitest
resolves the root config and its src-only include pattern. Jest globals
are no longer referenced anywhere, so they leave the ESLint config.
ts-jest ran in transpile-only mode, so spec files were never fully
type-checked, and the root tsconfig excludes them. Repurpose
tsconfig.test.json (previously only used by ts-jest) for a dedicated tsc
pass in the lint script. This surfaced a reference to the DOM-only
RequestInfo type, now derived from fetch itself.
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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fcb7c802-5d9d-4d86-9cdf-c4e567341ec9

📥 Commits

Reviewing files that changed from the base of the PR and between b93623e and 134a08d.

📒 Files selected for processing (2)
  • src/reader.ts
  • src/utils.ts

📝 Walkthrough

Walkthrough

The repository’s test tooling is migrated from Jest to Vitest, including root and end-to-end configurations, scripts, CI workflows, TypeScript settings, ESLint globals, test imports, coverage directives, and web client test assertions.

Changes

Vitest migration

Layer / File(s) Summary
Root test tooling and coverage
package.json, vitest.config.ts, tsconfig.test.json, eslint.config.mjs, src/*, CLAUDE.md
Root scripts and configuration now use Vitest, Jest typings and globals are removed, source tests import Vitest helpers, and coverage exclusions are added for unreachable paths.
End-to-end and CI test execution
.github/workflows/test.yml, e2e/js/*, e2e/ts/*
Both end-to-end suites use Vitest dependencies and isolated configurations, and CI invokes Vitest plus the dedicated coverage script.
Web client test validation
src/webServiceClient.spec.ts
Fetch request typing is tightened, missing anonymizer data is tested, and invalid JSON assertions verify SyntaxError causes.

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

Possibly related PRs

Suggested reviewers: oschwald, kevcenteno

Poem

I’m a rabbit with tests in my den,
Vitest hops where Jest once had been.
Coverage blooms bright,
CI runs just right,
And green little checks dance 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 clearly summarizes the main change: migrating the test stack from Jest to Vitest.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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.

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