-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
47 lines (41 loc) · 1.5 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
38
39
40
41
42
43
44
45
46
47
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: "./",
moduleDirectories: ["node_modules", "<rootDir>"],
});
const makeModuleNameMapper = (srcPath, tsconfigPath) => {
// Get paths from tsconfig
const { paths } = require(tsconfigPath).compilerOptions;
const aliases = {};
// Iterate over paths and convert them into moduleNameMapper format
Object.keys(paths).forEach((item) => {
const key = item.replace("/*", "/(.*)");
const path = paths[item][0].replace("/*", "/$1");
aliases[key] = srcPath + "/" + path;
});
return aliases;
};
// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const customJestConfig = {
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
moduleNameMapper: makeModuleNameMapper("<rootDir>", "./tsconfig.json"),
testEnvironment: "jest-environment-jsdom",
testPathIgnorePatterns: ["<rootDir>/node_modules/", "<rootDir>/.next/"],
roots: ["<rootDir>"],
testMatch: [
"**/__tests__/**/*.+(ts|tsx|js)",
"**/?(*.)+(spec|test).+(ts|tsx|js)",
],
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "babel-jest",
},
transformIgnorePatterns: [
"/node_modules/",
"^.+\\.module\\.(css|sass|scss)$",
],
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
};
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createJestConfig(customJestConfig);