mocha 5.1.0 → 6.0.0-1

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 (63) hide show
  1. package/CHANGELOG.md +653 -981
  2. package/README.md +2 -1
  3. package/{images → assets/growl}/error.png +0 -0
  4. package/{images → assets/growl}/ok.png +0 -0
  5. package/bin/_mocha +4 -595
  6. package/bin/mocha +84 -58
  7. package/bin/options.js +6 -39
  8. package/browser-entry.js +21 -17
  9. package/lib/browser/growl.js +164 -2
  10. package/lib/browser/progress.js +11 -11
  11. package/lib/{template.html → browser/template.html} +0 -0
  12. package/lib/browser/tty.js +2 -2
  13. package/lib/cli/cli.js +68 -0
  14. package/lib/cli/commands.js +13 -0
  15. package/lib/cli/config.js +79 -0
  16. package/lib/cli/index.js +9 -0
  17. package/lib/cli/init.js +37 -0
  18. package/lib/cli/node-flags.js +48 -0
  19. package/lib/cli/one-and-dones.js +70 -0
  20. package/lib/cli/options.js +299 -0
  21. package/lib/cli/run-helpers.js +328 -0
  22. package/lib/cli/run-option-metadata.js +72 -0
  23. package/lib/cli/run.js +293 -0
  24. package/lib/context.js +14 -14
  25. package/lib/errors.js +139 -0
  26. package/lib/growl.js +135 -0
  27. package/lib/hook.js +5 -16
  28. package/lib/interfaces/bdd.js +14 -13
  29. package/lib/interfaces/common.js +59 -16
  30. package/lib/interfaces/exports.js +4 -7
  31. package/lib/interfaces/qunit.js +8 -10
  32. package/lib/interfaces/tdd.js +10 -11
  33. package/lib/mocha.js +442 -255
  34. package/lib/mocharc.json +10 -0
  35. package/lib/pending.js +1 -5
  36. package/lib/reporters/base.js +92 -117
  37. package/lib/reporters/doc.js +18 -9
  38. package/lib/reporters/dot.js +13 -13
  39. package/lib/reporters/html.js +76 -47
  40. package/lib/reporters/json-stream.js +38 -23
  41. package/lib/reporters/json.js +26 -23
  42. package/lib/reporters/landing.js +9 -8
  43. package/lib/reporters/list.js +11 -10
  44. package/lib/reporters/markdown.js +13 -12
  45. package/lib/reporters/min.js +4 -3
  46. package/lib/reporters/nyan.js +36 -35
  47. package/lib/reporters/progress.js +8 -7
  48. package/lib/reporters/spec.js +14 -11
  49. package/lib/reporters/tap.js +243 -32
  50. package/lib/reporters/xunit.js +52 -33
  51. package/lib/runnable.js +103 -90
  52. package/lib/runner.js +156 -107
  53. package/lib/stats-collector.js +81 -0
  54. package/lib/suite.js +57 -51
  55. package/lib/test.js +13 -13
  56. package/lib/utils.js +192 -103
  57. package/mocha.js +3836 -2046
  58. package/package.json +122 -38
  59. package/bin/.eslintrc.yml +0 -3
  60. package/lib/browser/.eslintrc.yml +0 -4
  61. package/lib/ms.js +0 -94
  62. package/lib/reporters/base.js.orig +0 -498
  63. package/lib/reporters/json.js.orig +0 -128
@@ -0,0 +1,10 @@
1
+ {
2
+ "diff": true,
3
+ "extension": ["js"],
4
+ "opts": "./test/mocha.opts",
5
+ "package": "./package.json",
6
+ "reporter": "spec",
7
+ "slow": 75,
8
+ "timeout": 2000,
9
+ "ui": "bdd"
10
+ }
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
  }
@@ -8,7 +8,7 @@
8
8
 
9
9
  var tty = require('tty');
10
10
  var diff = require('diff');
11
- var ms = require('../ms');
11
+ var milliseconds = require('ms');
12
12
  var utils = require('../utils');
13
13
  var supportsColor = process.browser ? null : require('supports-color');
14
14
 
@@ -18,19 +18,6 @@ var supportsColor = process.browser ? null : require('supports-color');
18
18
 
19
19
  exports = module.exports = Base;
20
20
 
21
- /**
22
- * Save timer references to avoid Sinon interfering.
23
- * See: https://github.com/mochajs/mocha/issues/237
24
- */
25
-
26
- /* eslint-disable no-unused-vars, no-native-reassign */
27
- var Date = global.Date;
28
- var setTimeout = global.setTimeout;
29
- var setInterval = global.setInterval;
30
- var clearTimeout = global.clearTimeout;
31
- var clearInterval = global.clearInterval;
32
- /* eslint-enable no-unused-vars, no-native-reassign */
33
-
34
21
  /**
35
22
  * Check if both stdio streams are associated with a tty.
36
23
  */
@@ -41,7 +28,9 @@ var isatty = tty.isatty(1) && tty.isatty(2);
41
28
  * Enable coloring by default, except in the browser interface.
42
29
  */
43
30
 
44
- exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
31
+ exports.useColors =
32
+ !process.browser &&
33
+ (supportsColor.stdout || process.env.MOCHA_COLORS !== undefined);
45
34
 
46
35
  /**
47
36
  * Inline diffs instead of +/-
@@ -103,14 +92,14 @@ if (process.platform === 'win32') {
103
92
  * @param {string} type
104
93
  * @param {string} str
105
94
  * @return {string}
106
- * @api private
95
+ * @private
107
96
  */
108
- var color = exports.color = function (type, str) {
97
+ var color = (exports.color = function(type, str) {
109
98
  if (!exports.useColors) {
110
99
  return String(str);
111
100
  }
112
101
  return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
113
- };
102
+ });
114
103
 
115
104
  /**
116
105
  * Expose term window size, with some defaults for when stderr is not a tty.
@@ -131,23 +120,23 @@ if (isatty) {
131
120
  */
132
121
 
133
122
  exports.cursor = {
134
- hide: function () {
123
+ hide: function() {
135
124
  isatty && process.stdout.write('\u001b[?25l');
136
125
  },
137
126
 
138
- show: function () {
127
+ show: function() {
139
128
  isatty && process.stdout.write('\u001b[?25h');
140
129
  },
141
130
 
142
- deleteLine: function () {
131
+ deleteLine: function() {
143
132
  isatty && process.stdout.write('\u001b[2K');
144
133
  },
145
134
 
146
- beginningOfLine: function () {
135
+ beginningOfLine: function() {
147
136
  isatty && process.stdout.write('\u001b[0G');
148
137
  },
149
138
 
150
- CR: function () {
139
+ CR: function() {
151
140
  if (isatty) {
152
141
  exports.cursor.deleteLine();
153
142
  exports.cursor.beginningOfLine();
@@ -157,11 +146,16 @@ exports.cursor = {
157
146
  }
158
147
  };
159
148
 
160
- function showDiff (err) {
161
- return err && err.showDiff !== false && sameType(err.actual, err.expected) && err.expected !== undefined;
149
+ function showDiff(err) {
150
+ return (
151
+ err &&
152
+ err.showDiff !== false &&
153
+ sameType(err.actual, err.expected) &&
154
+ err.expected !== undefined
155
+ );
162
156
  }
163
157
 
164
- function stringifyDiffObjs (err) {
158
+ function stringifyDiffObjs(err) {
165
159
  if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
166
160
  err.actual = utils.stringify(err.actual);
167
161
  err.expected = utils.stringify(err.expected);
@@ -178,11 +172,11 @@ function stringifyDiffObjs (err) {
178
172
  * @param {string} expected
179
173
  * @return {string} Diff
180
174
  */
181
- var generateDiff = exports.generateDiff = function (actual, expected) {
175
+ var generateDiff = (exports.generateDiff = function(actual, expected) {
182
176
  return exports.inlineDiffs
183
177
  ? inlineDiff(actual, expected)
184
178
  : unifiedDiff(actual, expected);
185
- };
179
+ });
186
180
 
187
181
  /**
188
182
  * Output the given `failures` as a list.
@@ -191,14 +185,14 @@ var generateDiff = exports.generateDiff = function (actual, expected) {
191
185
  * @memberof Mocha.reporters.Base
192
186
  * @variation 1
193
187
  * @param {Array} failures
194
- * @api public
195
188
  */
196
189
 
197
- exports.list = function (failures) {
190
+ exports.list = function(failures) {
198
191
  console.log();
199
- failures.forEach(function (test, i) {
192
+ failures.forEach(function(test, i) {
200
193
  // format
201
- var fmt = color('error title', ' %s) %s:\n') +
194
+ var fmt =
195
+ color('error title', ' %s) %s:\n') +
202
196
  color('error message', ' %s') +
203
197
  color('error stack', '\n%s\n');
204
198
 
@@ -232,7 +226,8 @@ exports.list = function (failures) {
232
226
  // explicitly show diff
233
227
  if (!exports.hideDiff && showDiff(err)) {
234
228
  stringifyDiffObjs(err);
235
- fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
229
+ fmt =
230
+ color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
236
231
  var match = message.match(/^([^:]+): expected/);
237
232
  msg = '\n ' + color('error message', match ? match[1] : msg);
238
233
 
@@ -244,7 +239,7 @@ exports.list = function (failures) {
244
239
 
245
240
  // indented test title
246
241
  var testTitle = '';
247
- test.titlePath().forEach(function (str, index) {
242
+ test.titlePath().forEach(function(str, index) {
248
243
  if (index !== 0) {
249
244
  testTitle += '\n ';
250
245
  }
@@ -254,7 +249,7 @@ exports.list = function (failures) {
254
249
  testTitle += str;
255
250
  });
256
251
 
257
- console.log(fmt, (i + 1), testTitle, msg, stack);
252
+ console.log(fmt, i + 1, testTitle, msg, stack);
258
253
  });
259
254
  };
260
255
 
@@ -262,45 +257,24 @@ exports.list = function (failures) {
262
257
  * Initialize a new `Base` reporter.
263
258
  *
264
259
  * All other reporters generally
265
- * inherit from this reporter, providing
266
- * stats such as test duration, number
267
- * of tests passed / failed etc.
260
+ * inherit from this reporter.
268
261
  *
269
262
  * @memberof Mocha.reporters
270
263
  * @public
271
264
  * @class
272
265
  * @param {Runner} runner
273
- * @api public
274
266
  */
275
267
 
276
- function Base (runner) {
277
- var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
278
- var failures = this.failures = [];
268
+ function Base(runner) {
269
+ var failures = (this.failures = []);
279
270
 
280
271
  if (!runner) {
281
- return;
272
+ throw new TypeError('Missing runner argument');
282
273
  }
274
+ this.stats = runner.stats; // assigned so Reporters keep a closer reference
283
275
  this.runner = runner;
284
276
 
285
- runner.stats = stats;
286
-
287
- runner.on('start', function () {
288
- stats.start = new Date();
289
- });
290
-
291
- runner.on('suite', function (suite) {
292
- stats.suites = stats.suites || 0;
293
- suite.root || stats.suites++;
294
- });
295
-
296
- runner.on('test end', function () {
297
- stats.tests = stats.tests || 0;
298
- stats.tests++;
299
- });
300
-
301
- runner.on('pass', function (test) {
302
- stats.passes = stats.passes || 0;
303
-
277
+ runner.on('pass', function(test) {
304
278
  if (test.duration > test.slow()) {
305
279
  test.speed = 'slow';
306
280
  } else if (test.duration > test.slow() / 2) {
@@ -308,28 +282,15 @@ function Base (runner) {
308
282
  } else {
309
283
  test.speed = 'fast';
310
284
  }
311
-
312
- stats.passes++;
313
285
  });
314
286
 
315
- runner.on('fail', function (test, err) {
316
- stats.failures = stats.failures || 0;
317
- stats.failures++;
287
+ runner.on('fail', function(test, err) {
318
288
  if (showDiff(err)) {
319
289
  stringifyDiffObjs(err);
320
290
  }
321
291
  test.err = err;
322
292
  failures.push(test);
323
293
  });
324
-
325
- runner.once('end', function () {
326
- stats.end = new Date();
327
- stats.duration = stats.end - stats.start;
328
- });
329
-
330
- runner.on('pending', function () {
331
- stats.pending++;
332
- });
333
294
  }
334
295
 
335
296
  /**
@@ -338,27 +299,24 @@ function Base (runner) {
338
299
  *
339
300
  * @memberof Mocha.reporters.Base
340
301
  * @public
341
- * @api public
342
302
  */
343
- Base.prototype.epilogue = function () {
303
+ Base.prototype.epilogue = function() {
344
304
  var stats = this.stats;
345
305
  var fmt;
346
306
 
347
307
  console.log();
348
308
 
349
309
  // passes
350
- fmt = color('bright pass', ' ') +
310
+ fmt =
311
+ color('bright pass', ' ') +
351
312
  color('green', ' %d passing') +
352
313
  color('light', ' (%s)');
353
314
 
354
- console.log(fmt,
355
- stats.passes || 0,
356
- ms(stats.duration));
315
+ console.log(fmt, stats.passes || 0, milliseconds(stats.duration));
357
316
 
358
317
  // pending
359
318
  if (stats.pending) {
360
- fmt = color('pending', ' ') +
361
- color('pending', ' %d pending');
319
+ fmt = color('pending', ' ') + color('pending', ' %d pending');
362
320
 
363
321
  console.log(fmt, stats.pending);
364
322
  }
@@ -379,12 +337,12 @@ Base.prototype.epilogue = function () {
379
337
  /**
380
338
  * Pad the given `str` to `len`.
381
339
  *
382
- * @api private
340
+ * @private
383
341
  * @param {string} str
384
342
  * @param {string} len
385
343
  * @return {string}
386
344
  */
387
- function pad (str, len) {
345
+ function pad(str, len) {
388
346
  str = String(str);
389
347
  return Array(len - str.length + 1).join(' ') + str;
390
348
  }
@@ -392,25 +350,28 @@ function pad (str, len) {
392
350
  /**
393
351
  * Returns an inline diff between 2 strings with coloured ANSI output.
394
352
  *
395
- * @api private
353
+ * @private
396
354
  * @param {String} actual
397
355
  * @param {String} expected
398
356
  * @return {string} Diff
399
357
  */
400
- function inlineDiff (actual, expected) {
358
+ function inlineDiff(actual, expected) {
401
359
  var msg = errorDiff(actual, expected);
402
360
 
403
361
  // linenos
404
362
  var lines = msg.split('\n');
405
363
  if (lines.length > 4) {
406
364
  var width = String(lines.length).length;
407
- msg = lines.map(function (str, i) {
408
- return pad(++i, width) + ' |' + ' ' + str;
409
- }).join('\n');
365
+ msg = lines
366
+ .map(function(str, i) {
367
+ return pad(++i, width) + ' |' + ' ' + str;
368
+ })
369
+ .join('\n');
410
370
  }
411
371
 
412
372
  // legend
413
- msg = '\n' +
373
+ msg =
374
+ '\n' +
414
375
  color('diff removed', 'actual') +
415
376
  ' ' +
416
377
  color('diff added', 'expected') +
@@ -426,14 +387,14 @@ function inlineDiff (actual, expected) {
426
387
  /**
427
388
  * Returns a unified diff between two strings with coloured ANSI output.
428
389
  *
429
- * @api private
390
+ * @private
430
391
  * @param {String} actual
431
392
  * @param {String} expected
432
393
  * @return {string} The diff.
433
394
  */
434
- function unifiedDiff (actual, expected) {
395
+ function unifiedDiff(actual, expected) {
435
396
  var indent = ' ';
436
- function cleanUp (line) {
397
+ function cleanUp(line) {
437
398
  if (line[0] === '+') {
438
399
  return indent + colorLines('diff added', line);
439
400
  }
@@ -448,50 +409,62 @@ function unifiedDiff (actual, expected) {
448
409
  }
449
410
  return indent + line;
450
411
  }
451
- function notBlank (line) {
412
+ function notBlank(line) {
452
413
  return typeof line !== 'undefined' && line !== null;
453
414
  }
454
415
  var msg = diff.createPatch('string', actual, expected);
455
416
  var lines = msg.split('\n').splice(5);
456
- return '\n ' +
457
- colorLines('diff added', '+ expected') + ' ' +
417
+ return (
418
+ '\n ' +
419
+ colorLines('diff added', '+ expected') +
420
+ ' ' +
458
421
  colorLines('diff removed', '- actual') +
459
422
  '\n\n' +
460
- lines.map(cleanUp).filter(notBlank).join('\n');
423
+ lines
424
+ .map(cleanUp)
425
+ .filter(notBlank)
426
+ .join('\n')
427
+ );
461
428
  }
462
429
 
463
430
  /**
464
431
  * Return a character diff for `err`.
465
432
  *
466
- * @api private
433
+ * @private
467
434
  * @param {String} actual
468
435
  * @param {String} expected
469
436
  * @return {string} the diff
470
437
  */
471
- function errorDiff (actual, expected) {
472
- return diff.diffWordsWithSpace(actual, expected).map(function (str) {
473
- if (str.added) {
474
- return colorLines('diff added', str.value);
475
- }
476
- if (str.removed) {
477
- return colorLines('diff removed', str.value);
478
- }
479
- return str.value;
480
- }).join('');
438
+ function errorDiff(actual, expected) {
439
+ return diff
440
+ .diffWordsWithSpace(actual, expected)
441
+ .map(function(str) {
442
+ if (str.added) {
443
+ return colorLines('diff added', str.value);
444
+ }
445
+ if (str.removed) {
446
+ return colorLines('diff removed', str.value);
447
+ }
448
+ return str.value;
449
+ })
450
+ .join('');
481
451
  }
482
452
 
483
453
  /**
484
454
  * Color lines for `str`, using the color `name`.
485
455
  *
486
- * @api private
456
+ * @private
487
457
  * @param {string} name
488
458
  * @param {string} str
489
459
  * @return {string}
490
460
  */
491
- function colorLines (name, str) {
492
- return str.split('\n').map(function (str) {
493
- return color(name, str);
494
- }).join('\n');
461
+ function colorLines(name, str) {
462
+ return str
463
+ .split('\n')
464
+ .map(function(str) {
465
+ return color(name, str);
466
+ })
467
+ .join('\n');
495
468
  }
496
469
 
497
470
  /**
@@ -502,11 +475,13 @@ var objToString = Object.prototype.toString;
502
475
  /**
503
476
  * Check that a / b have the same type.
504
477
  *
505
- * @api private
478
+ * @private
506
479
  * @param {Object} a
507
480
  * @param {Object} b
508
481
  * @return {boolean}
509
482
  */
510
- function sameType (a, b) {
483
+ function sameType(a, b) {
511
484
  return objToString.call(a) === objToString.call(b);
512
485
  }
486
+
487
+ Base.abstract = true;
@@ -23,18 +23,17 @@ exports = module.exports = Doc;
23
23
  * @extends {Base}
24
24
  * @public
25
25
  * @param {Runner} runner
26
- * @api public
27
26
  */
28
- function Doc (runner) {
27
+ function Doc(runner) {
29
28
  Base.call(this, runner);
30
29
 
31
30
  var indents = 2;
32
31
 
33
- function indent () {
32
+ function indent() {
34
33
  return Array(indents).join(' ');
35
34
  }
36
35
 
37
- runner.on('suite', function (suite) {
36
+ runner.on('suite', function(suite) {
38
37
  if (suite.root) {
39
38
  return;
40
39
  }
@@ -45,7 +44,7 @@ function Doc (runner) {
45
44
  console.log('%s<dl>', indent());
46
45
  });
47
46
 
48
- runner.on('suite end', function (suite) {
47
+ runner.on('suite end', function(suite) {
49
48
  if (suite.root) {
50
49
  return;
51
50
  }
@@ -55,16 +54,26 @@ function Doc (runner) {
55
54
  --indents;
56
55
  });
57
56
 
58
- runner.on('pass', function (test) {
57
+ runner.on('pass', function(test) {
59
58
  console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
60
59
  var code = utils.escape(utils.clean(test.body));
61
60
  console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
62
61
  });
63
62
 
64
- runner.on('fail', function (test, err) {
65
- console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
63
+ runner.on('fail', function(test, err) {
64
+ console.log(
65
+ '%s <dt class="error">%s</dt>',
66
+ indent(),
67
+ utils.escape(test.title)
68
+ );
66
69
  var code = utils.escape(utils.clean(test.body));
67
- console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
70
+ console.log(
71
+ '%s <dd class="error"><pre><code>%s</code></pre></dd>',
72
+ indent(),
73
+ code
74
+ );
68
75
  console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
69
76
  });
70
77
  }
78
+
79
+ Doc.description = 'HTML documentation';
@@ -8,7 +8,6 @@
8
8
 
9
9
  var Base = require('./base');
10
10
  var inherits = require('../utils').inherits;
11
- var color = Base.color;
12
11
 
13
12
  /**
14
13
  * Expose `Dot`.
@@ -23,46 +22,45 @@ exports = module.exports = Dot;
23
22
  * @memberof Mocha.reporters
24
23
  * @extends Mocha.reporters.Base
25
24
  * @public
26
- * @api public
27
25
  * @param {Runner} runner
28
26
  */
29
- function Dot (runner) {
27
+ function Dot(runner) {
30
28
  Base.call(this, runner);
31
29
 
32
30
  var self = this;
33
- var width = Base.window.width * 0.75 | 0;
31
+ var width = (Base.window.width * 0.75) | 0;
34
32
  var n = -1;
35
33
 
36
- runner.on('start', function () {
34
+ runner.on('start', function() {
37
35
  process.stdout.write('\n');
38
36
  });
39
37
 
40
- runner.on('pending', function () {
38
+ runner.on('pending', function() {
41
39
  if (++n % width === 0) {
42
40
  process.stdout.write('\n ');
43
41
  }
44
- process.stdout.write(color('pending', Base.symbols.comma));
42
+ process.stdout.write(Base.color('pending', Base.symbols.comma));
45
43
  });
46
44
 
47
- runner.on('pass', function (test) {
45
+ runner.on('pass', function(test) {
48
46
  if (++n % width === 0) {
49
47
  process.stdout.write('\n ');
50
48
  }
51
49
  if (test.speed === 'slow') {
52
- process.stdout.write(color('bright yellow', Base.symbols.dot));
50
+ process.stdout.write(Base.color('bright yellow', Base.symbols.dot));
53
51
  } else {
54
- process.stdout.write(color(test.speed, Base.symbols.dot));
52
+ process.stdout.write(Base.color(test.speed, Base.symbols.dot));
55
53
  }
56
54
  });
57
55
 
58
- runner.on('fail', function () {
56
+ runner.on('fail', function() {
59
57
  if (++n % width === 0) {
60
58
  process.stdout.write('\n ');
61
59
  }
62
- process.stdout.write(color('fail', Base.symbols.bang));
60
+ process.stdout.write(Base.color('fail', Base.symbols.bang));
63
61
  });
64
62
 
65
- runner.once('end', function () {
63
+ runner.once('end', function() {
66
64
  console.log();
67
65
  self.epilogue();
68
66
  });
@@ -72,3 +70,5 @@ function Dot (runner) {
72
70
  * Inherit from `Base.prototype`.
73
71
  */
74
72
  inherits(Dot, Base);
73
+
74
+ Dot.description = 'dot matrix representation';