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
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module Base
4
+ */
3
5
  /**
4
6
  * Module dependencies.
5
7
  */
@@ -39,7 +41,9 @@ var isatty = tty.isatty(1) && tty.isatty(2);
39
41
  * Enable coloring by default, except in the browser interface.
40
42
  */
41
43
 
42
- exports.useColors = !process.browser && (supportsColor || (process.env.MOCHA_COLORS !== undefined));
44
+ exports.useColors =
45
+ !process.browser &&
46
+ (supportsColor.stdout || process.env.MOCHA_COLORS !== undefined);
43
47
 
44
48
  /**
45
49
  * Inline diffs instead of +/-
@@ -103,12 +107,12 @@ if (process.platform === 'win32') {
103
107
  * @return {string}
104
108
  * @api private
105
109
  */
106
- var color = exports.color = function (type, str) {
110
+ var color = (exports.color = function(type, str) {
107
111
  if (!exports.useColors) {
108
112
  return String(str);
109
113
  }
110
114
  return '\u001b[' + exports.colors[type] + 'm' + str + '\u001b[0m';
111
- };
115
+ });
112
116
 
113
117
  /**
114
118
  * Expose term window size, with some defaults for when stderr is not a tty.
@@ -129,23 +133,23 @@ if (isatty) {
129
133
  */
130
134
 
131
135
  exports.cursor = {
132
- hide: function () {
136
+ hide: function() {
133
137
  isatty && process.stdout.write('\u001b[?25l');
134
138
  },
135
139
 
136
- show: function () {
140
+ show: function() {
137
141
  isatty && process.stdout.write('\u001b[?25h');
138
142
  },
139
143
 
140
- deleteLine: function () {
144
+ deleteLine: function() {
141
145
  isatty && process.stdout.write('\u001b[2K');
142
146
  },
143
147
 
144
- beginningOfLine: function () {
148
+ beginningOfLine: function() {
145
149
  isatty && process.stdout.write('\u001b[0G');
146
150
  },
147
151
 
148
- CR: function () {
152
+ CR: function() {
149
153
  if (isatty) {
150
154
  exports.cursor.deleteLine();
151
155
  exports.cursor.beginningOfLine();
@@ -155,11 +159,16 @@ exports.cursor = {
155
159
  }
156
160
  };
157
161
 
158
- function showDiff (err) {
159
- return err && err.showDiff !== false && sameType(err.actual, err.expected) && err.expected !== undefined;
162
+ function showDiff(err) {
163
+ return (
164
+ err &&
165
+ err.showDiff !== false &&
166
+ sameType(err.actual, err.expected) &&
167
+ err.expected !== undefined
168
+ );
160
169
  }
161
170
 
162
- function stringifyDiffObjs (err) {
171
+ function stringifyDiffObjs(err) {
163
172
  if (!utils.isString(err.actual) || !utils.isString(err.expected)) {
164
173
  err.actual = utils.stringify(err.actual);
165
174
  err.expected = utils.stringify(err.expected);
@@ -176,24 +185,28 @@ function stringifyDiffObjs (err) {
176
185
  * @param {string} expected
177
186
  * @return {string} Diff
178
187
  */
179
- var generateDiff = exports.generateDiff = function (actual, expected) {
188
+ var generateDiff = (exports.generateDiff = function(actual, expected) {
180
189
  return exports.inlineDiffs
181
190
  ? inlineDiff(actual, expected)
182
191
  : unifiedDiff(actual, expected);
183
- };
192
+ });
184
193
 
185
194
  /**
186
195
  * Output the given `failures` as a list.
187
196
  *
197
+ * @public
198
+ * @memberof Mocha.reporters.Base
199
+ * @variation 1
188
200
  * @param {Array} failures
189
201
  * @api public
190
202
  */
191
203
 
192
- exports.list = function (failures) {
204
+ exports.list = function(failures) {
193
205
  console.log();
194
- failures.forEach(function (test, i) {
206
+ failures.forEach(function(test, i) {
195
207
  // format
196
- var fmt = color('error title', ' %s) %s:\n') +
208
+ var fmt =
209
+ color('error title', ' %s) %s:\n') +
197
210
  color('error message', ' %s') +
198
211
  color('error stack', '\n%s\n');
199
212
 
@@ -227,7 +240,8 @@ exports.list = function (failures) {
227
240
  // explicitly show diff
228
241
  if (!exports.hideDiff && showDiff(err)) {
229
242
  stringifyDiffObjs(err);
230
- fmt = color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
243
+ fmt =
244
+ color('error title', ' %s) %s:\n%s') + color('error stack', '\n%s\n');
231
245
  var match = message.match(/^([^:]+): expected/);
232
246
  msg = '\n ' + color('error message', match ? match[1] : msg);
233
247
 
@@ -239,7 +253,7 @@ exports.list = function (failures) {
239
253
 
240
254
  // indented test title
241
255
  var testTitle = '';
242
- test.titlePath().forEach(function (str, index) {
256
+ test.titlePath().forEach(function(str, index) {
243
257
  if (index !== 0) {
244
258
  testTitle += '\n ';
245
259
  }
@@ -249,7 +263,7 @@ exports.list = function (failures) {
249
263
  testTitle += str;
250
264
  });
251
265
 
252
- console.log(fmt, (i + 1), testTitle, msg, stack);
266
+ console.log(fmt, i + 1, testTitle, msg, stack);
253
267
  });
254
268
  };
255
269
 
@@ -261,13 +275,22 @@ exports.list = function (failures) {
261
275
  * stats such as test duration, number
262
276
  * of tests passed / failed etc.
263
277
  *
278
+ * @memberof Mocha.reporters
279
+ * @public
280
+ * @class
264
281
  * @param {Runner} runner
265
282
  * @api public
266
283
  */
267
284
 
268
- function Base (runner) {
269
- var stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 };
270
- var failures = this.failures = [];
285
+ function Base(runner) {
286
+ var stats = (this.stats = {
287
+ suites: 0,
288
+ tests: 0,
289
+ passes: 0,
290
+ pending: 0,
291
+ failures: 0
292
+ });
293
+ var failures = (this.failures = []);
271
294
 
272
295
  if (!runner) {
273
296
  return;
@@ -276,21 +299,21 @@ function Base (runner) {
276
299
 
277
300
  runner.stats = stats;
278
301
 
279
- runner.on('start', function () {
302
+ runner.on('start', function() {
280
303
  stats.start = new Date();
281
304
  });
282
305
 
283
- runner.on('suite', function (suite) {
306
+ runner.on('suite', function(suite) {
284
307
  stats.suites = stats.suites || 0;
285
308
  suite.root || stats.suites++;
286
309
  });
287
310
 
288
- runner.on('test end', function () {
311
+ runner.on('test end', function() {
289
312
  stats.tests = stats.tests || 0;
290
313
  stats.tests++;
291
314
  });
292
315
 
293
- runner.on('pass', function (test) {
316
+ runner.on('pass', function(test) {
294
317
  stats.passes = stats.passes || 0;
295
318
 
296
319
  if (test.duration > test.slow()) {
@@ -304,7 +327,7 @@ function Base (runner) {
304
327
  stats.passes++;
305
328
  });
306
329
 
307
- runner.on('fail', function (test, err) {
330
+ runner.on('fail', function(test, err) {
308
331
  stats.failures = stats.failures || 0;
309
332
  stats.failures++;
310
333
  if (showDiff(err)) {
@@ -314,12 +337,12 @@ function Base (runner) {
314
337
  failures.push(test);
315
338
  });
316
339
 
317
- runner.once('end', function () {
340
+ runner.once('end', function() {
318
341
  stats.end = new Date();
319
342
  stats.duration = stats.end - stats.start;
320
343
  });
321
344
 
322
- runner.on('pending', function () {
345
+ runner.on('pending', function() {
323
346
  stats.pending++;
324
347
  });
325
348
  }
@@ -328,27 +351,27 @@ function Base (runner) {
328
351
  * Output common epilogue used by many of
329
352
  * the bundled reporters.
330
353
  *
354
+ * @memberof Mocha.reporters.Base
355
+ * @public
331
356
  * @api public
332
357
  */
333
- Base.prototype.epilogue = function () {
358
+ Base.prototype.epilogue = function() {
334
359
  var stats = this.stats;
335
360
  var fmt;
336
361
 
337
362
  console.log();
338
363
 
339
364
  // passes
340
- fmt = color('bright pass', ' ') +
365
+ fmt =
366
+ color('bright pass', ' ') +
341
367
  color('green', ' %d passing') +
342
368
  color('light', ' (%s)');
343
369
 
344
- console.log(fmt,
345
- stats.passes || 0,
346
- ms(stats.duration));
370
+ console.log(fmt, stats.passes || 0, ms(stats.duration));
347
371
 
348
372
  // pending
349
373
  if (stats.pending) {
350
- fmt = color('pending', ' ') +
351
- color('pending', ' %d pending');
374
+ fmt = color('pending', ' ') + color('pending', ' %d pending');
352
375
 
353
376
  console.log(fmt, stats.pending);
354
377
  }
@@ -374,7 +397,7 @@ Base.prototype.epilogue = function () {
374
397
  * @param {string} len
375
398
  * @return {string}
376
399
  */
377
- function pad (str, len) {
400
+ function pad(str, len) {
378
401
  str = String(str);
379
402
  return Array(len - str.length + 1).join(' ') + str;
380
403
  }
@@ -387,20 +410,23 @@ function pad (str, len) {
387
410
  * @param {String} expected
388
411
  * @return {string} Diff
389
412
  */
390
- function inlineDiff (actual, expected) {
413
+ function inlineDiff(actual, expected) {
391
414
  var msg = errorDiff(actual, expected);
392
415
 
393
416
  // linenos
394
417
  var lines = msg.split('\n');
395
418
  if (lines.length > 4) {
396
419
  var width = String(lines.length).length;
397
- msg = lines.map(function (str, i) {
398
- return pad(++i, width) + ' |' + ' ' + str;
399
- }).join('\n');
420
+ msg = lines
421
+ .map(function(str, i) {
422
+ return pad(++i, width) + ' |' + ' ' + str;
423
+ })
424
+ .join('\n');
400
425
  }
401
426
 
402
427
  // legend
403
- msg = '\n' +
428
+ msg =
429
+ '\n' +
404
430
  color('diff removed', 'actual') +
405
431
  ' ' +
406
432
  color('diff added', 'expected') +
@@ -421,9 +447,9 @@ function inlineDiff (actual, expected) {
421
447
  * @param {String} expected
422
448
  * @return {string} The diff.
423
449
  */
424
- function unifiedDiff (actual, expected) {
450
+ function unifiedDiff(actual, expected) {
425
451
  var indent = ' ';
426
- function cleanUp (line) {
452
+ function cleanUp(line) {
427
453
  if (line[0] === '+') {
428
454
  return indent + colorLines('diff added', line);
429
455
  }
@@ -438,16 +464,22 @@ function unifiedDiff (actual, expected) {
438
464
  }
439
465
  return indent + line;
440
466
  }
441
- function notBlank (line) {
467
+ function notBlank(line) {
442
468
  return typeof line !== 'undefined' && line !== null;
443
469
  }
444
470
  var msg = diff.createPatch('string', actual, expected);
445
471
  var lines = msg.split('\n').splice(5);
446
- return '\n ' +
447
- colorLines('diff added', '+ expected') + ' ' +
472
+ return (
473
+ '\n ' +
474
+ colorLines('diff added', '+ expected') +
475
+ ' ' +
448
476
  colorLines('diff removed', '- actual') +
449
477
  '\n\n' +
450
- lines.map(cleanUp).filter(notBlank).join('\n');
478
+ lines
479
+ .map(cleanUp)
480
+ .filter(notBlank)
481
+ .join('\n')
482
+ );
451
483
  }
452
484
 
453
485
  /**
@@ -458,16 +490,19 @@ function unifiedDiff (actual, expected) {
458
490
  * @param {String} expected
459
491
  * @return {string} the diff
460
492
  */
461
- function errorDiff (actual, expected) {
462
- return diff.diffWordsWithSpace(actual, expected).map(function (str) {
463
- if (str.added) {
464
- return colorLines('diff added', str.value);
465
- }
466
- if (str.removed) {
467
- return colorLines('diff removed', str.value);
468
- }
469
- return str.value;
470
- }).join('');
493
+ function errorDiff(actual, expected) {
494
+ return diff
495
+ .diffWordsWithSpace(actual, expected)
496
+ .map(function(str) {
497
+ if (str.added) {
498
+ return colorLines('diff added', str.value);
499
+ }
500
+ if (str.removed) {
501
+ return colorLines('diff removed', str.value);
502
+ }
503
+ return str.value;
504
+ })
505
+ .join('');
471
506
  }
472
507
 
473
508
  /**
@@ -478,10 +513,13 @@ function errorDiff (actual, expected) {
478
513
  * @param {string} str
479
514
  * @return {string}
480
515
  */
481
- function colorLines (name, str) {
482
- return str.split('\n').map(function (str) {
483
- return color(name, str);
484
- }).join('\n');
516
+ function colorLines(name, str) {
517
+ return str
518
+ .split('\n')
519
+ .map(function(str) {
520
+ return color(name, str);
521
+ })
522
+ .join('\n');
485
523
  }
486
524
 
487
525
  /**
@@ -497,6 +535,6 @@ var objToString = Object.prototype.toString;
497
535
  * @param {Object} b
498
536
  * @return {boolean}
499
537
  */
500
- function sameType (a, b) {
538
+ function sameType(a, b) {
501
539
  return objToString.call(a) === objToString.call(b);
502
540
  }
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module Doc
4
+ */
3
5
  /**
4
6
  * Module dependencies.
5
7
  */
@@ -16,19 +18,23 @@ exports = module.exports = Doc;
16
18
  /**
17
19
  * Initialize a new `Doc` reporter.
18
20
  *
21
+ * @class
22
+ * @memberof Mocha.reporters
23
+ * @extends {Base}
24
+ * @public
19
25
  * @param {Runner} runner
20
26
  * @api public
21
27
  */
22
- function Doc (runner) {
28
+ function Doc(runner) {
23
29
  Base.call(this, runner);
24
30
 
25
31
  var indents = 2;
26
32
 
27
- function indent () {
33
+ function indent() {
28
34
  return Array(indents).join(' ');
29
35
  }
30
36
 
31
- runner.on('suite', function (suite) {
37
+ runner.on('suite', function(suite) {
32
38
  if (suite.root) {
33
39
  return;
34
40
  }
@@ -39,7 +45,7 @@ function Doc (runner) {
39
45
  console.log('%s<dl>', indent());
40
46
  });
41
47
 
42
- runner.on('suite end', function (suite) {
48
+ runner.on('suite end', function(suite) {
43
49
  if (suite.root) {
44
50
  return;
45
51
  }
@@ -49,16 +55,24 @@ function Doc (runner) {
49
55
  --indents;
50
56
  });
51
57
 
52
- runner.on('pass', function (test) {
58
+ runner.on('pass', function(test) {
53
59
  console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
54
60
  var code = utils.escape(utils.clean(test.body));
55
61
  console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
56
62
  });
57
63
 
58
- runner.on('fail', function (test, err) {
59
- console.log('%s <dt class="error">%s</dt>', indent(), utils.escape(test.title));
64
+ runner.on('fail', function(test, err) {
65
+ console.log(
66
+ '%s <dt class="error">%s</dt>',
67
+ indent(),
68
+ utils.escape(test.title)
69
+ );
60
70
  var code = utils.escape(utils.clean(test.body));
61
- console.log('%s <dd class="error"><pre><code>%s</code></pre></dd>', indent(), code);
71
+ console.log(
72
+ '%s <dd class="error"><pre><code>%s</code></pre></dd>',
73
+ indent(),
74
+ code
75
+ );
62
76
  console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
63
77
  });
64
78
  }
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
-
2
+ /**
3
+ * @module Dot
4
+ */
3
5
  /**
4
6
  * Module dependencies.
5
7
  */
@@ -17,28 +19,32 @@ exports = module.exports = Dot;
17
19
  /**
18
20
  * Initialize a new `Dot` matrix test reporter.
19
21
  *
22
+ * @class
23
+ * @memberof Mocha.reporters
24
+ * @extends Mocha.reporters.Base
25
+ * @public
20
26
  * @api public
21
27
  * @param {Runner} runner
22
28
  */
23
- function Dot (runner) {
29
+ function Dot(runner) {
24
30
  Base.call(this, runner);
25
31
 
26
32
  var self = this;
27
- var width = Base.window.width * 0.75 | 0;
33
+ var width = (Base.window.width * 0.75) | 0;
28
34
  var n = -1;
29
35
 
30
- runner.on('start', function () {
36
+ runner.on('start', function() {
31
37
  process.stdout.write('\n');
32
38
  });
33
39
 
34
- runner.on('pending', function () {
40
+ runner.on('pending', function() {
35
41
  if (++n % width === 0) {
36
42
  process.stdout.write('\n ');
37
43
  }
38
44
  process.stdout.write(color('pending', Base.symbols.comma));
39
45
  });
40
46
 
41
- runner.on('pass', function (test) {
47
+ runner.on('pass', function(test) {
42
48
  if (++n % width === 0) {
43
49
  process.stdout.write('\n ');
44
50
  }
@@ -49,14 +55,14 @@ function Dot (runner) {
49
55
  }
50
56
  });
51
57
 
52
- runner.on('fail', function () {
58
+ runner.on('fail', function() {
53
59
  if (++n % width === 0) {
54
60
  process.stdout.write('\n ');
55
61
  }
56
62
  process.stdout.write(color('fail', Base.symbols.bang));
57
63
  });
58
64
 
59
- runner.once('end', function () {
65
+ runner.once('end', function() {
60
66
  console.log();
61
67
  self.epilogue();
62
68
  });