forked from openreferral/ServiceNetGateway
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.conf.js
More file actions
76 lines (74 loc) · 2.34 KB
/
jest.conf.js
File metadata and controls
76 lines (74 loc) · 2.34 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const tsconfig = require('../../../tsconfig.json');
module.exports = {
transform: {
'^.+\\.([t|j]sx?)$': 'ts-jest'
},
rootDir: '../../../',
testURL: 'http://localhost/',
cacheDirectory: '<rootDir>/target/jest-cache',
coverageDirectory: '<rootDir>/target/test-results/',
testMatch: ['<rootDir>/src/test/javascript/spec/**/@(*.)@(spec.ts?(x))'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
coveragePathIgnorePatterns: [
'<rootDir>/src/test/javascript'
],
transformIgnorePatterns: [
"node_modules/(?!(@availity)/)"
],
moduleNameMapper: mapTypescriptAliasToJestAlias({
"\\.(css|scss)$": "identity-obj-proxy",
"\\.(png|svg|pdf|jpg|jpeg)$": "<rootDir>/src/test/javascript/__mocks__/fileMock.js"
}),
reporters: [
'default',
[ 'jest-junit', { outputDirectory: './target/test-results/', outputName: 'TESTS-results-jest.xml' } ]
],
testResultsProcessor: 'jest-sonar-reporter',
testPathIgnorePatterns: [
'<rootDir>/node_modules/'
],
setupFiles: [
'<rootDir>/src/test/javascript/spec/enzyme-setup.ts',
'<rootDir>/src/test/javascript/spec/storage-mock.ts'
],
snapshotSerializers: ['enzyme-to-json/serializer'],
globals: {
'ts-jest': {
tsConfig: './tsconfig.test.json',
diagnostics: false
}
},
collectCoverageFrom: [
"!**/*.d.ts",
"src/main/webapp/**/*.{js,jsx,ts,tsx}",
"!**/config/**",
]
};
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;
}