/** @type {import('jest').Config} */
module.exports = {
// Test environment
testEnvironment: 'node',
// TypeScript transformation
preset: 'ts-jest',
extensionsToTreatAsEsm: ['.ts'],
globals: {
'ts-jest': {
useESM: true
}
},
// Test file patterns
testMatch: [
'**/tests/**/*.test.ts',
'**/tests/**/*.spec.ts',
'**/__tests__/**/*.ts',
'**/?(*.)+(spec|test).ts'
],
// Ignore patterns
testPathIgnorePatterns: [
'/node_modules/',
'/build/',
'/dist/',
'/coverage/'
],
// Module resolution
moduleNameMapping: {
'^@/(.*)$': '<rootDir>/src/$1',
'^@tests/(.*)$': '<rootDir>/tests/$1'
},
// Setup files
setupFilesAfterEnv: [
'<rootDir>/tests/typescript/setup.ts'
],
// Coverage configuration
collectCoverage: false,
collectCoverageFrom: [
'src/**/*.{ts,js}',
'!src/**/*.d.ts',
'!src/**/*.test.{ts,js}',
'!src/**/*.spec.{ts,js}',
'!**/node_modules/**',
'!**/build/**',
'!**/dist/**'
],
coverageDirectory: 'coverage-typescript',
coverageReporters: [
'text',
'lcov',
'html',
'json-summary'
],
// Test execution
verbose: true,
testTimeout: 30000, // 30 second timeout for async tests
maxWorkers: 4,
// Output formatting
reporters: [
'default',
['jest-junit', {
outputDirectory: 'test-results',
outputName: 'typescript-junit.xml'
}]
],
// Transform configuration
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest'
},
// Module file extensions
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
// Clear mocks between tests
clearMocks: true,
restoreMocks: true,
// Error handling
errorOnDeprecated: true,
// Watch mode configuration
watchman: true,
watchPlugins: [
'jest-watch-typeahead/filename',
'jest-watch-typeahead/testname'
]
};