renovate/jest.config.ts

95 lines
2.4 KiB
TypeScript
Raw Normal View History

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: cpus.length,
2022-08-31 14:44:04 +00:00
workerIdleMemoryLimit: '1500MB', // '2GB',
2022-08-16 12:22:29 +00:00
};
}
const config: JestConfig = {
2020-02-28 08:25:14 +00:00
cacheDirectory: '.cache/jest',
clearMocks: true,
2020-02-28 08:25:14 +00:00
coverageDirectory: './coverage',
collectCoverage: true,
collectCoverageFrom: [
'lib/**/*.{js,ts}',
'!lib/**/*.{d,spec}.ts',
'!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: {
branches: 98,
2020-02-28 08:25:14 +00:00
functions: 100,
lines: 100,
statements: 100,
},
},
transform: {
'\\.ts$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
diagnostics: false,
isolatedModules: true,
},
],
2022-08-16 12:22:29 +00:00
},
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',
],
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',
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;