blob: fc870992c9c09474f8db8cfa6fa0e094384c218d [file] [log] [blame]
Yang Guo4fd355c2019-09-19 08:59:031'use strict';
2
3/**
4 * Metadata about various options of the `run` command
5 * @see module:lib/cli/run
6 * @module
7 * @private
8 */
9
10/**
11 * Dictionary of yargs option types to list of options having said type
12 * @type {{string:string[]}}
13 * @private
14 */
Peter Marshall4e161df2020-11-10 12:29:3815const TYPES = (exports.types = {
Yang Guo4fd355c2019-09-19 08:59:0316 array: [
17 'extension',
18 'file',
19 'global',
20 'ignore',
Yang Guo4fd355c2019-09-19 08:59:0321 'reporter-option',
Tim van der Lippe99190c92020-04-07 15:46:3222 'require',
23 'spec',
24 'watch-files',
25 'watch-ignore'
Yang Guo4fd355c2019-09-19 08:59:0326 ],
27 boolean: [
28 'allow-uncaught',
29 'async-only',
30 'bail',
31 'check-leaks',
32 'color',
33 'delay',
34 'diff',
Tim van der Lippe324d6032021-06-21 15:43:2635 'dry-run',
Yang Guo4fd355c2019-09-19 08:59:0336 'exit',
37 'forbid-only',
38 'forbid-pending',
39 'full-trace',
40 'growl',
41 'inline-diffs',
Yang Guo4fd355c2019-09-19 08:59:0342 'invert',
Tim van der Lippe99190c92020-04-07 15:46:3243 'list-interfaces',
44 'list-reporters',
Yang Guo4fd355c2019-09-19 08:59:0345 'no-colors',
Peter Marshall0b95ea12020-07-02 16:50:0446 'parallel',
Yang Guo4fd355c2019-09-19 08:59:0347 'recursive',
Yang Guo4fd355c2019-09-19 08:59:0348 'sort',
49 'watch'
50 ],
Peter Marshall0b95ea12020-07-02 16:50:0451 number: ['retries', 'jobs'],
Yang Guo4fd355c2019-09-19 08:59:0352 string: [
53 'config',
54 'fgrep',
55 'grep',
Yang Guo4fd355c2019-09-19 08:59:0356 'package',
57 'reporter',
58 'ui',
59 'slow',
60 'timeout'
61 ]
Peter Marshall4e161df2020-11-10 12:29:3862});
Yang Guo4fd355c2019-09-19 08:59:0363
64/**
65 * Option aliases keyed by canonical option name.
66 * Arrays used to reduce
67 * @type {{string:string[]}}
68 * @private
69 */
70exports.aliases = {
71 'async-only': ['A'],
72 bail: ['b'],
73 color: ['c', 'colors'],
Yang Guo4fd355c2019-09-19 08:59:0374 fgrep: ['f'],
75 global: ['globals'],
76 grep: ['g'],
77 growl: ['G'],
78 ignore: ['exclude'],
79 invert: ['i'],
Peter Marshall0b95ea12020-07-02 16:50:0480 jobs: ['j'],
Yang Guo4fd355c2019-09-19 08:59:0381 'no-colors': ['C'],
Peter Marshall0b95ea12020-07-02 16:50:0482 parallel: ['p'],
Yang Guo4fd355c2019-09-19 08:59:0383 reporter: ['R'],
84 'reporter-option': ['reporter-options', 'O'],
85 require: ['r'],
86 slow: ['s'],
87 sort: ['S'],
88 timeout: ['t', 'timeouts'],
89 ui: ['u'],
90 watch: ['w']
91};
Peter Marshall4e161df2020-11-10 12:29:3892
93const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
94 // gets all flags from each of the fields in `types`, adds those,
95 // then adds aliases of each flag (if any)
96 TYPES[key].forEach(flag => {
97 acc.add(flag);
98 const aliases = exports.aliases[flag] || [];
99 aliases.forEach(alias => {
100 acc.add(alias);
101 });
102 });
103 return acc;
104}, new Set());
105
106/**
107 * Returns `true` if the provided `flag` is known to Mocha.
108 * @param {string} flag - Flag to check
109 * @returns {boolean} If `true`, this is a Mocha flag
110 * @private
111 */
112exports.isMochaFlag = flag => {
113 return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, ''));
114};