|
| 1 | +import nextJest from 'next/jest.js'; |
| 2 | + |
| 3 | +const createJestConfig = nextJest({ |
| 4 | + dir: './', // load next.config + env from project root |
| 5 | +}); |
| 6 | + |
| 7 | +const customJestConfig = { |
| 8 | + // Path to setup file |
| 9 | + setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], |
| 10 | + |
| 11 | + testEnvironment: 'jest-environment-jsdom', |
| 12 | + |
| 13 | + // Map @/... to src/app/... |
| 14 | + moduleNameMapper: { |
| 15 | + '^@/(.*)$': '<rootDir>/src/app/$1', |
| 16 | + '^@/components/(.*)$': '<rootDir>/src/app/components/$1', |
| 17 | + '^@/utils/(.*)$': '<rootDir>/src/app/utils/$1', |
| 18 | + }, |
| 19 | + |
| 20 | + // Coverage – point to real paths |
| 21 | + collectCoverageFrom: [ |
| 22 | + 'src/app/components/**/*.{js,jsx,ts,tsx}', |
| 23 | + 'src/app/utils/**/*.{js,jsx,ts,tsx}', |
| 24 | + '!**/*.d.ts', |
| 25 | + '!**/node_modules/**', |
| 26 | + '!**/.next/**', |
| 27 | + '!**/coverage/**', |
| 28 | + ], |
| 29 | + |
| 30 | + // Tests location |
| 31 | + testMatch: [ |
| 32 | + 'src/app/tests/**/*.[jt]s?(x)', |
| 33 | + '**/__tests__/**/*.[jt]s?(x)', |
| 34 | + '**/?(*.)+(spec|test).[jt]s?(x)', |
| 35 | + ], |
| 36 | + |
| 37 | + testPathIgnorePatterns: ['/node_modules/', '/.next/'], |
| 38 | + |
| 39 | + transformIgnorePatterns: [ |
| 40 | + '/node_modules/', |
| 41 | + '^.+\\.module\\.(css|sass|scss)$', |
| 42 | + ], |
| 43 | + |
| 44 | + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'], |
| 45 | + |
| 46 | + coverageThreshold: { |
| 47 | + global: { |
| 48 | + branches: 70, |
| 49 | + functions: 70, |
| 50 | + lines: 70, |
| 51 | + statements: 70, |
| 52 | + }, |
| 53 | + }, |
| 54 | +}; |
| 55 | + |
| 56 | +export default createJestConfig(customJestConfig); |
0 commit comments