Configuration¶
rjest reads configuration from your jest.config.js or jest.config.ts file.
Configuration File¶
rjest looks for configuration in this order:
jest.config.jsjest.config.tsjest.config.mjsjest.config.jsonpackage.json(jestkey)
Supported Options¶
Test Matching¶
testMatch¶
Glob patterns for test files:
testRegex¶
Regex pattern for test files (alternative to testMatch):
testPathIgnorePatterns¶
Patterns to exclude from testing:
Module Resolution¶
moduleFileExtensions¶
File extensions to consider:
moduleNameMapper¶
Map module paths:
module.exports = {
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
'^~/(.*)$': '<rootDir>/src/$1',
},
};
roots¶
Directories to search for tests:
Setup Files¶
setupFiles¶
Scripts to run before test framework loads:
setupFilesAfterEnv¶
Scripts to run after test framework loads:
Example setup file:
// Add custom matchers
expect.extend({
toBeWithinRange(received, floor, ceiling) {
const pass = received >= floor && received <= ceiling;
return {
message: () => `expected ${received} to be within range ${floor} - ${ceiling}`,
pass,
};
},
});
Test Behavior¶
testTimeout¶
Default timeout for tests (milliseconds):
bail¶
Stop after first failure:
Mock Behavior¶
clearMocks¶
Clear mock calls between tests:
resetMocks¶
Reset mock state between tests:
restoreMocks¶
Restore original implementations between tests:
Snapshot¶
snapshotSerializers¶
Custom snapshot serializers:
Example Configurations¶
TypeScript Project¶
module.exports = {
testMatch: ['**/*.test.ts', '**/*.test.tsx'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
},
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testPathIgnorePatterns: ['/node_modules/', '/dist/'],
};
Monorepo¶
module.exports = {
roots: ['<rootDir>/packages'],
testMatch: ['**/src/**/*.test.ts'],
moduleNameMapper: {
'^@myorg/(.*)$': '<rootDir>/packages/$1/src',
},
};
Minimal Configuration¶
Options Not Supported¶
These Jest options are not yet supported:
| Option | Status |
|---|---|
transform |
Not needed (built-in SWC) |
preset |
Not supported |
testEnvironment |
Only Node environment |
coverageThreshold |
Coverage not implemented |
globalSetup |
Not supported |
globalTeardown |
Not supported |
projects |
Not supported |
reporters |
Only default reporter |
TypeScript Configuration¶
For TypeScript config files:
import type { Config } from 'jest';
const config: Config = {
testMatch: ['**/*.test.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
};
export default config;
Note
rjest compiles jest.config.ts automatically using the built-in SWC compiler.