June 20, 2026 • 1 min read
Why I Migrated From Jest to Vitest
ESM packages broke Jest. Tried to fix it. Could not. Switched to Vitest.
TL;DR
Supertest v7 and @thallesp/nestjs-better-auth are ESM-only. Jest could not load them. Tried transformIgnorePatterns. Did not work. Switched to Vitest.
- vitest
- jest
- testing
- typescript
- nestjs
Two packages I needed were ESM-only. Jest could not load them. I tried transformIgnorePatterns. It partially worked for one but not the other. Switched to Vitest. Everything worked immediately.
Uninstalled Jest. Installed Vitest. Rewrote configs.
// vitest.unit.config.ts
import { defineConfig, mergeConfig } from "vitest/config";
import baseConfig from "./vitest.base";
export default mergeConfig(
baseConfig,
defineConfig({
test: { include: ["src/**/*.unit.spec.ts"] },
}),
);
Unit config uses the default threads pool. Fast, no Docker.
// vitest.it.config.ts
import { defineConfig, mergeConfig } from "vitest/config";
import baseConfig from "./vitest.base";
export default mergeConfig(
baseConfig,
defineConfig({
test: {
include: ["test/**/*.it.spec.ts"],
pool: "forks",
testTimeout: 120_000,
},
}),
);
Unit and integration configs split by include pattern. Same assertions. Different imports. Auth tests passed immediately. CI scripts changed from jest to vitest.
One gotcha: Nest’s tsconfig.build.json does not exclude vitest*.ts by default. The import.meta in vitest configs breaks the build. Added it manually.
{
"exclude": ["node_modules", "dist", "vitest*.ts"]
}