This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
jest.config.js
37 lines (31 loc) · 1.58 KB
/
jest.config.js
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
const nextJest = require("next/jest");
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 = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
moduleNameMapper: {
// Handle module aliases (this will be automatically configured for you soon)
"^(components|context|constants|hooks|libs|modules|types)/(.*)$":
"<rootDir>/$1/$2",
},
testEnvironment: "jest-environment-jsdom",
transform: {
/*
NOTE: This overrides next/jest's jest-transformer in favor of babel with next's babel presets.
In its current state, the jest.mock doesn't appear to work with jest-transformer.
Since next/jest appears to be the future of configuring and running jest in next.js apps,
this keeps the majority of the config, but uses babel while we wait on a more stable transformer -JR
This is specifically overriding this transform:
https://github.com/vercel/next.js/blob/v12.0.7/packages/next/build/jest/jest.ts#L106-L115
More info on jest + babel + next:
https://github.com/vercel/next.js/blob/v12.0.7/examples/with-jest-babel/jest.config.js#L29
*/
"^.+\\.(js|jsx|ts|tsx)$": ["babel-jest", { presets: ["next/babel"] }],
},
testPathIgnorePatterns: ["/__utils__/"],
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);