-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjest.config.js
63 lines (46 loc) · 1.94 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* For a detailed explanation regarding each configuration property, visit:
* https://jestjs.io/docs/configuration
*/
const nextJest = require("next/jest");
/** @type {import('jest').Config} */
const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});
/** @type {import('jest').Config} */
const config = {
testPathIgnorePatterns: ['/node_modules/', 'e2e'],
// Automatically clear mock calls, instances, contexts and results before every test
clearMocks: true,
// Indicates whether the coverage information should be collected while executing the test
collectCoverage: true,
// The directory where Jest should output its coverage files
coverageDirectory: "coverage",
// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",
// The test environment that will be used for testing
testEnvironment: "jsdom",
moduleDirectories: ["node_modules", "src"],
moduleNameMapper: {
"^@/(.*)$": ['<rootDir>/$1'],
// https://github.com/jestjs/jest/issues/12036
'^d3-(.+)$': '<rootDir>/node_modules/d3-$1/dist/d3-$1.js',
},
setupFiles: ['<rootDir>/setup-jest.ts'],
preset: 'ts-jest',
// Ignore node_modules, EXCEPT the ones listed here
transformIgnorePatterns: ['/node_modules/(?!(p-queue|p-timeout|mui-sonner|d3-scale)/)']
};
// next adds /node_modules/ to the start of the ignore list, which we need to remove
// in order to add exceptions
function createModifiedJestConfig(jestConfig) {
return async () => {
const nextConfig = await createJestConfig(jestConfig)();
nextConfig.transformIgnorePatterns =
nextConfig.transformIgnorePatterns.filter((path) => path !== '/node_modules/');
return nextConfig;
};
}
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = createModifiedJestConfig(config);