1
- module . exports = {
2
- roots : [ "<rootDir>/__tests__/" ] ,
3
- collectCoverageFrom : [
4
- "**/*.{js,jsx,ts,tsx}" ,
5
- "!**/*.d.ts" ,
6
- "!**/node_modules/**" ,
7
- ] ,
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 = {
8
10
moduleNameMapper : {
9
11
/* Handle CSS imports (with CSS modules)
10
12
https://jestjs.io/docs/webpack#mocking-css-modules */
@@ -18,16 +20,10 @@ module.exports = {
18
20
"^.+\\.(jpg|jpeg|png|gif|webp|avif|svg)$" :
19
21
"<rootDir>/__mocks__/fileMock.js" ,
20
22
} ,
21
- testPathIgnorePatterns : [ "<rootDir>/node_modules/" , "<rootDir>/.next/" ] ,
22
- testEnvironment : "jsdom" ,
23
- transform : {
24
- /* Use babel-jest to transpile tests with the next/babel preset
25
- https://jestjs.io/docs/configuration#transform-objectstring-pathtotransformer--pathtotransformer-object */
26
- "^.+\\.(js|jsx|ts|tsx)$" : [ "babel-jest" , { presets : [ "next/babel" ] } ] ,
27
- } ,
28
- transformIgnorePatterns : [
29
- "/node_modules/" ,
30
- "^.+\\.module\\.(css|sass|scss)$" ,
31
- ] ,
23
+ roots : [ "<rootDir>/__tests__/" ] ,
32
24
setupFilesAfterEnv : [ "<rootDir>/jest.setup.js" ] ,
25
+ testEnvironment : "jest-environment-jsdom" ,
33
26
} ;
27
+
28
+ // createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
29
+ module . exports = createJestConfig ( customJestConfig ) ;
0 commit comments