@l.x/vitest-preset
v1.0.0
Published
Shared Vitest preset for Lux Exchange apps and packages.
Downloads
333
Readme
Vitest Presets
This package provides Vitest configuration presets that mirror the functionality of jest-presets.
Usage
In your vitest.config.js:
import { defineConfig } from 'vitest/config'
import vitestPreset from 'config/vitest-presets/vitest/vitest-preset.js'
export default defineConfig({
...vitestPreset,
// Add any additional overrides here
})Migration from Jest
Key Differences
Globals: Vitest globals are opt-in. We've enabled them in the preset with
globals: true.Module Mocking: Use
vi.mock()instead ofjest.mock(). Mocks are hoisted automatically.Transform Configuration: Vitest uses Vite's transform pipeline, so
transformIgnorePatternsis replaced withoptimizeDeps.include.Module Mapping: Jest's
moduleNameMapperis replaced with Vite'sresolve.alias.Setup Files: Jest's
setupFilesAfterEnvbecomes Vitest'ssetupFiles.
Configuration Mapping
| Jest | Vitest |
|------|--------|
| preset: 'ts-jest' | Not needed (TypeScript support is built-in) |
| testEnvironment: 'jsdom' | test.environment: 'jsdom' |
| moduleNameMapper | resolve.alias |
| setupFilesAfterEnv | test.setupFiles |
| transformIgnorePatterns | optimizeDeps.include |
| collectCoverage | test.coverage.enabled |
| coverageReporters | test.coverage.reporter |
| globals | test.env |
Mocked Libraries
All mocks from jest-presets have been migrated:
- Chrome storage API (using
mem-storage-area) - React Native AsyncStorage
- Redux Persist
- Expo libraries (clipboard, blur, haptics, linear-gradient, screen-capture)
- Amplitude Analytics
- React Native Device Info
- NetInfo
- WalletConnect packages
- AppsFlyer
Features Not Migrated
SVG Transform: The
jest-transformer-svgpackage needs a Vitest equivalent. For now, SVGs are handled through the alias system.Babel Transform: Vitest uses Vite's transform pipeline which handles modern JavaScript/TypeScript natively. Babel-specific transforms may need custom Vite plugins.
Jest-specific mock packages: Some packages provide Jest-specific mocks (e.g.,
@react-native-community/netinfo/jest/netinfo-mock.js). These have been replaced with custom Vitest mocks in the setup file.Statsig mocks: The Statsig SDK mocks that were importing from
uniswap/src/features/gating/*have been removed to avoid cross-package dependencies.
Testing the Configuration
Run the included tests to verify the configuration:
cd config/vitest-presets
bun run test