blob: 984ad4b75e726b4de4ee30a87ab84904dfce5b3c [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',
Tim van der Lippe61fe6852021-09-13 12:21:1621 'node-option',
Yang Guo4fd355c2019-09-19 08:59:0322 'reporter-option',
Tim van der Lippe99190c92020-04-07 15:46:3223 'require',
24 'spec',
25 'watch-files',
26 'watch-ignore'
Yang Guo4fd355c2019-09-19 08:59:0327 ],
28 boolean: [
29 'allow-uncaught',
30 'async-only',
31 'bail',
32 'check-leaks',
33 'color',
34 'delay',
35 'diff',
Tim van der Lippe324d6032021-06-21 15:43:2636 'dry-run',
Yang Guo4fd355c2019-09-19 08:59:0337 'exit',
Tim van der Lippe61fe6852021-09-13 12:21:1638 'fail-zero',
Yang Guo4fd355c2019-09-19 08:59:0339 'forbid-only',
40 'forbid-pending',
41 'full-trace',
42 'growl',
43 'inline-diffs',
Yang Guo4fd355c2019-09-19 08:59:0344 'invert',
Tim van der Lippe99190c92020-04-07 15:46:3245 'list-interfaces',
46 'list-reporters',
Yang Guo4fd355c2019-09-19 08:59:0347 'no-colors',
Peter Marshall0b95ea12020-07-02 16:50:0448 'parallel',
Yang Guo4fd355c2019-09-19 08:59:0349 'recursive',
Yang Guo4fd355c2019-09-19 08:59:0350 'sort',
51 'watch'
52 ],
Peter Marshall0b95ea12020-07-02 16:50:0453 number: ['retries', 'jobs'],
Yang Guo4fd355c2019-09-19 08:59:0354 string: [
55 'config',
56 'fgrep',
57 'grep',
Yang Guo4fd355c2019-09-19 08:59:0358 'package',
59 'reporter',
60 'ui',
61 'slow',
62 'timeout'
63 ]
Peter Marshall4e161df2020-11-10 12:29:3864});
Yang Guo4fd355c2019-09-19 08:59:0365
66/**
67 * Option aliases keyed by canonical option name.
68 * Arrays used to reduce
69 * @type {{string:string[]}}
70 * @private
71 */
72exports.aliases = {
73 'async-only': ['A'],
74 bail: ['b'],
75 color: ['c', 'colors'],
Yang Guo4fd355c2019-09-19 08:59:0376 fgrep: ['f'],
77 global: ['globals'],
78 grep: ['g'],
79 growl: ['G'],
80 ignore: ['exclude'],
81 invert: ['i'],
Peter Marshall0b95ea12020-07-02 16:50:0482 jobs: ['j'],
Yang Guo4fd355c2019-09-19 08:59:0383 'no-colors': ['C'],
Tim van der Lippe61fe6852021-09-13 12:21:1684 'node-option': ['n'],
Peter Marshall0b95ea12020-07-02 16:50:0485 parallel: ['p'],
Yang Guo4fd355c2019-09-19 08:59:0386 reporter: ['R'],
87 'reporter-option': ['reporter-options', 'O'],
88 require: ['r'],
89 slow: ['s'],
90 sort: ['S'],
91 timeout: ['t', 'timeouts'],
92 ui: ['u'],
93 watch: ['w']
94};
Peter Marshall4e161df2020-11-10 12:29:3895
96const ALL_MOCHA_FLAGS = Object.keys(TYPES).reduce((acc, key) => {
97 // gets all flags from each of the fields in `types`, adds those,
98 // then adds aliases of each flag (if any)
99 TYPES[key].forEach(flag => {
100 acc.add(flag);
101 const aliases = exports.aliases[flag] || [];
102 aliases.forEach(alias => {
103 acc.add(alias);
104 });
105 });
106 return acc;
107}, new Set());
108
109/**
110 * Returns `true` if the provided `flag` is known to Mocha.
111 * @param {string} flag - Flag to check
112 * @returns {boolean} If `true`, this is a Mocha flag
113 * @private
114 */
115exports.isMochaFlag = flag => {
116 return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, ''));
117};