-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.ts
More file actions
41 lines (38 loc) · 1.67 KB
/
jest.config.ts
File metadata and controls
41 lines (38 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import nextJest from 'next/jest';
import type { Config } from '@jest/types';
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: './',
});
// Add any custom config to be passed to Jest
const customJestConfig: Config.InitialOptions = {
preset: 'ts-jest',
// setupFiles: ['<rootDir>/jestSetup.js'],
setupFilesAfterEnv: ['<rootDir>/src/jest/jestCommonSetup.ts'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1',
// '^uuid$': require.resolve('uuid'), // Example for the 'uuid' package
'next-auth/react': '<rootDir>/__mocks__/next-auth/react.js',
'next-auth': '<rootDir>/__mocks__/next-auth/index.js',
},
transformIgnorePatterns: [
// Ignore transformation for most node_modules, but allow specific packages to be transformed
'node_modules/(?!.*@auth|.*@panva)',
],
transform: {
// Ensure we use the correct transform for TypeScript files
'^.+\\.(ts|tsx|js|jsx)$': 'ts-jest',
// '^.+\\.js$': ['babel-jest', { configFile: './babel.config.jest.js' }],
// '^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }],
},
// Support ES modules
// extensionsToTreatAsEsm: ['.ts', '.tsx', '.js', '.jsx'], // Validation Error: Option: extensionsToTreatAsEsm: ['.ts', '.tsx', '.js', '.jsx'] includes '.js' which is always inferred based on type in its nearest package.json.
extensionsToTreatAsEsm: ['.ts', '.tsx', '.jsx'],
globals: {
'ts-jest': {
useESM: true,
},
},
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);