forked from n8n-io/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.js
45 lines (40 loc) · 1.39 KB
/
jest.config.js
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
const { compilerOptions } = require('./tsconfig.json');
/** @type {import('ts-jest').TsJestGlobalOptions} */
const tsJestOptions = {
isolatedModules: true,
tsconfig: {
...compilerOptions,
declaration: false,
sourceMap: true,
},
};
const { baseUrl, paths } = require('get-tsconfig').getTsconfig().config?.compilerOptions;
/** @type {import('jest').Config} */
const config = {
verbose: true,
testEnvironment: 'node',
testRegex: '\\.(test|spec)\\.(js|ts)$',
testPathIgnorePatterns: ['/dist/', '/node_modules/'],
transform: {
'^.+\\.ts$': ['ts-jest', tsJestOptions],
},
// 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(/\/\*$/, '/(.*)$')}`;
mapping = mapping.replace(/^\.?\.\/(?:(.*)\/)?\*$/, '$1');
mapping = mapping ? `/${mapping}` : '';
acc[path] = mapping.startsWith('/test')
? '<rootDir>' + mapping + '/$1'
: '<rootDir>' + (baseUrl ? `/${baseUrl.replace(/^\.\//, '')}` : '') + mapping + '/$1';
return acc;
}, {}),
setupFilesAfterEnv: ['jest-expect-message'],
collectCoverage: process.env.COVERAGE_ENABLED === 'true',
coverageReporters: ['text-summary'],
collectCoverageFrom: ['src/**/*.ts'],
};
if (process.env.CI === 'true') {
config.workerIdleMemoryLimit = 1024;
config.coverageReporters = ['cobertura'];
}
module.exports = config;