-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjest.config.js
More file actions
31 lines (27 loc) · 881 Bytes
/
jest.config.js
File metadata and controls
31 lines (27 loc) · 881 Bytes
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
/** @type {import('ts-jest').JestConfigWithTsJest} */
function makeModuleNameMapper(srcPath, tsconfigPath) {
// Get paths from tsconfig
const tsConfig = require(tsconfigPath);
const { paths } = tsConfig.compilerOptions;
const aliases = {};
// Iterate over paths and convert them into moduleNameMapper format
Object.keys(paths).forEach(item => {
const key = `^${item.replace('/*', '/(.*)')}$`;
const path = paths[item][0].replace('./lib/', '').replace('*', '$1');
aliases[key] = srcPath + '/' + path;
});
return aliases;
}
const TS_CONFIG_PATH = './tsconfig.json';
const SRC_PATH = '<rootDir>/lib';
module.exports = {
moduleNameMapper: makeModuleNameMapper(SRC_PATH, TS_CONFIG_PATH),
preset: 'ts-jest',
testEnvironment: 'node',
clearMocks: true,
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.general.json',
},
},
};