mocha 5.0.4 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +119 -9
  2. package/bin/_mocha +90 -35
  3. package/bin/options.js +14 -8
  4. package/browser-entry.js +20 -16
  5. package/lib/browser/progress.js +8 -8
  6. package/lib/browser/tty.js +2 -2
  7. package/lib/context.js +11 -9
  8. package/lib/hook.js +7 -9
  9. package/lib/interfaces/bdd.js +12 -13
  10. package/lib/interfaces/common.js +20 -15
  11. package/lib/interfaces/exports.js +2 -7
  12. package/lib/interfaces/qunit.js +6 -10
  13. package/lib/interfaces/tdd.js +7 -11
  14. package/lib/mocha.js +94 -54
  15. package/lib/ms.js +12 -6
  16. package/lib/pending.js +1 -5
  17. package/lib/reporters/base.js +102 -64
  18. package/lib/reporters/doc.js +23 -9
  19. package/lib/reporters/dot.js +14 -8
  20. package/lib/reporters/html.js +81 -41
  21. package/lib/reporters/json-stream.js +16 -9
  22. package/lib/reporters/json.js +47 -12
  23. package/lib/reporters/json.js.orig +128 -0
  24. package/lib/reporters/landing.js +14 -8
  25. package/lib/reporters/list.js +16 -10
  26. package/lib/reporters/markdown.js +18 -12
  27. package/lib/reporters/min.js +9 -3
  28. package/lib/reporters/nyan.js +31 -25
  29. package/lib/reporters/progress.js +13 -7
  30. package/lib/reporters/spec.js +19 -11
  31. package/lib/reporters/tap.js +15 -9
  32. package/lib/reporters/xunit.js +48 -24
  33. package/lib/runnable.js +88 -66
  34. package/lib/runner.js +117 -90
  35. package/lib/suite.js +76 -63
  36. package/lib/test.js +9 -13
  37. package/lib/utils.js +137 -85
  38. package/mocha.js +1914 -1162
  39. package/package.json +462 -299
  40. package/CHANGELOG.md.orig +0 -1736
  41. package/README.md.orig +0 -132
  42. package/bin/.eslintrc.yml +0 -3
  43. package/images/error.png +0 -0
  44. package/images/ok.png +0 -0
  45. package/lib/browser/.eslintrc.yml +0 -4
package/lib/mocha.js CHANGED
@@ -6,19 +6,11 @@
6
6
  * MIT Licensed
7
7
  */
8
8
 
9
- /**
10
- * Module dependencies.
11
- */
12
-
13
9
  var escapeRe = require('escape-string-regexp');
14
10
  var path = require('path');
15
11
  var reporters = require('./reporters');
16
12
  var utils = require('./utils');
17
13
 
18
- /**
19
- * Expose `Mocha`.
20
- */
21
-
22
14
  exports = module.exports = Mocha;
23
15
 
24
16
  /**
@@ -34,11 +26,25 @@ if (!process.browser) {
34
26
  * Expose internals.
35
27
  */
36
28
 
29
+ /**
30
+ * @public
31
+ * @class utils
32
+ * @memberof Mocha
33
+ */
37
34
  exports.utils = utils;
38
35
  exports.interfaces = require('./interfaces');
36
+ /**
37
+ *
38
+ * @memberof Mocha
39
+ * @public
40
+ */
39
41
  exports.reporters = reporters;
40
42
  exports.Runnable = require('./runnable');
41
43
  exports.Context = require('./context');
44
+ /**
45
+ *
46
+ * @memberof Mocha
47
+ */
42
48
  exports.Runner = require('./runner');
43
49
  exports.Suite = require('./suite');
44
50
  exports.Hook = require('./hook');
@@ -47,12 +53,12 @@ exports.Test = require('./test');
47
53
  /**
48
54
  * Return image `name` path.
49
55
  *
50
- * @api private
56
+ * @private
51
57
  * @param {string} name
52
58
  * @return {string}
53
59
  */
54
- function image (name) {
55
- return path.join(__dirname, '../images', name + '.png');
60
+ function image(name) {
61
+ return path.join(__dirname, '..', 'assets', 'growl', name + '.png');
56
62
  }
57
63
 
58
64
  /**
@@ -71,10 +77,10 @@ function image (name) {
71
77
  * - `fullTrace` display the full stack-trace on failing
72
78
  * - `grep` string or regexp to filter tests with
73
79
  *
80
+ * @class Mocha
74
81
  * @param {Object} options
75
- * @api public
76
82
  */
77
- function Mocha (options) {
83
+ function Mocha(options) {
78
84
  options = options || {};
79
85
  this.files = [];
80
86
  this.options = options;
@@ -106,10 +112,11 @@ function Mocha (options) {
106
112
  /**
107
113
  * Enable or disable bailing on the first failure.
108
114
  *
115
+ * @public
109
116
  * @api public
110
117
  * @param {boolean} [bail]
111
118
  */
112
- Mocha.prototype.bail = function (bail) {
119
+ Mocha.prototype.bail = function(bail) {
113
120
  if (!arguments.length) {
114
121
  bail = true;
115
122
  }
@@ -120,10 +127,11 @@ Mocha.prototype.bail = function (bail) {
120
127
  /**
121
128
  * Add test `file`.
122
129
  *
130
+ * @public
123
131
  * @api public
124
132
  * @param {string} file
125
133
  */
126
- Mocha.prototype.addFile = function (file) {
134
+ Mocha.prototype.addFile = function(file) {
127
135
  this.files.push(file);
128
136
  return this;
129
137
  };
@@ -131,13 +139,14 @@ Mocha.prototype.addFile = function (file) {
131
139
  /**
132
140
  * Set reporter to `reporter`, defaults to "spec".
133
141
  *
142
+ * @public
134
143
  * @param {String|Function} reporter name or constructor
135
144
  * @param {Object} reporterOptions optional options
136
145
  * @api public
137
146
  * @param {string|Function} reporter name or constructor
138
147
  * @param {Object} reporterOptions optional options
139
148
  */
140
- Mocha.prototype.reporter = function (reporter, reporterOptions) {
149
+ Mocha.prototype.reporter = function(reporter, reporterOptions) {
141
150
  if (typeof reporter === 'function') {
142
151
  this._reporter = reporter;
143
152
  } else {
@@ -157,18 +166,28 @@ Mocha.prototype.reporter = function (reporter, reporterOptions) {
157
166
  try {
158
167
  _reporter = require(path.resolve(process.cwd(), reporter));
159
168
  } catch (_err) {
160
- err.message.indexOf('Cannot find module') !== -1 ? console.warn('"' + reporter + '" reporter not found')
161
- : console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
169
+ err.message.indexOf('Cannot find module') !== -1
170
+ ? console.warn('"' + reporter + '" reporter not found')
171
+ : console.warn(
172
+ '"' +
173
+ reporter +
174
+ '" reporter blew up with error:\n' +
175
+ err.stack
176
+ );
162
177
  }
163
178
  } else {
164
- console.warn('"' + reporter + '" reporter blew up with error:\n' + err.stack);
179
+ console.warn(
180
+ '"' + reporter + '" reporter blew up with error:\n' + err.stack
181
+ );
165
182
  }
166
183
  }
167
184
  }
168
185
  if (!_reporter && reporter === 'teamcity') {
169
- console.warn('The Teamcity reporter was moved to a package named ' +
170
- 'mocha-teamcity-reporter ' +
171
- '(https://npmjs.org/package/mocha-teamcity-reporter).');
186
+ console.warn(
187
+ 'The Teamcity reporter was moved to a package named ' +
188
+ 'mocha-teamcity-reporter ' +
189
+ '(https://npmjs.org/package/mocha-teamcity-reporter).'
190
+ );
172
191
  }
173
192
  if (!_reporter) {
174
193
  throw new Error('invalid reporter "' + reporter + '"');
@@ -181,11 +200,11 @@ Mocha.prototype.reporter = function (reporter, reporterOptions) {
181
200
 
182
201
  /**
183
202
  * Set test UI `name`, defaults to "bdd".
184
- *
203
+ * @public
185
204
  * @api public
186
205
  * @param {string} bdd
187
206
  */
188
- Mocha.prototype.ui = function (name) {
207
+ Mocha.prototype.ui = function(name) {
189
208
  name = name || 'bdd';
190
209
  this._ui = exports.interfaces[name];
191
210
  if (!this._ui) {
@@ -197,7 +216,7 @@ Mocha.prototype.ui = function (name) {
197
216
  }
198
217
  this._ui = this._ui(this.suite);
199
218
 
200
- this.suite.on('pre-require', function (context) {
219
+ this.suite.on('pre-require', function(context) {
201
220
  exports.afterEach = context.afterEach || context.teardown;
202
221
  exports.after = context.after || context.suiteTeardown;
203
222
  exports.beforeEach = context.beforeEach || context.setup;
@@ -222,10 +241,10 @@ Mocha.prototype.ui = function (name) {
222
241
  *
223
242
  * @api private
224
243
  */
225
- Mocha.prototype.loadFiles = function (fn) {
244
+ Mocha.prototype.loadFiles = function(fn) {
226
245
  var self = this;
227
246
  var suite = this.suite;
228
- this.files.forEach(function (file) {
247
+ this.files.forEach(function(file) {
229
248
  file = path.resolve(file);
230
249
  suite.emit('pre-require', global, file, self);
231
250
  suite.emit('require', require(file), file, self);
@@ -239,14 +258,14 @@ Mocha.prototype.loadFiles = function (fn) {
239
258
  *
240
259
  * @api private
241
260
  */
242
- Mocha.prototype._growl = function (runner, reporter) {
261
+ Mocha.prototype._growl = function(runner, reporter) {
243
262
  var notify = require('growl');
244
263
 
245
- runner.on('end', function () {
264
+ runner.on('end', function() {
246
265
  var stats = reporter.stats;
247
266
  if (stats.failures) {
248
267
  var msg = stats.failures + ' of ' + runner.total + ' tests failed';
249
- notify(msg, { name: 'mocha', title: 'Failed', image: image('error') });
268
+ notify(msg, {name: 'mocha', title: 'Failed', image: image('error')});
250
269
  } else {
251
270
  notify(stats.passes + ' tests passed in ' + stats.duration + 'ms', {
252
271
  name: 'mocha',
@@ -260,24 +279,26 @@ Mocha.prototype._growl = function (runner, reporter) {
260
279
  /**
261
280
  * Escape string and add it to grep as a regexp.
262
281
  *
282
+ * @public
263
283
  * @api public
264
284
  * @param str
265
285
  * @returns {Mocha}
266
286
  */
267
- Mocha.prototype.fgrep = function (str) {
287
+ Mocha.prototype.fgrep = function(str) {
268
288
  return this.grep(new RegExp(escapeRe(str)));
269
289
  };
270
290
 
271
291
  /**
272
292
  * Add regexp to grep, if `re` is a string it is escaped.
273
293
  *
294
+ * @public
274
295
  * @param {RegExp|String} re
275
296
  * @return {Mocha}
276
297
  * @api public
277
298
  * @param {RegExp|string} re
278
299
  * @return {Mocha}
279
300
  */
280
- Mocha.prototype.grep = function (re) {
301
+ Mocha.prototype.grep = function(re) {
281
302
  if (utils.isString(re)) {
282
303
  // extract args if it's regex-like, i.e: [string, pattern, flag]
283
304
  var arg = re.match(/^\/(.*)\/(g|i|)$|.*/);
@@ -290,10 +311,11 @@ Mocha.prototype.grep = function (re) {
290
311
  /**
291
312
  * Invert `.grep()` matches.
292
313
  *
314
+ * @public
293
315
  * @return {Mocha}
294
316
  * @api public
295
317
  */
296
- Mocha.prototype.invert = function () {
318
+ Mocha.prototype.invert = function() {
297
319
  this.options.invert = true;
298
320
  return this;
299
321
  };
@@ -301,13 +323,14 @@ Mocha.prototype.invert = function () {
301
323
  /**
302
324
  * Ignore global leaks.
303
325
  *
326
+ * @public
304
327
  * @param {Boolean} ignore
305
328
  * @return {Mocha}
306
329
  * @api public
307
330
  * @param {boolean} ignore
308
331
  * @return {Mocha}
309
332
  */
310
- Mocha.prototype.ignoreLeaks = function (ignore) {
333
+ Mocha.prototype.ignoreLeaks = function(ignore) {
311
334
  this.options.ignoreLeaks = Boolean(ignore);
312
335
  return this;
313
336
  };
@@ -317,8 +340,9 @@ Mocha.prototype.ignoreLeaks = function (ignore) {
317
340
  *
318
341
  * @return {Mocha}
319
342
  * @api public
343
+ * @public
320
344
  */
321
- Mocha.prototype.checkLeaks = function () {
345
+ Mocha.prototype.checkLeaks = function() {
322
346
  this.options.ignoreLeaks = false;
323
347
  return this;
324
348
  };
@@ -328,8 +352,9 @@ Mocha.prototype.checkLeaks = function () {
328
352
  *
329
353
  * @return {Mocha}
330
354
  * @api public
355
+ * @public
331
356
  */
332
- Mocha.prototype.fullTrace = function () {
357
+ Mocha.prototype.fullTrace = function() {
333
358
  this.options.fullStackTrace = true;
334
359
  return this;
335
360
  };
@@ -339,8 +364,9 @@ Mocha.prototype.fullTrace = function () {
339
364
  *
340
365
  * @return {Mocha}
341
366
  * @api public
367
+ * @public
342
368
  */
343
- Mocha.prototype.growl = function () {
369
+ Mocha.prototype.growl = function() {
344
370
  this.options.growl = true;
345
371
  return this;
346
372
  };
@@ -351,10 +377,11 @@ Mocha.prototype.growl = function () {
351
377
  * @param {Array|String} globals
352
378
  * @return {Mocha}
353
379
  * @api public
380
+ * @public
354
381
  * @param {Array|string} globals
355
382
  * @return {Mocha}
356
383
  */
357
- Mocha.prototype.globals = function (globals) {
384
+ Mocha.prototype.globals = function(globals) {
358
385
  this.options.globals = (this.options.globals || []).concat(globals);
359
386
  return this;
360
387
  };
@@ -365,10 +392,11 @@ Mocha.prototype.globals = function (globals) {
365
392
  * @param {Boolean} colors
366
393
  * @return {Mocha}
367
394
  * @api public
395
+ * @public
368
396
  * @param {boolean} colors
369
397
  * @return {Mocha}
370
398
  */
371
- Mocha.prototype.useColors = function (colors) {
399
+ Mocha.prototype.useColors = function(colors) {
372
400
  if (colors !== undefined) {
373
401
  this.options.useColors = colors;
374
402
  }
@@ -381,10 +409,11 @@ Mocha.prototype.useColors = function (colors) {
381
409
  * @param {Boolean} inlineDiffs
382
410
  * @return {Mocha}
383
411
  * @api public
412
+ * @public
384
413
  * @param {boolean} inlineDiffs
385
414
  * @return {Mocha}
386
415
  */
387
- Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
416
+ Mocha.prototype.useInlineDiffs = function(inlineDiffs) {
388
417
  this.options.useInlineDiffs = inlineDiffs !== undefined && inlineDiffs;
389
418
  return this;
390
419
  };
@@ -395,10 +424,11 @@ Mocha.prototype.useInlineDiffs = function (inlineDiffs) {
395
424
  * @param {Boolean} hideDiff
396
425
  * @return {Mocha}
397
426
  * @api public
427
+ * @public
398
428
  * @param {boolean} hideDiff
399
429
  * @return {Mocha}
400
430
  */
401
- Mocha.prototype.hideDiff = function (hideDiff) {
431
+ Mocha.prototype.hideDiff = function(hideDiff) {
402
432
  this.options.hideDiff = hideDiff !== undefined && hideDiff;
403
433
  return this;
404
434
  };
@@ -409,10 +439,11 @@ Mocha.prototype.hideDiff = function (hideDiff) {
409
439
  * @param {Number} timeout
410
440
  * @return {Mocha}
411
441
  * @api public
442
+ * @public
412
443
  * @param {number} timeout
413
444
  * @return {Mocha}
414
445
  */
415
- Mocha.prototype.timeout = function (timeout) {
446
+ Mocha.prototype.timeout = function(timeout) {
416
447
  this.suite.timeout(timeout);
417
448
  return this;
418
449
  };
@@ -423,8 +454,9 @@ Mocha.prototype.timeout = function (timeout) {
423
454
  * @param {Number} retry times
424
455
  * @return {Mocha}
425
456
  * @api public
457
+ * @public
426
458
  */
427
- Mocha.prototype.retries = function (n) {
459
+ Mocha.prototype.retries = function(n) {
428
460
  this.suite.retries(n);
429
461
  return this;
430
462
  };
@@ -435,10 +467,11 @@ Mocha.prototype.retries = function (n) {
435
467
  * @param {Number} slow
436
468
  * @return {Mocha}
437
469
  * @api public
470
+ * @public
438
471
  * @param {number} slow
439
472
  * @return {Mocha}
440
473
  */
441
- Mocha.prototype.slow = function (slow) {
474
+ Mocha.prototype.slow = function(slow) {
442
475
  this.suite.slow(slow);
443
476
  return this;
444
477
  };
@@ -449,11 +482,14 @@ Mocha.prototype.slow = function (slow) {
449
482
  * @param {Boolean} enabled
450
483
  * @return {Mocha}
451
484
  * @api public
485
+ * @public
452
486
  * @param {boolean} enabled
453
487
  * @return {Mocha}
454
488
  */
455
- Mocha.prototype.enableTimeouts = function (enabled) {
456
- this.suite.enableTimeouts(arguments.length && enabled !== undefined ? enabled : true);
489
+ Mocha.prototype.enableTimeouts = function(enabled) {
490
+ this.suite.enableTimeouts(
491
+ arguments.length && enabled !== undefined ? enabled : true
492
+ );
457
493
  return this;
458
494
  };
459
495
 
@@ -462,8 +498,9 @@ Mocha.prototype.enableTimeouts = function (enabled) {
462
498
  *
463
499
  * @return {Mocha}
464
500
  * @api public
501
+ * @public
465
502
  */
466
- Mocha.prototype.asyncOnly = function () {
503
+ Mocha.prototype.asyncOnly = function() {
467
504
  this.options.asyncOnly = true;
468
505
  return this;
469
506
  };
@@ -472,8 +509,9 @@ Mocha.prototype.asyncOnly = function () {
472
509
  * Disable syntax highlighting (in browser).
473
510
  *
474
511
  * @api public
512
+ * @public
475
513
  */
476
- Mocha.prototype.noHighlighting = function () {
514
+ Mocha.prototype.noHighlighting = function() {
477
515
  this.options.noHighlighting = true;
478
516
  return this;
479
517
  };
@@ -483,8 +521,9 @@ Mocha.prototype.noHighlighting = function () {
483
521
  *
484
522
  * @return {Mocha}
485
523
  * @api public
524
+ * @public
486
525
  */
487
- Mocha.prototype.allowUncaught = function () {
526
+ Mocha.prototype.allowUncaught = function() {
488
527
  this.options.allowUncaught = true;
489
528
  return this;
490
529
  };
@@ -493,7 +532,7 @@ Mocha.prototype.allowUncaught = function () {
493
532
  * Delay root suite execution.
494
533
  * @returns {Mocha}
495
534
  */
496
- Mocha.prototype.delay = function delay () {
535
+ Mocha.prototype.delay = function delay() {
497
536
  this.options.delay = true;
498
537
  return this;
499
538
  };
@@ -502,7 +541,7 @@ Mocha.prototype.delay = function delay () {
502
541
  * Tests marked only fail the suite
503
542
  * @returns {Mocha}
504
543
  */
505
- Mocha.prototype.forbidOnly = function () {
544
+ Mocha.prototype.forbidOnly = function() {
506
545
  this.options.forbidOnly = true;
507
546
  return this;
508
547
  };
@@ -511,7 +550,7 @@ Mocha.prototype.forbidOnly = function () {
511
550
  * Pending tests and tests marked skip fail the suite
512
551
  * @returns {Mocha}
513
552
  */
514
- Mocha.prototype.forbidPending = function () {
553
+ Mocha.prototype.forbidPending = function() {
515
554
  this.options.forbidPending = true;
516
555
  return this;
517
556
  };
@@ -528,10 +567,11 @@ Mocha.prototype.forbidPending = function () {
528
567
  * cache first in whichever manner best suits your needs.
529
568
  *
530
569
  * @api public
570
+ * @public
531
571
  * @param {Function} fn
532
572
  * @return {Runner}
533
573
  */
534
- Mocha.prototype.run = function (fn) {
574
+ Mocha.prototype.run = function(fn) {
535
575
  if (this.files.length) {
536
576
  this.loadFiles();
537
577
  }
@@ -561,7 +601,7 @@ Mocha.prototype.run = function (fn) {
561
601
  exports.reporters.Base.inlineDiffs = options.useInlineDiffs;
562
602
  exports.reporters.Base.hideDiff = options.hideDiff;
563
603
 
564
- function done (failures) {
604
+ function done(failures) {
565
605
  if (reporter.done) {
566
606
  reporter.done(failures, fn);
567
607
  } else {
package/lib/ms.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module milliseconds
4
+ */
3
5
  /**
4
6
  * Helpers.
5
7
  */
@@ -13,11 +15,13 @@ var y = d * 365.25;
13
15
  /**
14
16
  * Parse or format the given `val`.
15
17
  *
18
+ * @memberof Mocha
19
+ * @public
16
20
  * @api public
17
21
  * @param {string|number} val
18
22
  * @return {string|number}
19
23
  */
20
- module.exports = function (val) {
24
+ module.exports = function(val) {
21
25
  if (typeof val === 'string') {
22
26
  return parse(val);
23
27
  }
@@ -31,8 +35,10 @@ module.exports = function (val) {
31
35
  * @param {string} str
32
36
  * @return {number}
33
37
  */
34
- function parse (str) {
35
- var match = (/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i).exec(str);
38
+ function parse(str) {
39
+ var match = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(
40
+ str
41
+ );
36
42
  if (!match) {
37
43
  return;
38
44
  }
@@ -62,7 +68,7 @@ function parse (str) {
62
68
  case 'ms':
63
69
  return n;
64
70
  default:
65
- // No default case
71
+ // No default case
66
72
  }
67
73
  }
68
74
 
@@ -73,7 +79,7 @@ function parse (str) {
73
79
  * @param {number} ms
74
80
  * @return {string}
75
81
  */
76
- function format (ms) {
82
+ function format(ms) {
77
83
  if (ms >= d) {
78
84
  return Math.round(ms / d) + 'd';
79
85
  }
package/lib/pending.js CHANGED
@@ -1,9 +1,5 @@
1
1
  'use strict';
2
2
 
3
- /**
4
- * Expose `Pending`.
5
- */
6
-
7
3
  module.exports = Pending;
8
4
 
9
5
  /**
@@ -11,6 +7,6 @@ module.exports = Pending;
11
7
  *
12
8
  * @param {string} message
13
9
  */
14
- function Pending (message) {
10
+ function Pending(message) {
15
11
  this.message = message;
16
12
  }