|
| 1 | +const nextJest = require('next/jest'); |
| 2 | + |
| 3 | +const createJestConfig = nextJest({ |
| 4 | + // Provide the path to your Next.js app to load next.config.js and .env files in your test environment |
| 5 | + dir: './', |
| 6 | +}); |
| 7 | + |
| 8 | +// Add any custom config to be passed to Jest |
| 9 | +const customJestConfig = { |
| 10 | + // Add more setup options before each test is run |
| 11 | + setupFilesAfterEnv: ['<rootDir>/jest.setup.js'], |
| 12 | + // if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work |
| 13 | + moduleDirectories: ['node_modules', '<rootDir>/'], |
| 14 | + testEnvironment: 'jest-environment-jsdom', |
| 15 | + moduleNameMapper: { |
| 16 | + // Handle module aliases (this will be automatically configured for you soon) |
| 17 | + '^@/components/(.*)$': '<rootDir>/components/$1', |
| 18 | + '^@/app/(.*)$': '<rootDir>/app/$1', |
| 19 | + '^@/lib/(.*)$': '<rootDir>/lib/$1', |
| 20 | + '^@/types/(.*)$': '<rootDir>/types/$1', |
| 21 | + '^.+\\.(css|sass|scss)$': '<rootDir>/__mocks__/styleMock.js', |
| 22 | + '^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$': '<rootDir>/__mocks__/fileMock.js', |
| 23 | + }, |
| 24 | + // Don't ignore node_modules by default |
| 25 | + transformIgnorePatterns: [ |
| 26 | + '/node_modules/(?!(@upstash|@radix-ui|@hookform|@auth|@aws-sdk|@emotion|@mui|@prisma|@radix-ui|@react-email|@supabase|@types|@upstash|next-auth|react-markdown|rehype-raw|remark-gfm|uuid|react-syntax-highlighter)/)', |
| 27 | + ], |
| 28 | + // Add more configuration options as needed |
| 29 | + // transform: { |
| 30 | + // // Use babel-jest to transpile tests with the next/babel preset |
| 31 | + // // https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object |
| 32 | + // '^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }], |
| 33 | + // }, |
| 34 | + // testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/.next/'], |
| 35 | + // testEnvironment: 'jsdom', |
| 36 | + // transform: { |
| 37 | + // // Use babel-jest to transpile tests with the next/babel preset |
| 38 | + // // https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object |
| 39 | + // '^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }], |
| 40 | + // }, |
| 41 | + // transformIgnorePatterns: [ |
| 42 | + // '/node_modules/(?!(react-syntax-highlighter|@heroicons|@aws-sdk|@radix-ui|@emotion|@mui|@prisma|@radix-ui|@react-email|@supabase|@types|@upstash|next-auth|react-markdown|rehype-raw|remark-gfm|uuid)/)', |
| 43 | + // ], |
| 44 | +}; |
| 45 | + |
| 46 | +// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async |
| 47 | +module.exports = createJestConfig(customJestConfig); |
0 commit comments