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