2022-10-25 13:06:03 -07:00
|
|
|
const { compilerOptions } = require('./tsconfig.json');
|
|
|
|
|
2023-09-28 07:53:05 -07:00
|
|
|
/** @type {import('ts-jest').TsJestGlobalOptions} */
|
2022-11-14 06:37:32 -08:00
|
|
|
const tsJestOptions = {
|
|
|
|
isolatedModules: true,
|
|
|
|
tsconfig: {
|
|
|
|
...compilerOptions,
|
|
|
|
declaration: false,
|
2023-01-24 17:18:39 -08:00
|
|
|
sourceMap: true,
|
2022-11-14 06:37:32 -08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-08-01 08:32:43 -07:00
|
|
|
const { baseUrl, paths } = require('get-tsconfig').getTsconfig().config?.compilerOptions;
|
|
|
|
|
2022-10-25 13:06:03 -07:00
|
|
|
/** @type {import('jest').Config} */
|
2022-12-28 00:58:14 -08:00
|
|
|
const config = {
|
2022-10-25 13:06:03 -07:00
|
|
|
verbose: true,
|
|
|
|
testEnvironment: 'node',
|
|
|
|
testRegex: '\\.(test|spec)\\.(js|ts)$',
|
|
|
|
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
|
2022-11-14 06:37:32 -08:00
|
|
|
transform: {
|
|
|
|
'^.+\\.ts$': ['ts-jest', tsJestOptions],
|
2022-10-25 13:06:03 -07:00
|
|
|
},
|
2023-08-01 08:32:43 -07:00
|
|
|
// This resolve the path mappings from the tsconfig relative to each jest.config.js
|
|
|
|
moduleNameMapper: Object.entries(paths || {}).reduce((acc, [path, [mapping]]) => {
|
|
|
|
path = `^${path.replace(/\/\*$/, '/(.*)$')}`;
|
2024-06-06 03:18:47 -07:00
|
|
|
mapping = mapping.replace(/^\.?\.\/(?:(.*)\/)?\*$/, '$1');
|
2023-08-01 08:32:43 -07:00
|
|
|
mapping = mapping ? `/${mapping}` : '';
|
2024-06-06 03:18:47 -07:00
|
|
|
acc[path] = mapping.startsWith('/test')
|
|
|
|
? '<rootDir>' + mapping + '/$1'
|
|
|
|
: '<rootDir>' + (baseUrl ? `/${baseUrl.replace(/^\.\//, '')}` : '') + mapping + '/$1';
|
2023-08-01 08:32:43 -07:00
|
|
|
return acc;
|
|
|
|
}, {}),
|
2023-05-05 08:50:10 -07:00
|
|
|
setupFilesAfterEnv: ['jest-expect-message'],
|
2023-11-07 05:19:39 -08:00
|
|
|
collectCoverage: process.env.COVERAGE_ENABLED === 'true',
|
2024-01-09 07:18:20 -08:00
|
|
|
coverageReporters: ['text-summary'],
|
2023-03-10 07:53:05 -08:00
|
|
|
collectCoverageFrom: ['src/**/*.ts'],
|
2022-10-25 13:06:03 -07:00
|
|
|
};
|
2022-12-28 00:58:14 -08:00
|
|
|
|
|
|
|
if (process.env.CI === 'true') {
|
2023-03-17 09:24:05 -07:00
|
|
|
config.workerIdleMemoryLimit = 1024;
|
2023-03-10 07:53:05 -08:00
|
|
|
config.coverageReporters = ['cobertura'];
|
2022-12-28 00:58:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = config;
|