Skip to content

refactor(test): jest -> vitest - #165

Merged
github-actions[bot] merged 1 commit into
mainfrom
refactor/jest-to-vitest
Aug 29, 2026
Merged

refactor(test): jest -> vitest#165
github-actions[bot] merged 1 commit into
mainfrom
refactor/jest-to-vitest

Conversation

@catomean

Copy link
Copy Markdown
Collaborator

Jest is CJS-rooted, needs transform configuration for ESM and TypeScript, and every shared CI template has to accommodate its dialect. vitest is ESM/TS native and jest-compatible at the API level.

Verified locally before pushing: 272 passed, 2 skipped, 23 files.

Keeping the diff small

globals: true keeps describe/it/expect/beforeEach/vi available without imports, so the diff is the jest.* API names and nothing else. Only types had to be imported, because a type cannot come from a global.

next/jest supplied the path alias, the next/server mock and the jsdom environment implicitly — vitest.config.ts now states them, so they are visible rather than inherited.

The transformIgnorePatterns override for ESM-only packages (ai-kit) is deleted rather than translated. Jest ran CJS and died on Unexpected token 'export', which is the entire reason that workaround existed; vitest loads ESM natively.

Three things only running the suite could have found

__mocks__/next/server.ts was outside the first rewrite pass every test importing it died with jest is not defined
vitest builds a mocked constructor with Reflect.construct, and an arrow function is not constructible vi.fn().mockImplementation(() => ({…})) threw "is not a constructor" the moment the code did new SESClient(). Jest tolerated it — two mocks needed function expressions
removing @types/jest took the global describe/it/expect declarations with it tsconfig now carries "types": ["vitest/globals"]

Each of those passed a source review and failed a test run. That is the argument for doing this repo by repo with the suite actually executing, rather than as a fleet-wide sweep.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UvjGNAS9CMfEGNW26tUR4P

Jest is CJS-rooted, needs transform configuration for ESM and TypeScript, and
every shared CI template has to accommodate its dialect. vitest is ESM/TS
native and jest-compatible at the API level.

`globals: true` keeps describe/it/expect/beforeEach/vi available without
imports, so the diff is the jest.* API names and nothing else. Only TYPES had
to be imported, because a type cannot come from a global.

next/jest supplied the path alias, the next/server mock and the jsdom
environment implicitly; vitest.config.ts states them, so they are visible
rather than inherited. The transformIgnorePatterns override for ESM-only
packages (ai-kit) is DELETED rather than translated — jest ran CJS and died on
`Unexpected token export`, which is the entire reason that workaround existed.
vitest loads ESM natively.

Three things only running the suite could have found:

  * __mocks__/next/server.ts was outside the first rewrite pass, so every test
    importing it died with `jest is not defined`.
  * vitest builds a mocked constructor with Reflect.construct, and an ARROW
    function is not constructible — `vi.fn().mockImplementation(() => ({...}))`
    threw "is not a constructor" the moment the code did `new SESClient()`.
    jest tolerated it. Two mocks needed function expressions.
  * removing @types/jest took the global describe/it/expect declarations with
    it; tsconfig now carries "types": ["vitest/globals"].

Verified locally before pushing: 272 passed, 2 skipped, 23 files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UvjGNAS9CMfEGNW26tUR4P
@github-actions
github-actions Bot merged commit 62e055a into main Aug 29, 2026
1 check passed
@github-actions
github-actions Bot deleted the refactor/jest-to-vitest branch August 29, 2026 09:15
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.

1 participant