Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 1 | '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 Marshall | 4e161df | 2020-11-10 12:29:38 | [diff] [blame] | 15 | const TYPES = (exports.types = { |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 16 | array: [ |
| 17 | 'extension', |
| 18 | 'file', |
| 19 | 'global', |
| 20 | 'ignore', |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 21 | 'reporter-option', |
Tim van der Lippe | 99190c9 | 2020-04-07 15:46:32 | [diff] [blame] | 22 | 'require', |
| 23 | 'spec', |
| 24 | 'watch-files', |
| 25 | 'watch-ignore' |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 26 | ], |
| 27 | boolean: [ |
| 28 | 'allow-uncaught', |
| 29 | 'async-only', |
| 30 | 'bail', |
| 31 | 'check-leaks', |
| 32 | 'color', |
| 33 | 'delay', |
| 34 | 'diff', |
Tim van der Lippe | 324d603 | 2021-06-21 15:43:26 | [diff] [blame^] | 35 | 'dry-run', |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 36 | 'exit', |
| 37 | 'forbid-only', |
| 38 | 'forbid-pending', |
| 39 | 'full-trace', |
| 40 | 'growl', |
| 41 | 'inline-diffs', |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 42 | 'invert', |
Tim van der Lippe | 99190c9 | 2020-04-07 15:46:32 | [diff] [blame] | 43 | 'list-interfaces', |
| 44 | 'list-reporters', |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 45 | 'no-colors', |
Peter Marshall | 0b95ea1 | 2020-07-02 16:50:04 | [diff] [blame] | 46 | 'parallel', |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 47 | 'recursive', |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 48 | 'sort', |
| 49 | 'watch' |
| 50 | ], |
Peter Marshall | 0b95ea1 | 2020-07-02 16:50:04 | [diff] [blame] | 51 | number: ['retries', 'jobs'], |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 52 | string: [ |
| 53 | 'config', |
| 54 | 'fgrep', |
| 55 | 'grep', |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 56 | 'package', |
| 57 | 'reporter', |
| 58 | 'ui', |
| 59 | 'slow', |
| 60 | 'timeout' |
| 61 | ] |
Peter Marshall | 4e161df | 2020-11-10 12:29:38 | [diff] [blame] | 62 | }); |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 63 | |
| 64 | /** |
| 65 | * Option aliases keyed by canonical option name. |
| 66 | * Arrays used to reduce |
| 67 | * @type {{string:string[]}} |
| 68 | * @private |
| 69 | */ |
| 70 | exports.aliases = { |
| 71 | 'async-only': ['A'], |
| 72 | bail: ['b'], |
| 73 | color: ['c', 'colors'], |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 74 | fgrep: ['f'], |
| 75 | global: ['globals'], |
| 76 | grep: ['g'], |
| 77 | growl: ['G'], |
| 78 | ignore: ['exclude'], |
| 79 | invert: ['i'], |
Peter Marshall | 0b95ea1 | 2020-07-02 16:50:04 | [diff] [blame] | 80 | jobs: ['j'], |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 81 | 'no-colors': ['C'], |
Peter Marshall | 0b95ea1 | 2020-07-02 16:50:04 | [diff] [blame] | 82 | parallel: ['p'], |
Yang Guo | 4fd355c | 2019-09-19 08:59:03 | [diff] [blame] | 83 | 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 Marshall | 4e161df | 2020-11-10 12:29:38 | [diff] [blame] | 92 | |
| 93 | const 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 | */ |
| 112 | exports.isMochaFlag = flag => { |
| 113 | return ALL_MOCHA_FLAGS.has(flag.replace(/^--?/, '')); |
| 114 | }; |