-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjest.shared.ts
101 lines (92 loc) · 3.04 KB
/
jest.shared.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
import path from 'path';
import { lstatSync, readdirSync } from 'fs';
import inspector from 'inspector';
import { Config } from '@jest/types';
export { Config };
// get listing of packages in the mono repo
export const basePath = path.resolve(__dirname, 'packages');
export const packages = readdirSync(basePath).filter((name) => lstatSync(path.join(basePath, name)).isDirectory());
// If we are debugging then extend the timeout to max value, otherwise use the default.
const testTimeout = inspector.url() ? 1e8 : undefined;
const colors = [
'green',
'yellow',
'blue',
'magenta',
'cyan',
'greenBright',
'yellowBright',
'blueBright',
'magentaBright',
'cyanBright',
] as const;
const transform: Config.InitialProjectOptions['transform'] = {
'^.+\\.tsx?$': '@swc/jest',
};
export const rootConfig: Config.InitialOptions = {
rootDir: __dirname,
coverageDirectory: '<rootDir>/coverage',
preset: '@lifeomic/jest-config',
testEnvironment: 'node',
collectCoverage: true,
clearMocks: true,
restoreMocks: true,
resetMocks: true,
transform,
verbose: true,
testTimeout,
};
const projectConfigsMap = packages.reduce<Record<string, Config.InitialProjectOptions>>((acc, packageName, idx) => ({
...acc,
[packageName]: {
rootDir: path.join(basePath, packageName),
displayName: { name: packageName, color: colors[idx % colors.length] },
testMatch: ['<rootDir>/test/unit/**/*.test.ts'],
transform,
// Started getting strange errors where the mocks weren't reset. Moving these configs here fixed the issue...
clearMocks: true,
restoreMocks: true,
resetMocks: true,
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
coveragePathIgnorePatterns: [
'.yarn',
'<rootDir>/test',
],
},
}), {} as Record<string, Config.InitialProjectOptions>);
export const getProjectConfig = (dirName: string): Config.InitialProjectOptions => projectConfigsMap[path.basename(dirName)];
export const rootIntegrationConfig: Config.InitialOptions = {
preset: '@lifeomic/jest-config',
testEnvironment: 'node',
collectCoverage: false,
clearMocks: true,
restoreMocks: true,
resetMocks: true,
verbose: true,
testTimeout,
};
const projectIntegrationConfigsMap = packages.reduce<Record<string, Config.InitialProjectOptions>>((acc, packageName, idx) => ({
...acc,
[packageName]: {
collectCoverageFrom: [
'<rootDir>/src/**/*.ts',
],
rootDir: path.join(basePath, packageName),
displayName: { name: packageName, color: colors[idx % colors.length] },
testMatch: ['<rootDir>/test/integration/**/*.test.ts'],
transform,
// Started getting strange errors where the mocks weren't reset. Moving these configs here fixed the issue...
clearMocks: true,
restoreMocks: true,
resetMocks: true,
},
}), {} as Record<string, Config.InitialProjectOptions>);
export const getProjectIntegrationConfig = (dirName: string): Config.InitialProjectOptions =>
projectIntegrationConfigsMap[path.basename(dirName)];