args.mjs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. import { cpus } from 'os';
  2. import yargs from 'yargs';
  3. const rulesAndBehavior = 'Mocha: Rules & Behavior';
  4. const reportingAndOutput = 'Mocha: Reporting & Output';
  5. const fileHandling = 'Mocha: File Handling';
  6. const testFilters = 'Mocha: Test Filters';
  7. const testCoverage = 'Test Coverage';
  8. const vscodeSection = 'VS Code Options';
  9. export const configFileDefault = 'nearest .vscode-test.js';
  10. export const cliArgs = yargs(process.argv)
  11. .epilogue('See https://code.visualstudio.com/api/working-with-extensions/testing-extension for help')
  12. .option('config', {
  13. type: 'string',
  14. description: 'Config file to use',
  15. default: configFileDefault,
  16. group: vscodeSection,
  17. })
  18. .option('label', {
  19. alias: 'l',
  20. type: 'array',
  21. description: 'Specify the test configuration to run based on its label in configuration',
  22. group: vscodeSection,
  23. })
  24. .option('code-version', {
  25. type: 'string',
  26. description: 'Override the VS Code version used to run tests',
  27. group: vscodeSection,
  28. })
  29. .option('install-extensions', {
  30. type: 'array',
  31. description: 'A list of vscode extensions to install prior to running the tests, in the same format as `code --install-extensions`',
  32. group: vscodeSection,
  33. })
  34. .option('skip-extension-dependencies', {
  35. type: 'boolean',
  36. default: false,
  37. description: "Skip installing extensions' the `extensionDependencies`",
  38. group: vscodeSection,
  39. })
  40. //#region Rules & Behavior
  41. .option('bail', {
  42. alias: 'b',
  43. type: 'boolean',
  44. description: 'Abort ("bail") after first test failure',
  45. group: rulesAndBehavior,
  46. })
  47. .option('dry-run', {
  48. type: 'boolean',
  49. description: 'Report tests without executing them',
  50. group: rulesAndBehavior,
  51. })
  52. .option('list-configuration', {
  53. type: 'boolean',
  54. description: 'List configurations and that they woud run, without executing them',
  55. group: rulesAndBehavior,
  56. })
  57. .option('fail-zero', {
  58. type: 'boolean',
  59. description: 'Fail test run if no test(s) encountered',
  60. group: rulesAndBehavior,
  61. })
  62. .option('forbid-only', {
  63. type: 'boolean',
  64. description: 'Fail if exclusive test(s) encountered',
  65. group: rulesAndBehavior,
  66. })
  67. .option('forbid-pending', {
  68. type: 'boolean',
  69. description: 'Fail if pending test(s) encountered',
  70. group: rulesAndBehavior,
  71. })
  72. .option('jobs', {
  73. alias: 'j',
  74. type: 'number',
  75. description: 'Number of concurrent jobs for --parallel; use 1 to run in serial',
  76. default: Math.max(1, cpus().length - 1),
  77. group: rulesAndBehavior,
  78. })
  79. .options('parallel', {
  80. alias: 'p',
  81. type: 'boolean',
  82. description: 'Run tests in parallel',
  83. group: rulesAndBehavior,
  84. })
  85. .option('retries', {
  86. alias: 'r',
  87. type: 'number',
  88. description: 'Number of times to retry failed tests',
  89. group: rulesAndBehavior,
  90. })
  91. .option('slow', {
  92. alias: 's',
  93. type: 'number',
  94. description: 'Specify "slow" test threshold (in milliseconds)',
  95. default: 75,
  96. group: rulesAndBehavior,
  97. })
  98. .option('timeout', {
  99. alias: 't',
  100. type: 'number',
  101. description: 'Specify test timeout threshold (in milliseconds)',
  102. default: 2000,
  103. group: rulesAndBehavior,
  104. })
  105. //#endregion
  106. //#region Reporting & Output
  107. .option('color', {
  108. alias: 'c',
  109. type: 'boolean',
  110. description: 'Force-enable color output',
  111. group: reportingAndOutput,
  112. })
  113. .option('diff', {
  114. type: 'boolean',
  115. description: 'Show diff on failure',
  116. default: true,
  117. group: reportingAndOutput,
  118. })
  119. .option('full-trace', {
  120. type: 'boolean',
  121. description: 'Display full stack traces',
  122. group: reportingAndOutput,
  123. })
  124. .option('inline-diffs', {
  125. type: 'boolean',
  126. description: 'Display actual/expected differences inline within each string',
  127. group: reportingAndOutput,
  128. })
  129. .option('reporter', {
  130. alias: 'R',
  131. type: 'string',
  132. description: 'Specify reporter to use',
  133. default: 'spec',
  134. group: reportingAndOutput,
  135. })
  136. .option('reporter-option', {
  137. alias: 'O',
  138. type: 'array',
  139. description: 'Reporter-specific options (<k=v,[k1=v1,..]>)',
  140. group: reportingAndOutput,
  141. })
  142. //#endregion
  143. //#region File Handling
  144. .option('file', {
  145. type: 'array',
  146. description: 'Specify file(s) to be loaded prior to root suite',
  147. group: fileHandling,
  148. })
  149. .option('ignore', {
  150. alias: 'exclude',
  151. type: 'array',
  152. description: 'Ignore file(s) or glob pattern(s)',
  153. group: fileHandling,
  154. })
  155. .option('watch', {
  156. alias: 'w',
  157. type: 'boolean',
  158. description: 'Watch files in the current working directory for changes',
  159. group: fileHandling,
  160. })
  161. .option('watch-files', {
  162. type: 'array',
  163. description: 'List of paths or globs to watch',
  164. group: fileHandling,
  165. })
  166. .option('watch-ignore', {
  167. type: 'array',
  168. description: 'List of paths or globs to exclude from watching',
  169. group: fileHandling,
  170. })
  171. .option('run', {
  172. type: 'array',
  173. description: 'List of specific files to run',
  174. group: fileHandling,
  175. })
  176. //#endregion
  177. //#region Test Filters
  178. .option('fgrep', {
  179. type: 'string',
  180. alias: 'f',
  181. description: 'Only run tests containing this string',
  182. group: testFilters,
  183. })
  184. .option('grep', {
  185. type: 'string',
  186. alias: 'g',
  187. description: 'Only run tests matching this string or regexp',
  188. group: testFilters,
  189. })
  190. .option('invert', {
  191. alias: 'i',
  192. type: 'boolean',
  193. description: 'Inverts --grep and --fgrep matches',
  194. group: testFilters,
  195. })
  196. //#endregion
  197. //#region Test Coverage
  198. .option('coverage', {
  199. type: 'boolean',
  200. description: 'Whether to run with coverage.',
  201. group: testCoverage,
  202. })
  203. .option('coverage-output', {
  204. type: 'string',
  205. description: 'Directory where coverage data should be written.',
  206. group: testCoverage,
  207. })
  208. .option('coverage-reporter', {
  209. type: 'array',
  210. description: 'One or more coverage reporters to use.',
  211. group: testCoverage,
  212. });
  213. //#endregion
  214. cliArgs.wrap(Math.min(120, cliArgs.terminalWidth()));