const nextJest = require('next/jest'); const createJestConfig = nextJest({ // Provide the path to your Next.js app to load next.config.js and .env files dir: './', }); // Add any custom config to be passed to Jest const customJestConfig = { setupFilesAfterEnv: ['/jest.setup.js'], testEnvironment: 'jsdom', moduleNameMapper: { '^@/(.*)$': '/src/$1', '^@/components/(.*)$': '/src/components/$1', '^@/lib/(.*)$': '/src/lib/$1', '^@/utils/(.*)$': '/src/utils/$1', '^@/hooks/(.*)$': '/src/hooks/$1', '^@/types/(.*)$': '/src/types/$1', }, collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts', '!src/**/index.ts'], coverageThreshold: { global: { branches: 70, functions: 70, lines: 70, statements: 70, }, }, testMatch: ['**/__tests__/**/*.(js|jsx|ts|tsx)', '**/*.(test|spec).(js|jsx|ts|tsx)'], testPathIgnorePatterns: ['/.next/', '/node_modules/', '/e2e/'], transform: { '^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }], }, transformIgnorePatterns: ['/node_modules/', '^.+\\.module\\.(css|sass|scss)$'], // Performance optimizations maxWorkers: '50%', cache: true, cacheDirectory: '.jest-cache', clearMocks: true, collectCoverage: false, // Only collect coverage when explicitly requested coverageReporters: ['text', 'lcov'], errorOnDeprecated: true, // Reduce memory usage logHeapUsage: true, // Faster test discovery testLocationInResults: true, // Skip coverage for faster runs in watch mode watchPathIgnorePatterns: ['/coverage/', '/.next/'], }; // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async module.exports = createJestConfig(customJestConfig);