-
Notifications
You must be signed in to change notification settings - Fork 38
/
jest.config.ut.js
98 lines (95 loc) · 2.96 KB
/
jest.config.ut.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const { resolve, relative } = require('node:path');
const { readFileSync } = require('node:fs');
const { pathsToModuleNameMapper } = require('ts-jest');
const ts = require('typescript');
globalThis.ngJest = {
skipNgcc: true
};
/**
* Jest configuration that can be set at project level
* @param rootDir {string}
* @param isAngularSetup {boolean}
* @param options.tsconfig {string}
* @param options.baseTsconfig {string}
* @returns {import('ts-jest/dist/types').JestConfigWithTsJest}
*/
module.exports.getJestProjectConfig = (rootDir, isAngularSetup, options) => {
const baseTsconfigPath = options?.baseTsconfig ?? resolve(__dirname, './tsconfig.base.json');
const { compilerOptions } = ts.parseConfigFileTextToJson(baseTsconfigPath, readFileSync(baseTsconfigPath, { encoding: 'utf-8' })).config;
const relativePath = relative(rootDir, options?.baseTsconfig ? __dirname(options.baseTsconfig) : __dirname);
const moduleNameMapper = Object.fromEntries(
Object.entries(pathsToModuleNameMapper(compilerOptions.paths))
.map(([moduleName, path]) => [moduleName, `<rootDir>/${relativePath}/${path}`])
);
return {
preset: 'ts-jest',
setupFilesAfterEnv: ['<rootDir>/testing/setup-jest.ts'],
rootDir,
moduleNameMapper,
modulePathIgnorePatterns: [
'<rootDir>/dist',
'<rootDir>/src/package.json'
],
testMatch: [
'<rootDir>/**/*.spec.ts'
],
testPathIgnorePatterns: [
'<rootDir>/.*/templates/.*',
'\\.it\\.spec\\.ts$'
],
fakeTimers: {
enableGlobally: true
},
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\.[mc]?tsx?$': [
'ts-jest',
{
tsconfig: options?.tsconfig ?? '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.html$'
}
]
},
testEnvironmentOptions: {
// workaround for the SDK Core
customExportConditions: ['require', 'node']
},
workerIdleMemoryLimit: '700MB',
...isAngularSetup ? {
preset: 'jest-preset-angular',
transform: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'^.+\\.tsx?$': [
'jest-preset-angular',
{
tsconfig: options?.tsconfig ?? '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.html$'
}
]
},
globalSetup: 'jest-preset-angular/global-setup',
} : {}
};
}
/**
* Jest configuration that can be set at root level
* @returns {import('ts-jest/dist/types').JestConfigWithTsJest}
*/
module.exports.getJestGlobalConfig = (rootDir) => {
return {
testTimeout: 30000,
coverageReporters: ['cobertura'],
reporters: [
'default',
['jest-junit', { outputDirectory: '<rootDir>/dist-test', outputName: 'junit.xml', classNameTemplate: '{filepath}' }],
'github-actions'
],
rootDir,
testMatch: [
'<rootDir>/**/*.spec.ts'
],
testPathIgnorePatterns: [
'\\.spec\\.ts$'
]
}
}