-
Notifications
You must be signed in to change notification settings - Fork 1
/
jest.preset.ts
80 lines (64 loc) · 2.54 KB
/
jest.preset.ts
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
// @ts-nocheck
const nxPreset = require('@nx/jest/preset');
const isCI = require('is-ci');
const { pathsToModuleNameMapper } = require('ts-jest');
const { paths } = require('./tsconfig.base.json').compilerOptions;
const jestPresetAngularSerializers = require('jest-preset-angular/build/serializers');
// Since some folders are nested (util-test, firebase-test, etc.) we declare the global testFolderRootPath in their jest.preset.ts and it gets read here.
const appTestType = global.appTestType ?? 'node';
let customTestSetup = [].concat(global.customTestSetup ?? []);
const rootPath = global.testFolderRootPath ?? '<rootDir>/../..'; // most packages are 2 folders deep.
let testSetup = `${rootPath}/jest.setup.${appTestType}.ts`;
let testEnvironment = 'node';
let appTestTypeSetupFiles = [testSetup];
let snapshotSerializers = [];
let globalSetup;
let transform;
switch (appTestType) {
case 'angular':
// angular needs jsdom and serializers
// globalSetup = 'jest-preset-angular/global-setup';
snapshotSerializers = jestPresetAngularSerializers;
testEnvironment = 'jsdom';
transform = {
'^.+\\.(ts|js|mjs|html|svg)$': ['jest-preset-angular', { tsconfig: '<rootDir>/tsconfig.spec.json', stringifyContentPathRegex: '\\.(html|svg)$' }]
};
break;
case 'firebase':
case 'nestjs':
case 'node':
transform = {
'^.+\\.(ts|js|mjs|html|svg)$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json', stringifyContentPathRegex: '\\.(html|svg)$' }]
};
break;
}
module.exports = {
/**
* Presets here: https://github.com/nrwl/nx/blob/master/packages/jest/preset/jest-preset.ts
*
* This project prefers to keep all the configuration between projects here, switching between them using the "appTestType" global variable for configuring things.
*/
...nxPreset,
maxWorkers: 3,
setupFilesAfterEnv: [...(nxPreset.setupFilesAfterEnv ?? []), ...appTestTypeSetupFiles, ...(customTestSetup ? customTestSetup : []), 'jest-date'],
testEnvironment,
testEnvironmentOptions: {},
globalSetup,
moduleNameMapper: pathsToModuleNameMapper(paths, { prefix: `${rootPath}/` }), // use to resolve packages in the project
resolver: `${rootPath}/jest.resolver.js`, // '@nx/jest/plugins/resolver',
transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
tsConfig: undefined, // clear tsConfig if set
transform,
snapshotSerializers,
reporters: isCI
? [
'default',
[
'jest-junit',
{
outputDirectory: `${rootPath}/.reports/jest`
}
]
]
: ['default']
};