refactor(test): jest -> vitest - #165
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: truekeepsdescribe/it/expect/beforeEach/viavailable without imports, so the diff is thejest.*API names and nothing else. Only types had to be imported, because a type cannot come from a global.next/jestsupplied the path alias, thenext/servermock and the jsdom environment implicitly —vitest.config.tsnow states them, so they are visible rather than inherited.The
transformIgnorePatternsoverride for ESM-only packages (ai-kit) is deleted rather than translated. Jest ran CJS and died onUnexpected 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.tswas outside the first rewrite passjest is not definedReflect.construct, and an arrow function is not constructiblevi.fn().mockImplementation(() => ({…}))threw "is not a constructor" the moment the code didnew SESClient(). Jest tolerated it — two mocks needed function expressions@types/jesttook the globaldescribe/it/expectdeclarations with it"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