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