-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
Config.ts
496 lines (469 loc) · 13.4 KB
/
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import type {ForegroundColor} from 'chalk';
import type {ReportOptions} from 'istanbul-reports';
import type {Arguments} from 'yargs';
import type {TestPathPatterns} from '@jest/pattern';
import type {InitialOptions, SnapshotFormat} from '@jest/schemas';
export type {InitialOptions} from '@jest/schemas';
type CoverageProvider = 'babel' | 'v8';
export type FakeableAPI =
| 'Date'
| 'hrtime'
| 'nextTick'
| 'performance'
| 'queueMicrotask'
| 'requestAnimationFrame'
| 'cancelAnimationFrame'
| 'requestIdleCallback'
| 'cancelIdleCallback'
| 'setImmediate'
| 'clearImmediate'
| 'setInterval'
| 'clearInterval'
| 'setTimeout'
| 'clearTimeout';
export type GlobalFakeTimersConfig = {
/**
* Whether fake timers should be enabled globally for all test files.
*
* @defaultValue
* The default is `false`.
*/
enableGlobally?: boolean;
};
export type FakeTimersConfig = {
/**
* If set to `true` all timers will be advanced automatically
* by 20 milliseconds every 20 milliseconds. A custom time delta
* may be provided by passing a number.
*
* @defaultValue
* The default is `false`.
*/
advanceTimers?: boolean | number;
/**
* List of names of APIs (e.g. `Date`, `nextTick()`, `setImmediate()`,
* `setTimeout()`) that should not be faked.
*
* @defaultValue
* The default is `[]`, meaning all APIs are faked.
*/
doNotFake?: Array<FakeableAPI>;
/**
* Sets current system time to be used by fake timers, in milliseconds.
*
* @defaultValue
* The default is `Date.now()`.
*/
now?: number | Date;
/**
* The maximum number of recursive timers that will be run when calling
* `jest.runAllTimers()`.
*
* @defaultValue
* The default is `100_000` timers.
*/
timerLimit?: number;
/**
* Use the old fake timers implementation instead of one backed by
* [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers).
*
* @defaultValue
* The default is `false`.
*/
legacyFakeTimers?: false;
};
export type LegacyFakeTimersConfig = {
/**
* Use the old fake timers implementation instead of one backed by
* [`@sinonjs/fake-timers`](https://github.com/sinonjs/fake-timers).
*
* @defaultValue
* The default is `false`.
*/
legacyFakeTimers?: true;
};
type FakeTimers = GlobalFakeTimersConfig &
(
| (FakeTimersConfig & {
now?: Exclude<FakeTimersConfig['now'], Date>;
})
| LegacyFakeTimersConfig
);
export type HasteConfig = {
/** Whether to hash files using SHA-1. */
computeSha1?: boolean;
/** The platform to use as the default, e.g. 'ios'. */
defaultPlatform?: string | null;
/** Force use of Node's `fs` APIs rather than shelling out to `find` */
forceNodeFilesystemAPI?: boolean;
/**
* Whether to follow symlinks when crawling for files.
* This options cannot be used in projects which use watchman.
* Projects with `watchman` set to true will error if this option is set to true.
*/
enableSymlinks?: boolean;
/** string to a custom implementation of Haste. */
hasteImplModulePath?: string;
/** All platforms to target, e.g ['ios', 'android']. */
platforms?: Array<string>;
/** Whether to throw on error on module collision. */
throwOnModuleCollision?: boolean;
/** Custom HasteMap module */
hasteMapModulePath?: string;
/** Whether to retain all files, allowing e.g. search for tests in `node_modules`. */
retainAllFiles?: boolean;
};
export type CoverageReporterName = keyof ReportOptions;
export type CoverageReporterWithOptions<K = CoverageReporterName> =
K extends CoverageReporterName
? ReportOptions[K] extends never
? never
: [K, Partial<ReportOptions[K]>]
: never;
export type CoverageReporters = Array<
CoverageReporterName | CoverageReporterWithOptions
>;
export type ReporterConfig = [string, Record<string, unknown>];
export type TransformerConfig = [string, Record<string, unknown>];
export interface ConfigGlobals {
[K: string]: unknown;
}
export type DefaultOptions = {
automock: boolean;
bail: number;
cache: boolean;
cacheDirectory: string;
changedFilesWithAncestor: boolean;
ci: boolean;
clearMocks: boolean;
collectCoverage: boolean;
coveragePathIgnorePatterns: Array<string>;
coverageReporters: Array<CoverageReporterName>;
coverageProvider: CoverageProvider;
detectLeaks: boolean;
detectOpenHandles: boolean;
errorOnDeprecated: boolean;
expand: boolean;
extensionsToTreatAsEsm: Array<string>;
fakeTimers: FakeTimers;
forceCoverageMatch: Array<string>;
globals: ConfigGlobals;
haste: HasteConfig;
injectGlobals: boolean;
listTests: boolean;
maxConcurrency: number;
maxWorkers: number | string;
moduleDirectories: Array<string>;
moduleFileExtensions: Array<string>;
moduleNameMapper: Record<string, string | Array<string>>;
modulePathIgnorePatterns: Array<string>;
noStackTrace: boolean;
notify: boolean;
notifyMode: NotifyMode;
openHandlesTimeout: number;
passWithNoTests: boolean;
prettierPath: string;
resetMocks: boolean;
resetModules: boolean;
restoreMocks: boolean;
roots: Array<string>;
runTestsByPath: boolean;
runner: string;
setupFiles: Array<string>;
setupFilesAfterEnv: Array<string>;
skipFilter: boolean;
slowTestThreshold: number;
snapshotFormat: SnapshotFormat;
snapshotSerializers: Array<string>;
testEnvironment: string;
testEnvironmentOptions: Record<string, unknown>;
testFailureExitCode: number;
testLocationInResults: boolean;
testMatch: Array<string>;
testPathIgnorePatterns: Array<string>;
testRegex: Array<string>;
testRunner: string;
testSequencer: string;
transformIgnorePatterns: Array<string>;
useStderr: boolean;
waitNextEventLoopTurnForUnhandledRejectionEvents: boolean;
watch: boolean;
watchPathIgnorePatterns: Array<string>;
watchman: boolean;
workerThreads: boolean;
};
export type DisplayName = {
name: string;
color: typeof ForegroundColor;
};
export type InitialOptionsWithRootDir = InitialOptions &
Required<Pick<InitialOptions, 'rootDir'>>;
export type InitialProjectOptions = Pick<
InitialOptions & {cwd?: string},
keyof ProjectConfig
>;
export type SnapshotUpdateState = 'all' | 'new' | 'none';
type NotifyMode =
| 'always'
| 'failure'
| 'success'
| 'change'
| 'success-change'
| 'failure-change';
export type CoverageThresholdValue = {
branches?: number;
functions?: number;
lines?: number;
statements?: number;
};
type CoverageThreshold = {
[path: string]: CoverageThresholdValue;
global: CoverageThresholdValue;
};
type ShardConfig = {
shardIndex: number;
shardCount: number;
};
export type GlobalConfig = {
bail: number;
changedSince?: string;
changedFilesWithAncestor: boolean;
ci: boolean;
collectCoverage: boolean;
collectCoverageFrom: Array<string>;
coverageDirectory: string;
coveragePathIgnorePatterns?: Array<string>;
coverageProvider: CoverageProvider;
coverageReporters: CoverageReporters;
coverageThreshold?: CoverageThreshold;
detectLeaks: boolean;
detectOpenHandles: boolean;
expand: boolean;
filter?: string;
findRelatedTests: boolean;
forceExit: boolean;
json: boolean;
globalSetup?: string;
globalTeardown?: string;
lastCommit: boolean;
logHeapUsage: boolean;
listTests: boolean;
maxConcurrency: number;
maxWorkers: number;
noStackTrace: boolean;
nonFlagArgs: Array<string>;
noSCM?: boolean;
notify: boolean;
notifyMode: NotifyMode;
outputFile?: string;
onlyChanged: boolean;
onlyFailures: boolean;
openHandlesTimeout: number;
passWithNoTests: boolean;
projects: Array<string>;
randomize?: boolean;
replname?: string;
reporters?: Array<ReporterConfig>;
runInBand: boolean;
runTestsByPath: boolean;
rootDir: string;
seed: number;
showSeed?: boolean;
shard?: ShardConfig;
silent?: boolean;
skipFilter: boolean;
snapshotFormat: SnapshotFormat;
errorOnDeprecated: boolean;
testFailureExitCode: number;
testNamePattern?: string;
testPathPatterns: TestPathPatterns;
testResultsProcessor?: string;
testSequencer: string;
testTimeout?: number;
updateSnapshot: SnapshotUpdateState;
useStderr: boolean;
verbose?: boolean;
waitNextEventLoopTurnForUnhandledRejectionEvents: boolean;
watch: boolean;
watchAll: boolean;
watchman: boolean;
watchPlugins?: Array<{
path: string;
config: Record<string, unknown>;
}> | null;
workerIdleMemoryLimit?: number;
// TODO: make non-optional in Jest 30
workerThreads?: boolean;
};
export type ProjectConfig = {
automock: boolean;
cache: boolean;
cacheDirectory: string;
clearMocks: boolean;
collectCoverageFrom: Array<string>;
coverageDirectory: string;
coveragePathIgnorePatterns: Array<string>;
coverageReporters: CoverageReporters;
cwd: string;
dependencyExtractor?: string;
detectLeaks: boolean;
detectOpenHandles: boolean;
displayName?: DisplayName;
errorOnDeprecated: boolean;
extensionsToTreatAsEsm: Array<string>;
fakeTimers: FakeTimers;
filter?: string;
forceCoverageMatch: Array<string>;
globalSetup?: string;
globalTeardown?: string;
globals: ConfigGlobals;
haste: HasteConfig;
id: string;
injectGlobals: boolean;
moduleDirectories: Array<string>;
moduleFileExtensions: Array<string>;
moduleNameMapper: Array<[string, string]>;
modulePathIgnorePatterns: Array<string>;
modulePaths?: Array<string>;
openHandlesTimeout: number;
preset?: string;
prettierPath: string;
reporters: Array<string | ReporterConfig>;
resetMocks: boolean;
resetModules: boolean;
resolver?: string;
restoreMocks: boolean;
rootDir: string;
roots: Array<string>;
runner: string;
runtime?: string;
sandboxInjectedGlobals: Array<keyof typeof globalThis>;
setupFiles: Array<string>;
setupFilesAfterEnv: Array<string>;
skipFilter: boolean;
skipNodeResolution?: boolean;
slowTestThreshold: number;
snapshotResolver?: string;
snapshotSerializers: Array<string>;
snapshotFormat: SnapshotFormat;
testEnvironment: string;
testEnvironmentOptions: Record<string, unknown>;
testMatch: Array<string>;
testLocationInResults: boolean;
testPathIgnorePatterns: Array<string>;
testRegex: Array<string | RegExp>;
testRunner: string;
testTimeout: number;
transform: Array<[string, string, Record<string, unknown>]>;
transformIgnorePatterns: Array<string>;
watchPathIgnorePatterns: Array<string>;
unmockedModulePathPatterns?: Array<string>;
waitNextEventLoopTurnForUnhandledRejectionEvents: boolean;
workerIdleMemoryLimit?: number;
};
export type SetupAfterEnvPerfStats = {
setupAfterEnvStart: number;
setupAfterEnvEnd: number;
};
export type Argv = Arguments<
Partial<{
all: boolean;
automock: boolean;
bail: boolean | number;
cache: boolean;
cacheDirectory: string;
changedFilesWithAncestor: boolean;
changedSince: string;
ci: boolean;
clearCache: boolean;
clearMocks: boolean;
collectCoverage: boolean;
collectCoverageFrom: string;
color: boolean;
colors: boolean;
config: string;
coverage: boolean;
coverageDirectory: string;
coveragePathIgnorePatterns: Array<string>;
coverageReporters: Array<string>;
coverageThreshold: string;
debug: boolean;
env: string;
expand: boolean;
findRelatedTests: boolean;
forceExit: boolean;
globals: string;
globalSetup: string | null | undefined;
globalTeardown: string | null | undefined;
haste: string;
ignoreProjects: Array<string>;
injectGlobals: boolean;
json: boolean;
lastCommit: boolean;
logHeapUsage: boolean;
maxWorkers: number | string;
moduleDirectories: Array<string>;
moduleFileExtensions: Array<string>;
moduleNameMapper: string;
modulePathIgnorePatterns: Array<string>;
modulePaths: Array<string>;
noStackTrace: boolean;
notify: boolean;
notifyMode: string;
onlyChanged: boolean;
onlyFailures: boolean;
outputFile: string;
preset: string | null | undefined;
prettierPath: string | null | undefined;
projects: Array<string>;
randomize: boolean;
reporters: Array<string>;
resetMocks: boolean;
resetModules: boolean;
resolver: string | null | undefined;
restoreMocks: boolean;
rootDir: string;
roots: Array<string>;
runInBand: boolean;
seed: number;
showSeed: boolean;
selectProjects: Array<string>;
setupFiles: Array<string>;
setupFilesAfterEnv: Array<string>;
shard: string;
showConfig: boolean;
silent: boolean;
snapshotSerializers: Array<string>;
testEnvironment: string;
testEnvironmentOptions: string;
testFailureExitCode: string | null | undefined;
testMatch: Array<string>;
testNamePattern: string;
testPathIgnorePatterns: Array<string>;
testPathPatterns: Array<string>;
testRegex: string | Array<string>;
testResultsProcessor: string;
testRunner: string;
testSequencer: string;
testTimeout: number | null | undefined;
transform: string;
transformIgnorePatterns: Array<string>;
unmockedModulePathPatterns: Array<string> | null | undefined;
updateSnapshot: boolean;
useStderr: boolean;
verbose: boolean;
version: boolean;
watch: boolean;
watchAll: boolean;
watchman: boolean;
watchPathIgnorePatterns: Array<string>;
workerIdleMemoryLimit: number | string;
workerThreads: boolean;
}>
>;