-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.conf.js
41 lines (39 loc) · 1.42 KB
/
jest.conf.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
const tsconfig = require('./tsconfig.json');
module.exports = {
setupFiles: ['jest-date-mock'],
cacheDirectory: '<rootDir>/target/jest-cache',
coverageDirectory: '<rootDir>/target/test-results/',
moduleNameMapper: mapTypescriptAliasToJestAlias(),
reporters: ['default', ['jest-junit', { outputDirectory: './target/test-results/', outputName: 'TESTS-results-jest.xml' }]],
testResultsProcessor: 'jest-sonar-reporter',
testMatch: ['<rootDir>/src/main/webapp/app/**/@(*.)@(spec.ts)'],
testURL: 'http://localhost/',
};
function mapTypescriptAliasToJestAlias(alias = {}) {
const jestAliases = { ...alias };
if (!tsconfig.compilerOptions.paths) {
return jestAliases;
}
Object.entries(tsconfig.compilerOptions.paths)
.filter(([key, value]) => {
// use Typescript alias in Jest only if this has value
if (value.length) {
return true;
}
return false;
})
.map(([key, value]) => {
// if Typescript alias ends with /* then in Jest:
// - alias key must end with /(.*)
// - alias value must end with /$1
const regexToReplace = /(.*)\/\*$/;
const aliasKey = key.replace(regexToReplace, '$1/(.*)');
const aliasValue = value[0].replace(regexToReplace, '$1/$$1');
return [aliasKey, `<rootDir>/${aliasValue}`];
})
.reduce((aliases, [key, value]) => {
aliases[key] = value;
return aliases;
}, jestAliases);
return jestAliases;
}