-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathjest.config.ts
111 lines (105 loc) · 4.26 KB
/
jest.config.ts
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* eslint-disable @typescript-eslint/naming-convention */
import type { Config } from "@jest/types";
// Needs commonjs due to ts-jest issues with verbatim modules
const fs = require("fs");
const path = require("path");
//import { pathsToModuleNameMapper } from "ts-jest";
// const t = Object.assign(ts_preset, puppeteer_preset);
// const compilerOptions = JSON.parse(fs.readFileSync(path.resolve(__dirname, "./tsconfig.json"), "utf8")).compilerOptions;
const createProject = (type: string) => {
const setupFileLocation = path.resolve(".", `jest.${type}.setup.ts`);
const setupFilesAfterEnvLocation = path.resolve(".", `jest.${type}.setup.afterEnv.ts`);
const tsConfigPath = path.resolve(".", "tsconfig.json");
const tsTestConfigPath = path.resolve(".", "tsconfig.test.json");
const globalSetup = fs.existsSync(setupFileLocation) ? setupFileLocation : undefined;
const setupFilesAfterEnv = fs.existsSync(setupFilesAfterEnvLocation) ? [setupFilesAfterEnvLocation] : undefined;
const returnValue: Partial<Config.ProjectConfig> = {
displayName: {
name: type,
color: "yellow",
},
testRegex: [`(/test/${type}/.*(test|spec))\\.[tj]sx?$`],
// ----
// moduleNameMapper: pathsToModuleNameMapper(
// {
// "@babylonjs/smart-filters/dist/*": ["core/src/*"],
// "@babylonjs/smart-filters": ["core/src"],
// },
// { prefix: "<rootDir>/packages/" }
// ) as any,
// ----
roots: [path.resolve(".")],
setupFilesAfterEnv: ["@alex_neo/jest-expect-message"],
transform: {
"^.+\\.(ts|tsx)$": [
'ts-jest',
{
useESM: true,
isolatedModules: true,
tsconfig: fs.existsSync(tsTestConfigPath) ? tsTestConfigPath : fs.existsSync(tsConfigPath) ? tsConfigPath : path.resolve(__dirname, "tsconfig.json"),
diagnostics: {
ignoreCodes: ['TS151001'],
},
},
],
"\\.[j]sx?$": "babel-jest",
} as any,
transformIgnorePatterns: ["<rootDir>/node_modules/(?!(@babylonjs)/).*/"],
};
if (globalSetup) {
returnValue.globalSetup = globalSetup;
}
if (setupFilesAfterEnv) {
returnValue.setupFilesAfterEnv?.push(...setupFilesAfterEnv);
}
if (type === "unit") {
return {
...returnValue,
preset: "ts-jest/presets/default-esm", // if puppeteer is needed: "./" + path.relative(__dirname, path.resolve(__dirname, "./scripts/tsPuppeteer.js")),
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts"],
};
} else if (type === "visualization") {
return {
...returnValue,
preset: "./" + path.relative(__dirname, path.resolve(__dirname, "./scripts/tsPuppeteer.js")),
extensionsToTreatAsEsm: [".ts"],
};
} else if (type === "integration" || type === "performance") {
// not yet used
return {
...returnValue,
// preset: "./" + path.relative(__dirname, path.resolve(__dirname, "./scripts/tsPuppeteer.js")),
globalSetup: "jest-environment-puppeteer/setup",
globalTeardown: "jest-environment-puppeteer/teardown",
testEnvironment: "jest-environment-puppeteer",
preset: "jest-puppeteer",
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
"^.+\\.ts$": "ts-jest",
},
extensionsToTreatAsEsm: [".ts"],
};
} else if (type === "interactions") {
return {
...returnValue,
preset: "ts-jest/presets/default-esm",
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts"],
};
} else {
return {};
}
};
// Sync object
module.exports = {
projects: [
createProject("unit"),
// createProject("visualization"),
// createProject("integration"),
// createProject("performance"),
// createProject("interactions")
],
// reporters: ["default", "jest-screenshot/reporter", "jest-junit"],
reporters: ["default", "jest-junit"],
};