Skip to content

fix(deps): migrate off jest/ts-jest to vitest - #419

Merged
cdmren merged 2 commits into
mainfrom
cdm/migrate-to-vitest
Aug 5, 2026
Merged

fix(deps): migrate off jest/ts-jest to vitest#419
cdmren merged 2 commits into
mainfrom
cdm/migrate-to-vitest

Conversation

@cdmren

@cdmren cdmren commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

AI Slop

ts-jest@29.4.12 (latest) requires typescript: >=4.3 <7, so TypeScript 7
(bumped in #407) breaks every test suite. #418 fixes this by pinning
typescript back to ^6; this PR takes a different angle since the team
is moving off jest anyway: swap the test runner to vitest.

Vitest uses esbuild to strip types rather than going through the TS
compiler API the way ts-jest does, so it has no such version constraint —
typescript stays on ^7.0.2 here.

Changes:

  • Replace jest/ts-jest/@types/jest with vitest
  • Add vitest.config.ts (environment: "node", mockReset: true,
    mirroring the old jest.config.js)
  • Swap @jest/globals imports for vitest imports across all test files;
    jest.fn/jest.spyOnvi.fn/vi.spyOn

Verified locally: yarn build and yarn test both pass (8/8 suites,
44/44 tests).

Only one of #418 / this PR should merge — they fix the same failure two
different ways.

ts-jest (latest 29.4.12) requires typescript <7, which is what's
breaking the build check on main and every PR rebased onto it (see
#407, #417). Rather than pin typescript back, this swaps the test
runner: vitest uses esbuild to strip types instead of going through
the TS compiler API, so it has no such constraint and typescript can
stay on ^7.0.2.

- Replace jest/ts-jest/@types/jest with vitest
- Add vitest.config.ts (environment: node, mockReset: true, mirroring
  the old jest config)
- Swap @jest/globals imports for vitest imports across all test files;
  jest.fn/jest.spyOn -> vi.fn/vi.spyOn

Verified locally: yarn build and yarn test both pass (8/8 suites,
44/44 tests).
cdmren added a commit that referenced this pull request Aug 4, 2026
ts-jest (latest 29.4.12) requires typescript <7, which is what's
breaking the build check on main and every PR rebased onto it (see
#407, #417). This is a third angle on the same fix (alongside #418
and #419): move off Node/yarn/jest entirely in favor of bun, whose
built-in test runner transpiles TS itself and has no such constraint,
so typescript stays on ^7.0.2.

- Replace yarn.lock with bun.lock; drop .nvmrc in favor of
  .bun-version
- Drop jest/ts-jest/@types/jest; add @types/bun for bun:test's types
- package.json test script: "bun test"
- Test files: swap @jest/globals imports for bun:test's native
  mock/spyOn, and add explicit beforeEach(() => mock.clearAllMocks())
  where mocks carry state across tests, since bun doesn't have jest's
  resetMocks/vitest's mockReset config equivalent
- with-cache.test.ts: expect(async () => {...}).rejects.toThrow()
  doesn't work under bun (it requires an actual Promise, not a
  function reference, unlike jest/vitest which auto-invoke); changed
  to pass the invoked promise directly
- CI/example/release workflows: swap actions/setup-node + yarn for
  oven-sh/setup-bun + bun
- .releaserc.yaml: prepareCmd now runs bun instead of yarn

Verified locally: bun install, bun test (44/44 across 8 files), and
bun run build (tsc + ncc) all pass.
@cdmren
cdmren marked this pull request as ready for review August 4, 2026 16:40
@cdmren
cdmren requested a review from a team as a code owner August 4, 2026 16:40
@cdmren
cdmren requested review from jleichty-ren and pbrisbin and removed request for a team and jleichty-ren August 4, 2026 16:40
pbrisbin
pbrisbin previously approved these changes Aug 4, 2026
@cdmren

cdmren commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Fixed conflicts in the lock file

@cdmren
cdmren enabled auto-merge (squash) August 5, 2026 19:48
@cdmren
cdmren disabled auto-merge August 5, 2026 19:48
@cdmren
cdmren enabled auto-merge (squash) August 5, 2026 19:49

@pbrisbin pbrisbin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM as a straight jest/vitest port.

FWIW, in general we are using the vitest globals so you don't need to import describe-et-al. You can see that setup in typescript-action-template.

@cdmren
cdmren merged commit 3983c60 into main Aug 5, 2026
21 checks passed
@cdmren
cdmren deleted the cdm/migrate-to-vitest branch August 5, 2026 19:55
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