-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjest.config.js
More file actions
56 lines (52 loc) · 2 KB
/
Copy pathjest.config.js
File metadata and controls
56 lines (52 loc) · 2 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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: "./",
});
// Add any custom config to be passed to Jest
const config = {
coverageProvider: "babel",
// Mirrors the "@/*" -> "./src/*" alias in tsconfig.json so tests can mock
// modules by the same specifier the source imports them with.
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1",
},
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
testEnvironment: "jsdom",
// The two end-to-end suites drive real browsers and have their own runners.
// Without this, Jest collects the Playwright specs and fails on
// `@playwright/test` refusing to be imported outside a Playwright process.
testPathIgnorePatterns: [
"<rootDir>/node_modules/",
"<rootDir>/e2e-tests/",
"<rootDir>/e2e-web/",
"<rootDir>/out/",
],
};
// next/jest builds its own `transformIgnorePatterns` from the ESM-only
// packages it finds in package.json and discards whatever the caller passes.
// It spots `d3` (a direct dependency) but not the `d3-*` packages d3 itself
// pulls in, so importing any d3 entry point still blows up on `export`. These
// are spliced into next's own allow-list rather than added as extra patterns:
// a path is ignored when *any* pattern matches, so a new pattern would not
// undo an existing match.
const EXTRA_ESM_PACKAGES = [
"d3-[^/]+",
"internmap",
"delaunator",
"robust-predicates",
].join("|");
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
module.exports = async () => {
const nextConfig = await createJestConfig(config)();
return {
...nextConfig,
transformIgnorePatterns: (nextConfig.transformIgnorePatterns ?? []).map(
(pattern) =>
pattern.includes("/node_modules/")
? pattern.replace("(?!(", `(?!(${EXTRA_ESM_PACKAGES}|`)
: pattern
),
};
};