jest
> Jest configuration with ts-jest, coverage thresholds and sensible defaults.
> 🛠️ Maintenance mode: dependency and security updates only. New projects should use @jmlweb/vitest-config.
✨ Features
Section titled “✨ Features”- 🔧 TypeScript: ts-jest transform out of the box
- 📊 Coverage: 80% global thresholds, text/json/html reporters
- 🎯 Sensible defaults: Node environment, mocks cleared and restored between tests
- 🚀 Configurable:
createJestConfig()factory with typed options
📦 Installation
Section titled “📦 Installation”npm install --save-dev @jmlweb/jest-config jest ts-jest @types/jest> 💡 Upgrading? See the Migration Guide.
🚀 Quick Start
Section titled “🚀 Quick Start”import jestConfig from '@jmlweb/jest-config';
export default jestConfig;With a TypeScript config file (jest.config.ts), Jest also needs ts-node.
💡 Examples
Section titled “💡 Examples”Factory with options
Section titled “Factory with options”import { createJestConfig } from '@jmlweb/jest-config';
export default createJestConfig({ testEnvironment: 'jsdom', setupFilesAfterEnv: ['<rootDir>/src/test/setup.ts'], moduleNameMapper: { '^@/(.*)$': '<rootDir>/src/$1' },});jsdom needs jest-environment-jsdom installed.
Custom coverage thresholds
Section titled “Custom coverage thresholds”import { createJestConfig } from '@jmlweb/jest-config';
export default createJestConfig({ coverageThreshold: { global: { lines: 90, functions: 90, branches: 85, statements: 90 }, },});Spread the base config
Section titled “Spread the base config”import jestConfig from '@jmlweb/jest-config';
export default { ...jestConfig, testTimeout: 10000,};📋 Configuration Details
Section titled “📋 Configuration Details”createJestConfig(options) options and defaults:
| Option | Default |
|---|---|
testEnvironment |
'node' |
moduleFileExtensions |
['ts', 'tsx', 'js', 'jsx', 'json'] |
testMatch |
['**/*.{test,spec}.{ts,tsx,js,jsx}'] |
testPathIgnorePatterns |
/node_modules/, /dist/, /build/, /.git/, /.cache/ |
collectCoverageFrom |
['src/**/*.{ts,tsx,js,jsx}'] |
coveragePathIgnorePatterns |
node_modules, dist, build, coverage, .d.ts, config, test and spec files |
coverageThreshold |
global: 80 for lines, functions, branches, statements |
coverageReporters |
['text', 'json', 'html'] |
setupFilesAfterEnv |
[] (omitted when empty) |
moduleNameMapper |
{} (omitted when empty) |
transform |
ts-jest for .ts/.tsx with esModuleInterop and allowSyntheticDefaultImports |
testTimeout |
5000 |
Fixed settings: collectCoverage: false (use --coverage), verbose: true, clearMocks: true, restoreMocks: true, resetModules: false.
🎯 When to Use
Section titled “🎯 When to Use”- ✅ Existing Jest projects with TypeScript
- ✅ Shared coverage baseline
Not for you if you are starting a new project: use @jmlweb/vitest-config.
🔧 Extending the Configuration
Section titled “🔧 Extending the Configuration”Pass options to createJestConfig, or spread the result and override. Passing transform replaces the default entirely, so include the ts-jest entry again if you still need it.
📝 Usage with Scripts
Section titled “📝 Usage with Scripts”{ "scripts": { "test": "jest", "test:watch": "jest --watch", "test:coverage": "jest --coverage" }}📋 Requirements
Section titled “📋 Requirements”- Node.js >= 22.12.0
- Jest >= 29.0.0
- ts-jest >= 29.0.0
📦 Peer Dependencies
Section titled “📦 Peer Dependencies”jest(>=29.0.0)ts-jest(>=29.0.0)@types/jest(>=29.0.0)
🔗 Related Packages
Section titled “🔗 Related Packages”@jmlweb/vitest-config- Recommended replacement@jmlweb/tsconfig-base- TypeScript configuration@jmlweb/oxlint-config-base- Oxlint config
🔄 Migration Guide
Section titled “🔄 Migration Guide”1.x to 2.0
Section titled “1.x to 2.0”Breaking: Node.js >= 22.12.0 is required.
- Upgrade Node.js to 22.12.0 or later.
- Update:
npm install --save-dev @jmlweb/jest-config@latest
See the Changelog for details.
📄 License
Section titled “📄 License”MIT