mirror of
https://github.com/bitbaum/botsmann.git
synced 2026-12-04 05:08:02 +01:00
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>
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { defineConfig } from 'vitest/config';
|
|
import path from 'node:path';
|
|
|
|
/**
|
|
* Replaces jest.config.js + next/jest.
|
|
*
|
|
* next/jest supplied the path alias, the next/server mock and the jsdom
|
|
* environment implicitly; vitest wants them stated, so they are visible here
|
|
* rather than inherited.
|
|
*
|
|
* The old config carried a transformIgnorePatterns override for ESM-only
|
|
* packages (ai-kit), because jest runs CJS and died on `Unexpected token
|
|
* 'export'`. vitest loads ESM natively, so that workaround is gone rather
|
|
* than translated.
|
|
*/
|
|
export default defineConfig({
|
|
test: {
|
|
// Keeps describe/it/expect/beforeEach/vi global, so the migration touched
|
|
// only the jest.* API names and not every import line in the suite.
|
|
globals: true,
|
|
environment: 'jsdom',
|
|
setupFiles: ['./vitest.setup.ts'],
|
|
include: ['tests/**/*.test.{ts,tsx,js,jsx}'],
|
|
},
|
|
resolve: {
|
|
alias: [
|
|
// was moduleNameMapper: '^next/server$'
|
|
{
|
|
find: /^next\/server$/,
|
|
replacement: path.resolve(__dirname, './__mocks__/next/server.ts'),
|
|
},
|
|
// was moduleNameMapper: '^@/(.*)$'
|
|
{ find: /^@\//, replacement: path.resolve(__dirname, './') + '/' },
|
|
],
|
|
},
|
|
});
|