Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

run.js 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. 'use strict';
  2. /**
  3. * Definition for Mocha's default ("run tests") command
  4. *
  5. * @module
  6. * @private
  7. */
  8. const Mocha = require('../mocha');
  9. const {
  10. createUnsupportedError,
  11. createInvalidArgumentValueError,
  12. createMissingArgumentError
  13. } = require('../errors');
  14. const {
  15. list,
  16. handleRequires,
  17. validatePlugin,
  18. loadRootHooks,
  19. runMocha
  20. } = require('./run-helpers');
  21. const {ONE_AND_DONES, ONE_AND_DONE_ARGS} = require('./one-and-dones');
  22. const debug = require('debug')('mocha:cli:run');
  23. const defaults = require('../mocharc');
  24. const {types, aliases} = require('./run-option-metadata');
  25. /**
  26. * Logical option groups
  27. * @constant
  28. */
  29. const GROUPS = {
  30. FILES: 'File Handling',
  31. FILTERS: 'Test Filters',
  32. NODEJS: 'Node.js & V8',
  33. OUTPUT: 'Reporting & Output',
  34. RULES: 'Rules & Behavior',
  35. CONFIG: 'Configuration'
  36. };
  37. exports.command = ['$0 [spec..]', 'inspect'];
  38. exports.describe = 'Run tests with Mocha';
  39. exports.builder = yargs =>
  40. yargs
  41. .options({
  42. 'allow-uncaught': {
  43. description: 'Allow uncaught errors to propagate',
  44. group: GROUPS.RULES
  45. },
  46. 'async-only': {
  47. description:
  48. 'Require all tests to use a callback (async) or return a Promise',
  49. group: GROUPS.RULES
  50. },
  51. bail: {
  52. description: 'Abort ("bail") after first test failure',
  53. group: GROUPS.RULES
  54. },
  55. 'check-leaks': {
  56. description: 'Check for global variable leaks',
  57. group: GROUPS.RULES
  58. },
  59. color: {
  60. description: 'Force-enable color output',
  61. group: GROUPS.OUTPUT
  62. },
  63. config: {
  64. config: true,
  65. defaultDescription: '(nearest rc file)',
  66. description: 'Path to config file',
  67. group: GROUPS.CONFIG
  68. },
  69. delay: {
  70. description: 'Delay initial execution of root suite',
  71. group: GROUPS.RULES
  72. },
  73. diff: {
  74. default: true,
  75. description: 'Show diff on failure',
  76. group: GROUPS.OUTPUT
  77. },
  78. exit: {
  79. description: 'Force Mocha to quit after tests complete',
  80. group: GROUPS.RULES
  81. },
  82. extension: {
  83. default: defaults.extension,
  84. description: 'File extension(s) to load',
  85. group: GROUPS.FILES,
  86. requiresArg: true,
  87. coerce: list
  88. },
  89. fgrep: {
  90. conflicts: 'grep',
  91. description: 'Only run tests containing this string',
  92. group: GROUPS.FILTERS,
  93. requiresArg: true
  94. },
  95. file: {
  96. defaultDescription: '(none)',
  97. description:
  98. 'Specify file(s) to be loaded prior to root suite execution',
  99. group: GROUPS.FILES,
  100. normalize: true,
  101. requiresArg: true
  102. },
  103. 'forbid-only': {
  104. description: 'Fail if exclusive test(s) encountered',
  105. group: GROUPS.RULES
  106. },
  107. 'forbid-pending': {
  108. description: 'Fail if pending test(s) encountered',
  109. group: GROUPS.RULES
  110. },
  111. 'full-trace': {
  112. description: 'Display full stack traces',
  113. group: GROUPS.OUTPUT
  114. },
  115. global: {
  116. coerce: list,
  117. description: 'List of allowed global variables',
  118. group: GROUPS.RULES,
  119. requiresArg: true
  120. },
  121. grep: {
  122. coerce: value => (!value ? null : value),
  123. conflicts: 'fgrep',
  124. description: 'Only run tests matching this string or regexp',
  125. group: GROUPS.FILTERS,
  126. requiresArg: true
  127. },
  128. growl: {
  129. description: 'Enable Growl notifications',
  130. group: GROUPS.OUTPUT
  131. },
  132. ignore: {
  133. defaultDescription: '(none)',
  134. description: 'Ignore file(s) or glob pattern(s)',
  135. group: GROUPS.FILES,
  136. requiresArg: true
  137. },
  138. 'inline-diffs': {
  139. description:
  140. 'Display actual/expected differences inline within each string',
  141. group: GROUPS.OUTPUT
  142. },
  143. invert: {
  144. description: 'Inverts --grep and --fgrep matches',
  145. group: GROUPS.FILTERS
  146. },
  147. 'list-interfaces': {
  148. conflicts: Array.from(ONE_AND_DONE_ARGS),
  149. description: 'List built-in user interfaces & exit'
  150. },
  151. 'list-reporters': {
  152. conflicts: Array.from(ONE_AND_DONE_ARGS),
  153. description: 'List built-in reporters & exit'
  154. },
  155. 'no-colors': {
  156. description: 'Force-disable color output',
  157. group: GROUPS.OUTPUT,
  158. hidden: true
  159. },
  160. opts: {
  161. default: defaults.opts,
  162. description: 'Path to `mocha.opts` (DEPRECATED)',
  163. group: GROUPS.CONFIG,
  164. normalize: true,
  165. requiresArg: true
  166. },
  167. package: {
  168. description: 'Path to package.json for config',
  169. group: GROUPS.CONFIG,
  170. normalize: true,
  171. requiresArg: true
  172. },
  173. recursive: {
  174. description: 'Look for tests in subdirectories',
  175. group: GROUPS.FILES
  176. },
  177. reporter: {
  178. default: defaults.reporter,
  179. description: 'Specify reporter to use',
  180. group: GROUPS.OUTPUT,
  181. requiresArg: true
  182. },
  183. 'reporter-option': {
  184. coerce: opts =>
  185. list(opts).reduce((acc, opt) => {
  186. const pair = opt.split('=');
  187. if (pair.length > 2 || !pair.length) {
  188. throw createInvalidArgumentValueError(
  189. `invalid reporter option '${opt}'`,
  190. '--reporter-option',
  191. opt,
  192. 'expected "key=value" format'
  193. );
  194. }
  195. acc[pair[0]] = pair.length === 2 ? pair[1] : true;
  196. return acc;
  197. }, {}),
  198. description: 'Reporter-specific options (<k=v,[k1=v1,..]>)',
  199. group: GROUPS.OUTPUT,
  200. requiresArg: true
  201. },
  202. require: {
  203. defaultDescription: '(none)',
  204. description: 'Require module',
  205. group: GROUPS.FILES,
  206. requiresArg: true
  207. },
  208. retries: {
  209. description: 'Retry failed tests this many times',
  210. group: GROUPS.RULES
  211. },
  212. slow: {
  213. default: defaults.slow,
  214. description: 'Specify "slow" test threshold (in milliseconds)',
  215. group: GROUPS.RULES
  216. },
  217. sort: {
  218. description: 'Sort test files',
  219. group: GROUPS.FILES
  220. },
  221. timeout: {
  222. default: defaults.timeout,
  223. description: 'Specify test timeout threshold (in milliseconds)',
  224. group: GROUPS.RULES
  225. },
  226. ui: {
  227. default: defaults.ui,
  228. description: 'Specify user interface',
  229. group: GROUPS.RULES,
  230. requiresArg: true
  231. },
  232. watch: {
  233. description: 'Watch files in the current working directory for changes',
  234. group: GROUPS.FILES
  235. },
  236. 'watch-files': {
  237. description: 'List of paths or globs to watch',
  238. group: GROUPS.FILES,
  239. requiresArg: true,
  240. coerce: list
  241. },
  242. 'watch-ignore': {
  243. description: 'List of paths or globs to exclude from watching',
  244. group: GROUPS.FILES,
  245. requiresArg: true,
  246. coerce: list,
  247. default: defaults['watch-ignore']
  248. }
  249. })
  250. .positional('spec', {
  251. default: ['test'],
  252. description: 'One or more files, directories, or globs to test',
  253. type: 'array'
  254. })
  255. .check(argv => {
  256. // "one-and-dones"; let yargs handle help and version
  257. Object.keys(ONE_AND_DONES).forEach(opt => {
  258. if (argv[opt]) {
  259. ONE_AND_DONES[opt].call(null, yargs);
  260. process.exit();
  261. }
  262. });
  263. // yargs.implies() isn't flexible enough to handle this
  264. if (argv.invert && !('fgrep' in argv || 'grep' in argv)) {
  265. throw createMissingArgumentError(
  266. '"--invert" requires one of "--fgrep <str>" or "--grep <regexp>"',
  267. '--fgrep|--grep',
  268. 'string|regexp'
  269. );
  270. }
  271. if (argv.compilers) {
  272. throw createUnsupportedError(
  273. `--compilers is DEPRECATED and no longer supported.
  274. See https://git.io/vdcSr for migration information.`
  275. );
  276. }
  277. if (argv.opts) {
  278. throw createUnsupportedError(
  279. `--opts: configuring Mocha via 'mocha.opts' is DEPRECATED and no longer supported.
  280. Please use a configuration file instead.`
  281. );
  282. }
  283. return true;
  284. })
  285. .middleware(async argv => {
  286. // load requires first, because it can impact "plugin" validation
  287. const rawRootHooks = await handleRequires(argv.require);
  288. validatePlugin(argv, 'reporter', Mocha.reporters);
  289. validatePlugin(argv, 'ui', Mocha.interfaces);
  290. if (rawRootHooks.length) {
  291. argv.rootHooks = await loadRootHooks(rawRootHooks);
  292. }
  293. })
  294. .array(types.array)
  295. .boolean(types.boolean)
  296. .string(types.string)
  297. .number(types.number)
  298. .alias(aliases);
  299. exports.handler = async function(argv) {
  300. debug('post-yargs config', argv);
  301. const mocha = new Mocha(argv);
  302. try {
  303. await runMocha(mocha, argv);
  304. } catch (err) {
  305. console.error('\n' + (err.stack || `Error: ${err.message || err}`));
  306. process.exit(1);
  307. }
  308. };