Migrate Jest to Vitest
As a Developer, I want to migrate the test framework from Jest to Vitest, so that I can benefit from faster test execution, better ESM support, and improved developer experience.
Acceptance Criteria
Section titled âAcceptance Criteriaâ- All existing Jest tests must be migrated to Vitest without changing test logic or assertions
- Test coverage thresholds must be maintained at current levels
- All test scripts in
package.jsonmust be updated to use Vitest - Test execution must be faster than Jest (target: 30-50% improvement)
- CI/CD pipeline must continue to work with Vitest
- All 317 existing tests must pass with Vitest
- Coverage reporting must work correctly with Vitest
- React Native testing library integration must work with Vitest
- Expo-specific test utilities must continue to function
- Path aliases (
@/) must work correctly in tests - TypeScript configuration must be compatible with Vitest
Migration Steps
Section titled âMigration Stepsâ1. Install Vitest and Dependencies
Section titled â1. Install Vitest and Dependenciesâ- Install
vitestas a dev dependency - Install
@vitest/uifor test UI (optional) - Install
@vitest/coverage-v8for coverage reporting - Install
jsdomorhappy-domfor DOM environment (if needed) - Install
@testing-library/jest-domcompatible matchers for Vitest
2. Create Vitest Configuration
Section titled â2. Create Vitest Configurationâ- Create
vitest.config.tsfile - Configure test environment (React Native/Expo compatible)
- Set up path aliases (
@/â<rootDir>/) - Configure coverage settings matching current Jest thresholds
- Set up transform patterns for TypeScript and JSX
- Configure test file patterns matching current Jest patterns
- Set up module name mapping for React Native dependencies
3. Update Test Setup Files
Section titled â3. Update Test Setup Filesâ- Migrate
jest.setup.jstovitest.setup.tsor similar - Ensure all global test utilities are available
- Configure React Native testing library for Vitest
- Set up any Expo-specific mocks or utilities
4. Update Package.json Scripts
Section titled â4. Update Package.json Scriptsâ- Replace
jestcommands withvitestequivalents:testâvitest runtest:watchâvitest watchtest:coverageâvitest run --coveragetest:ciâvitest run --coverage --reporter=verbose- Update all test path pattern commands to use Vitest syntax
5. Update Test Files
Section titled â5. Update Test Filesâ- Replace Jest imports with Vitest imports:
import { describe, it, expect, beforeEach, afterEach } from 'vitest'- Replace
jest.fn()withvi.fn() - Replace
jest.mock()withvi.mock() - Replace
jest.spyOn()withvi.spyOn()
- Update any Jest-specific APIs to Vitest equivalents
- Ensure React Native testing library matchers work with Vitest
6. Update Transform and Module Resolution
Section titled â6. Update Transform and Module Resolutionâ- Configure Vitest to handle React Native and Expo dependencies
- Set up proper transform ignore patterns
- Ensure native modules are properly mocked or handled
7. Update CI/CD Configuration
Section titled â7. Update CI/CD Configurationâ- Update GitHub Actions workflow to use Vitest
- Ensure coverage reporting works in CI
- Update any test result reporting if needed
8. Remove Jest Dependencies
Section titled â8. Remove Jest Dependenciesâ- Remove
jestfrom devDependencies - Remove
jest-expofrom devDependencies - Remove
@testing-library/jest-nativeif no longer needed - Remove
jest.config.jsfile - Clean up any Jest-specific configuration
9. Verify Test Execution
Section titled â9. Verify Test Executionâ- Run all test suites and verify they pass
- Verify coverage reports match expected thresholds
- Test watch mode functionality
- Test CI mode functionality
- Verify test performance improvements
Technical Considerations
Section titled âTechnical ConsiderationsâReact Native Compatibility
Section titled âReact Native Compatibilityâ- Vitest may require special configuration for React Native
- Expo-specific utilities may need custom setup
- Native module mocking may need adjustment
Coverage Thresholds
Section titled âCoverage ThresholdsâCurrent coverage thresholds that must be maintained:
./utils/recipeFlavorCalculation.ts: 90% statements, 65% branches, 100% functions, 90% lines./data/ingredients/index.ts: 95% statements, 95% branches, 100% functions, 95% lines./data/recipes/index.ts: 90% statements, 45% branches, 100% functions, 87% lines
Test Environment
Section titled âTest Environmentâ- Current Jest config uses
testEnvironment: 'node' - May need to configure Vitest environment for React Native/Expo
- Consider using
@vitest/environment-nodeor custom environment
Module Resolution
Section titled âModule Resolutionâ- Current Jest config has complex
transformIgnorePatternsfor React Native - Vitest uses Viteâs module resolution which may handle this differently
- Path aliases (
@/) must continue to work
Performance Targets
Section titled âPerformance Targetsâ- Current test suite: 317 tests across 18 test suites
- Target: 30-50% faster execution time
- Watch mode should be responsive and fast
Related Files
Section titled âRelated Filesâshaker/jest.config.js- Current Jest configurationshaker/jest.setup.js- Current Jest setup fileshaker/package.json- Package scripts and dependenciesshaker/__tests__/- All test files (317 tests).github/workflows/- CI/CD configuration
Risks and Mitigation
Section titled âRisks and MitigationâRisk: React Native Compatibility Issues
Section titled âRisk: React Native Compatibility Issuesâ- Mitigation: Test thoroughly with React Native testing library, may need custom Vitest environment
Risk: Expo-Specific Utilities Breaking
Section titled âRisk: Expo-Specific Utilities Breakingâ- Mitigation: Verify all Expo test utilities work, may need to maintain some Jest compatibility layer
Risk: Coverage Reporting Differences
Section titled âRisk: Coverage Reporting Differencesâ- Mitigation: Compare coverage reports between Jest and Vitest, adjust thresholds if needed
Risk: CI/CD Pipeline Breaking
Section titled âRisk: CI/CD Pipeline Breakingâ- Mitigation: Test CI configuration thoroughly before merging, have rollback plan
Success Criteria
Section titled âSuccess Criteriaâ- â All 317 tests pass with Vitest
- â Test execution is 30-50% faster
- â Coverage thresholds are maintained
- â All test scripts work correctly
- â CI/CD pipeline passes
- â Watch mode works smoothly
- â No regressions in test functionality
Priority
Section titled âPriorityâMedium - Performance and developer experience improvement, but not blocking core functionality
Estimated Effort
Section titled âEstimated EffortâHigh - Comprehensive migration affecting all test files and configuration
Dependencies
Section titled âDependenciesâ- None - Can be done independently of other features