2022-08-16 12:22:29 +00:00
|
|
|
import os from 'os';
|
2022-08-31 14:44:04 +00:00
|
|
|
import v8 from 'v8';
|
2021-03-02 16:16:05 +00:00
|
|
|
import type { InitialOptionsTsJest } from 'ts-jest/dist/types';
|
|
|
|
|
2020-02-28 08:25:14 +00:00
|
|
|
const ci = !!process.env.CI;
|
|
|
|
|
2022-08-16 12:22:29 +00:00
|
|
|
type JestConfig = InitialOptionsTsJest & {
|
|
|
|
// https://github.com/renovatebot/renovate/issues/17034
|
|
|
|
workerIdleMemoryLimit?: string;
|
|
|
|
};
|
|
|
|
|
2022-08-31 14:44:04 +00:00
|
|
|
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
|
|
|
|
`);
|
|
|
|
|
2022-08-16 12:22:29 +00:00
|
|
|
/**
|
|
|
|
* https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources
|
2022-08-31 14:44:04 +00:00
|
|
|
* Currently it seems the runner only have 4GB
|
2022-08-16 12:22:29 +00:00
|
|
|
*/
|
|
|
|
function jestGithubRunnerSpecs(): JestConfig {
|
2022-08-31 14:44:04 +00:00
|
|
|
// if (os.platform() === 'darwin') {
|
|
|
|
// return {
|
|
|
|
// maxWorkers: 2,
|
|
|
|
// workerIdleMemoryLimit: '4GB',
|
|
|
|
// };
|
|
|
|
// }
|
2022-08-16 12:22:29 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
maxWorkers: 2,
|
2022-08-31 14:44:04 +00:00
|
|
|
workerIdleMemoryLimit: '1500MB', // '2GB',
|
2022-08-16 12:22:29 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const config: JestConfig = {
|
2021-03-02 16:16:05 +00:00
|
|
|
preset: 'ts-jest',
|
2020-02-28 08:25:14 +00:00
|
|
|
cacheDirectory: '.cache/jest',
|
|
|
|
coverageDirectory: './coverage',
|
|
|
|
collectCoverage: true,
|
|
|
|
collectCoverageFrom: [
|
|
|
|
'lib/**/*.{js,ts}',
|
|
|
|
'!lib/**/*.{d,spec}.ts',
|
2021-08-05 15:05:22 +00:00
|
|
|
'!lib/**/{__fixtures__,__mocks__,__testutil__,test}/**/*.{js,ts}',
|
2021-03-02 20:44:55 +00:00
|
|
|
'!lib/**/types.ts',
|
2020-02-28 08:25:14 +00:00
|
|
|
],
|
|
|
|
coverageReporters: ci
|
2020-02-28 11:19:18 +00:00
|
|
|
? ['html', 'json', 'text-summary']
|
|
|
|
: ['html', 'text-summary'],
|
2020-02-28 08:25:14 +00:00
|
|
|
coverageThreshold: {
|
|
|
|
global: {
|
2021-12-09 20:50:53 +00:00
|
|
|
branches: 98,
|
2020-02-28 08:25:14 +00:00
|
|
|
functions: 100,
|
|
|
|
lines: 100,
|
|
|
|
statements: 100,
|
|
|
|
},
|
|
|
|
},
|
2022-08-16 12:22:29 +00:00
|
|
|
globals: {
|
|
|
|
'ts-jest': {
|
|
|
|
tsconfig: '<rootDir>/tsconfig.spec.json',
|
|
|
|
diagnostics: false,
|
|
|
|
isolatedModules: true,
|
|
|
|
},
|
|
|
|
},
|
2021-05-26 08:27:39 +00:00
|
|
|
modulePathIgnorePatterns: ['<rootDir>/dist/', '/__fixtures__/'],
|
2022-06-16 16:03:50 +00:00
|
|
|
reporters: ci ? ['default', 'github-actions'] : ['default'],
|
2021-10-27 05:24:36 +00:00
|
|
|
setupFilesAfterEnv: [
|
2021-11-01 15:12:25 +00:00
|
|
|
'jest-extended/all',
|
2021-10-27 05:24:36 +00:00
|
|
|
'expect-more-jest',
|
|
|
|
'<rootDir>/test/setup.ts',
|
2022-01-10 21:01:57 +00:00
|
|
|
'<rootDir>/test/to-migrate.ts',
|
2021-10-27 05:24:36 +00:00
|
|
|
],
|
2020-02-28 08:25:14 +00:00
|
|
|
snapshotSerializers: ['<rootDir>/test/newline-snapshot-serializer.ts'],
|
2020-05-15 11:50:34 +00:00
|
|
|
testEnvironment: 'node',
|
|
|
|
testRunner: 'jest-circus/runner',
|
2021-12-04 09:42:20 +00:00
|
|
|
watchPathIgnorePatterns: ['<rootDir>/.cache/', '<rootDir>/coverage/'],
|
2022-08-16 12:22:29 +00:00
|
|
|
// We can play with that value later for best dev experience
|
|
|
|
workerIdleMemoryLimit: '500MB',
|
|
|
|
// add github runner specific limits
|
|
|
|
...(ci && jestGithubRunnerSpecs()),
|
2020-02-28 08:25:14 +00:00
|
|
|
};
|
2021-03-02 16:16:05 +00:00
|
|
|
|
|
|
|
export default config;
|