-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.config.ts
53 lines (47 loc) · 1.38 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
import tsConfig from "./tsconfig.json";
import { createDefaultPreset } from "ts-jest";
import type { Config } from "@jest/types";
import * as path from "node:path";
interface TsConfigPaths {
[key: string]: string[];
}
function convertTsConfigPathsToModuleNameMapper(
paths: TsConfigPaths = {},
): Record<string, string> {
const moduleNameMapper: Record<string, string> = {};
for (const [key, value] of Object.entries(paths)) {
const jestKey = `^${key.replace(/\*/, "(.*)")}$`;
const jestValue = path.join(
"<rootDir>",
"./",
value[0].replace(/\*/, "$1"),
);
moduleNameMapper[jestKey] = jestValue;
}
return moduleNameMapper;
}
const defaultPreset = createDefaultPreset();
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
...defaultPreset,
testEnvironment: "node",
extensionsToTreatAsEsm: [".ts", ".tsx"],
transformIgnorePatterns: ["/node_modules/"],
reporters: [
"default",
["jest-junit", { outputDirectory: "./coverage", outputName: "junit.xml" }],
],
coverageReporters: ["html", "text", "text-summary", "cobertura"],
coveragePathIgnorePatterns: [
"/node_modules/",
"/src/index.ts",
"/src/zod/*",
"/dist/",
"/types/",
"/test/arbitrary.ts",
"/config/",
],
moduleNameMapper: convertTsConfigPathsToModuleNameMapper(
tsConfig.compilerOptions.paths,
),
} as Config.InitialOptions;