Migrate from Jest to Vitest
✓Works with OpenClaudeYou are a JavaScript testing framework migration specialist. The user wants to migrate their test suite from Jest to Vitest while maintaining test coverage and functionality.
What to check first
- Run
npm list jestto identify Jest version and confirm it's installed - Check
jest.config.jsorjestfield inpackage.jsonto see current Jest configuration - Run
npm test -- --listTeststo see how many test files exist - Verify Node.js version is 14.18+ (required for Vitest)
Steps
- Install Vitest and required dependencies:
npm install -D vitest @vitest/ui(and@vitest/coverage-v8if using coverage) - Create
vitest.config.tsin the project root, copying relevant settings fromjest.config.js(test environment, moduleNameMapper, setupFilesAfterEnv, etc.) - Update
package.jsontest script from"jest"to"vitest"and add"test:ui": "vitest --ui"for debugging - Replace Jest imports in all test files: change
import { describe, it, expect } from '@jest/globals'toimport { describe, it, expect } from 'vitest' - Replace Jest-specific matchers: change
.toHaveBeenCalledWith()to.toHaveBeenCalledWith()(same API), but updatejest.mock()tovi.mock()andjest.spyOn()tovi.spyOn() - Update setup files: rename
setupFilesAfterEnvreferences and ensure they use Vitest hooks likebeforeAll,afterEachfrom vitest - Migrate moduleNameMapper for path aliases: convert Jest's string patterns to Vitest's resolver format in
vitest.config.ts - Run
npm testand fix failing tests by updating Jest-specific globals (removejest.useFakeTimers(), usevi.useFakeTimers()instead)
Code
// vitest.config.ts
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import path from 'path'
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'jsdom',
setupFiles: ['./src/setupTests.ts'],
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html'],
},
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@components': path.resolve(__dirname, './src/components'),
},
},
})
// src/setupTests.ts (updated from Jest setup)
import { expect, afterEach, vi } from 'vitest'
import { cleanup } from '@
Note: this example was truncated in the source. See the GitHub repo for the latest full version.
Common Pitfalls
- Treating this skill as a one-shot solution — most workflows need iteration and verification
- Skipping the verification steps — you don't know it worked until you measure
- Applying this skill without understanding the underlying problem — read the related docs first
When NOT to Use This Skill
- When a simpler manual approach would take less than 10 minutes
- On critical production systems without testing in staging first
- When you don't have permission or authorization to make these changes
How to Verify It Worked
- Run the verification steps documented above
- Compare the output against your expected baseline
- Check logs for any warnings or errors — silent failures are the worst kind
Production Considerations
- Test in staging before deploying to production
- Have a rollback plan — every change should be reversible
- Monitor the affected systems for at least 24 hours after the change
Related Migration & Upgrades Skills
Other Claude Code skills in the same category — free to download.
Node Upgrade
Upgrade Node.js version with compatibility fixes
React Upgrade
Upgrade React to latest version
Next.js Migration
Migrate from Pages Router to App Router
TypeScript Migration
Migrate JavaScript project to TypeScript
CJS to ESM
Convert CommonJS to ES Modules
Webpack to Vite
Migrate from Webpack to Vite
Database Migration
Migrate between databases
Want a Migration & Upgrades skill personalized to YOUR project?
This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.