UNPKG

22.4 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.options = exports.docs = exports.usage = exports.check = void 0;
7
8function _jestConfig() {
9 const data = require('jest-config');
10
11 _jestConfig = function _jestConfig() {
12 return data;
13 };
14
15 return data;
16}
17
18function _isCi() {
19 const data = _interopRequireDefault(require('is-ci'));
20
21 _isCi = function _isCi() {
22 return data;
23 };
24
25 return data;
26}
27
28function _interopRequireDefault(obj) {
29 return obj && obj.__esModule ? obj : {default: obj};
30}
31
32/**
33 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
34 *
35 * This source code is licensed under the MIT license found in the
36 * LICENSE file in the root directory of this source tree.
37 */
38const check = argv => {
39 if (argv.runInBand && argv.hasOwnProperty('maxWorkers')) {
40 throw new Error(
41 'Both --runInBand and --maxWorkers were specified, but these two ' +
42 'options do not make sense together. Which is it?'
43 );
44 }
45
46 var _arr = [
47 'onlyChanged',
48 'lastCommit',
49 'changedFilesWithAncestor',
50 'changedSince'
51 ];
52
53 for (var _i = 0; _i < _arr.length; _i++) {
54 const key = _arr[_i];
55
56 if (argv[key] && argv.watchAll) {
57 throw new Error(
58 `Both --${key} and --watchAll were specified, but these two ` +
59 'options do not make sense together. Try the --watch option which ' +
60 'reruns only tests related to changed files.'
61 );
62 }
63 }
64
65 if (argv.findRelatedTests && argv._.length === 0) {
66 throw new Error(
67 'The --findRelatedTests option requires file paths to be specified.\n' +
68 'Example usage: jest --findRelatedTests ./src/source.js ' +
69 './src/index.js.'
70 );
71 }
72
73 if (argv.hasOwnProperty('maxWorkers') && argv.maxWorkers === undefined) {
74 throw new Error(
75 'The --maxWorkers (-w) option requires a number or string to be specified.\n' +
76 'Example usage: jest --maxWorkers 2\n' +
77 'Example usage: jest --maxWorkers 50%\n' +
78 'Or did you mean --watch?'
79 );
80 }
81
82 if (
83 argv.config &&
84 !(0, _jestConfig().isJSONString)(argv.config) &&
85 !argv.config.match(/\.js(on)?$/)
86 ) {
87 throw new Error(
88 'The --config option requires a JSON string literal, or a file path with a .js or .json extension.\n' +
89 'Example usage: jest --config ./jest.config.js'
90 );
91 }
92
93 return true;
94};
95
96exports.check = check;
97const usage = 'Usage: $0 [--config=<pathToConfigFile>] [TestPathPattern]';
98exports.usage = usage;
99const docs = 'Documentation: https://jestjs.io/';
100exports.docs = docs;
101const options = {
102 all: {
103 default: undefined,
104 description:
105 'The opposite of `onlyChanged`. If `onlyChanged` is set by ' +
106 'default, running jest with `--all` will force Jest to run all tests ' +
107 'instead of running only tests related to changed files.',
108 type: 'boolean'
109 },
110 automock: {
111 default: undefined,
112 description: 'Automock all files by default.',
113 type: 'boolean'
114 },
115 bail: {
116 alias: 'b',
117 default: undefined,
118 description:
119 'Exit the test suite immediately after `n` number of failing tests.',
120 type: 'boolean'
121 },
122 browser: {
123 default: undefined,
124 description:
125 'Respect the "browser" field in package.json ' +
126 'when resolving modules. Some packages export different versions ' +
127 'based on whether they are operating in node.js or a browser.',
128 type: 'boolean'
129 },
130 cache: {
131 default: undefined,
132 description:
133 'Whether to use the transform cache. Disable the cache ' +
134 'using --no-cache.',
135 type: 'boolean'
136 },
137 cacheDirectory: {
138 description:
139 'The directory where Jest should store its cached ' +
140 ' dependency information.',
141 type: 'string'
142 },
143 changedFilesWithAncestor: {
144 default: undefined,
145 description:
146 'Runs tests related to the current changes and the changes made in the ' +
147 'last commit. Behaves similarly to `--onlyChanged`.',
148 type: 'boolean'
149 },
150 changedSince: {
151 description:
152 'Runs tests related to the changes since the provided branch. If the ' +
153 'current branch has diverged from the given branch, then only changes ' +
154 'made locally will be tested. Behaves similarly to `--onlyChanged`.',
155 nargs: 1,
156 type: 'string'
157 },
158 ci: {
159 default: _isCi().default,
160 description:
161 'Whether to run Jest in continuous integration (CI) mode. ' +
162 'This option is on by default in most popular CI environments. It will ' +
163 ' prevent snapshots from being written unless explicitly requested.',
164 type: 'boolean'
165 },
166 clearCache: {
167 default: undefined,
168 description:
169 'Clears the configured Jest cache directory and then exits. ' +
170 'Default directory can be found by calling jest --showConfig',
171 type: 'boolean'
172 },
173 clearMocks: {
174 default: undefined,
175 description:
176 'Automatically clear mock calls and instances between every ' +
177 'test. Equivalent to calling jest.clearAllMocks() between each test.',
178 type: 'boolean'
179 },
180 collectCoverage: {
181 default: undefined,
182 description: 'Alias for --coverage.',
183 type: 'boolean'
184 },
185 collectCoverageFrom: {
186 description:
187 'A glob pattern relative to <rootDir> matching the files that coverage ' +
188 'info needs to be collected from.',
189 type: 'string'
190 },
191 collectCoverageOnlyFrom: {
192 description: 'Explicit list of paths coverage will be restricted to.',
193 string: true,
194 type: 'array'
195 },
196 color: {
197 default: undefined,
198 description:
199 'Forces test results output color highlighting (even if ' +
200 'stdout is not a TTY). Set to false if you would like to have no colors.',
201 type: 'boolean'
202 },
203 colors: {
204 default: undefined,
205 description: 'Alias for `--color`.',
206 type: 'boolean'
207 },
208 config: {
209 alias: 'c',
210 description:
211 'The path to a jest config file specifying how to find ' +
212 'and execute tests. If no rootDir is set in the config, the directory ' +
213 'containing the config file is assumed to be the rootDir for the project.' +
214 'This can also be a JSON encoded value which Jest will use as configuration.',
215 type: 'string'
216 },
217 coverage: {
218 default: undefined,
219 description:
220 'Indicates that test coverage information should be ' +
221 'collected and reported in the output.',
222 type: 'boolean'
223 },
224 coverageDirectory: {
225 description: 'The directory where Jest should output its coverage files.',
226 type: 'string'
227 },
228 coveragePathIgnorePatterns: {
229 description:
230 'An array of regexp pattern strings that are matched ' +
231 'against all file paths before executing the test. If the file path' +
232 'matches any of the patterns, coverage information will be skipped.',
233 string: true,
234 type: 'array'
235 },
236 coverageReporters: {
237 description:
238 'A list of reporter names that Jest uses when writing ' +
239 'coverage reports. Any istanbul reporter can be used.',
240 string: true,
241 type: 'array'
242 },
243 coverageThreshold: {
244 description:
245 'A JSON string with which will be used to configure ' +
246 'minimum threshold enforcement for coverage results',
247 type: 'string'
248 },
249 debug: {
250 default: undefined,
251 description: 'Print debugging info about your jest config.',
252 type: 'boolean'
253 },
254 detectLeaks: {
255 default: false,
256 description:
257 '**EXPERIMENTAL**: Detect memory leaks in tests. After executing a ' +
258 'test, it will try to garbage collect the global object used, and fail ' +
259 'if it was leaked',
260 type: 'boolean'
261 },
262 detectOpenHandles: {
263 default: false,
264 description:
265 'Print out remaining open handles preventing Jest from exiting at the ' +
266 'end of a test run. Implies `runInBand`.',
267 type: 'boolean'
268 },
269 env: {
270 description:
271 'The test environment used for all tests. This can point to ' +
272 'any file or node module. Examples: `jsdom`, `node` or ' +
273 '`path/to/my-environment.js`',
274 type: 'string'
275 },
276 errorOnDeprecated: {
277 default: false,
278 description: 'Make calling deprecated APIs throw helpful error messages.',
279 type: 'boolean'
280 },
281 expand: {
282 alias: 'e',
283 default: undefined,
284 description: 'Use this flag to show full diffs instead of a patch.',
285 type: 'boolean'
286 },
287 filter: {
288 default: undefined,
289 description:
290 'Path to a module exporting a filtering function. This method receives ' +
291 'a list of tests which can be manipulated to exclude tests from ' +
292 'running. Especially useful when used in conjunction with a testing ' +
293 'infrastructure to filter known broken tests.',
294 type: 'string'
295 },
296 findRelatedTests: {
297 default: undefined,
298 description:
299 'Find related tests for a list of source files that were ' +
300 'passed in as arguments. Useful for pre-commit hook integration to run ' +
301 'the minimal amount of tests necessary.',
302 type: 'boolean'
303 },
304 forceExit: {
305 default: undefined,
306 description:
307 'Force Jest to exit after all tests have completed running. ' +
308 'This is useful when resources set up by test code cannot be ' +
309 'adequately cleaned up.',
310 type: 'boolean'
311 },
312 globalSetup: {
313 description: 'The path to a module that runs before All Tests.',
314 type: 'string'
315 },
316 globalTeardown: {
317 description: 'The path to a module that runs after All Tests.',
318 type: 'string'
319 },
320 globals: {
321 description:
322 'A JSON string with map of global variables that need ' +
323 'to be available in all test environments.',
324 type: 'string'
325 },
326 haste: {
327 description:
328 'A JSON string with map of variables for the haste module system',
329 type: 'string'
330 },
331 init: {
332 description: 'Generate a basic configuration file',
333 type: 'boolean'
334 },
335 json: {
336 default: undefined,
337 description:
338 'Prints the test results in JSON. This mode will send all ' +
339 'other test output and user messages to stderr.',
340 type: 'boolean'
341 },
342 lastCommit: {
343 default: undefined,
344 description:
345 'Run all tests affected by file changes in the last commit made. ' +
346 'Behaves similarly to `--onlyChanged`.',
347 type: 'boolean'
348 },
349 listTests: {
350 default: false,
351 description:
352 'Lists all tests Jest will run given the arguments and ' +
353 'exits. Most useful in a CI system together with `--findRelatedTests` ' +
354 'to determine the tests Jest will run based on specific files',
355 type: 'boolean'
356 },
357 logHeapUsage: {
358 default: undefined,
359 description:
360 'Logs the heap usage after every test. Useful to debug ' +
361 'memory leaks. Use together with `--runInBand` and `--expose-gc` in ' +
362 'node.',
363 type: 'boolean'
364 },
365 mapCoverage: {
366 default: undefined,
367 description:
368 'Maps code coverage reports against original source code ' +
369 'when transformers supply source maps.\n\nDEPRECATED',
370 type: 'boolean'
371 },
372 maxConcurrency: {
373 default: 5,
374 description:
375 'Specifies the maximum number of tests that are allowed to run' +
376 'concurrently. This only affects tests using `test.concurrent`.',
377 type: 'number'
378 },
379 maxWorkers: {
380 alias: 'w',
381 description:
382 'Specifies the maximum number of workers the worker-pool ' +
383 'will spawn for running tests. This defaults to the number of the ' +
384 'cores available on your machine. (its usually best not to override ' +
385 'this default)',
386 type: 'string'
387 },
388 moduleDirectories: {
389 description:
390 'An array of directory names to be searched recursively ' +
391 "up from the requiring module's location.",
392 string: true,
393 type: 'array'
394 },
395 moduleFileExtensions: {
396 description:
397 'An array of file extensions your modules use. If you ' +
398 'require modules without specifying a file extension, these are the ' +
399 'extensions Jest will look for. ',
400 string: true,
401 type: 'array'
402 },
403 moduleNameMapper: {
404 description:
405 'A JSON string with a map from regular expressions to ' +
406 'module names that allow to stub out resources, like images or ' +
407 'styles with a single module',
408 type: 'string'
409 },
410 modulePathIgnorePatterns: {
411 description:
412 'An array of regexp pattern strings that are matched ' +
413 'against all module paths before those paths are to be considered ' +
414 '"visible" to the module loader.',
415 string: true,
416 type: 'array'
417 },
418 modulePaths: {
419 description:
420 'An alternative API to setting the NODE_PATH env variable, ' +
421 'modulePaths is an array of absolute paths to additional locations to ' +
422 'search when resolving modules.',
423 string: true,
424 type: 'array'
425 },
426 noStackTrace: {
427 default: undefined,
428 description: 'Disables stack trace in test results output',
429 type: 'boolean'
430 },
431 notify: {
432 default: undefined,
433 description: 'Activates notifications for test results.',
434 type: 'boolean'
435 },
436 notifyMode: {
437 default: 'failure-change',
438 description: 'Specifies when notifications will appear for test results.',
439 type: 'string'
440 },
441 onlyChanged: {
442 alias: 'o',
443 default: undefined,
444 description:
445 'Attempts to identify which tests to run based on which ' +
446 "files have changed in the current repository. Only works if you're " +
447 'running tests in a git or hg repository at the moment.',
448 type: 'boolean'
449 },
450 onlyFailures: {
451 alias: 'f',
452 default: undefined,
453 description: 'Run tests that failed in the previous execution.',
454 type: 'boolean'
455 },
456 outputFile: {
457 description:
458 'Write test results to a file when the --json option is ' +
459 'also specified.',
460 type: 'string'
461 },
462 passWithNoTests: {
463 default: false,
464 description:
465 'Will not fail if no tests are found (for example while using `--testPathPattern`.)',
466 type: 'boolean'
467 },
468 preset: {
469 description: "A preset that is used as a base for Jest's configuration.",
470 type: 'string'
471 },
472 prettierPath: {
473 default: undefined,
474 description: 'The path to the "prettier" module used for inline snapshots.',
475 type: 'string'
476 },
477 projects: {
478 description:
479 'A list of projects that use Jest to run all tests of all ' +
480 'projects in a single instance of Jest.',
481 string: true,
482 type: 'array'
483 },
484 reporters: {
485 description: 'A list of custom reporters for the test suite.',
486 string: true,
487 type: 'array'
488 },
489 resetMocks: {
490 default: undefined,
491 description:
492 'Automatically reset mock state between every test. ' +
493 'Equivalent to calling jest.resetAllMocks() between each test.',
494 type: 'boolean'
495 },
496 resetModules: {
497 default: undefined,
498 description:
499 'If enabled, the module registry for every test file will ' +
500 'be reset before running each individual test.',
501 type: 'boolean'
502 },
503 resolver: {
504 description: 'A JSON string which allows the use of a custom resolver.',
505 type: 'string'
506 },
507 restoreMocks: {
508 default: undefined,
509 description:
510 'Automatically restore mock state and implementation between every test. ' +
511 'Equivalent to calling jest.restoreAllMocks() between each test.',
512 type: 'boolean'
513 },
514 rootDir: {
515 description:
516 'The root directory that Jest should scan for tests and ' +
517 'modules within.',
518 type: 'string'
519 },
520 roots: {
521 description:
522 'A list of paths to directories that Jest should use to ' +
523 'search for files in.',
524 string: true,
525 type: 'array'
526 },
527 runInBand: {
528 alias: 'i',
529 default: undefined,
530 description:
531 'Run all tests serially in the current process (rather than ' +
532 'creating a worker pool of child processes that run tests). This ' +
533 'is sometimes useful for debugging, but such use cases are pretty ' +
534 'rare.',
535 type: 'boolean'
536 },
537 runTestsByPath: {
538 default: false,
539 description:
540 'Used when provided patterns are exact file paths. This avoids ' +
541 'converting them into a regular expression and matching it against ' +
542 'every single file.',
543 type: 'boolean'
544 },
545 runner: {
546 description:
547 "Allows to use a custom runner instead of Jest's default test runner.",
548 type: 'string'
549 },
550 setupFiles: {
551 description:
552 'A list of paths to modules that run some code to configure or ' +
553 'set up the testing environment before each test. ',
554 string: true,
555 type: 'array'
556 },
557 setupFilesAfterEnv: {
558 description:
559 'A list of paths to modules that run some code to configure or ' +
560 'set up the testing framework before each test ',
561 string: true,
562 type: 'array'
563 },
564 showConfig: {
565 default: undefined,
566 description: 'Print your jest config and then exits.',
567 type: 'boolean'
568 },
569 silent: {
570 default: undefined,
571 description: 'Prevent tests from printing messages through the console.',
572 type: 'boolean'
573 },
574 skipFilter: {
575 default: undefined,
576 description:
577 'Disables the filter provided by --filter. Useful for CI jobs, or ' +
578 'local enforcement when fixing tests.',
579 type: 'boolean'
580 },
581 snapshotSerializers: {
582 description:
583 'A list of paths to snapshot serializer modules Jest should ' +
584 'use for snapshot testing.',
585 string: true,
586 type: 'array'
587 },
588 testEnvironment: {
589 description: 'Alias for --env',
590 type: 'string'
591 },
592 testEnvironmentOptions: {
593 description:
594 'Test environment options that will be passed to the testEnvironment. ' +
595 'The relevant options depend on the environment.',
596 type: 'string' // Object
597 },
598 testFailureExitCode: {
599 description: 'Exit code of `jest` command if the test run failed',
600 type: 'string' // number
601 },
602 testLocationInResults: {
603 default: false,
604 description: 'Add `location` information to the test results',
605 type: 'boolean'
606 },
607 testMatch: {
608 description: 'The glob patterns Jest uses to detect test files.',
609 string: true,
610 type: 'array'
611 },
612 testNamePattern: {
613 alias: 't',
614 description: 'Run only tests with a name that matches the regex pattern.',
615 type: 'string'
616 },
617 testPathIgnorePatterns: {
618 description:
619 'An array of regexp pattern strings that are matched ' +
620 'against all test paths before executing the test. If the test path ' +
621 'matches any of the patterns, it will be skipped.',
622 string: true,
623 type: 'array'
624 },
625 testPathPattern: {
626 description:
627 'A regexp pattern string that is matched against all tests ' +
628 'paths before executing the test.',
629 string: true,
630 type: 'array'
631 },
632 testRegex: {
633 description:
634 'A string or array of string regexp patterns that Jest uses to detect test files.',
635 string: true,
636 type: 'array'
637 },
638 testResultsProcessor: {
639 description:
640 'Allows the use of a custom results processor. ' +
641 'This processor must be a node module that exports ' +
642 'a function expecting as the first argument the result object.',
643 type: 'string'
644 },
645 testRunner: {
646 description:
647 'Allows to specify a custom test runner. The default is ' +
648 ' `jasmine2`. A path to a custom test runner can be provided: ' +
649 '`<rootDir>/path/to/testRunner.js`.',
650 type: 'string'
651 },
652 testSequencer: {
653 description:
654 'Allows to specify a custom test sequencer. The default is ' +
655 '`@jest/test-sequencer`. A path to a custom test sequencer can be ' +
656 'provided: `<rootDir>/path/to/testSequencer.js`',
657 type: 'string'
658 },
659 testTimeout: {
660 description: 'This option sets the default timeouts of test cases.',
661 type: 'number'
662 },
663 testURL: {
664 description: 'This option sets the URL for the jsdom environment.',
665 type: 'string'
666 },
667 timers: {
668 description:
669 'Setting this value to fake allows the use of fake timers ' +
670 'for functions such as setTimeout.',
671 type: 'string'
672 },
673 transform: {
674 description:
675 'A JSON string which maps from regular expressions to paths ' +
676 'to transformers.',
677 type: 'string'
678 },
679 transformIgnorePatterns: {
680 description:
681 'An array of regexp pattern strings that are matched ' +
682 'against all source file paths before transformation.',
683 string: true,
684 type: 'array'
685 },
686 unmockedModulePathPatterns: {
687 description:
688 'An array of regexp pattern strings that are matched ' +
689 'against all modules before the module loader will automatically ' +
690 'return a mock for them.',
691 string: true,
692 type: 'array'
693 },
694 updateSnapshot: {
695 alias: 'u',
696 default: undefined,
697 description:
698 'Use this flag to re-record snapshots. ' +
699 'Can be used together with a test suite pattern or with ' +
700 '`--testNamePattern` to re-record snapshot for test matching ' +
701 'the pattern',
702 type: 'boolean'
703 },
704 useStderr: {
705 default: undefined,
706 description: 'Divert all output to stderr.',
707 type: 'boolean'
708 },
709 verbose: {
710 default: undefined,
711 description:
712 'Display individual test results with the test suite hierarchy.',
713 type: 'boolean'
714 },
715 version: {
716 alias: 'v',
717 default: undefined,
718 description: 'Print the version and exit',
719 type: 'boolean'
720 },
721 watch: {
722 default: undefined,
723 description:
724 'Watch files for changes and rerun tests related to ' +
725 'changed files. If you want to re-run all tests when a file has ' +
726 'changed, use the `--watchAll` option.',
727 type: 'boolean'
728 },
729 watchAll: {
730 default: undefined,
731 description:
732 'Watch files for changes and rerun all tests. If you want ' +
733 'to re-run only the tests related to the changed files, use the ' +
734 '`--watch` option.',
735 type: 'boolean'
736 },
737 watchPathIgnorePatterns: {
738 description:
739 'An array of regexp pattern strings that are matched ' +
740 'against all paths before trigger test re-run in watch mode. ' +
741 'If the test path matches any of the patterns, it will be skipped.',
742 string: true,
743 type: 'array'
744 },
745 watchman: {
746 default: undefined,
747 description:
748 'Whether to use watchman for file crawling. Disable using ' +
749 '--no-watchman.',
750 type: 'boolean'
751 }
752};
753exports.options = options;