Skip to content

Migrate jest to vitest#573

Merged
korthout merged 10 commits intomainfrom
korthout-migrate-jest-to-vitest
Mar 19, 2026
Merged

Migrate jest to vitest#573
korthout merged 10 commits intomainfrom
korthout-migrate-jest-to-vitest

Conversation

@korthout
Copy link
Owner

Jest requires --experimental-vm-modules for ESM support, relies on jest.unstable_mockModule for mocking ES modules, and needs ts-jest as a separate transform layer for TypeScript. This adds configuration complexity (NODE_OPTIONS, moduleNameMapper, tsconfig.test.json) and builds on unstable Node.js APIs.

Vitest has native ESM and TypeScript support, stable ESM mocking via vi.mock(), and requires minimal configuration. Its Jest-compatible API (describe/it/expect) means existing tests need few changes. It replaces three dev dependencies (jest, ts-jest, @types/jest) with one (vitest). Additionally, Vitest is much faster than jest which will help running tests in agent sessions.

node:test was considered as a zero-dependency alternative but requires rewriting all assertions from expect() to node:assert and needs a TypeScript loader. Given planned test coverage expansion, Vitest's lower migration cost and richer API make it the better choice.

korthout and others added 9 commits March 19, 2026 11:21
Jest requires --experimental-vm-modules for ESM support, relies on
jest.unstable_mockModule for mocking ES modules, and needs ts-jest as a
separate transform layer for TypeScript. This adds configuration
complexity (NODE_OPTIONS, moduleNameMapper, tsconfig.test.json) and
builds on unstable Node.js APIs.

Vitest has native ESM and TypeScript support, stable ESM mocking via
vi.mock(), and requires minimal configuration. Its Jest-compatible API
(describe/it/expect) means existing tests need few changes. It replaces
three dev dependencies (jest, ts-jest, @types/jest) with one (vitest).
Additionally, Vitest is much faster than jest which will help running
tests in agent sessions.

node:test was considered as a zero-dependency alternative but requires
rewriting all assertions from expect() to node:assert and needs a
TypeScript loader. Given planned test coverage expansion, Vitest's lower
migration cost and richer API make it the better choice.
Remove jest, ts-jest, @types/jest and add vitest, @types/node.
Replace jest.config.ts with vitest.config.ts. Update tsconfig
files and npm scripts accordingly.

Vitest has native ESM and TypeScript support, eliminating the
need for --experimental-vm-modules, ts-jest transforms, and
moduleNameMapper workarounds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add explicit import of describe, it, expect from vitest.
This file has no mocking — only the import line changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace @jest/globals with vitest imports. Convert
jest.unstable_mockModule to vi.mock and jest.fn to vi.fn.
The dynamic await import() pattern is preserved — it works
with Vitest and ensures the mock is applied before module load.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add explicit import of describe, it, expect from vitest.
This file has no mocking — only the import line changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
All automated and manual verification checks pass:
- 53 tests across 3 files pass with vitest
- Build, format-check, and package all succeed
- No jest packages remain in dependency tree

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The plan has been implemented. The thoughts could go out of date. Best
to rebuild them in the moment.
@korthout korthout requested a review from Copilot March 19, 2026 10:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the repository’s TypeScript ESM test setup from Jest/ts-jest to Vitest to reduce configuration complexity and improve test execution speed.

Changes:

  • Add Vitest configuration and switch npm test scripts to vitest run.
  • Remove Jest configuration and Jest-specific TypeScript typings/config references.
  • Update existing tests to use Vitest APIs (vitest imports, vi.mock).

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.config.ts Adds Vitest test runner configuration (root under src, mock clearing).
package.json Replaces Jest/ts-jest dependencies and scripts with Vitest equivalents.
jest.config.ts Removes Jest configuration entirely.
tsconfig.test.json Drops Jest typings/config inclusion for the test TS config.
tsconfig.json Updates build excludes to avoid compiling the new Vitest config file.
src/test/utils.test.ts Imports describe/it/expect from Vitest.
src/test/backport.test.ts Imports describe/it/expect from Vitest.
src/test/git.test.ts Replaces Jest ESM mocking with vi.mock and updates imports accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

The outDir in tsconfig.test.json was a leftover reference to Jest.
This path is unused (Vitest uses esbuild, not tsc, for test
transformation) but renaming it avoids confusion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@korthout korthout requested a review from Copilot March 19, 2026 11:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates the project’s TypeScript/ESM test setup from Jest + ts-jest to Vitest to reduce configuration complexity and improve test run performance.

Changes:

  • Add vitest.config.ts and switch package.json test scripts/devDependencies to Vitest.
  • Remove Jest configuration and Jest-specific TypeScript settings.
  • Update existing tests to use Vitest APIs (vi.mock, describe/it/expect imports).

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vitest.config.ts Introduces Vitest configuration (test root + mock behavior).
tsconfig.test.json Removes Jest types/config include; adjusts test build output folder.
tsconfig.json Replaces Jest config exclusion with Vitest config exclusion.
src/test/utils.test.ts Imports Vitest test APIs.
src/test/git.test.ts Replaces Jest ESM mocking with vi.mock and updates imports.
src/test/backport.test.ts Imports Vitest test APIs.
package.json Updates test scripts and replaces Jest/ts-jest deps with Vitest.
jest.config.ts Removes Jest configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@korthout korthout merged commit 710c359 into main Mar 19, 2026
5 checks passed
@korthout korthout deleted the korthout-migrate-jest-to-vitest branch March 19, 2026 11:22
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.

2 participants