mocha 6.1.3 → 6.2.2

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.
@@ -25,7 +25,12 @@ exports = module.exports = Base;
25
25
  * Check if both stdio streams are associated with a tty.
26
26
  */
27
27
 
28
- var isatty = tty.isatty(1) && tty.isatty(2);
28
+ var isatty = process.stdout.isTTY && process.stderr.isTTY;
29
+
30
+ /**
31
+ * Save log references to avoid tests interfering (see GH-3604).
32
+ */
33
+ var consoleLog = console.log;
29
34
 
30
35
  /**
31
36
  * Enable coloring by default, except in the browser interface.
@@ -192,7 +197,8 @@ var generateDiff = (exports.generateDiff = function(actual, expected) {
192
197
  * Error property
193
198
  */
194
199
  exports.list = function(failures) {
195
- console.log();
200
+ var multipleErr, multipleTest;
201
+ Base.consoleLog();
196
202
  failures.forEach(function(test, i) {
197
203
  // format
198
204
  var fmt =
@@ -202,7 +208,16 @@ exports.list = function(failures) {
202
208
 
203
209
  // msg
204
210
  var msg;
205
- var err = test.err;
211
+ var err;
212
+ if (test.err && test.err.multiple) {
213
+ if (multipleTest !== test) {
214
+ multipleTest = test;
215
+ multipleErr = [test.err].concat(test.err.multiple);
216
+ }
217
+ err = multipleErr.shift();
218
+ } else {
219
+ err = test.err;
220
+ }
206
221
  var message;
207
222
  if (err.message && typeof err.message.toString === 'function') {
208
223
  message = err.message + '';
@@ -253,7 +268,7 @@ exports.list = function(failures) {
253
268
  testTitle += str;
254
269
  });
255
270
 
256
- console.log(fmt, i + 1, testTitle, msg, stack);
271
+ Base.consoleLog(fmt, i + 1, testTitle, msg, stack);
257
272
  });
258
273
  };
259
274
 
@@ -293,7 +308,12 @@ function Base(runner, options) {
293
308
  if (showDiff(err)) {
294
309
  stringifyDiffObjs(err);
295
310
  }
296
- test.err = err;
311
+ // more than one error per test
312
+ if (test.err && err instanceof Error) {
313
+ test.err.multiple = (test.err.multiple || []).concat(err);
314
+ } else {
315
+ test.err = err;
316
+ }
297
317
  failures.push(test);
298
318
  });
299
319
  }
@@ -302,13 +322,13 @@ function Base(runner, options) {
302
322
  * Outputs common epilogue used by many of the bundled reporters.
303
323
  *
304
324
  * @public
305
- * @memberof Mocha.reporters.Base
325
+ * @memberof Mocha.reporters
306
326
  */
307
327
  Base.prototype.epilogue = function() {
308
328
  var stats = this.stats;
309
329
  var fmt;
310
330
 
311
- console.log();
331
+ Base.consoleLog();
312
332
 
313
333
  // passes
314
334
  fmt =
@@ -316,26 +336,26 @@ Base.prototype.epilogue = function() {
316
336
  color('green', ' %d passing') +
317
337
  color('light', ' (%s)');
318
338
 
319
- console.log(fmt, stats.passes || 0, milliseconds(stats.duration));
339
+ Base.consoleLog(fmt, stats.passes || 0, milliseconds(stats.duration));
320
340
 
321
341
  // pending
322
342
  if (stats.pending) {
323
343
  fmt = color('pending', ' ') + color('pending', ' %d pending');
324
344
 
325
- console.log(fmt, stats.pending);
345
+ Base.consoleLog(fmt, stats.pending);
326
346
  }
327
347
 
328
348
  // failures
329
349
  if (stats.failures) {
330
350
  fmt = color('fail', ' %d failing');
331
351
 
332
- console.log(fmt, stats.failures);
352
+ Base.consoleLog(fmt, stats.failures);
333
353
 
334
354
  Base.list(this.failures);
335
- console.log();
355
+ Base.consoleLog();
336
356
  }
337
357
 
338
- console.log();
358
+ Base.consoleLog();
339
359
  };
340
360
 
341
361
  /**
@@ -488,4 +508,6 @@ function sameType(a, b) {
488
508
  return objToString.call(a) === objToString.call(b);
489
509
  }
490
510
 
511
+ Base.consoleLog = consoleLog;
512
+
491
513
  Base.abstract = true;
@@ -44,41 +44,45 @@ function Doc(runner, options) {
44
44
  return;
45
45
  }
46
46
  ++indents;
47
- console.log('%s<section class="suite">', indent());
47
+ Base.consoleLog('%s<section class="suite">', indent());
48
48
  ++indents;
49
- console.log('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
50
- console.log('%s<dl>', indent());
49
+ Base.consoleLog('%s<h1>%s</h1>', indent(), utils.escape(suite.title));
50
+ Base.consoleLog('%s<dl>', indent());
51
51
  });
52
52
 
53
53
  runner.on(EVENT_SUITE_END, function(suite) {
54
54
  if (suite.root) {
55
55
  return;
56
56
  }
57
- console.log('%s</dl>', indent());
57
+ Base.consoleLog('%s</dl>', indent());
58
58
  --indents;
59
- console.log('%s</section>', indent());
59
+ Base.consoleLog('%s</section>', indent());
60
60
  --indents;
61
61
  });
62
62
 
63
63
  runner.on(EVENT_TEST_PASS, function(test) {
64
- console.log('%s <dt>%s</dt>', indent(), utils.escape(test.title));
64
+ Base.consoleLog('%s <dt>%s</dt>', indent(), utils.escape(test.title));
65
65
  var code = utils.escape(utils.clean(test.body));
66
- console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
66
+ Base.consoleLog('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
67
67
  });
68
68
 
69
69
  runner.on(EVENT_TEST_FAIL, function(test, err) {
70
- console.log(
70
+ Base.consoleLog(
71
71
  '%s <dt class="error">%s</dt>',
72
72
  indent(),
73
73
  utils.escape(test.title)
74
74
  );
75
75
  var code = utils.escape(utils.clean(test.body));
76
- console.log(
76
+ Base.consoleLog(
77
77
  '%s <dd class="error"><pre><code>%s</code></pre></dd>',
78
78
  indent(),
79
79
  code
80
80
  );
81
- console.log('%s <dd class="error">%s</dd>', indent(), utils.escape(err));
81
+ Base.consoleLog(
82
+ '%s <dd class="error">%s</dd>',
83
+ indent(),
84
+ utils.escape(err)
85
+ );
82
86
  });
83
87
  }
84
88
 
@@ -68,7 +68,7 @@ function Dot(runner, options) {
68
68
  });
69
69
 
70
70
  runner.once(EVENT_RUN_END, function() {
71
- console.log();
71
+ process.stdout.write('\n');
72
72
  self.epilogue();
73
73
  });
74
74
  }
@@ -357,8 +357,8 @@ function hideSuitesWithout(classname) {
357
357
  */
358
358
  function unhide() {
359
359
  var els = document.getElementsByClassName('suite hidden');
360
- for (var i = 0; i < els.length; ++i) {
361
- els[i].className = els[i].className.replace('suite hidden', 'suite');
360
+ while (els.length > 0) {
361
+ els[0].className = els[0].className.replace('suite hidden', 'suite');
362
362
  }
363
363
  }
364
364
 
@@ -95,7 +95,7 @@ function Landing(runner, options) {
95
95
 
96
96
  runner.once(EVENT_RUN_END, function() {
97
97
  cursor.show();
98
- console.log();
98
+ process.stdout.write('\n');
99
99
  self.epilogue();
100
100
  });
101
101
  }
@@ -41,7 +41,7 @@ function List(runner, options) {
41
41
  var n = 0;
42
42
 
43
43
  runner.on(EVENT_RUN_BEGIN, function() {
44
- console.log();
44
+ Base.consoleLog();
45
45
  });
46
46
 
47
47
  runner.on(EVENT_TEST_BEGIN, function(test) {
@@ -50,7 +50,7 @@ function List(runner, options) {
50
50
 
51
51
  runner.on(EVENT_TEST_PENDING, function(test) {
52
52
  var fmt = color('checkmark', ' -') + color('pending', ' %s');
53
- console.log(fmt, test.fullTitle());
53
+ Base.consoleLog(fmt, test.fullTitle());
54
54
  });
55
55
 
56
56
  runner.on(EVENT_TEST_PASS, function(test) {
@@ -59,12 +59,12 @@ function List(runner, options) {
59
59
  color('pass', ' %s: ') +
60
60
  color(test.speed, '%dms');
61
61
  cursor.CR();
62
- console.log(fmt, test.fullTitle(), test.duration);
62
+ Base.consoleLog(fmt, test.fullTitle(), test.duration);
63
63
  });
64
64
 
65
65
  runner.on(EVENT_TEST_FAIL, function(test) {
66
66
  cursor.CR();
67
- console.log(color('fail', ' %d) %s'), ++n, test.fullTitle());
67
+ Base.consoleLog(color('fail', ' %d) %s'), ++n, test.fullTitle());
68
68
  });
69
69
 
70
70
  runner.once(EVENT_RUN_END, self.epilogue.bind(self));
@@ -58,7 +58,7 @@ function Progress(runner, options) {
58
58
 
59
59
  // tests started
60
60
  runner.on(EVENT_RUN_BEGIN, function() {
61
- console.log();
61
+ process.stdout.write('\n');
62
62
  cursor.hide();
63
63
  });
64
64
 
@@ -91,7 +91,7 @@ function Progress(runner, options) {
91
91
  // and the failures if any
92
92
  runner.once(EVENT_RUN_END, function() {
93
93
  cursor.show();
94
- console.log();
94
+ process.stdout.write('\n');
95
95
  self.epilogue();
96
96
  });
97
97
  }
@@ -46,24 +46,24 @@ function Spec(runner, options) {
46
46
  }
47
47
 
48
48
  runner.on(EVENT_RUN_BEGIN, function() {
49
- console.log();
49
+ Base.consoleLog();
50
50
  });
51
51
 
52
52
  runner.on(EVENT_SUITE_BEGIN, function(suite) {
53
53
  ++indents;
54
- console.log(color('suite', '%s%s'), indent(), suite.title);
54
+ Base.consoleLog(color('suite', '%s%s'), indent(), suite.title);
55
55
  });
56
56
 
57
57
  runner.on(EVENT_SUITE_END, function() {
58
58
  --indents;
59
59
  if (indents === 1) {
60
- console.log();
60
+ Base.consoleLog();
61
61
  }
62
62
  });
63
63
 
64
64
  runner.on(EVENT_TEST_PENDING, function(test) {
65
65
  var fmt = indent() + color('pending', ' - %s');
66
- console.log(fmt, test.title);
66
+ Base.consoleLog(fmt, test.title);
67
67
  });
68
68
 
69
69
  runner.on(EVENT_TEST_PASS, function(test) {
@@ -73,19 +73,19 @@ function Spec(runner, options) {
73
73
  indent() +
74
74
  color('checkmark', ' ' + Base.symbols.ok) +
75
75
  color('pass', ' %s');
76
- console.log(fmt, test.title);
76
+ Base.consoleLog(fmt, test.title);
77
77
  } else {
78
78
  fmt =
79
79
  indent() +
80
80
  color('checkmark', ' ' + Base.symbols.ok) +
81
81
  color('pass', ' %s') +
82
82
  color(test.speed, ' (%dms)');
83
- console.log(fmt, test.title, test.duration);
83
+ Base.consoleLog(fmt, test.title, test.duration);
84
84
  }
85
85
  });
86
86
 
87
87
  runner.on(EVENT_TEST_FAIL, function(test) {
88
- console.log(indent() + color('fail', ' %d) %s'), ++n, test.title);
88
+ Base.consoleLog(indent() + color('fail', ' %d) %s'), ++n, test.title);
89
89
  });
90
90
 
91
91
  runner.once(EVENT_RUN_END, self.epilogue.bind(self));
@@ -142,7 +142,7 @@ XUnit.prototype.write = function(line) {
142
142
  } else if (typeof process === 'object' && process.stdout) {
143
143
  process.stdout.write(line + '\n');
144
144
  } else {
145
- console.log(line);
145
+ Base.consoleLog(line);
146
146
  }
147
147
  };
148
148
 
package/lib/runner.js CHANGED
@@ -141,7 +141,7 @@ function Runner(suite, delay) {
141
141
  });
142
142
  this._defaultGrep = /.*/;
143
143
  this.grep(this._defaultGrep);
144
- this.globals(this.globalProps().concat(extraGlobals()));
144
+ this.globals(this.globalProps());
145
145
  }
146
146
 
147
147
  /**
@@ -865,7 +865,7 @@ Runner.prototype.uncaught = function(err) {
865
865
  }
866
866
 
867
867
  // bail
868
- this.emit(constants.EVENT_RUN_END);
868
+ this.abort();
869
869
  };
870
870
 
871
871
  /**
@@ -1016,30 +1016,6 @@ function thrown2Error(err) {
1016
1016
  );
1017
1017
  }
1018
1018
 
1019
- /**
1020
- * Array of globals dependent on the environment.
1021
- *
1022
- * @return {Array}
1023
- * @deprecated
1024
- * @todo remove; long since unsupported
1025
- * @private
1026
- */
1027
- function extraGlobals() {
1028
- if (typeof process === 'object' && typeof process.version === 'string') {
1029
- var parts = process.version.split('.');
1030
- var nodeVersion = parts.reduce(function(a, v) {
1031
- return (a << 8) | v;
1032
- });
1033
-
1034
- // 'errno' was renamed to process._errno in v0.9.11.
1035
- if (nodeVersion < 0x00090b) {
1036
- return ['errno'];
1037
- }
1038
- }
1039
-
1040
- return [];
1041
- }
1042
-
1043
1019
  Runner.constants = constants;
1044
1020
 
1045
1021
  /**
package/lib/utils.js CHANGED
@@ -562,32 +562,41 @@ function isHiddenOnUnix(pathname) {
562
562
  *
563
563
  * @public
564
564
  * @memberof Mocha.utils
565
- * @todo Fix extension handling
566
565
  * @param {string} filepath - Base path to start searching from.
567
- * @param {string[]} extensions - File extensions to look for.
568
- * @param {boolean} recursive - Whether to recurse into subdirectories.
566
+ * @param {string[]} [extensions=[]] - File extensions to look for.
567
+ * @param {boolean} [recursive=false] - Whether to recurse into subdirectories.
569
568
  * @return {string[]} An array of paths.
570
569
  * @throws {Error} if no files match pattern.
571
570
  * @throws {TypeError} if `filepath` is directory and `extensions` not provided.
572
571
  */
573
572
  exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
573
+ extensions = extensions || [];
574
+ recursive = recursive || false;
574
575
  var files = [];
575
576
  var stat;
576
577
 
577
578
  if (!fs.existsSync(filepath)) {
578
- if (fs.existsSync(filepath + '.js')) {
579
- filepath += '.js';
579
+ var pattern;
580
+ if (glob.hasMagic(filepath)) {
581
+ // Handle glob as is without extensions
582
+ pattern = filepath;
580
583
  } else {
581
- // Handle glob
582
- files = glob.sync(filepath);
583
- if (!files.length) {
584
- throw createNoFilesMatchPatternError(
585
- 'Cannot find any files matching pattern ' + exports.dQuote(filepath),
586
- filepath
587
- );
588
- }
589
- return files;
584
+ // glob pattern e.g. 'filepath+(.js|.ts)'
585
+ var strExtensions = extensions
586
+ .map(function(v) {
587
+ return '.' + v;
588
+ })
589
+ .join('|');
590
+ pattern = filepath + '+(' + strExtensions + ')';
591
+ }
592
+ files = glob.sync(pattern, {nodir: true});
593
+ if (!files.length) {
594
+ throw createNoFilesMatchPatternError(
595
+ 'Cannot find any files matching pattern ' + exports.dQuote(filepath),
596
+ filepath
597
+ );
590
598
  }
599
+ return files;
591
600
  }
592
601
 
593
602
  // Handle file
@@ -618,7 +627,7 @@ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
618
627
  // ignore error
619
628
  return;
620
629
  }
621
- if (!extensions) {
630
+ if (!extensions.length) {
622
631
  throw createMissingArgumentError(
623
632
  util.format(
624
633
  'Argument %s required when argument %s is a directory',
@@ -714,7 +723,8 @@ exports.stackTraceFilter = function() {
714
723
  function isMochaInternal(line) {
715
724
  return (
716
725
  ~line.indexOf('node_modules' + slash + 'mocha' + slash) ||
717
- ~line.indexOf(slash + 'mocha.js')
726
+ ~line.indexOf(slash + 'mocha.js') ||
727
+ ~line.indexOf(slash + 'mocha.min.js')
718
728
  );
719
729
  }
720
730
 
package/mocha.css CHANGED
@@ -139,7 +139,6 @@ body {
139
139
  #mocha .test .html-error {
140
140
  overflow: auto;
141
141
  color: black;
142
- line-height: 1.5;
143
142
  display: block;
144
143
  float: left;
145
144
  clear: left;