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/utils.js CHANGED
@@ -1,5 +1,9 @@
1
1
  'use strict';
2
2
 
3
+ /**
4
+ * @module
5
+ */
6
+
3
7
  /**
4
8
  * Module dependencies.
5
9
  */
@@ -26,8 +30,8 @@ exports.inherits = require('util').inherits;
26
30
  * @param {string} html
27
31
  * @return {string}
28
32
  */
29
- exports.escape = function (html) {
30
- return he.encode(String(html), { useNamedReferences: false });
33
+ exports.escape = function(html) {
34
+ return he.encode(String(html), {useNamedReferences: false});
31
35
  };
32
36
 
33
37
  /**
@@ -37,7 +41,7 @@ exports.escape = function (html) {
37
41
  * @param {Object} obj
38
42
  * @return {boolean}
39
43
  */
40
- exports.isString = function (obj) {
44
+ exports.isString = function(obj) {
41
45
  return typeof obj === 'string';
42
46
  };
43
47
 
@@ -49,11 +53,11 @@ exports.isString = function (obj) {
49
53
  * @param {Array} files
50
54
  * @param {Function} fn
51
55
  */
52
- exports.watch = function (files, fn) {
53
- var options = { interval: 100 };
54
- files.forEach(function (file) {
56
+ exports.watch = function(files, fn) {
57
+ var options = {interval: 100};
58
+ files.forEach(function(file) {
55
59
  debug('file %s', file);
56
- fs.watchFile(file, options, function (curr, prev) {
60
+ fs.watchFile(file, options, function(curr, prev) {
57
61
  if (prev.mtime < curr.mtime) {
58
62
  fn(file);
59
63
  }
@@ -68,7 +72,7 @@ exports.watch = function (files, fn) {
68
72
  * @param {string} path
69
73
  * @return {boolean}
70
74
  */
71
- function ignored (path) {
75
+ function ignored(path) {
72
76
  return !~ignore.indexOf(path);
73
77
  }
74
78
 
@@ -81,15 +85,16 @@ function ignored (path) {
81
85
  * @param {Array} [ret=[]]
82
86
  * @return {Array}
83
87
  */
84
- exports.files = function (dir, ext, ret) {
88
+ exports.files = function(dir, ext, ret) {
85
89
  ret = ret || [];
86
90
  ext = ext || ['js'];
87
91
 
88
92
  var re = new RegExp('\\.(' + ext.join('|') + ')$');
89
93
 
90
- fs.readdirSync(dir)
94
+ fs
95
+ .readdirSync(dir)
91
96
  .filter(ignored)
92
- .forEach(function (path) {
97
+ .forEach(function(path) {
93
98
  path = join(dir, path);
94
99
  if (fs.lstatSync(path).isDirectory()) {
95
100
  exports.files(path, ext, ret);
@@ -108,7 +113,7 @@ exports.files = function (dir, ext, ret) {
108
113
  * @param {string} str
109
114
  * @return {string}
110
115
  */
111
- exports.slug = function (str) {
116
+ exports.slug = function(str) {
112
117
  return str
113
118
  .toLowerCase()
114
119
  .replace(/ +/g, '-')
@@ -121,15 +126,22 @@ exports.slug = function (str) {
121
126
  * @param {string} str
122
127
  * @return {string}
123
128
  */
124
- exports.clean = function (str) {
129
+ exports.clean = function(str) {
125
130
  str = str
126
- .replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '')
131
+ .replace(/\r\n?|[\n\u2028\u2029]/g, '\n')
132
+ .replace(/^\uFEFF/, '')
127
133
  // (traditional)-> space/name parameters body (lambda)-> parameters body multi-statement/single keep body content
128
- .replace(/^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/, '$1$2$3');
134
+ .replace(
135
+ /^function(?:\s*|\s+[^(]*)\([^)]*\)\s*\{((?:.|\n)*?)\s*\}$|^\([^)]*\)\s*=>\s*(?:\{((?:.|\n)*?)\s*\}|((?:.|\n)*))$/,
136
+ '$1$2$3'
137
+ );
129
138
 
130
139
  var spaces = str.match(/^\n?( *)/)[1].length;
131
140
  var tabs = str.match(/^\n?(\t*)/)[1].length;
132
- var re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs || spaces) + '}', 'gm');
141
+ var re = new RegExp(
142
+ '^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs || spaces) + '}',
143
+ 'gm'
144
+ );
133
145
 
134
146
  str = str.replace(re, '');
135
147
 
@@ -143,17 +155,20 @@ exports.clean = function (str) {
143
155
  * @param {string} qs
144
156
  * @return {Object}
145
157
  */
146
- exports.parseQuery = function (qs) {
147
- return qs.replace('?', '').split('&').reduce(function (obj, pair) {
148
- var i = pair.indexOf('=');
149
- var key = pair.slice(0, i);
150
- var val = pair.slice(++i);
151
-
152
- // Due to how the URLSearchParams API treats spaces
153
- obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));
154
-
155
- return obj;
156
- }, {});
158
+ exports.parseQuery = function(qs) {
159
+ return qs
160
+ .replace('?', '')
161
+ .split('&')
162
+ .reduce(function(obj, pair) {
163
+ var i = pair.indexOf('=');
164
+ var key = pair.slice(0, i);
165
+ var val = pair.slice(++i);
166
+
167
+ // Due to how the URLSearchParams API treats spaces
168
+ obj[key] = decodeURIComponent(val.replace(/\+/g, '%20'));
169
+
170
+ return obj;
171
+ }, {});
157
172
  };
158
173
 
159
174
  /**
@@ -163,7 +178,7 @@ exports.parseQuery = function (qs) {
163
178
  * @param {string} js
164
179
  * @return {string}
165
180
  */
166
- function highlight (js) {
181
+ function highlight(js) {
167
182
  return js
168
183
  .replace(/</g, '&lt;')
169
184
  .replace(/>/g, '&gt;')
@@ -171,8 +186,14 @@ function highlight (js) {
171
186
  .replace(/('.*?')/gm, '<span class="string">$1</span>')
172
187
  .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
173
188
  .replace(/(\d+)/gm, '<span class="number">$1</span>')
174
- .replace(/\bnew[ \t]+(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
175
- .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>');
189
+ .replace(
190
+ /\bnew[ \t]+(\w+)/gm,
191
+ '<span class="keyword">new</span> <span class="init">$1</span>'
192
+ )
193
+ .replace(
194
+ /\b(function|new|throw|return|var|if|else)\b/gm,
195
+ '<span class="keyword">$1</span>'
196
+ );
176
197
  }
177
198
 
178
199
  /**
@@ -181,7 +202,7 @@ function highlight (js) {
181
202
  * @api private
182
203
  * @param {string} name
183
204
  */
184
- exports.highlightTags = function (name) {
205
+ exports.highlightTags = function(name) {
185
206
  var code = document.getElementById('mocha').getElementsByTagName(name);
186
207
  for (var i = 0, len = code.length; i < len; ++i) {
187
208
  code[i].innerHTML = highlight(code[i].innerHTML);
@@ -202,7 +223,7 @@ exports.highlightTags = function (name) {
202
223
  * @param {string} typeHint The type of the value
203
224
  * @returns {string}
204
225
  */
205
- function emptyRepresentation (value, typeHint) {
226
+ function emptyRepresentation(value, typeHint) {
206
227
  switch (typeHint) {
207
228
  case 'function':
208
229
  return '[Function]';
@@ -236,7 +257,7 @@ function emptyRepresentation (value, typeHint) {
236
257
  * type(global) // 'global'
237
258
  * type(new String('foo') // 'object'
238
259
  */
239
- var type = exports.type = function type (value) {
260
+ var type = (exports.type = function type(value) {
240
261
  if (value === undefined) {
241
262
  return 'undefined';
242
263
  } else if (value === null) {
@@ -244,10 +265,11 @@ var type = exports.type = function type (value) {
244
265
  } else if (Buffer.isBuffer(value)) {
245
266
  return 'buffer';
246
267
  }
247
- return Object.prototype.toString.call(value)
268
+ return Object.prototype.toString
269
+ .call(value)
248
270
  .replace(/^\[.+\s(.+?)]$/, '$1')
249
271
  .toLowerCase();
250
- };
272
+ });
251
273
 
252
274
  /**
253
275
  * Stringify `value`. Different behavior depending on type of value:
@@ -264,21 +286,23 @@ var type = exports.type = function type (value) {
264
286
  * @param {*} value
265
287
  * @return {string}
266
288
  */
267
- exports.stringify = function (value) {
289
+ exports.stringify = function(value) {
268
290
  var typeHint = type(value);
269
291
 
270
292
  if (!~['object', 'array', 'function'].indexOf(typeHint)) {
271
293
  if (typeHint === 'buffer') {
272
294
  var json = Buffer.prototype.toJSON.call(value);
273
295
  // Based on the toJSON result
274
- return jsonStringify(json.data && json.type ? json.data : json, 2)
275
- .replace(/,(\n|$)/g, '$1');
296
+ return jsonStringify(
297
+ json.data && json.type ? json.data : json,
298
+ 2
299
+ ).replace(/,(\n|$)/g, '$1');
276
300
  }
277
301
 
278
302
  // IE7/IE8 has a bizarre String constructor; needs to be coerced
279
303
  // into an array and back to obj.
280
304
  if (typeHint === 'string' && typeof value === 'object') {
281
- value = value.split('').reduce(function (acc, char, idx) {
305
+ value = value.split('').reduce(function(acc, char, idx) {
282
306
  acc[idx] = char;
283
307
  return acc;
284
308
  }, {});
@@ -290,7 +314,10 @@ exports.stringify = function (value) {
290
314
 
291
315
  for (var prop in value) {
292
316
  if (Object.prototype.hasOwnProperty.call(value, prop)) {
293
- return jsonStringify(exports.canonicalize(value, null, typeHint), 2).replace(/,(\n|$)/g, '$1');
317
+ return jsonStringify(
318
+ exports.canonicalize(value, null, typeHint),
319
+ 2
320
+ ).replace(/,(\n|$)/g, '$1');
294
321
  }
295
322
  }
296
323
 
@@ -306,7 +333,7 @@ exports.stringify = function (value) {
306
333
  * @param {number=} depth
307
334
  * @returns {*}
308
335
  */
309
- function jsonStringify (object, spaces, depth) {
336
+ function jsonStringify(object, spaces, depth) {
310
337
  if (typeof spaces === 'undefined') {
311
338
  // primitive types
312
339
  return _stringify(object);
@@ -316,13 +343,16 @@ function jsonStringify (object, spaces, depth) {
316
343
  var space = spaces * depth;
317
344
  var str = Array.isArray(object) ? '[' : '{';
318
345
  var end = Array.isArray(object) ? ']' : '}';
319
- var length = typeof object.length === 'number' ? object.length : Object.keys(object).length;
346
+ var length =
347
+ typeof object.length === 'number'
348
+ ? object.length
349
+ : Object.keys(object).length;
320
350
  // `.repeat()` polyfill
321
- function repeat (s, n) {
351
+ function repeat(s, n) {
322
352
  return new Array(n).join(s);
323
353
  }
324
354
 
325
- function _stringify (val) {
355
+ function _stringify(val) {
326
356
  switch (type(val)) {
327
357
  case 'null':
328
358
  case 'undefined':
@@ -336,9 +366,10 @@ function jsonStringify (object, spaces, depth) {
336
366
  case 'regexp':
337
367
  case 'symbol':
338
368
  case 'number':
339
- val = val === 0 && (1 / val) === -Infinity // `-0`
340
- ? '-0'
341
- : val.toString();
369
+ val =
370
+ val === 0 && 1 / val === -Infinity // `-0`
371
+ ? '-0'
372
+ : val.toString();
342
373
  break;
343
374
  case 'date':
344
375
  var sDate = isNaN(val.getTime()) ? val.toString() : val.toISOString();
@@ -351,9 +382,10 @@ function jsonStringify (object, spaces, depth) {
351
382
  val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
352
383
  break;
353
384
  default:
354
- val = (val === '[Function]' || val === '[Circular]')
355
- ? val
356
- : JSON.stringify(val); // string
385
+ val =
386
+ val === '[Function]' || val === '[Circular]'
387
+ ? val
388
+ : JSON.stringify(val); // string
357
389
  }
358
390
  return val;
359
391
  }
@@ -363,15 +395,19 @@ function jsonStringify (object, spaces, depth) {
363
395
  continue; // not my business
364
396
  }
365
397
  --length;
366
- str += '\n ' + repeat(' ', space) +
398
+ str +=
399
+ '\n ' +
400
+ repeat(' ', space) +
367
401
  (Array.isArray(object) ? '' : '"' + i + '": ') + // key
368
402
  _stringify(object[i]) + // value
369
403
  (length ? ',' : ''); // comma
370
404
  }
371
405
 
372
- return str +
406
+ return (
407
+ str +
373
408
  // [], {}
374
- (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end);
409
+ (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end)
410
+ );
375
411
  }
376
412
 
377
413
  /**
@@ -393,13 +429,13 @@ function jsonStringify (object, spaces, depth) {
393
429
  * @param {string} [typeHint] Type hint
394
430
  * @return {(Object|Array|Function|string|undefined)}
395
431
  */
396
- exports.canonicalize = function canonicalize (value, stack, typeHint) {
432
+ exports.canonicalize = function canonicalize(value, stack, typeHint) {
397
433
  var canonicalizedObj;
398
434
  /* eslint-disable no-unused-vars */
399
435
  var prop;
400
436
  /* eslint-enable no-unused-vars */
401
437
  typeHint = typeHint || type(value);
402
- function withStack (value, fn) {
438
+ function withStack(value, fn) {
403
439
  stack.push(value);
404
440
  fn();
405
441
  stack.pop();
@@ -418,8 +454,8 @@ exports.canonicalize = function canonicalize (value, stack, typeHint) {
418
454
  canonicalizedObj = value;
419
455
  break;
420
456
  case 'array':
421
- withStack(value, function () {
422
- canonicalizedObj = value.map(function (item) {
457
+ withStack(value, function() {
458
+ canonicalizedObj = value.map(function(item) {
423
459
  return exports.canonicalize(item, stack);
424
460
  });
425
461
  });
@@ -438,10 +474,12 @@ exports.canonicalize = function canonicalize (value, stack, typeHint) {
438
474
  /* falls through */
439
475
  case 'object':
440
476
  canonicalizedObj = canonicalizedObj || {};
441
- withStack(value, function () {
442
- Object.keys(value).sort().forEach(function (key) {
443
- canonicalizedObj[key] = exports.canonicalize(value[key], stack);
444
- });
477
+ withStack(value, function() {
478
+ Object.keys(value)
479
+ .sort()
480
+ .forEach(function(key) {
481
+ canonicalizedObj[key] = exports.canonicalize(value[key], stack);
482
+ });
445
483
  });
446
484
  break;
447
485
  case 'date':
@@ -461,13 +499,15 @@ exports.canonicalize = function canonicalize (value, stack, typeHint) {
461
499
  /**
462
500
  * Lookup file names at the given `path`.
463
501
  *
502
+ * @memberof Mocha.utils
503
+ * @public
464
504
  * @api public
465
505
  * @param {string} filepath Base path to start searching from.
466
506
  * @param {string[]} extensions File extensions to look for.
467
507
  * @param {boolean} recursive Whether or not to recurse into subdirectories.
468
508
  * @return {string[]} An array of paths.
469
509
  */
470
- exports.lookupFiles = function lookupFiles (filepath, extensions, recursive) {
510
+ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) {
471
511
  var files = [];
472
512
 
473
513
  if (!fs.existsSync(filepath)) {
@@ -492,7 +532,7 @@ exports.lookupFiles = function lookupFiles (filepath, extensions, recursive) {
492
532
  return;
493
533
  }
494
534
 
495
- fs.readdirSync(filepath).forEach(function (file) {
535
+ fs.readdirSync(filepath).forEach(function(file) {
496
536
  file = path.join(filepath, file);
497
537
  try {
498
538
  var stat = fs.statSync(file);
@@ -506,6 +546,11 @@ exports.lookupFiles = function lookupFiles (filepath, extensions, recursive) {
506
546
  // ignore error
507
547
  return;
508
548
  }
549
+ if (!extensions) {
550
+ throw new Error(
551
+ 'extensions parameter required when filepath is a directory'
552
+ );
553
+ }
509
554
  var re = new RegExp('\\.(?:' + extensions.join('|') + ')$');
510
555
  if (!stat.isFile() || !re.test(file) || path.basename(file)[0] === '.') {
511
556
  return;
@@ -522,8 +567,10 @@ exports.lookupFiles = function lookupFiles (filepath, extensions, recursive) {
522
567
  * @return {Error}
523
568
  */
524
569
 
525
- exports.undefinedError = function () {
526
- return new Error('Caught undefined error, did you throw without specifying what?');
570
+ exports.undefinedError = function() {
571
+ return new Error(
572
+ 'Caught undefined error, did you throw without specifying what?'
573
+ );
527
574
  };
528
575
 
529
576
  /**
@@ -533,7 +580,7 @@ exports.undefinedError = function () {
533
580
  * @return {Error}
534
581
  */
535
582
 
536
- exports.getError = function (err) {
583
+ exports.getError = function(err) {
537
584
  return err || exports.undefinedError();
538
585
  };
539
586
 
@@ -546,9 +593,9 @@ exports.getError = function (err) {
546
593
  * (i.e: strip Mocha and internal node functions from stack trace).
547
594
  * @returns {Function}
548
595
  */
549
- exports.stackTraceFilter = function () {
596
+ exports.stackTraceFilter = function() {
550
597
  // TODO: Replace with `process.browser`
551
- var is = typeof document === 'undefined' ? { node: true } : { browser: true };
598
+ var is = typeof document === 'undefined' ? {node: true} : {browser: true};
552
599
  var slash = path.sep;
553
600
  var cwd;
554
601
  if (is.node) {
@@ -556,30 +603,35 @@ exports.stackTraceFilter = function () {
556
603
  } else {
557
604
  cwd = (typeof location === 'undefined'
558
605
  ? window.location
559
- : location).href.replace(/\/[^/]*$/, '/');
606
+ : location
607
+ ).href.replace(/\/[^/]*$/, '/');
560
608
  slash = '/';
561
609
  }
562
610
 
563
- function isMochaInternal (line) {
564
- return (~line.indexOf('node_modules' + slash + 'mocha' + slash)) ||
565
- (~line.indexOf('node_modules' + slash + 'mocha.js')) ||
566
- (~line.indexOf('bower_components' + slash + 'mocha.js')) ||
567
- (~line.indexOf(slash + 'mocha.js'));
611
+ function isMochaInternal(line) {
612
+ return (
613
+ ~line.indexOf('node_modules' + slash + 'mocha' + slash) ||
614
+ ~line.indexOf('node_modules' + slash + 'mocha.js') ||
615
+ ~line.indexOf('bower_components' + slash + 'mocha.js') ||
616
+ ~line.indexOf(slash + 'mocha.js')
617
+ );
568
618
  }
569
619
 
570
- function isNodeInternal (line) {
571
- return (~line.indexOf('(timers.js:')) ||
572
- (~line.indexOf('(events.js:')) ||
573
- (~line.indexOf('(node.js:')) ||
574
- (~line.indexOf('(module.js:')) ||
575
- (~line.indexOf('GeneratorFunctionPrototype.next (native)')) ||
576
- false;
620
+ function isNodeInternal(line) {
621
+ return (
622
+ ~line.indexOf('(timers.js:') ||
623
+ ~line.indexOf('(events.js:') ||
624
+ ~line.indexOf('(node.js:') ||
625
+ ~line.indexOf('(module.js:') ||
626
+ ~line.indexOf('GeneratorFunctionPrototype.next (native)') ||
627
+ false
628
+ );
577
629
  }
578
630
 
579
- return function (stack) {
631
+ return function(stack) {
580
632
  stack = stack.split('\n');
581
633
 
582
- stack = stack.reduce(function (list, line) {
634
+ stack = stack.reduce(function(list, line) {
583
635
  if (isMochaInternal(line)) {
584
636
  return list;
585
637
  }
@@ -607,7 +659,7 @@ exports.stackTraceFilter = function () {
607
659
  * @param {*} value
608
660
  * @returns {boolean} Whether or not `value` is a Promise
609
661
  */
610
- exports.isPromise = function isPromise (value) {
662
+ exports.isPromise = function isPromise(value) {
611
663
  return typeof value === 'object' && typeof value.then === 'function';
612
664
  };
613
665
 
@@ -615,4 +667,4 @@ exports.isPromise = function isPromise (value) {
615
667
  * It's a noop.
616
668
  * @api
617
669
  */
618
- exports.noop = function () {};
670
+ exports.noop = function() {};