Files
botsmann/__mocks__/next
GandClaude Opus 5 9cf91812aa refactor(test): jest -> vitest (#165)
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.


Claude-Session: https://claude.ai/code/session_01UvjGNAS9CMfEGNW26tUR4P

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-29 09:15:12 +00:00
..