-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
/
args.js
634 lines (624 loc) · 18.8 KB
/
args.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
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
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {Argv} from 'types/Argv';
import {isJSONString} from 'jest-config';
import isCI from 'is-ci';
export const check = (argv: Argv) => {
if (argv.runInBand && argv.hasOwnProperty('maxWorkers')) {
throw new Error(
'Both --runInBand and --maxWorkers were specified, but these two ' +
'options do not make sense together. Which is it?',
);
}
for (const key of [
'onlyChanged',
'lastCommit',
'changedFilesWithAncestor',
'changedSince',
]) {
if (argv[key] && argv.watchAll) {
throw new Error(
`Both --${key} and --watchAll were specified, but these two ` +
'options do not make sense together. Try the --watch option which ' +
'reruns only tests related to changed files.',
);
}
}
if (argv.findRelatedTests && argv._.length === 0) {
throw new Error(
'The --findRelatedTests option requires file paths to be specified.\n' +
'Example usage: jest --findRelatedTests ./src/source.js ' +
'./src/index.js.',
);
}
if (argv.hasOwnProperty('maxWorkers') && argv.maxWorkers === undefined) {
throw new Error(
'The --maxWorkers (-w) option requires a number to be specified.\n' +
'Example usage: jest --maxWorkers 2\n' +
'Or did you mean --watch?',
);
}
if (
argv.config &&
!isJSONString(argv.config) &&
!argv.config.match(/\.js(on)?$/)
) {
throw new Error(
'The --config option requires a JSON string literal, or a file path with a .js or .json extension.\n' +
'Example usage: jest --config ./jest.config.js',
);
}
return true;
};
export const usage =
'Usage: $0 [--config=<pathToConfigFile>] [TestPathPattern]';
export const docs = 'Documentation: https://facebook.github.io/jest/';
export const options = {
all: {
default: undefined,
description:
'The opposite of `onlyChanged`. If `onlyChanged` is set by ' +
'default, running jest with `--all` will force Jest to run all tests ' +
'instead of running only tests related to changed files.',
},
automock: {
default: undefined,
description: 'Automock all files by default.',
type: 'boolean',
},
bail: {
alias: 'b',
default: undefined,
description: 'Exit the test suite immediately upon the first failing test.',
type: 'boolean',
},
browser: {
default: undefined,
description:
'Respect the "browser" field in package.json ' +
'when resolving modules. Some packages export different versions ' +
'based on whether they are operating in node.js or a browser.',
type: 'boolean',
},
cache: {
default: undefined,
description:
'Whether to use the transform cache. Disable the cache ' +
'using --no-cache.',
type: 'boolean',
},
cacheDirectory: {
description:
'The directory where Jest should store its cached ' +
' dependency information.',
type: 'string',
},
changedFilesWithAncestor: {
default: undefined,
description:
'Runs tests related to the current changes and the changes made in the ' +
'last commit. Behaves similarly to `--onlyChanged`.',
type: 'boolean',
},
changedSince: {
description:
'Runs tests related the changes since the provided branch. If the ' +
'current branch has diverged from the given branch, then only changes ' +
'made locally will be tested. Behaves similarly to `--onlyChanged`.',
nargs: 1,
type: 'string',
},
ci: {
default: isCI,
description:
'Whether to run Jest in continuous integration (CI) mode. ' +
'This option is on by default in most popular CI environments. It will ' +
' prevent snapshots from being written unless explicitly requested.',
type: 'boolean',
},
clearCache: {
default: undefined,
description:
'Clears the configured Jest cache directory and then exits. ' +
'Default directory can be found by calling jest --showConfig',
type: 'boolean',
},
clearMocks: {
default: undefined,
description:
'Automatically clear mock calls and instances between every ' +
'test. Equivalent to calling jest.clearAllMocks() between each test.',
type: 'boolean',
},
collectCoverage: {
default: undefined,
description: 'Alias for --coverage.',
type: 'boolean',
},
collectCoverageFrom: {
description:
'relative to <rootDir> glob pattern matching the files ' +
'that coverage info needs to be collected from.',
type: 'string',
},
collectCoverageOnlyFrom: {
description: 'Explicit list of paths coverage will be restricted to.',
type: 'array',
},
color: {
default: undefined,
description:
'Forces test results output color highlighting (even if ' +
'stdout is not a TTY). Set to false if you would like to have no colors.',
type: 'boolean',
},
colors: {
default: undefined,
description: 'Alias for `--color`.',
type: 'boolean',
},
config: {
alias: 'c',
description:
'The path to a jest config file specifying how to find ' +
'and execute tests. If no rootDir is set in the config, the current ' +
'directory is assumed to be the rootDir for the project. This can also ' +
'be a JSON encoded value which Jest will use as configuration.',
type: 'string',
},
coverage: {
default: undefined,
description:
'Indicates that test coverage information should be ' +
'collected and reported in the output.',
type: 'boolean',
},
coverageDirectory: {
description: 'The directory where Jest should output its coverage files.',
type: 'string',
},
coveragePathIgnorePatterns: {
description:
'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.',
type: 'array',
},
coverageReporters: {
description:
'A list of reporter names that Jest uses when writing ' +
'coverage reports. Any istanbul reporter can be used.',
type: 'array',
},
coverageThreshold: {
description:
'A JSON string with which will be used to configure ' +
'minimum threshold enforcement for coverage results',
type: 'string',
},
debug: {
default: undefined,
description: 'Print debugging info about your jest config.',
type: 'boolean',
},
detectLeaks: {
default: false,
description:
'**EXPERIMENTAL**: Detect memory leaks in tests. After executing a ' +
'test, it will try to garbage collect the global object used, and fail ' +
'if it was leaked',
type: 'boolean',
},
env: {
description:
'The test environment used for all tests. This can point to ' +
'any file or node module. Examples: `jsdom`, `node` or ' +
'`path/to/my-environment.js`',
type: 'string',
},
expand: {
alias: 'e',
default: undefined,
description: 'Use this flag to show full diffs instead of a patch.',
type: 'boolean',
},
findRelatedTests: {
default: undefined,
description:
'Find related tests for a list of source files that were ' +
'passed in as arguments. Useful for pre-commit hook integration to run ' +
'the minimal amount of tests necessary.',
type: 'boolean',
},
forceExit: {
default: undefined,
description:
'Force Jest to exit after all tests have completed running. ' +
'This is useful when resources set up by test code cannot be ' +
'adequately cleaned up.',
type: 'boolean',
},
globalSetup: {
description: 'The path to a module that runs before All Tests.',
type: 'string',
},
globalTeardown: {
description: 'The path to a module that runs after All Tests.',
type: 'string',
},
globals: {
description:
'A JSON string with map of global variables that need ' +
'to be available in all test environments.',
type: 'string',
},
haste: {
description:
'A JSON string with map of variables for the haste module system',
type: 'string',
},
json: {
default: undefined,
description:
'Prints the test results in JSON. This mode will send all ' +
'other test output and user messages to stderr.',
type: 'boolean',
},
lastCommit: {
default: undefined,
description:
'Run all tests affected by file changes in the last commit made. ' +
'Behaves similarly to `--onlyChanged`.',
type: 'boolean',
},
listTests: {
default: false,
description:
'Lists all tests Jest will run given the arguments and ' +
'exits. Most useful in a CI system together with `--findRelatedTests` ' +
'to determine the tests Jest will run based on specific files',
type: 'boolean',
},
logHeapUsage: {
default: undefined,
description:
'Logs the heap usage after every test. Useful to debug ' +
'memory leaks. Use together with `--runInBand` and `--expose-gc` in ' +
'node.',
type: 'boolean',
},
mapCoverage: {
default: undefined,
description:
'Maps code coverage reports against original source code ' +
'when transformers supply source maps.',
type: 'boolean',
},
maxWorkers: {
alias: 'w',
description:
'Specifies the maximum number of workers the worker-pool ' +
'will spawn for running tests. This defaults to the number of the ' +
'cores available on your machine. (its usually best not to override ' +
'this default)',
type: 'number',
},
moduleDirectories: {
description:
'An array of directory names to be searched recursively ' +
"up from the requiring module's location.",
type: 'array',
},
moduleFileExtensions: {
description:
'An array of file extensions your modules use. If you ' +
'require modules without specifying a file extension, these are the ' +
'extensions Jest will look for. ',
type: 'array',
},
moduleNameMapper: {
description:
'A JSON string with a map from regular expressions to ' +
'module names that allow to stub out resources, like images or ' +
'styles with a single module',
type: 'string',
},
modulePathIgnorePatterns: {
description:
'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.',
type: 'array',
},
modulePaths: {
description:
'An alternative API to setting the NODE_PATH env variable, ' +
'modulePaths is an array of absolute paths to additional locations to ' +
'search when resolving modules.',
type: 'array',
},
noStackTrace: {
default: undefined,
description: 'Disables stack trace in test results output',
type: 'boolean',
},
notify: {
default: undefined,
description: 'Activates notifications for test results.',
type: 'boolean',
},
notifyMode: {
default: 'always',
description: 'Specifies when notifications will appear for test results.',
type: 'string',
},
onlyChanged: {
alias: 'o',
default: undefined,
description:
'Attempts to identify which tests to run based on which ' +
"files have changed in the current repository. Only works if you're " +
'running tests in a git or hg repository at the moment.',
type: 'boolean',
},
onlyFailures: {
alias: 'f',
default: undefined,
description: 'Run tests that failed in the previous execution.',
type: 'boolean',
},
outputFile: {
description:
'Write test results to a file when the --json option is ' +
'also specified.',
type: 'string',
},
passWithNoTests: {
default: false,
description:
'Will not fail if no tests are found (for example while using `--testPathPattern`.)',
type: 'boolean',
},
preset: {
description: "A preset that is used as a base for Jest's configuration.",
type: 'string',
},
projects: {
description:
'A list of projects that use Jest to run all tests of all ' +
'projects in a single instance of Jest.',
type: 'array',
},
reporters: {
description: 'A list of custom reporters for the test suite.',
type: 'array',
},
resetMocks: {
default: undefined,
description:
'Automatically reset mock state between every test. ' +
'Equivalent to calling jest.resetAllMocks() between each test.',
type: 'boolean',
},
resetModules: {
default: undefined,
description:
'If enabled, the module registry for every test file will ' +
'be reset before running each individual test.',
type: 'boolean',
},
resolver: {
description: 'A JSON string which allows the use of a custom resolver.',
type: 'string',
},
restoreMocks: {
default: undefined,
description:
'Automatically restore mock state and implementation between every test. ' +
'Equivalent to calling jest.restoreAllMocks() between each test.',
type: 'boolean',
},
rootDir: {
description:
'The root directory that Jest should scan for tests and ' +
'modules within.',
type: 'string',
},
roots: {
description:
'A list of paths to directories that Jest should use to ' +
'search for files in.',
type: 'array',
},
runInBand: {
alias: 'i',
default: undefined,
description:
'Run all tests serially in the current process (rather than ' +
'creating a worker pool of child processes that run tests). This ' +
'is sometimes useful for debugging, but such use cases are pretty ' +
'rare.',
type: 'boolean',
},
runTestsByPath: {
default: false,
description:
'Used when provided patterns are exact file paths. This avoids ' +
'converting them into a regular expression and matching it against ' +
'every single file.',
type: 'boolean',
},
setupFiles: {
description:
'The paths to modules that run some code to configure or ' +
'set up the testing environment before each test. ',
type: 'array',
},
setupTestFrameworkScriptFile: {
description:
'The path to a module that runs some code to configure or ' +
'set up the testing framework before each test.',
type: 'string',
},
showConfig: {
default: undefined,
description: 'Print your jest config and then exits.',
type: 'boolean',
},
silent: {
default: undefined,
description: 'Prevent tests from printing messages through the console.',
type: 'boolean',
},
snapshotSerializers: {
description:
'A list of paths to snapshot serializer modules Jest should ' +
'use for snapshot testing.',
type: 'array',
},
testEnvironment: {
description: 'Alias for --env',
type: 'string',
},
testFailureExitCode: {
description: 'Exit code of `jest` command if the test run failed',
type: 'string', // number
},
testLocationInResults: {
default: false,
description: 'Add `location` information to the test results',
type: 'boolean',
},
testMatch: {
description: 'The glob patterns Jest uses to detect test files.',
type: 'array',
},
testNamePattern: {
alias: 't',
description: 'Run only tests with a name that matches the regex pattern.',
type: 'string',
},
testPathIgnorePatterns: {
description:
'An array of regexp pattern strings that are matched ' +
'against all test paths before executing the test. If the test path ' +
'matches any of the patterns, it will be skipped.',
type: 'array',
},
testPathPattern: {
description:
'A regexp pattern string that is matched against all tests ' +
'paths before executing the test.',
type: 'array',
},
testRegex: {
description: 'The regexp pattern Jest uses to detect test files.',
type: 'string',
},
testResultsProcessor: {
description:
'Allows the use of a custom results processor. ' +
'This processor must be a node module that exports ' +
'a function expecting as the first argument the result object',
type: 'string',
},
testRunner: {
description:
'Allows to specify a custom test runner. The default is ' +
' `jasmine2`. A path to a custom test runner can be provided: ' +
'`<rootDir>/path/to/testRunner.js`.',
type: 'string',
},
testURL: {
description: 'This option sets the URL for the jsdom environment.',
type: 'string',
},
timers: {
description:
'Setting this value to fake allows the use of fake timers ' +
'for functions such as setTimeout.',
type: 'string',
},
transform: {
description:
'A JSON string which maps from regular expressions to paths ' +
'to transformers.',
type: 'string',
},
transformIgnorePatterns: {
description:
'An array of regexp pattern strings that are matched ' +
'against all source file paths before transformation.',
type: 'array',
},
unmockedModulePathPatterns: {
description:
'An array of regexp pattern strings that are matched ' +
'against all modules before the module loader will automatically ' +
'return a mock for them.',
type: 'array',
},
updateSnapshot: {
alias: 'u',
default: undefined,
description:
'Use this flag to re-record snapshots. ' +
'Can be used together with a test suite pattern or with ' +
'`--testNamePattern` to re-record snapshot for test matching ' +
'the pattern',
type: 'boolean',
},
useStderr: {
default: undefined,
description: 'Divert all output to stderr.',
type: 'boolean',
},
verbose: {
default: undefined,
description:
'Display individual test results with the test suite hierarchy.',
type: 'boolean',
},
version: {
alias: 'v',
default: undefined,
description: 'Print the version and exit',
type: 'boolean',
},
watch: {
default: undefined,
description:
'Watch files for changes and rerun tests related to ' +
'changed files. If you want to re-run all tests when a file has ' +
'changed, use the `--watchAll` option.',
type: 'boolean',
},
watchAll: {
default: undefined,
description:
'Watch files for changes and rerun all tests. If you want ' +
'to re-run only the tests related to the changed files, use the ' +
'`--watch` option.',
type: 'boolean',
},
watchPathIgnorePatterns: {
description:
'An array of regexp pattern strings that are matched ' +
'against all paths before trigger test re-run in watch mode. ' +
'If the test path matches any of the patterns, it will be skipped.',
type: 'array',
},
watchman: {
default: undefined,
description:
'Whether to use watchman for file crawling. Disable using ' +
'--no-watchman.',
type: 'boolean',
},
};