-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.config.ts
More file actions
91 lines (82 loc) · 3.35 KB
/
Copy pathjest.config.ts
File metadata and controls
91 lines (82 loc) · 3.35 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/**
* Jest configuration with three projects:
* - backend: node environment, mongoose mocked, for entities/applications/infrastructure/interface/API-route unit tests
* - frontend: jsdom environment for components and lib
* - integration: node environment against a real in-memory MongoDB (no mongoose mock)
*/
import { AsyncLocalStorage } from "node:async_hooks";
import type { Config } from "jest";
import nextJest from "next/jest.js";
// Next's server modules (pulled in by the integration project's real route
// imports) capture globalThis.AsyncLocalStorage at import time and otherwise use
// a stub that throws on use. They load in the real Node context, so expose it on
// the real global here (covers in-band runs) and forward it into forked Jest
// workers via NODE_OPTIONS (covers the default parallel runner).
(globalThis as { AsyncLocalStorage?: unknown }).AsyncLocalStorage ??=
AsyncLocalStorage;
const preload = `${process.cwd()}/jest.preload.integration.mjs`;
if (!process.env.NODE_OPTIONS?.includes(preload)) {
process.env.NODE_OPTIONS =
`${process.env.NODE_OPTIONS ?? ""} --import ${preload}`.trim();
}
const createJestConfig = nextJest({ dir: "./" });
// next/jest resolves transform/moduleNameMapper; inject into each project for TS support
export default async function jestConfig() {
const nextResolved = await createJestConfig({})();
const sharedConfig: Partial<Config> = {
transform: nextResolved.transform,
moduleNameMapper: {
...nextResolved.moduleNameMapper,
"^@/(.*)$": "<rootDir>/src/$1",
},
transformIgnorePatterns: [
"/node_modules/(?!.*(inversify|@inversifyjs)/)",
"^.+\\.module\\.(css|sass|scss)$",
],
testPathIgnorePatterns: ["<rootDir>/.next/", "<rootDir>/node_modules/"],
collectCoverageFrom: [
"src/**/*.{ts,tsx}",
"!src/**/*.d.ts",
"!src/types/**/*",
],
};
const backendProject: Config = {
...sharedConfig,
displayName: "backend",
testEnvironment: "node",
setupFilesAfterEnv: ["<rootDir>/jest.setup.backend.ts"],
testMatch: [
"<rootDir>/src/entities/**/*.{spec,test}.{js,jsx,ts,tsx}",
"<rootDir>/src/applications/**/*.{spec,test}.{js,jsx,ts,tsx}",
"<rootDir>/src/infrastructure/**/*.{spec,test}.{js,jsx,ts,tsx}",
"<rootDir>/src/interface/**/*.{spec,test}.{js,jsx,ts,tsx}",
"<rootDir>/src/app/api/**/*.{spec,test}.{js,jsx,ts,tsx}",
"<rootDir>/src/app/apple-splash/**/*.{spec,test}.{js,jsx,ts,tsx}",
],
};
const frontendProject: Config = {
...sharedConfig,
displayName: "frontend",
testEnvironment: "jsdom",
setupFilesAfterEnv: ["<rootDir>/jest.setup.frontend.ts"],
testMatch: [
"<rootDir>/src/components/**/*.{spec,test}.{js,jsx,ts,tsx}",
"<rootDir>/src/lib/**/*.{spec,test}.{js,jsx,ts,tsx}",
"<rootDir>/src/hooks/**/*.{spec,test}.{js,jsx,ts,tsx}",
"<rootDir>/src/app/\\(tabs\\)/**/*.{spec,test}.{js,jsx,ts,tsx}",
],
};
const integrationProject: Config = {
...sharedConfig,
displayName: "integration",
testEnvironment: "node",
setupFilesAfterEnv: ["<rootDir>/jest.setup.integration.ts"],
testMatch: ["<rootDir>/test/integration/**/*.itest.{js,jsx,ts,tsx}"],
};
return {
collectCoverage: true,
coverageDirectory: "coverage",
coverageProvider: "v8",
projects: [backendProject, frontendProject, integrationProject],
} satisfies Config;
}