forked from renovatebot/renovate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.ts
94 lines (86 loc) · 2.44 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
import os from 'node:os';
import v8 from 'node:v8';
import type { InitialOptionsTsJest } from 'ts-jest/dist/types';
const ci = !!process.env.CI;
type JestConfig = InitialOptionsTsJest & {
// https://github.com/renovatebot/renovate/issues/17034
workerIdleMemoryLimit?: string;
};
const cpus = os.cpus();
const mem = os.totalmem();
const stats = v8.getHeapStatistics();
process.stderr.write(`Host stats:
Cpus: ${cpus.length}
Memory: ${(mem / 1024 / 1024 / 1024).toFixed(2)} GB
HeapLimit: ${(stats.heap_size_limit / 1024 / 1024 / 1024).toFixed(2)} GB
`);
/**
* https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
* Currently it seems the runner only have 4GB
*/
function jestGithubRunnerSpecs(): JestConfig {
// if (os.platform() === 'darwin') {
// return {
// maxWorkers: 2,
// workerIdleMemoryLimit: '4GB',
// };
// }
return {
maxWorkers: cpus.length,
workerIdleMemoryLimit: '1500MB', // '2GB',
};
}
const config: JestConfig = {
cacheDirectory: '.cache/jest',
clearMocks: true,
collectCoverage: true,
collectCoverageFrom: [
'lib/**/*.{js,ts}',
'!lib/**/*.{d,spec}.ts',
'!lib/**/{__fixtures__,__mocks__,__testutil__,test}/**/*.{js,ts}',
'!lib/**/types.ts',
],
coverageDirectory: './coverage',
coverageReporters: ci
? ['html', 'json', 'text-summary']
: ['html', 'text-summary'],
coverageThreshold: {
global: {
branches: 98,
functions: 100,
lines: 100,
statements: 100,
},
},
transform: {
'\\.ts$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
diagnostics: false,
isolatedModules: true,
},
],
},
modulePathIgnorePatterns: [
'<rootDir>/dist/',
'/__fixtures__/',
'/__mocks__/',
],
reporters: ci ? ['default', 'github-actions'] : ['default'],
setupFilesAfterEnv: [
'jest-extended/all',
'expect-more-jest',
'<rootDir>/test/setup.ts',
'<rootDir>/test/to-migrate.ts',
],
snapshotSerializers: ['<rootDir>/test/newline-snapshot-serializer.ts'],
testEnvironment: 'node',
testRunner: 'jest-circus/runner',
watchPathIgnorePatterns: ['<rootDir>/.cache/', '<rootDir>/coverage/'],
// We can play with that value later for best dev experience
workerIdleMemoryLimit: '500MB',
// add github runner specific limits
...(ci && jestGithubRunnerSpecs()),
};
export default config;