<objective Expert guidance for migrating from Jest to Vitest and working with the Vitest testing framework. This skill focuses primarily on automated migration from Jest while covering setup, configuration, and best practices. Key benefits of Vitest over Jest: - 2-10x faster test startup (built on Vite and esbuild) - Native TypeScript support without ts-jest - Hot Module Replacement for instant re-runs - Jest-compatible API requiring minimal code changes - Modern ESM-first architecture </objective <quick start <automated migration RECOMMENDED APPROACH : Use automated codemods for fastest migr…

: '\u003crootDir>/src/$1'\n }\n}\n\n// vitest.config.ts (Vitest)\nimport { defineConfig } from 'vitest/config'\n\nexport default defineConfig({\n test: {\n environment: 'jsdom',\n setupFiles: ['./vitest.setup.ts'],\n include: ['**/*.test.js'],\n },\n resolve: {\n alias: {\n '@': '/src'\n }\n }\n})\n```\n\n#### Configuration Property Mapping\n\n| Jest | Vitest | Notes |\n|------|--------|-------|\n| `testEnvironment` | `test.environment` | Same values |\n| `setupFiles` | `test.setupFiles` | Identical |\n| `setupFilesAfterEnv` | `test.setupFiles` | No distinction |\n| `testMatch` | `test.include` | Different syntax |\n| `testPathIgnorePatterns` | `test.exclude` | Use glob patterns |\n| `moduleNameMapper` | `resolve.alias` | Different format |\n| `transform` | ❌ Use Vite plugins | Not needed |\n| `globals` | `test.globals` | Enable for compatibility |\n| `coverageDirectory` | `test.coverage.reportsDirectory` | Different nesting |\n| `coverageReporters` | `test.coverage.reporter` | Same values |\n| `collectCoverageFrom` | `test.coverage.include` | Use glob patterns |\n| `coveragePathIgnorePatterns` | `test.coverage.exclude` | Use glob patterns |\n| `testTimeout` | `test.testTimeout` | Identical |\n| `clearMocks` | `test.clearMocks` | Identical |\n| `resetMocks` | `test.mockReset` | Identical |\n| `restoreMocks` | `test.restoreMocks` | Identical |\n| `verbose` | ❌ Use reporters | Different approach |\n| `maxWorkers` | `test.maxWorkers` | Identical |\n| `bail` | `test.bail` | Identical |\n\n### Environment Configuration\n\n```typescript\n// Jest\n{\n testEnvironment: 'jsdom',\n testEnvironmentOptions: {\n url: 'http://localhost'\n }\n}\n\n// Vitest\n{\n test: {\n environment: 'jsdom', // or 'happy-dom' for faster alternative\n environmentOptions: {\n jsdom: {\n url: 'http://localhost'\n }\n }\n }\n}\n```\n\n### Path Aliases\n\n```typescript\n// Jest\n{\n moduleNameMapper: {\n '^@/(.*)

<objective Expert guidance for migrating from Jest to Vitest and working with the Vitest testing framework. This skill focuses primarily on automated migration from Jest while covering setup, configuration, and best practices. Key benefits of Vitest over Jest: - 2-10x faster test startup (built on Vite and esbuild) - Native TypeScript support without ts-jest - Hot Module Replacement for instant re-runs - Jest-compatible API requiring minimal code changes - Modern ESM-first architecture </objective <quick start <automated migration RECOMMENDED APPROACH : Use automated codemods for fastest migr…

: '\u003crootDir>/src/$1',\n '^@components/(.*)

<objective Expert guidance for migrating from Jest to Vitest and working with the Vitest testing framework. This skill focuses primarily on automated migration from Jest while covering setup, configuration, and best practices. Key benefits of Vitest over Jest: - 2-10x faster test startup (built on Vite and esbuild) - Native TypeScript support without ts-jest - Hot Module Replacement for instant re-runs - Jest-compatible API requiring minimal code changes - Modern ESM-first architecture </objective <quick start <automated migration RECOMMENDED APPROACH : Use automated codemods for fastest migr…

: '\u003crootDir>/src/components/$1',\n '\\\\.(css|less|scss)

<objective Expert guidance for migrating from Jest to Vitest and working with the Vitest testing framework. This skill focuses primarily on automated migration from Jest while covering setup, configuration, and best practices. Key benefits of Vitest over Jest: - 2-10x faster test startup (built on Vite and esbuild) - Native TypeScript support without ts-jest - Hot Module Replacement for instant re-runs - Jest-compatible API requiring minimal code changes - Modern ESM-first architecture </objective <quick start <automated migration RECOMMENDED APPROACH : Use automated codemods for fastest migr…

: 'identity-obj-proxy'\n }\n}\n\n// Vitest\nimport path from 'path'\n\n{\n resolve: {\n alias: {\n '@': path.resolve(__dirname, './src'),\n '@components': path.resolve(__dirname, './src/components'),\n }\n },\n // For CSS modules, no need for identity-obj-proxy\n // Vitest handles CSS imports automatically\n}\n```\n\n### Transform Configuration\n\nJest's `transform` is NOT needed in Vitest. Vite handles transformations automatically.\n\n```typescript\n// Jest (NOT needed in Vitest)\n{\n transform: {\n '^.+\\\\.tsx?

<objective Expert guidance for migrating from Jest to Vitest and working with the Vitest testing framework. This skill focuses primarily on automated migration from Jest while covering setup, configuration, and best practices. Key benefits of Vitest over Jest: - 2-10x faster test startup (built on Vite and esbuild) - Native TypeScript support without ts-jest - Hot Module Replacement for instant re-runs - Jest-compatible API requiring minimal code changes - Modern ESM-first architecture </objective <quick start <automated migration RECOMMENDED APPROACH : Use automated codemods for fastest migr…

: 'ts-jest',\n '^.+\\\\.jsx?

<objective Expert guidance for migrating from Jest to Vitest and working with the Vitest testing framework. This skill focuses primarily on automated migration from Jest while covering setup, configuration, and best practices. Key benefits of Vitest over Jest: - 2-10x faster test startup (built on Vite and esbuild) - Native TypeScript support without ts-jest - Hot Module Replacement for instant re-runs - Jest-compatible API requiring minimal code changes - Modern ESM-first architecture </objective <quick start <automated migration RECOMMENDED APPROACH : Use automated codemods for fastest migr…

: 'babel-jest'\n }\n}\n\n// Vitest - automatic, no configuration needed!\n// For special transforms, use Vite plugins instead\n{\n plugins: [\n myCustomVitePlugin()\n ]\n}\n```\n\n### Coverage Configuration\n\n```typescript\n// Jest\n{\n collectCoverage: true,\n coverageDirectory: 'coverage',\n coverageReporters: ['text', 'lcov', 'html'],\n collectCoverageFrom: [\n 'src/**/*.{js,ts}',\n '!src/**/*.d.ts'\n ],\n coveragePathIgnorePatterns: [\n '/node_modules/',\n '/dist/'\n ],\n coverageThreshold: {\n global: {\n branches: 80,\n functions: 80,\n lines: 80,\n statements: 80\n }\n }\n}\n\n// Vitest\n{\n test: {\n coverage: {\n enabled: true, // or use --coverage flag\n provider: 'v8', // or 'istanbul' to match Jest\n reportsDirectory: './coverage',\n reporter: ['text', 'lcov', 'html'],\n include: ['src/**/*.{js,ts}'],\n exclude: [\n 'node_modules/',\n 'dist/',\n '**/*.d.ts'\n ],\n thresholds: {\n branches: 80,\n functions: 80,\n lines: 80,\n statements: 80\n }\n }\n }\n}\n```\n\n## Common Migration Patterns\n\n### Pattern 1: Mocking Modules\n\n```typescript\n// Jest\njest.mock('./api', () => ({\n fetchUser: jest.fn()\n}))\n\n// Vitest - identical!\nvi.mock('./api', () => ({\n fetchUser: vi.fn()\n}))\n```\n\n### Pattern 2: Mocking with Implementation\n\n```typescript\n// Jest\nconst mockFetch = jest.fn()\nmockFetch.mockImplementation(() =>\n Promise.resolve({ json: () => ({ data: 'test' }) })\n)\n\n// Vitest - identical!\nconst mockFetch = vi.fn()\nmockFetch.mockImplementation(() =>\n Promise.resolve({ json: () => ({ data: 'test' }) })\n)\n```\n\n### Pattern 3: Partial Module Mocking\n\n```typescript\n// Jest\njest.mock('./utils', () => ({\n ...jest.requireActual('./utils'),\n specificFn: jest.fn()\n}))\n\n// Vitest - note async!\nvi.mock('./utils', async () => ({\n ...await vi.importActual('./utils'),\n specificFn: vi.fn()\n}))\n```\n\n### Pattern 4: Auto-Mocking Dependencies\n\n```typescript\n// Jest - auto-mocks __mocks__ directory\n// __mocks__/api.js exists, automatically used\n\n// Vitest - must explicitly mock\n// __mocks__/api.js\nexport const fetchUser = vi.fn()\n\n// test file\nvi.mock('./api') // Now uses __mocks__/api.js\n```\n\n### Pattern 5: Callback-Based Tests\n\n```typescript\n// Jest - supports done callback\ntest('async operation', (done) => {\n doAsync(() => {\n expect(true).toBe(true)\n done()\n })\n})\n\n// Vitest - use async/await\ntest('async operation', async () => {\n await new Promise(resolve => {\n doAsync(() => {\n expect(true).toBe(true)\n resolve()\n })\n })\n})\n```\n\n### Pattern 6: beforeEach/afterEach Cleanup\n\n```typescript\n// Jest & Vitest - identical!\nbeforeEach(() => {\n // Setup\n})\n\nafterEach(() => {\n // Cleanup\n vi.clearAllMocks() // or jest.clearAllMocks()\n})\n```\n\n### Pattern 7: Snapshot Testing\n\n```typescript\n// Jest & Vitest - identical!\ntest('component snapshot', () => {\n const result = render(\u003cComponent />)\n expect(result).toMatchSnapshot()\n})\n\n// Update snapshots: npm run test -- -u\n```\n\n## Troubleshooting Guide\n\n### Issue: \"vi is not defined\"\n\n**Cause**: Not importing `vi` from vitest\n\n**Solution**:\n\n```typescript\n// Add import\nimport { vi } from 'vitest'\n\n// OR enable globals\n// vitest.config.ts\nexport default defineConfig({\n test: { globals: true }\n})\n\n// tsconfig.json\n{\n \"compilerOptions\": {\n \"types\": [\"vitest/globals\"]\n }\n}\n```\n\n### Issue: \"Cannot find module '@testing-library/jest-dom'\"\n\n**Cause**: Package name didn't change, but imports might need updating\n\n**Solution**:\n\n```typescript\n// Keep jest-dom package\nnpm install -D @testing-library/jest-dom\n\n// Import in setup file\n// vitest.setup.ts\nimport '@testing-library/jest-dom'\n\n// OR for explicit imports\nimport '@testing-library/jest-dom/vitest'\n```\n\n### Issue: \"cleanup not running automatically\"\n\n**Cause**: With `globals: false`, testing-library auto-cleanup disabled\n\n**Solution**:\n\n```typescript\n// vitest.setup.ts\nimport { cleanup } from '@testing-library/react'\nimport { afterEach } from 'vitest'\n\nafterEach(() => {\n cleanup()\n})\n```\n\n### Issue: \"Mock not resetting between tests\"\n\n**Cause**: `mockReset` behavior difference or missing config\n\n**Solution**:\n\n```typescript\n// Option 1: Configure auto-reset\n// vitest.config.ts\nexport default defineConfig({\n test: {\n clearMocks: true,\n mockReset: true,\n restoreMocks: true,\n }\n})\n\n// Option 2: Manual cleanup\nafterEach(() => {\n vi.clearAllMocks()\n vi.resetAllMocks()\n})\n```\n\n### Issue: \"Snapshots have different formatting\"\n\n**Cause**: Test name separator changed from space to `>`\n\n**Solution**:\n\n```bash\n# Regenerate all snapshots\nnpm run test -- -u\n\n# Or manually update snapshot files\n# Change: \"describe title test title\"\n# To: \"describe title > test title\"\n```\n\n### Issue: \"Path aliases not resolving\"\n\n**Cause**: `moduleNameMapper` not configured in Vitest\n\n**Solution**:\n\n```typescript\n// vitest.config.ts\nimport path from 'path'\n\nexport default defineConfig({\n resolve: {\n alias: {\n '@': path.resolve(__dirname, './src'),\n '@components': path.resolve(__dirname, './src/components'),\n }\n }\n})\n```\n\n### Issue: \"CSS/SCSS imports failing\"\n\n**Cause**: Missing CSS handling configuration\n\n**Solution**:\n\n```typescript\n// Vitest handles CSS automatically, but for CSS modules:\n// vitest.config.ts\nexport default defineConfig({\n css: {\n modules: {\n classNameStrategy: 'non-scoped'\n }\n }\n})\n\n// Or mock CSS imports\nvi.mock('./styles.css', () => ({}))\n```\n\n### Issue: \"Dynamic imports not working\"\n\n**Cause**: Vitest handles dynamic imports differently\n\n**Solution**:\n\n```typescript\n// Ensure using await with vi.importActual\nvi.mock('./module', async () => {\n const actual = await vi.importActual('./module')\n return {\n ...actual,\n override: vi.fn()\n }\n})\n```\n\n### Issue: \"Tests slower than Jest\"\n\n**Cause**: Wrong environment or pool configuration\n\n**Solution**:\n\n```typescript\n// Use faster environment\nexport default defineConfig({\n test: {\n environment: 'happy-dom', // instead of 'jsdom'\n\n // Optimize pool\n pool: 'threads', // or 'forks'\n\n // Reduce isolation overhead\n isolate: false, // use with caution\n\n // Increase parallelism\n maxWorkers: 4,\n }\n})\n```\n\n### Issue: \"beforeAll return value causing issues\"\n\n**Cause**: Vitest interprets return values as cleanup functions\n\n**Solution**:\n\n```typescript\n// Jest - return value ignored\nbeforeAll(() => {\n return someValue\n})\n\n// Vitest - wrap in function body if not cleanup\nbeforeAll(() => {\n const value = someValue\n // Don't return unless it's a cleanup function\n})\n\n// Or explicitly return undefined\nbeforeAll(() => {\n setup()\n return undefined\n})\n```\n\n## Framework-Specific Migrations\n\n### React Testing Library\n\n**Migration**: Mostly seamless!\n\n```typescript\n// No changes needed for most code\nimport { render, screen } from '@testing-library/react'\nimport { describe, test, expect } from 'vitest'\n\ndescribe('Component', () => {\n test('renders', () => {\n render(\u003cComponent />)\n expect(screen.getByText('Hello')).toBeInTheDocument()\n })\n})\n```\n\n**Setup file changes**:\n\n```typescript\n// jest.setup.js → vitest.setup.ts\nimport '@testing-library/jest-dom'\n\n// If globals disabled, add cleanup\nimport { afterEach } from 'vitest'\nimport { cleanup } from '@testing-library/react'\n\nafterEach(() => {\n cleanup()\n})\n```\n\n### Vue Test Utils\n\n**Migration**: Minimal changes\n\n```typescript\n// Works the same way\nimport { mount } from '@vue/test-utils'\nimport { describe, test, expect } from 'vitest'\n\ndescribe('Component', () => {\n test('renders', () => {\n const wrapper = mount(Component)\n expect(wrapper.text()).toContain('Hello')\n })\n})\n```\n\n### Angular Testing\n\n**Migration**: More complex, requires additional setup\n\n```typescript\n// Install Vitest Angular dependencies\nnpm install -D @analogjs/vite-plugin-angular\n\n// vitest.config.ts\nimport { defineConfig } from 'vitest/config'\nimport angular from '@analogjs/vite-plugin-angular'\n\nexport default defineConfig({\n plugins: [angular()],\n test: {\n globals: true,\n environment: 'jsdom',\n setupFiles: ['src/test-setup.ts'],\n },\n})\n```\n\nSee: \u003chttps://cookbook.marmicode.io/angular/testing/migrating-to-vitest>\n\n### Next.js\n\n**Migration**: Requires Vite config adjustments\n\n```typescript\n// vitest.config.ts\nimport { defineConfig } from 'vitest/config'\nimport react from '@vitejs/plugin-react'\nimport path from 'path'\n\nexport default defineConfig({\n plugins: [react()],\n test: {\n environment: 'jsdom',\n setupFiles: './vitest.setup.ts',\n },\n resolve: {\n alias: {\n '@': path.resolve(__dirname, './src'),\n }\n }\n})\n```\n\n### Node.js (Backend) Tests\n\n**Migration**: Very straightforward\n\n```typescript\n// Usually just API changes, no config needed\n// vitest.config.ts\nexport default defineConfig({\n test: {\n environment: 'node', // explicit, though it's default\n }\n})\n```\n\n## Migration Validation Checklist\n\nAfter migration, verify:\n\n- [ ] All tests passing\n- [ ] Coverage reports generated correctly\n- [ ] CI/CD pipeline updated and working\n- [ ] Watch mode functioning\n- [ ] Snapshots regenerated and committed\n- [ ] Mock behaviors correct\n- [ ] TypeScript types working\n- [ ] Import paths resolving\n- [ ] Test execution speed acceptable\n- [ ] No console errors or warnings\n- [ ] Team documentation updated\n- [ ] Old Jest dependencies removed\n\n## Rollback Plan\n\nIf migration fails:\n\n1. **Revert branch**:\n ```bash\n git checkout main\n git branch -D vitest-migration\n ```\n\n2. **Restore package.json**:\n ```bash\n npm install -D jest @types/jest ts-jest\n npm uninstall vitest @vitest/ui\n ```\n\n3. **Keep learnings**: Document issues for future attempts\n\n## Performance Comparison\n\nExpected improvements after migration:\n\n| Metric | Jest | Vitest | Improvement |\n|--------|------|--------|-------------|\n| Cold start | 5-10s | 1-2s | 5x faster |\n| Watch mode reload | 2-5s | \u003c1s | 5x faster |\n| Test execution | Baseline | 1.5-2x faster | 2x faster |\n| TypeScript tests | Slow (ts-jest) | Fast (native) | 10x faster |\n\nNote: Actual improvements vary by project size and complexity.\n\n## Additional Resources\n\n- Vitest migration guide: \u003chttps://vitest.dev/guide/migration>\n- vitest-codemod repo: \u003chttps://github.com/trivikr/vitest-codemod>\n- Vitest vs Jest comparison: \u003chttps://vitest.dev/guide/comparisons>\n- Vitest Discord: \u003chttps://chat.vitest.dev>\n","content_type":"text/markdown; charset=utf-8","language":"markdown","size":20339,"content_sha256":"c0b2f7bb570e17ee6aa91c22ed0f3229a3090a21c6901988425ab2bb94b3f565"},{"filename":"scripts/comprehensive-migrate.sh","content":"#!/bin/bash\n# comprehensive-migrate.sh - Comprehensive Jest to Vitest migration\n# Usage: ./comprehensive-migrate.sh\n\nset -e\n\n# Colors for output\nGREEN='\\033[0;32m'\nYELLOW='\\033[1;33m'\nRED='\\033[0;31m'\nNC='\\033[0m' # No Color\n\nlog_info() {\n echo -e \"${GREEN}[INFO]${NC} $1\"\n}\n\nlog_warn() {\n echo -e \"${YELLOW}[WARN]${NC} $1\"\n}\n\nlog_error() {\n echo -e \"${RED}[ERROR]${NC} $1\"\n}\n\n# Configuration\nBACKUP_BRANCH=\"jest-backup-$(date +%Y%m%d-%H%M%S)\"\nTEST_PATTERNS='src/**/*.{test,spec}.{js,ts,jsx,tsx}'\nUSE_CODEMOD=true\nUSE_HAPPY_DOM=true # Set to false to use jsdom\n\nlog_info \"Starting Jest to Vitest migration\"\n\n# Step 1: Pre-migration checks\nlog_info \"Running pre-migration checks...\"\n\n# Check if git repo\nif ! git rev-parse --git-dir > /dev/null 2>&1; then\n log_error \"Not a git repository. Please initialize git first.\"\n exit 1\nfi\n\n# Check for uncommitted changes\nif ! git diff-index --quiet HEAD --; then\n log_warn \"You have uncommitted changes. Committing them now...\"\n git add -A\n git commit -m \"WIP: Before Vitest migration\"\nfi\n\n# Check if Jest is installed\nif ! npm list jest > /dev/null 2>&1; then\n log_error \"Jest not found in package.json\"\n exit 1\nfi\n\n# Step 2: Create backup branch\nlog_info \"Creating backup branch: $BACKUP_BRANCH\"\ngit branch \"$BACKUP_BRANCH\"\ngit checkout -b \"vitest-migration\"\n\n# Step 3: Run tests with Jest first\nlog_info \"Running Jest tests to verify current state...\"\nif npm run test -- --passWithNoTests; then\n log_info \"Jest tests passed\"\nelse\n log_error \"Jest tests failing. Fix tests before migration.\"\n exit 1\nfi\n\n# Step 4: Detect project type\nlog_info \"Detecting project type...\"\nHAS_REACT=false\nHAS_VUE=false\nHAS_TESTING_LIBRARY=false\n\nif npm list react > /dev/null 2>&1; then\n HAS_REACT=true\n log_info \"Detected React project\"\nfi\n\nif npm list vue > /dev/null 2>&1; then\n HAS_VUE=true\n log_info \"Detected Vue project\"\nfi\n\nif npm list @testing-library/react > /dev/null 2>&1 || npm list @testing-library/vue > /dev/null 2>&1; then\n HAS_TESTING_LIBRARY=true\n log_info \"Detected Testing Library\"\nfi\n\n# Step 5: Backup Jest configuration\nlog_info \"Backing up Jest configuration...\"\nif [ -f \"jest.config.js\" ]; then\n cp jest.config.js jest.config.js.backup\nfi\nif [ -f \"jest.config.ts\" ]; then\n cp jest.config.ts jest.config.ts.backup\nfi\nif [ -f \"jest.setup.js\" ]; then\n cp jest.setup.js jest.setup.js.backup\nfi\nif [ -f \"jest.setup.ts\" ]; then\n cp jest.setup.ts jest.setup.ts.backup\nfi\n\n# Step 6: Remove Jest dependencies\nlog_info \"Removing Jest dependencies...\"\nnpm uninstall \\\n jest \\\n @types/jest \\\n ts-jest \\\n jest-environment-jsdom \\\n @jest/globals \\\n babel-jest \\\n jest-transform-stub \\\n 2>/dev/null || true\n\n# Step 7: Install Vitest dependencies\nlog_info \"Installing Vitest dependencies...\"\n\nDEPS=\"vitest @vitest/ui\"\n\nif [ \"$USE_HAPPY_DOM\" = true ]; then\n DEPS=\"$DEPS happy-dom\"\nelse\n DEPS=\"$DEPS jsdom\"\nfi\n\nif [ \"$HAS_REACT\" = true ]; then\n DEPS=\"$DEPS @vitejs/plugin-react\"\nfi\n\nif [ \"$HAS_VUE\" = true ]; then\n DEPS=\"$DEPS @vitejs/plugin-vue\"\nfi\n\nnpm install -D $DEPS\n\n# Step 8: Run automated codemod\nif [ \"$USE_CODEMOD\" = true ]; then\n log_info \"Running automated codemod transformation...\"\n\n # Install codemod if not available\n if ! command -v vitest-codemod &> /dev/null; then\n log_info \"Installing vitest-codemod...\"\n npm install -g @vitest-codemod/jest\n fi\n\n # Run codemod on test files\n vitest-codemod jest $TEST_PATTERNS || log_warn \"Codemod completed with warnings\"\nelse\n log_warn \"Skipping codemod. Manual migration required.\"\nfi\n\n# Step 9: Create Vitest configuration\nlog_info \"Creating vitest.config.ts...\"\n\nif [ \"$HAS_REACT\" = true ]; then\ncat > vitest.config.ts \u003c\u003c 'EOF'\nimport { defineConfig } from 'vitest/config'\nimport react from '@vitejs/plugin-react'\nimport path from 'path'\n\nexport default defineConfig({\n plugins: [react()],\n test: {\n globals: true,\n environment: 'happy-dom',\n setupFiles: './vitest.setup.ts',\n css: true,\n clearMocks: true,\n restoreMocks: true,\n coverage: {\n provider: 'v8',\n reporter: ['text', 'json', 'html'],\n exclude: [\n 'node_modules/',\n 'dist/',\n '**/*.d.ts',\n '**/*.config.*',\n ]\n },\n },\n resolve: {\n alias: {\n '@': path.resolve(__dirname, './src'),\n }\n }\n})\nEOF\n\nelif [ \"$HAS_VUE\" = true ]; then\ncat > vitest.config.ts \u003c\u003c 'EOF'\nimport { defineConfig } from 'vitest/config'\nimport vue from '@vitejs/plugin-vue'\n\nexport default defineConfig({\n plugins: [vue()],\n test: {\n globals: true,\n environment: 'happy-dom',\n setupFiles: './vitest.setup.ts',\n clearMocks: true,\n restoreMocks: true,\n }\n})\nEOF\n\nelse\ncat > vitest.config.ts \u003c\u003c 'EOF'\nimport { defineConfig } from 'vitest/config'\n\nexport default defineConfig({\n test: {\n globals: true,\n environment: 'node',\n setupFiles: './vitest.setup.ts',\n clearMocks: true,\n restoreMocks: true,\n coverage: {\n provider: 'v8',\n reporter: ['text', 'json', 'html'],\n }\n }\n})\nEOF\nfi\n\n# Step 10: Create setup file\nlog_info \"Creating vitest.setup.ts...\"\n\nif [ \"$HAS_TESTING_LIBRARY\" = true ]; then\ncat > vitest.setup.ts \u003c\u003c 'EOF'\nimport { expect, afterEach } from 'vitest'\nimport { cleanup } from '@testing-library/react'\nimport * as matchers from '@testing-library/jest-dom/matchers'\n\nexpect.extend(matchers)\n\nafterEach(() => {\n cleanup()\n})\nEOF\nelse\ncat > vitest.setup.ts \u003c\u003c 'EOF'\nimport { expect } from 'vitest'\n\n// Global setup\nEOF\nfi\n\n# Step 11: Update package.json\nlog_info \"Updating package.json scripts...\"\nnpm pkg delete scripts.test\nnpm pkg set scripts.test=\"vitest\"\nnpm pkg set scripts.test:ui=\"vitest --ui\"\nnpm pkg set scripts.test:run=\"vitest run\"\nnpm pkg set scripts.test:coverage=\"vitest run --coverage\"\n\n# Step 12: Update TypeScript configuration\nlog_info \"Updating tsconfig.json...\"\nif [ -f \"tsconfig.json\" ]; then\n # Use node to update JSON (more reliable than manual editing)\n node -e \"\n const fs = require('fs');\n const config = JSON.parse(fs.readFileSync('tsconfig.json', 'utf8'));\n config.compilerOptions = config.compilerOptions || {};\n config.compilerOptions.types = config.compilerOptions.types || [];\n if (!config.compilerOptions.types.includes('vitest/globals')) {\n config.compilerOptions.types.push('vitest/globals');\n }\n // Remove jest types\n config.compilerOptions.types = config.compilerOptions.types.filter(t => t !== '@types/jest');\n fs.writeFileSync('tsconfig.json', JSON.stringify(config, null, 2));\n \"\nfi\n\n# Step 13: Remove old configuration files\nlog_info \"Removing old Jest configuration files...\"\nrm -f jest.config.js jest.config.ts jest.setup.js jest.setup.ts\n\n# Step 14: Search for remaining Jest references\nlog_info \"Searching for remaining Jest references...\"\nJEST_REFS=$(grep -r \"from 'jest'\" src/ test/ 2>/dev/null | wc -l || echo \"0\")\nif [ \"$JEST_REFS\" -gt 0 ]; then\n log_warn \"Found $JEST_REFS Jest import references that may need manual update\"\n grep -r \"from 'jest'\" src/ test/ 2>/dev/null || true\nfi\n\n# Step 15: Commit changes\nlog_info \"Committing migration changes...\"\ngit add -A\ngit commit -m \"Migrate from Jest to Vitest\n\n- Remove Jest dependencies\n- Install Vitest and plugins\n- Run automated codemod transformations\n- Create vitest.config.ts\n- Update package.json scripts\n- Update TypeScript configuration\n\"\n\n# Step 16: Run tests with Vitest\nlog_info \"Running Vitest tests...\"\nif npm run test:run; then\n log_info \"✅ Migration successful! All tests passing.\"\nelse\n log_error \"❌ Tests failing. Review the output above and fix issues.\"\n log_info \"To rollback: git checkout $BACKUP_BRANCH\"\n exit 1\nfi\n\n# Success summary\nlog_info \"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\"\nlog_info \"✅ Migration completed successfully!\"\nlog_info \"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\"\nlog_info \"\"\nlog_info \"Next steps:\"\nlog_info \"1. Review git diff to verify changes\"\nlog_info \"2. Run 'npm run test:ui' to explore test UI\"\nlog_info \"3. Run 'npm run test:coverage' to check coverage\"\nlog_info \"4. Update CI/CD pipelines to use Vitest\"\nlog_info \"5. Clean up: rm *.backup\"\nlog_info \"\"\nlog_info \"Backup branch: $BACKUP_BRANCH\"\nlog_info \"To rollback: git checkout $BACKUP_BRANCH\"\n","content_type":"application/x-sh; charset=utf-8","language":"bash","size":8432,"content_sha256":"d59dd09d3fbeccd21ba6d7273958e985358f139d15816e01fd05e3a28cd228eb"},{"filename":"scripts/quick-migrate.sh","content":"#!/bin/bash\n# quick-migrate.sh - Quick Jest to Vitest migration\n# Usage: ./quick-migrate.sh\n\nset -e # Exit on error\n\necho \"🚀 Starting Jest to Vitest migration...\"\n\n# 1. Backup current state\necho \"📦 Creating backup...\"\ngit add -A\ngit commit -m \"Backup before Vitest migration\" || true\n\n# 2. Remove Jest dependencies\necho \"🗑️ Removing Jest...\"\nnpm uninstall jest @types/jest ts-jest jest-environment-jsdom @jest/globals\n\n# 3. Install Vitest\necho \"📥 Installing Vitest...\"\nnpm install -D vitest @vitest/ui happy-dom\n\n# 4. Run automated codemod\necho \"🔄 Running automated codemod...\"\nnpx @vitest-codemod/jest src/**/*.{test,spec}.{js,ts,jsx,tsx}\n\n# 5. Create basic config\necho \"⚙️ Creating vitest.config.ts...\"\ncat > vitest.config.ts \u003c\u003c 'EOF'\nimport { defineConfig } from 'vitest/config'\n\nexport default defineConfig({\n test: {\n globals: true,\n environment: 'happy-dom',\n setupFiles: './vitest.setup.ts',\n clearMocks: true,\n restoreMocks: true,\n },\n})\nEOF\n\n# 6. Create setup file\necho \"📝 Creating vitest.setup.ts...\"\ncat > vitest.setup.ts \u003c\u003c 'EOF'\nimport { expect, afterEach } from 'vitest'\nimport { cleanup } from '@testing-library/react'\nimport * as matchers from '@testing-library/jest-dom/matchers'\n\nexpect.extend(matchers)\n\nafterEach(() => {\n cleanup()\n})\nEOF\n\n# 7. Update package.json scripts\necho \"📝 Updating package.json scripts...\"\nnpm pkg set scripts.test=\"vitest\"\nnpm pkg set scripts.test:ui=\"vitest --ui\"\nnpm pkg set scripts.test:run=\"vitest run\"\nnpm pkg set scripts.test:coverage=\"vitest run --coverage\"\n\n# 8. Update tsconfig.json\necho \"📝 Updating tsconfig.json...\"\nnpx json -I -f tsconfig.json -e 'this.compilerOptions.types=[\"vitest/globals\"]' 2>/dev/null || echo \"⚠️ Skipping tsconfig update (install 'json' package or update manually)\"\n\n# 9. Remove old config files\necho \"🗑️ Removing old config files...\"\nrm -f jest.config.js jest.config.ts jest.setup.js jest.setup.ts\n\necho \"✅ Migration complete!\"\necho \"🧪 Run 'npm test' to verify migration\"\n","content_type":"application/x-sh; charset=utf-8","language":"bash","size":2021,"content_sha256":"cc87a37f09d8e1ba0cd94df381a32fae05f62e5ef75479d2f7871e221fcb3437"}],"content_json":{"type":"doc","content":[{"type":"paragraph","content":[{"text":"\u003cobjective> Expert guidance for migrating from Jest to Vitest and working with the Vitest testing framework. This skill focuses primarily on ","type":"text"},{"text":"automated migration from Jest","type":"text","marks":[{"type":"strong"}]},{"text":" while covering setup, configuration, and best practices.","type":"text"}]},{"type":"paragraph","content":[{"text":"Key benefits of Vitest over Jest:","type":"text","marks":[{"type":"strong"}]}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"2-10x faster test startup (built on Vite and esbuild)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Native TypeScript support without ts-jest","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Hot Module Replacement for instant re-runs","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Jest-compatible API requiring minimal code changes","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Modern ESM-first architecture \u003c/objective>","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"\u003cquick_start> \u003cautomated_migration> ","type":"text"},{"text":"RECOMMENDED APPROACH","type":"text","marks":[{"type":"strong"}]},{"text":": Use automated codemods for fastest migration.","type":"text"}]},{"type":"paragraph","content":[{"text":"Option 1: vitest-codemod","type":"text","marks":[{"type":"strong"}]},{"text":" (recommended)","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# Install globally\nnpm install -g @vitest-codemod/jest\n\n# Run migration on test files\nvitest-codemod jest path/to/tests/**/*.test.js\n\n# Or use npx (no installation)\nnpx @vitest-codemod/jest path/to/tests","type":"text"}]},{"type":"paragraph","content":[{"text":"Option 2: Codemod.com Platform","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# Using VS Code extension\n# Install \"Codemod\" extension from marketplace\n# Right-click project → \"Run Codemod\" → \"Jest to Vitest\"\n\n# Using CLI\nnpx codemod jest/vitest","type":"text"}]},{"type":"paragraph","content":[{"text":"What codemods handle automatically:","type":"text","marks":[{"type":"strong"}]}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"✓ Convert ","type":"text"},{"text":"jest.mock()","type":"text","marks":[{"type":"code_inline"}]},{"text":" → ","type":"text"},{"text":"vi.mock()","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"✓ Convert ","type":"text"},{"text":"jest.fn()","type":"text","marks":[{"type":"code_inline"}]},{"text":" → ","type":"text"},{"text":"vi.fn()","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"✓ Convert ","type":"text"},{"text":"jest.spyOn()","type":"text","marks":[{"type":"code_inline"}]},{"text":" → ","type":"text"},{"text":"vi.spyOn()","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"✓ Convert ","type":"text"},{"text":"jest.setTimeout()","type":"text","marks":[{"type":"code_inline"}]},{"text":" → ","type":"text"},{"text":"vi.setConfig({ testTimeout })","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"✓ Update global matchers and timer mocks","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"✓ Transform ","type":"text"},{"text":"jest.requireActual()","type":"text","marks":[{"type":"code_inline"}]},{"text":" → ","type":"text"},{"text":"vi.importActual()","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"✓ Update mock resets/clears/restores \u003c/automated_migration>","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"\u003cmanual_migration> ","type":"text"},{"text":"For users who need manual control or want to understand changes:","type":"text","marks":[{"type":"strong"}]}]},{"type":"paragraph","content":[{"text":"1. Install Vitest","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"# Remove Jest\nnpm uninstall jest @types/jest ts-jest jest-environment-jsdom\n\n# Install Vitest\nnpm install -D vitest @vitest/ui happy-dom","type":"text"}]},{"type":"paragraph","content":[{"text":"2. Create vitest.config.ts","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"import { defineConfig } from 'vitest/config'\n\nexport default defineConfig({\n test: {\n globals: true, // Enable globals for Jest compatibility\n environment: 'happy-dom', // Faster than jsdom\n setupFiles: ['./vitest.setup.ts'],\n clearMocks: true,\n restoreMocks: true,\n },\n})","type":"text"}]},{"type":"paragraph","content":[{"text":"3. Update package.json","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"json"},"content":[{"text":"{\n \"scripts\": {\n \"test\": \"vitest\",\n \"test:ui\": \"vitest --ui\",\n \"test:run\": \"vitest run\",\n \"test:coverage\": \"vitest run --coverage\"\n }\n}","type":"text"}]},{"type":"paragraph","content":[{"text":"4. Update TypeScript config","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"json"},"content":[{"text":"{\n \"compilerOptions\": {\n \"types\": [\"vitest/globals\"]\n }\n}","type":"text"}]},{"type":"paragraph","content":[{"text":"5. Update mock syntax","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"// Replace in all test files:\njest.fn → vi.fn\njest.spyOn → vi.spyOn\njest.mock → vi.mock\njest.useFakeTimers → vi.useFakeTimers\njest.clearAllMocks → vi.clearAllMocks","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/manual_migration>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003cautomated_scripts> ","type":"text"},{"text":"For comprehensive migrations with validation and rollback:","type":"text","marks":[{"type":"strong"}]}]},{"type":"paragraph","content":[{"text":"Ready-to-run migration scripts available in ","type":"text"},{"text":"scripts/","type":"text","marks":[{"type":"code_inline"}]},{"text":" directory:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"quick-migrate.sh","type":"text","marks":[{"type":"code_inline"}]},{"text":" - Fast 30-second migration for simple projects","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"comprehensive-migrate.sh","type":"text","marks":[{"type":"code_inline"}]},{"text":" - Full-featured migration with project detection, backups, and validation","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"See ","type":"text"},{"text":"references/MIGRATION_SCRIPT.md","type":"text","marks":[{"type":"link","attrs":{"href":"references/MIGRATION_SCRIPT.md","title":null}}]},{"text":" for usage instructions. \u003c/automated_scripts> \u003c/quick_start>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003ccritical_differences> \u003cmodule_mocking> ","type":"text"},{"text":"Jest","type":"text","marks":[{"type":"strong"}]},{"text":": Auto-returns default export","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"jest.mock('./module', () => 'hello')","type":"text"}]},{"type":"paragraph","content":[{"text":"Vitest","type":"text","marks":[{"type":"strong"}]},{"text":": Must specify exports explicitly","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"vi.mock('./module', () => ({\n default: 'hello' // Explicit default export required\n}))","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/module_mocking>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003cmock_reset_behavior> ","type":"text"},{"text":"Jest","type":"text","marks":[{"type":"strong"}]},{"text":": ","type":"text"},{"text":"mockReset()","type":"text","marks":[{"type":"code_inline"}]},{"text":" replaces with empty function returning ","type":"text"},{"text":"undefined","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"paragraph","content":[{"text":"Vitest","type":"text","marks":[{"type":"strong"}]},{"text":": ","type":"text"},{"text":"mockReset()","type":"text","marks":[{"type":"code_inline"}]},{"text":" resets to original implementation","type":"text"}]},{"type":"paragraph","content":[{"text":"To match Jest behavior in Vitest:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"mockFn.mockReset()\nmockFn.mockImplementation(() => undefined)","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/mock_reset_behavior>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003cglobals_configuration> ","type":"text"},{"text":"Jest","type":"text","marks":[{"type":"strong"}]},{"text":": Globals enabled by default","type":"text"}]},{"type":"paragraph","content":[{"text":"Vitest","type":"text","marks":[{"type":"strong"}]},{"text":": Must explicitly enable:","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"export default defineConfig({\n test: {\n globals: true // Enable for Jest compatibility\n }\n})","type":"text"}]},{"type":"paragraph","content":[{"text":"Then add to ","type":"text"},{"text":"tsconfig.json","type":"text","marks":[{"type":"code_inline"}]},{"text":":","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"json"},"content":[{"text":"{\n \"compilerOptions\": {\n \"types\": [\"vitest/globals\"]\n }\n}","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/globals_configuration>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003cauto_mocking> ","type":"text"},{"text":"Jest","type":"text","marks":[{"type":"strong"}]},{"text":": Files in ","type":"text"},{"text":"__mocks__/","type":"text","marks":[{"type":"code_inline"}]},{"text":" auto-load","type":"text"}]},{"type":"paragraph","content":[{"text":"Vitest","type":"text","marks":[{"type":"strong"}]},{"text":": Must call ","type":"text"},{"text":"vi.mock()","type":"text","marks":[{"type":"code_inline"}]},{"text":" explicitly, or add to ","type":"text"},{"text":"setupFiles","type":"text","marks":[{"type":"code_inline"}]},{"text":":","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"// vitest.setup.ts\nvi.mock('./path/to/module')","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/auto_mocking>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003casync_tests> ","type":"text"},{"text":"Jest","type":"text","marks":[{"type":"strong"}]},{"text":": Supports callback style with ","type":"text"},{"text":"done()","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"paragraph","content":[{"text":"Vitest","type":"text","marks":[{"type":"strong"}]},{"text":": Use async/await or Promises","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"// Before (Jest)\ntest('async test', (done) => {\n setTimeout(() => {\n expect(true).toBe(true)\n done()\n }, 100)\n})\n\n// After (Vitest)\ntest('async test', async () => {\n await new Promise(resolve => {\n setTimeout(() => {\n expect(true).toBe(true)\n resolve()\n }, 100)\n })\n})","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/async_tests> \u003c/critical_differences>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003ccommon_issues> \u003ctesting_library_cleanup> ","type":"text"},{"text":"Problem","type":"text","marks":[{"type":"strong"}]},{"text":": Auto-cleanup doesn't run when ","type":"text"},{"text":"globals: false","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"paragraph","content":[{"text":"Solution","type":"text","marks":[{"type":"strong"}]},{"text":": Manually import cleanup in setup file","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"// vitest.setup.ts\nimport { cleanup } from '@testing-library/react'\nimport { afterEach } from 'vitest'\n\nafterEach(() => {\n cleanup()\n})","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/testing_library_cleanup>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003cpath_aliases> ","type":"text"},{"text":"Problem","type":"text","marks":[{"type":"strong"}]},{"text":": Jest's ","type":"text"},{"text":"moduleNameMapper","type":"text","marks":[{"type":"code_inline"}]},{"text":" not working","type":"text"}]},{"type":"paragraph","content":[{"text":"Solution","type":"text","marks":[{"type":"strong"}]},{"text":": Configure in ","type":"text"},{"text":"vitest.config.ts","type":"text","marks":[{"type":"code_inline"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"import { defineConfig } from 'vitest/config'\nimport path from 'path'\n\nexport default defineConfig({\n resolve: {\n alias: {\n '@': path.resolve(__dirname, './src'),\n '@components': path.resolve(__dirname, './src/components'),\n }\n }\n})","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/path_aliases>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003ccoverage_differences> ","type":"text"},{"text":"Problem","type":"text","marks":[{"type":"strong"}]},{"text":": Coverage numbers don't match Jest","type":"text"}]},{"type":"paragraph","content":[{"text":"Solution","type":"text","marks":[{"type":"strong"}]},{"text":": Vitest uses V8 by default. For Istanbul (Jest's provider):","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"npm install -D @vitest/coverage-istanbul","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"export default defineConfig({\n test: {\n coverage: {\n provider: 'istanbul'\n }\n }\n})","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/coverage_differences>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003csnapshot_names> ","type":"text"},{"text":"Problem","type":"text","marks":[{"type":"strong"}]},{"text":": Test names in snapshots use ","type":"text"},{"text":">","type":"text","marks":[{"type":"code_inline"}]},{"text":" separator instead of spaces","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":""},"content":[{"text":"Jest: \"describe title test title\"\nVitest: \"describe title > test title\"","type":"text"}]},{"type":"paragraph","content":[{"text":"Solution","type":"text","marks":[{"type":"strong"}]},{"text":": Regenerate snapshots with ","type":"text"},{"text":"npm run test -u","type":"text","marks":[{"type":"code_inline"}]},{"text":" \u003c/snapshot_names> \u003c/common_issues>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003cbest_practices>","type":"text"}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use ","type":"text","marks":[{"type":"strong"}]},{"text":"happy-dom","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":" over ","type":"text","marks":[{"type":"strong"}]},{"text":"jsdom","type":"text","marks":[{"type":"code_inline"},{"type":"strong"}]},{"text":" - 2-3x faster for most use cases","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Enable globals for easier migration","type":"text","marks":[{"type":"strong"}]},{"text":" - Set ","type":"text"},{"text":"globals: true","type":"text","marks":[{"type":"code_inline"}]},{"text":" in config","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use watch mode during development","type":"text","marks":[{"type":"strong"}]},{"text":" - ","type":"text"},{"text":"npm run test","type":"text","marks":[{"type":"code_inline"}]},{"text":" (default behavior)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Leverage UI mode for debugging","type":"text","marks":[{"type":"strong"}]},{"text":" - ","type":"text"},{"text":"npm run test:ui","type":"text","marks":[{"type":"code_inline"}]},{"text":" opens browser interface","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Configure auto-cleanup","type":"text","marks":[{"type":"strong"}]},{"text":" - Set ","type":"text"},{"text":"clearMocks: true","type":"text","marks":[{"type":"code_inline"}]},{"text":" and ","type":"text"},{"text":"restoreMocks: true","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Use workspace configuration for monorepos","type":"text","marks":[{"type":"strong"}]},{"text":" - See ","type":"text"},{"text":"CONFIG.md","type":"text","marks":[{"type":"link","attrs":{"href":"references/CONFIG.md","title":null}}]},{"text":" \u003c/best_practices>","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"\u003cperformance_optimization>","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"typescript"},"content":[{"text":"export default defineConfig({\n test: {\n environment: 'node', // or 'happy-dom' instead of 'jsdom'\n maxWorkers: 4, // Increase for parallel execution\n fileParallelism: true,\n testTimeout: 5000,\n isolate: false, // Faster but use with caution\n pool: 'threads', // or 'forks' for better isolation\n }\n})","type":"text"}]},{"type":"paragraph","content":[{"text":"Pool options:","type":"text","marks":[{"type":"strong"}]}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"threads","type":"text","marks":[{"type":"code_inline"}]},{"text":" (default) - Fast, CPU-intensive tests","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"forks","type":"text","marks":[{"type":"code_inline"}]},{"text":" - Better isolation, more memory","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"vmThreads","type":"text","marks":[{"type":"code_inline"}]},{"text":" - Best for TypeScript performance \u003c/performance_optimization>","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"\u003cmigration_workflow> ","type":"text"},{"text":"Recommended migration process:","type":"text","marks":[{"type":"strong"}]}]},{"type":"ordered_list","attrs":{"order":1,"listStyle":"number"},"content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Prepare","type":"text","marks":[{"type":"strong"}]}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Ensure all Jest tests passing","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Commit working state","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Create migration branch","type":"text"}]}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Install dependencies","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"npm install -D vitest @vitest/ui happy-dom","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Run automated codemod","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"npx @vitest-codemod/jest src/**/*.test.ts","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Create configuration","type":"text","marks":[{"type":"strong"}]}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Add ","type":"text"},{"text":"vitest.config.ts","type":"text","marks":[{"type":"code_inline"}]},{"text":" with ","type":"text"},{"text":"globals: true","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Update ","type":"text"},{"text":"package.json","type":"text","marks":[{"type":"code_inline"}]},{"text":" scripts","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Update ","type":"text"},{"text":"tsconfig.json","type":"text","marks":[{"type":"code_inline"}]},{"text":" types","type":"text"}]}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Run tests and fix issues","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"npm run test","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Address failures one by one","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Check ","type":"text"},{"text":"MIGRATION.md","type":"text","marks":[{"type":"link","attrs":{"href":"references/MIGRATION.md","title":null}}]},{"text":" for solutions","type":"text"}]}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Update CI/CD","type":"text","marks":[{"type":"strong"}]}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Replace Jest commands with Vitest","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Update coverage paths if needed","type":"text"}]}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Cleanup","type":"text","marks":[{"type":"strong"}]}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"npm uninstall jest @types/jest ts-jest\nrm jest.config.js","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"\u003c/migration_workflow>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003ccommon_commands>","type":"text"}]},{"type":"code_block","attrs":{"wrap":false,"language":"bash"},"content":[{"text":"npm run test # Watch mode\nnpm run test:run # Run once (CI mode)\nnpm run test:coverage # With coverage\nnpm run test:ui # Visual UI\nnpm run test path/to/file.test.ts # Specific file\nnpm run test -t \"pattern\" # Matching pattern\nnpm run test --environment jsdom # Specific environment\nnpm run test -u # Update snapshots","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003c/common_commands>","type":"text"}]},{"type":"paragraph","content":[{"text":"\u003cdetailed_references> For comprehensive information:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"MIGRATION.md","type":"text","marks":[{"type":"link","attrs":{"href":"references/MIGRATION.md","title":null}},{"type":"strong"}]},{"text":" - Complete Jest→Vitest API mapping, troubleshooting, framework-specific guides","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"CONFIG.md","type":"text","marks":[{"type":"link","attrs":{"href":"references/CONFIG.md","title":null}},{"type":"strong"}]},{"text":" - Full configuration reference with examples for React, Vue, TypeScript, Node.js, monorepos","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"MIGRATION_SCRIPT.md","type":"text","marks":[{"type":"link","attrs":{"href":"references/MIGRATION_SCRIPT.md","title":null}},{"type":"strong"}]},{"text":" - Automated migration script usage and customization","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Official Vitest docs","type":"text","marks":[{"type":"strong"}]},{"text":": ","type":"text"},{"text":"https://vitest.dev","type":"text","marks":[{"type":"link","attrs":{"href":"https://vitest.dev","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Vitest migration guide","type":"text","marks":[{"type":"strong"}]},{"text":": ","type":"text"},{"text":"https://vitest.dev/guide/migration","type":"text","marks":[{"type":"link","attrs":{"href":"https://vitest.dev/guide/migration","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"vitest-codemod tool","type":"text","marks":[{"type":"strong"}]},{"text":": ","type":"text"},{"text":"https://github.com/trivikr/vitest-codemod","type":"text","marks":[{"type":"link","attrs":{"href":"https://github.com/trivikr/vitest-codemod","title":null}}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Codemod platform","type":"text","marks":[{"type":"strong"}]},{"text":": ","type":"text"},{"text":"https://codemod.com/migrations/jest-to-vitest","type":"text","marks":[{"type":"link","attrs":{"href":"https://codemod.com/migrations/jest-to-vitest","title":null}}]},{"text":" \u003c/detailed_references>","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"\u003csuccess_criteria> Migration is successful when:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"All tests passing with ","type":"text"},{"text":"npm run test:run","type":"text","marks":[{"type":"code_inline"}]}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Coverage reports generate correctly","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"CI/CD pipeline runs tests successfully","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"No ","type":"text"},{"text":"jest","type":"text","marks":[{"type":"code_inline"}]},{"text":" references remain in codebase","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"TypeScript types resolve without errors","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Test execution is noticeably faster (2-10x improvement) \u003c/success_criteria>","type":"text"}]}]}]},{"type":"paragraph","content":[{"text":"\u003cwhen_successful> After successful migration, you should observe:","type":"text"}]},{"type":"bullet_list","content":[{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"5x faster cold start","type":"text","marks":[{"type":"strong"}]},{"text":" - Initial test run (10s → 2s typical)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"5x faster watch mode","type":"text","marks":[{"type":"strong"}]},{"text":" - Hot reload (5s → \u003c1s typical)","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"2x faster execution","type":"text","marks":[{"type":"strong"}]},{"text":" - Overall test suite runtime","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"10x faster TypeScript tests","type":"text","marks":[{"type":"strong"}]},{"text":" - No ts-jest compilation overhead","type":"text"}]}]},{"type":"list_item","content":[{"type":"paragraph","content":[{"text":"Better DX","type":"text","marks":[{"type":"strong"}]},{"text":" - Instant feedback, visual UI, better error messages \u003c/when_successful>","type":"text"}]}]}]},{"type":"hr","attrs":{"markup":"---"}}]},"metadata":{"date":"2026-06-05","name":"vitest","author":"@skillopedia","source":{"stars":10,"repo_name":"ai-context","origin_url":"https://github.com/el-feo/ai-context/blob/HEAD/plugins/js-ts/skills/vitest/SKILL.md","repo_owner":"el-feo","body_sha256":"4793c1bec2098a60b5a93b637fe0bee81bde89ea38908fc7621780e1124a1b04","cluster_key":"91ceb8c1557cfdc3694659c6a390ad1d541ad849731fb63c867bf4226fd6b0f5","clean_bundle":{"format":"clean-skill-bundle-v1","source":"el-feo/ai-context/plugins/js-ts/skills/vitest/SKILL.md","attachments":[{"id":"e229530b-9ba5-5d3c-9a59-33017569fa0d","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/e229530b-9ba5-5d3c-9a59-33017569fa0d/attachment.md","path":"references/CONFIG.md","size":19041,"sha256":"ba948e64e79c0e23c6d5e7aaff09ea661fc7ecb1aff5991d57574b5fddd25e74","contentType":"text/markdown; charset=utf-8"},{"id":"ede5459e-3006-5bba-9c1a-ace06cfd144e","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/ede5459e-3006-5bba-9c1a-ace06cfd144e/attachment.md","path":"references/MIGRATION.md","size":20339,"sha256":"c0b2f7bb570e17ee6aa91c22ed0f3229a3090a21c6901988425ab2bb94b3f565","contentType":"text/markdown; charset=utf-8"},{"id":"8d89e4c9-d0c7-5419-a0ea-83e7d8a27ae4","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/8d89e4c9-d0c7-5419-a0ea-83e7d8a27ae4/attachment.md","path":"references/MIGRATION_SCRIPT.md","size":6727,"sha256":"23bccb186055ed91d072846639817b8c7e94a0c03b3794daef5ea964d83de417","contentType":"text/markdown; charset=utf-8"},{"id":"b6d28ea6-a11f-57af-a33d-60ce260f4f9d","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/b6d28ea6-a11f-57af-a33d-60ce260f4f9d/attachment.sh","path":"scripts/comprehensive-migrate.sh","size":8432,"sha256":"d59dd09d3fbeccd21ba6d7273958e985358f139d15816e01fd05e3a28cd228eb","contentType":"application/x-sh; charset=utf-8"},{"id":"744e3e5f-150e-57d7-9da5-0bf542d4936a","key":"uploads/10433ee7-ad12-4ae0-b34e-97553e46c6c8/744e3e5f-150e-57d7-9da5-0bf542d4936a/attachment.sh","path":"scripts/quick-migrate.sh","size":2021,"sha256":"cc87a37f09d8e1ba0cd94df381a32fae05f62e5ef75479d2f7871e221fcb3437","contentType":"application/x-sh; charset=utf-8"}],"bundle_sha256":"bd01ed7d99a2c4d243c0563dcab398b1da55f11ec7da447539dc9a78adbe3f34","attachment_count":5,"text_attachments":5,"attachment_storage":"skillopedia-attachments-v1","binary_attachments":0,"excluded_attachments":[]},"cluster_size":1,"skill_md_path":"plugins/js-ts/skills/vitest/SKILL.md","import_metadata":{"date":"2026-06-05","author":"@skillopedia","version":"v1","category":"testing-qa","category_label":"Testing"},"exact_dupes_collapsed_into_this":0},"version":"v1","category":"testing-qa","import_tag":"clean-skills-v1","description":"Comprehensive Vitest testing framework guide with strong emphasis on Jest-to-Vitest migration. Covers automated migration using codemods, configuration setup, API differences, best practices, and troubleshooting. Use when migrating from Jest, setting up Vitest, writing tests, configuring test environments, or resolving migration issues. Primary focus is seamless Jest migration with minimal code changes."}},"renderedAt":1782981764906}

<objective Expert guidance for migrating from Jest to Vitest and working with the Vitest testing framework. This skill focuses primarily on automated migration from Jest while covering setup, configuration, and best practices. Key benefits of Vitest over Jest: - 2-10x faster test startup (built on Vite and esbuild) - Native TypeScript support without ts-jest - Hot Module Replacement for instant re-runs - Jest-compatible API requiring minimal code changes - Modern ESM-first architecture </objective <quick start <automated migration RECOMMENDED APPROACH : Use automated codemods for fastest migr…