-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.config.ts
176 lines (150 loc) · 6 KB
/
jest.config.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/// <reference lib="es2021" />
import {resolve} from 'node:path';
import type {JestConfigWithTsJest} from 'ts-jest';
import {pathsToModuleNameMapper} from 'ts-jest';
process.env.TZ = 'Europe/Moscow';
process.env.FORCE_COLOR = 'true';
process.env.TS_JEST_DISABLE_VER_CHECKER = 'true';
const {compilerOptions} = require(resolve(__dirname, 'tsconfig.json'));
const maxParallel = require('node:os').cpus().length / 2;
const config: JestConfigWithTsJest = {
rootDir: __dirname,
/**
* The preset sets up the environment and is very opinionated
* and based on what we found to be useful at Facebook.
* All of the configuration options can be overwritten
* just as they can be customized when no preset is used.
*/
preset: 'jest-preset-angular',
/**
* The test environment that will be used for testing.
* The default environment in Jest is a Node.js environment.
* If you are building a web app, you can use a browser-like environment through jsdom instead.
*/
testEnvironment: 'jsdom',
/**
* A set of global variables that need
* to be available in all test environments.
*/
/**
* Jest will run .mjs and .js files with nearest package.json's type
* field set to module as ECMAScript Modules. If you have any other files
* that should run with native ESM, you need to specify their file extension here.
*/
extensionsToTreatAsEsm: ['.ts'],
/**
* A list of paths to modules that run some code to configure
* or to set up the testing framework before each test.
*/
setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'],
/**
* A map from regular expressions to paths to transformers.
*/
transform: {
'^.+\\.(ts|js|mjs|html|svg)$': [
'jest-preset-angular',
{
tsconfig: resolve(__dirname, 'tsconfig.spec.json'),
stringifyContentPathRegex: String.raw`\.html$`,
isolatedModules: true,
diagnostics: true,
},
],
},
transformIgnorePatterns: ['node_modules/(?!@angular|rxjs|ngx-highlightjs|@maskito)'],
/**
* The glob patterns Jest uses to detect test files.
*/
testMatch: ['<rootDir>/projects/**/*.spec.ts'],
/**
* A single or array of regexp pattern strings that are tested
* against all tests paths before executing the test.
*/
testPathIgnorePatterns: ['/demo-cypress/', '/demo-playwright/', '/node_modules/'],
/**
* The directory where Jest should output its coverage files.
*/
coverageDirectory: '<rootDir>/coverage',
/**
* An array of glob patterns indicating a set of files for which coverage
* information should be collected. If a file matches the specified glob pattern,
* coverage information will be collected for it even if no tests exist for this file and
* it's never required in the test suite.
*/
collectCoverageFrom: ['<rootDir>/projects/**/*.ts'],
/**
* An array of regexp pattern strings that are matched against
* all file paths before executing the test. If the file path matches
* any of the patterns, coverage information will be skipped.
*/
coveragePathIgnorePatterns: [
'node_modules',
'schematics',
'load-assets.ts',
'.spec.ts',
'.cy.ts',
],
/**
* A map from regular expressions to module names that allow to stub out resources,
* like images or styles with a single module. Modules that are mapped to an alias are
* un mocked by default, regardless of whether auto mocking is enabled or not.
* Use <rootDir> string token to refer to rootDir value if you want to use file paths.
* Additionally, you can substitute captured regex groups using numbered back references.
*/
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
prefix: `<rootDir>/${compilerOptions.baseUrl}/`
.replaceAll('./', '/')
.replaceAll(/\/\/+/g, '/'),
}),
/**
* An array of regexp pattern strings that are matched against all module paths before those
* paths are to be considered 'visible' to the module loader. If a given module's path
* matches any of the patterns, it will not be require()-able in the test environment.
*/
modulePathIgnorePatterns: ['.cache', 'dist', '<rootDir>/dist/', 'package.json'],
/**
* A list of reporter names that Jest uses when writing coverage reports.
* Any istanbul reporter can be used.
*/
coverageReporters: ['lcov', 'clover'],
/**
* The directory where Jest should store its cached dependency information.
*/
cacheDirectory: '<rootDir>/node_modules/.cache/jest',
/**
* A number limiting the number of tests that are allowed to run at the same time when
* using test.concurrent. any test above this limit will be queued and executed once
* a slot is released.
*/
maxConcurrency: maxParallel,
/**
* Specifies the maximum number of workers the worker-pool will spawn for running tests.
* In single run mode, this defaults to the number of the cores available
* on your machine minus one for the main thread.
*/
maxWorkers: maxParallel,
/**
* Display individual test results with the test suite hierarchy.
*/
verbose: true,
/**
* By default, Jest runs all tests and produces all errors into the console upon completion.
* The bail config option can be used here to have Jest stop running tests after n failures.
* Setting bail to true is the same as setting bail to 1
*/
bail: 1,
/**
* Run tests with specified reporters
*/
reporters: ['default'],
/**
* Allows the test suite to pass when no files are found.
*/
passWithNoTests: true,
/**
* Indicates that test coverage information should be collected and reported in the output.
* Optionally pass <boolean> to override option set in configuration.
*/
collectCoverage: true,
};
export default config;