mocha 2.2.5 → 2.3.3

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 (50) hide show
  1. package/HISTORY.md +1034 -0
  2. package/bin/.eslintrc +3 -0
  3. package/bin/_mocha +12 -15
  4. package/bin/mocha +3 -10
  5. package/bin/options.js +6 -5
  6. package/lib/browser/debug.js +3 -3
  7. package/lib/browser/events.js +42 -26
  8. package/lib/browser/progress.js +37 -45
  9. package/lib/browser/tty.js +4 -5
  10. package/lib/context.js +26 -32
  11. package/lib/hook.js +5 -7
  12. package/lib/interfaces/bdd.js +21 -26
  13. package/lib/interfaces/common.js +33 -15
  14. package/lib/interfaces/exports.js +7 -7
  15. package/lib/interfaces/qunit.js +16 -17
  16. package/lib/interfaces/tdd.js +24 -28
  17. package/lib/mocha.js +140 -99
  18. package/lib/ms.js +43 -24
  19. package/lib/pending.js +2 -3
  20. package/lib/reporters/base.js +159 -138
  21. package/lib/reporters/doc.js +13 -13
  22. package/lib/reporters/dot.js +23 -19
  23. package/lib/reporters/html-cov.js +25 -19
  24. package/lib/reporters/html.js +130 -91
  25. package/lib/reporters/index.js +19 -17
  26. package/lib/reporters/json-cov.js +39 -41
  27. package/lib/reporters/json-stream.js +14 -17
  28. package/lib/reporters/json.js +16 -19
  29. package/lib/reporters/landing.js +20 -24
  30. package/lib/reporters/list.js +14 -16
  31. package/lib/reporters/markdown.js +17 -20
  32. package/lib/reporters/min.js +4 -5
  33. package/lib/reporters/nyan.js +49 -48
  34. package/lib/reporters/progress.js +20 -23
  35. package/lib/reporters/spec.js +23 -22
  36. package/lib/reporters/tap.js +15 -19
  37. package/lib/reporters/xunit.js +83 -63
  38. package/lib/runnable.js +134 -94
  39. package/lib/runner.js +291 -167
  40. package/lib/suite.js +105 -95
  41. package/lib/template.html +1 -1
  42. package/lib/test.js +3 -4
  43. package/lib/utils.js +227 -199
  44. package/mocha.css +35 -0
  45. package/mocha.js +8324 -2471
  46. package/package.json +250 -10
  47. package/lib/browser/escape-string-regexp.js +0 -11
  48. package/lib/browser/fs.js +0 -0
  49. package/lib/browser/glob.js +0 -0
  50. package/lib/browser/path.js +0 -0
package/lib/utils.js CHANGED
@@ -1,14 +1,17 @@
1
+ /* eslint-env browser */
2
+
1
3
  /**
2
4
  * Module dependencies.
3
5
  */
4
6
 
5
- var fs = require('fs')
6
- , path = require('path')
7
- , basename = path.basename
8
- , exists = fs.existsSync || path.existsSync
9
- , glob = require('glob')
10
- , join = path.join
11
- , debug = require('debug')('mocha:watch');
7
+ var basename = require('path').basename;
8
+ var debug = require('debug')('mocha:watch');
9
+ var exists = require('fs').existsSync || require('path').existsSync;
10
+ var glob = require('glob');
11
+ var join = require('path').join;
12
+ var readdirSync = require('fs').readdirSync;
13
+ var statSync = require('fs').statSync;
14
+ var watchFile = require('fs').watchFile;
12
15
 
13
16
  /**
14
17
  * Ignored directories.
@@ -16,15 +19,16 @@ var fs = require('fs')
16
19
 
17
20
  var ignore = ['node_modules', '.git'];
18
21
 
22
+ exports.inherits = require('util').inherits;
23
+
19
24
  /**
20
25
  * Escape special characters in the given string of html.
21
26
  *
22
- * @param {String} html
23
- * @return {String}
24
27
  * @api private
28
+ * @param {string} html
29
+ * @return {string}
25
30
  */
26
-
27
- exports.escape = function(html){
31
+ exports.escape = function(html) {
28
32
  return String(html)
29
33
  .replace(/&/g, '&')
30
34
  .replace(/"/g, '"')
@@ -35,57 +39,59 @@ exports.escape = function(html){
35
39
  /**
36
40
  * Array#forEach (<=IE8)
37
41
  *
38
- * @param {Array} array
42
+ * @api private
43
+ * @param {Array} arr
39
44
  * @param {Function} fn
40
45
  * @param {Object} scope
41
- * @api private
42
46
  */
43
-
44
- exports.forEach = function(arr, fn, scope){
45
- for (var i = 0, l = arr.length; i < l; i++)
47
+ exports.forEach = function(arr, fn, scope) {
48
+ for (var i = 0, l = arr.length; i < l; i++) {
46
49
  fn.call(scope, arr[i], i);
50
+ }
47
51
  };
48
52
 
49
53
  /**
50
- * Test if the given obj is type of string
54
+ * Test if the given obj is type of string.
51
55
  *
56
+ * @api private
52
57
  * @param {Object} obj
53
- * @returns Boolean
58
+ * @return {boolean}
54
59
  */
55
-
56
60
  exports.isString = function(obj) {
57
- return 'string' === typeof obj;
61
+ return typeof obj === 'string';
58
62
  };
59
63
 
60
64
  /**
61
65
  * Array#map (<=IE8)
62
66
  *
63
- * @param {Array} array
67
+ * @api private
68
+ * @param {Array} arr
64
69
  * @param {Function} fn
65
70
  * @param {Object} scope
66
- * @api private
71
+ * @return {Array}
67
72
  */
68
-
69
- exports.map = function(arr, fn, scope){
73
+ exports.map = function(arr, fn, scope) {
70
74
  var result = [];
71
- for (var i = 0, l = arr.length; i < l; i++)
75
+ for (var i = 0, l = arr.length; i < l; i++) {
72
76
  result.push(fn.call(scope, arr[i], i, arr));
77
+ }
73
78
  return result;
74
79
  };
75
80
 
76
81
  /**
77
82
  * Array#indexOf (<=IE8)
78
83
  *
79
- * @parma {Array} arr
80
- * @param {Object} obj to find index of
81
- * @param {Number} start
82
84
  * @api private
85
+ * @param {Array} arr
86
+ * @param {Object} obj to find index of
87
+ * @param {number} start
88
+ * @return {number}
83
89
  */
84
-
85
- exports.indexOf = function(arr, obj, start){
90
+ exports.indexOf = function(arr, obj, start) {
86
91
  for (var i = start || 0, l = arr.length; i < l; i++) {
87
- if (arr[i] === obj)
92
+ if (arr[i] === obj) {
88
93
  return i;
94
+ }
89
95
  }
90
96
  return -1;
91
97
  };
@@ -93,13 +99,13 @@ exports.indexOf = function(arr, obj, start){
93
99
  /**
94
100
  * Array#reduce (<=IE8)
95
101
  *
96
- * @param {Array} array
97
- * @param {Function} fn
98
- * @param {Object} initial value
99
102
  * @api private
103
+ * @param {Array} arr
104
+ * @param {Function} fn
105
+ * @param {Object} val Initial value.
106
+ * @return {*}
100
107
  */
101
-
102
- exports.reduce = function(arr, fn, val){
108
+ exports.reduce = function(arr, fn, val) {
103
109
  var rval = val;
104
110
 
105
111
  for (var i = 0, l = arr.length; i < l; i++) {
@@ -112,17 +118,19 @@ exports.reduce = function(arr, fn, val){
112
118
  /**
113
119
  * Array#filter (<=IE8)
114
120
  *
115
- * @param {Array} array
116
- * @param {Function} fn
117
121
  * @api private
122
+ * @param {Array} arr
123
+ * @param {Function} fn
124
+ * @return {Array}
118
125
  */
119
-
120
- exports.filter = function(arr, fn){
126
+ exports.filter = function(arr, fn) {
121
127
  var ret = [];
122
128
 
123
129
  for (var i = 0, l = arr.length; i < l; i++) {
124
130
  var val = arr[i];
125
- if (fn(val, i, arr)) ret.push(val);
131
+ if (fn(val, i, arr)) {
132
+ ret.push(val);
133
+ }
126
134
  }
127
135
 
128
136
  return ret;
@@ -131,14 +139,13 @@ exports.filter = function(arr, fn){
131
139
  /**
132
140
  * Object.keys (<=IE8)
133
141
  *
142
+ * @api private
134
143
  * @param {Object} obj
135
144
  * @return {Array} keys
136
- * @api private
137
145
  */
138
-
139
- exports.keys = Object.keys || function(obj) {
140
- var keys = []
141
- , has = Object.prototype.hasOwnProperty; // for `window` on <=IE8
146
+ exports.keys = typeof Object.keys === 'function' ? Object.keys : function(obj) {
147
+ var keys = [];
148
+ var has = Object.prototype.hasOwnProperty; // for `window` on <=IE8
142
149
 
143
150
  for (var key in obj) {
144
151
  if (has.call(obj, key)) {
@@ -153,17 +160,18 @@ exports.keys = Object.keys || function(obj) {
153
160
  * Watch the given `files` for changes
154
161
  * and invoke `fn(file)` on modification.
155
162
  *
163
+ * @api private
156
164
  * @param {Array} files
157
165
  * @param {Function} fn
158
- * @api private
159
166
  */
160
-
161
- exports.watch = function(files, fn){
167
+ exports.watch = function(files, fn) {
162
168
  var options = { interval: 100 };
163
- files.forEach(function(file){
169
+ files.forEach(function(file) {
164
170
  debug('file %s', file);
165
- fs.watchFile(file, options, function(curr, prev){
166
- if (prev.mtime < curr.mtime) fn(file);
171
+ watchFile(file, options, function(curr, prev) {
172
+ if (prev.mtime < curr.mtime) {
173
+ fn(file);
174
+ }
167
175
  });
168
176
  });
169
177
  };
@@ -171,51 +179,56 @@ exports.watch = function(files, fn){
171
179
  /**
172
180
  * Array.isArray (<=IE8)
173
181
  *
182
+ * @api private
174
183
  * @param {Object} obj
175
184
  * @return {Boolean}
176
- * @api private
177
185
  */
178
- var isArray = Array.isArray || function (obj) {
179
- return '[object Array]' == {}.toString.call(obj);
186
+ var isArray = typeof Array.isArray === 'function' ? Array.isArray : function(obj) {
187
+ return Object.prototype.toString.call(obj) === '[object Array]';
180
188
  };
181
189
 
182
190
  /**
183
- * @description
184
- * Buffer.prototype.toJSON polyfill
191
+ * Buffer.prototype.toJSON polyfill.
192
+ *
185
193
  * @type {Function}
186
194
  */
187
- if(typeof Buffer !== 'undefined' && Buffer.prototype) {
188
- Buffer.prototype.toJSON = Buffer.prototype.toJSON || function () {
195
+ if (typeof Buffer !== 'undefined' && Buffer.prototype) {
196
+ Buffer.prototype.toJSON = Buffer.prototype.toJSON || function() {
189
197
  return Array.prototype.slice.call(this, 0);
190
198
  };
191
199
  }
192
200
 
193
201
  /**
194
202
  * Ignored files.
203
+ *
204
+ * @api private
205
+ * @param {string} path
206
+ * @return {boolean}
195
207
  */
196
-
197
- function ignored(path){
208
+ function ignored(path) {
198
209
  return !~ignore.indexOf(path);
199
210
  }
200
211
 
201
212
  /**
202
213
  * Lookup files in the given `dir`.
203
214
  *
204
- * @return {Array}
205
215
  * @api private
216
+ * @param {string} dir
217
+ * @param {string[]} [ext=['.js']]
218
+ * @param {Array} [ret=[]]
219
+ * @return {Array}
206
220
  */
207
-
208
- exports.files = function(dir, ext, ret){
221
+ exports.files = function(dir, ext, ret) {
209
222
  ret = ret || [];
210
223
  ext = ext || ['js'];
211
224
 
212
225
  var re = new RegExp('\\.(' + ext.join('|') + ')$');
213
226
 
214
- fs.readdirSync(dir)
227
+ readdirSync(dir)
215
228
  .filter(ignored)
216
- .forEach(function(path){
229
+ .forEach(function(path) {
217
230
  path = join(dir, path);
218
- if (fs.statSync(path).isDirectory()) {
231
+ if (statSync(path).isDirectory()) {
219
232
  exports.files(path, ext, ret);
220
233
  } else if (path.match(re)) {
221
234
  ret.push(path);
@@ -228,12 +241,11 @@ exports.files = function(dir, ext, ret){
228
241
  /**
229
242
  * Compute a slug from the given `str`.
230
243
  *
231
- * @param {String} str
232
- * @return {String}
233
244
  * @api private
245
+ * @param {string} str
246
+ * @return {string}
234
247
  */
235
-
236
- exports.slug = function(str){
248
+ exports.slug = function(str) {
237
249
  return str
238
250
  .toLowerCase()
239
251
  .replace(/ +/g, '-')
@@ -241,19 +253,20 @@ exports.slug = function(str){
241
253
  };
242
254
 
243
255
  /**
244
- * Strip the function definition from `str`,
245
- * and re-indent for pre whitespace.
256
+ * Strip the function definition from `str`, and re-indent for pre whitespace.
257
+ *
258
+ * @param {string} str
259
+ * @return {string}
246
260
  */
247
-
248
261
  exports.clean = function(str) {
249
262
  str = str
250
- .replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '')
263
+ .replace(/\r\n?|[\n\u2028\u2029]/g, '\n').replace(/^\uFEFF/, '')
251
264
  .replace(/^function *\(.*\)\s*{|\(.*\) *=> *{?/, '')
252
265
  .replace(/\s+\}$/, '');
253
266
 
254
- var spaces = str.match(/^\n?( *)/)[1].length
255
- , tabs = str.match(/^\n?(\t*)/)[1].length
256
- , re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs ? tabs : spaces) + '}', 'gm');
267
+ var spaces = str.match(/^\n?( *)/)[1].length;
268
+ var tabs = str.match(/^\n?(\t*)/)[1].length;
269
+ var re = new RegExp('^\n?' + (tabs ? '\t' : ' ') + '{' + (tabs ? tabs : spaces) + '}', 'gm');
257
270
 
258
271
  str = str.replace(re, '');
259
272
 
@@ -263,28 +276,26 @@ exports.clean = function(str) {
263
276
  /**
264
277
  * Trim the given `str`.
265
278
  *
266
- * @param {String} str
267
- * @return {String}
268
279
  * @api private
280
+ * @param {string} str
281
+ * @return {string}
269
282
  */
270
-
271
- exports.trim = function(str){
283
+ exports.trim = function(str) {
272
284
  return str.replace(/^\s+|\s+$/g, '');
273
285
  };
274
286
 
275
287
  /**
276
288
  * Parse the given `qs`.
277
289
  *
278
- * @param {String} qs
279
- * @return {Object}
280
290
  * @api private
291
+ * @param {string} qs
292
+ * @return {Object}
281
293
  */
282
-
283
- exports.parseQuery = function(qs){
284
- return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair){
285
- var i = pair.indexOf('=')
286
- , key = pair.slice(0, i)
287
- , val = pair.slice(++i);
294
+ exports.parseQuery = function(qs) {
295
+ return exports.reduce(qs.replace('?', '').split('&'), function(obj, pair) {
296
+ var i = pair.indexOf('=');
297
+ var key = pair.slice(0, i);
298
+ var val = pair.slice(++i);
288
299
 
289
300
  obj[key] = decodeURIComponent(val);
290
301
  return obj;
@@ -294,11 +305,10 @@ exports.parseQuery = function(qs){
294
305
  /**
295
306
  * Highlight the given string of `js`.
296
307
  *
297
- * @param {String} js
298
- * @return {String}
299
308
  * @api private
309
+ * @param {string} js
310
+ * @return {string}
300
311
  */
301
-
302
312
  function highlight(js) {
303
313
  return js
304
314
  .replace(/</g, '&lt;')
@@ -308,16 +318,15 @@ function highlight(js) {
308
318
  .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
309
319
  .replace(/(\d+)/gm, '<span class="number">$1</span>')
310
320
  .replace(/\bnew[ \t]+(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
311
- .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')
321
+ .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>');
312
322
  }
313
323
 
314
324
  /**
315
325
  * Highlight the contents of tag `name`.
316
326
  *
317
- * @param {String} name
318
327
  * @api private
328
+ * @param {string} name
319
329
  */
320
-
321
330
  exports.highlightTags = function(name) {
322
331
  var code = document.getElementById('mocha').getElementsByTagName(name);
323
332
  for (var i = 0, len = code.length; i < len; ++i) {
@@ -326,22 +335,23 @@ exports.highlightTags = function(name) {
326
335
  };
327
336
 
328
337
  /**
329
- * If a value could have properties, and has none, this function is called, which returns
330
- * a string representation of the empty value.
338
+ * If a value could have properties, and has none, this function is called,
339
+ * which returns a string representation of the empty value.
331
340
  *
332
341
  * Functions w/ no properties return `'[Function]'`
333
342
  * Arrays w/ length === 0 return `'[]'`
334
343
  * Objects w/ no properties return `'{}'`
335
344
  * All else: return result of `value.toString()`
336
345
  *
337
- * @param {*} value Value to inspect
346
+ * @api private
347
+ * @param {*} value The value to inspect.
338
348
  * @param {string} [type] The type of the value, if known.
339
349
  * @returns {string}
340
350
  */
341
- var emptyRepresentation = function emptyRepresentation(value, type) {
351
+ function emptyRepresentation(value, type) {
342
352
  type = type || exports.type(value);
343
353
 
344
- switch(type) {
354
+ switch (type) {
345
355
  case 'function':
346
356
  return '[Function]';
347
357
  case 'object':
@@ -351,11 +361,16 @@ var emptyRepresentation = function emptyRepresentation(value, type) {
351
361
  default:
352
362
  return value.toString();
353
363
  }
354
- };
364
+ }
355
365
 
356
366
  /**
357
- * Takes some variable and asks `{}.toString()` what it thinks it is.
358
- * @param {*} value Anything
367
+ * Takes some variable and asks `Object.prototype.toString()` what it thinks it
368
+ * is.
369
+ *
370
+ * @api private
371
+ * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
372
+ * @param {*} value The value to test.
373
+ * @returns {string}
359
374
  * @example
360
375
  * type({}) // 'object'
361
376
  * type([]) // 'array'
@@ -367,12 +382,13 @@ var emptyRepresentation = function emptyRepresentation(value, type) {
367
382
  * type(/foo/) // 'regexp'
368
383
  * type('type') // 'string'
369
384
  * type(global) // 'global'
370
- * @api private
371
- * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
372
- * @returns {string}
373
385
  */
374
386
  exports.type = function type(value) {
375
- if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
387
+ if (value === undefined) {
388
+ return 'undefined';
389
+ } else if (value === null) {
390
+ return 'null';
391
+ } else if (typeof Buffer !== 'undefined' && Buffer.isBuffer(value)) {
376
392
  return 'buffer';
377
393
  }
378
394
  return Object.prototype.toString.call(value)
@@ -381,8 +397,8 @@ exports.type = function type(value) {
381
397
  };
382
398
 
383
399
  /**
384
- * @summary Stringify `value`.
385
- * @description Different behavior depending on type of value.
400
+ * Stringify `value`. Different behavior depending on type of value:
401
+ *
386
402
  * - If `value` is undefined or null, return `'[undefined]'` or `'[null]'`, respectively.
387
403
  * - If `value` is not an object, function or array, return result of `value.toString()` wrapped in double-quotes.
388
404
  * - If `value` is an *empty* object, function, or array, return result of function
@@ -390,17 +406,16 @@ exports.type = function type(value) {
390
406
  * - If `value` has properties, call {@link exports.canonicalize} on it, then return result of
391
407
  * JSON.stringify().
392
408
  *
409
+ * @api private
393
410
  * @see exports.type
394
411
  * @param {*} value
395
412
  * @return {string}
396
- * @api private
397
413
  */
398
-
399
414
  exports.stringify = function(value) {
400
415
  var type = exports.type(value);
401
416
 
402
417
  if (!~exports.indexOf(['object', 'array', 'function'], type)) {
403
- if(type != 'buffer') {
418
+ if (type !== 'buffer') {
404
419
  return jsonStringify(value);
405
420
  }
406
421
  var json = value.toJSON();
@@ -419,23 +434,29 @@ exports.stringify = function(value) {
419
434
  };
420
435
 
421
436
  /**
422
- * @description
423
437
  * like JSON.stringify but more sense.
438
+ *
439
+ * @api private
424
440
  * @param {Object} object
425
- * @param {Number=} spaces
441
+ * @param {number=} spaces
426
442
  * @param {number=} depth
427
443
  * @returns {*}
428
- * @private
429
444
  */
430
445
  function jsonStringify(object, spaces, depth) {
431
- if(typeof spaces == 'undefined') return _stringify(object); // primitive types
446
+ if (typeof spaces === 'undefined') {
447
+ // primitive types
448
+ return _stringify(object);
449
+ }
432
450
 
433
451
  depth = depth || 1;
434
- var space = spaces * depth
435
- , str = isArray(object) ? '[' : '{'
436
- , end = isArray(object) ? ']' : '}'
437
- , length = object.length || exports.keys(object).length
438
- , repeat = function(s, n) { return new Array(n).join(s); }; // `.repeat()` polyfill
452
+ var space = spaces * depth;
453
+ var str = isArray(object) ? '[' : '{';
454
+ var end = isArray(object) ? ']' : '}';
455
+ var length = object.length || exports.keys(object).length;
456
+ // `.repeat()` polyfill
457
+ function repeat(s, n) {
458
+ return new Array(n).join(s);
459
+ }
439
460
 
440
461
  function _stringify(val) {
441
462
  switch (exports.type(val)) {
@@ -450,7 +471,7 @@ function jsonStringify(object, spaces, depth) {
450
471
  case 'boolean':
451
472
  case 'regexp':
452
473
  case 'number':
453
- val = val === 0 && (1/val) === -Infinity // `-0`
474
+ val = val === 0 && (1 / val) === -Infinity // `-0`
454
475
  ? '-0'
455
476
  : val.toString();
456
477
  break;
@@ -467,40 +488,44 @@ function jsonStringify(object, spaces, depth) {
467
488
  val = '[Buffer: ' + jsonStringify(json, 2, depth + 1) + ']';
468
489
  break;
469
490
  default:
470
- val = (val == '[Function]' || val == '[Circular]')
491
+ val = (val === '[Function]' || val === '[Circular]')
471
492
  ? val
472
- : JSON.stringify(val); //string
493
+ : JSON.stringify(val); // string
473
494
  }
474
495
  return val;
475
496
  }
476
497
 
477
- for(var i in object) {
478
- if(!object.hasOwnProperty(i)) continue; // not my business
498
+ for (var i in object) {
499
+ if (!object.hasOwnProperty(i)) {
500
+ continue; // not my business
501
+ }
479
502
  --length;
480
503
  str += '\n ' + repeat(' ', space)
481
504
  + (isArray(object) ? '' : '"' + i + '": ') // key
482
- + _stringify(object[i]) // value
505
+ + _stringify(object[i]) // value
483
506
  + (length ? ',' : ''); // comma
484
507
  }
485
508
 
486
- return str + (str.length != 1 // [], {}
487
- ? '\n' + repeat(' ', --space) + end
488
- : end);
509
+ return str
510
+ // [], {}
511
+ + (str.length !== 1 ? '\n' + repeat(' ', --space) + end : end);
489
512
  }
490
513
 
491
514
  /**
492
- * Return if obj is a Buffer
493
- * @param {Object} arg
494
- * @return {Boolean}
515
+ * Test if a value is a buffer.
516
+ *
495
517
  * @api private
518
+ * @param {*} value The value to test.
519
+ * @return {boolean} True if `value` is a buffer, otherwise false
496
520
  */
497
- exports.isBuffer = function (arg) {
498
- return typeof Buffer !== 'undefined' && Buffer.isBuffer(arg);
521
+ exports.isBuffer = function(value) {
522
+ return typeof Buffer !== 'undefined' && Buffer.isBuffer(value);
499
523
  };
500
524
 
501
525
  /**
502
- * @summary Return a new Thing that has the keys in sorted order. Recursive.
503
- * @description If the Thing...
526
+ * Return a new Thing that has the keys in sorted order. Recursive.
527
+ *
528
+ * If the Thing...
504
529
  * - has already been seen, return string `'[Circular]'`
505
530
  * - is `undefined`, return string `'[undefined]'`
506
531
  * - is `null`, return value `null`
@@ -509,22 +534,23 @@ exports.isBuffer = function (arg) {
509
534
  * - is a non-empty `Array`, `Object`, or `Function`, return the result of calling this function again.
510
535
  * - is an empty `Array`, `Object`, or `Function`, return the result of calling `emptyRepresentation()`
511
536
  *
537
+ * @api private
538
+ * @see {@link exports.stringify}
512
539
  * @param {*} value Thing to inspect. May or may not have properties.
513
540
  * @param {Array} [stack=[]] Stack of seen values
514
541
  * @return {(Object|Array|Function|string|undefined)}
515
- * @see {@link exports.stringify}
516
- * @api private
517
542
  */
518
-
519
543
  exports.canonicalize = function(value, stack) {
520
- var canonicalizedObj,
521
- type = exports.type(value),
522
- prop,
523
- withStack = function withStack(value, fn) {
524
- stack.push(value);
525
- fn();
526
- stack.pop();
527
- };
544
+ var canonicalizedObj;
545
+ /* eslint-disable no-unused-vars */
546
+ var prop;
547
+ /* eslint-enable no-unused-vars */
548
+ var type = exports.type(value);
549
+ function withStack(value, fn) {
550
+ stack.push(value);
551
+ fn();
552
+ stack.pop();
553
+ }
528
554
 
529
555
  stack = stack || [];
530
556
 
@@ -532,24 +558,26 @@ exports.canonicalize = function(value, stack) {
532
558
  return '[Circular]';
533
559
  }
534
560
 
535
- switch(type) {
561
+ switch (type) {
536
562
  case 'undefined':
537
563
  case 'buffer':
538
564
  case 'null':
539
565
  canonicalizedObj = value;
540
566
  break;
541
567
  case 'array':
542
- withStack(value, function () {
543
- canonicalizedObj = exports.map(value, function (item) {
568
+ withStack(value, function() {
569
+ canonicalizedObj = exports.map(value, function(item) {
544
570
  return exports.canonicalize(item, stack);
545
571
  });
546
572
  });
547
573
  break;
548
574
  case 'function':
575
+ /* eslint-disable guard-for-in */
549
576
  for (prop in value) {
550
577
  canonicalizedObj = {};
551
578
  break;
552
579
  }
580
+ /* eslint-enable guard-for-in */
553
581
  if (!canonicalizedObj) {
554
582
  canonicalizedObj = emptyRepresentation(value, type);
555
583
  break;
@@ -557,8 +585,8 @@ exports.canonicalize = function(value, stack) {
557
585
  /* falls through */
558
586
  case 'object':
559
587
  canonicalizedObj = canonicalizedObj || {};
560
- withStack(value, function () {
561
- exports.forEach(exports.keys(value).sort(), function (key) {
588
+ withStack(value, function() {
589
+ exports.forEach(exports.keys(value).sort(), function(key) {
562
590
  canonicalizedObj[key] = exports.canonicalize(value[key], stack);
563
591
  });
564
592
  });
@@ -578,6 +606,12 @@ exports.canonicalize = function(value, stack) {
578
606
 
579
607
  /**
580
608
  * Lookup file names at the given `path`.
609
+ *
610
+ * @api public
611
+ * @param {string} path Base path to start searching from.
612
+ * @param {string[]} extensions File extensions to look for.
613
+ * @param {boolean} recursive Whether or not to recurse into subdirectories.
614
+ * @return {string[]} An array of paths.
581
615
  */
582
616
  exports.lookupFiles = function lookupFiles(path, extensions, recursive) {
583
617
  var files = [];
@@ -588,34 +622,40 @@ exports.lookupFiles = function lookupFiles(path, extensions, recursive) {
588
622
  path += '.js';
589
623
  } else {
590
624
  files = glob.sync(path);
591
- if (!files.length) throw new Error("cannot resolve path (or pattern) '" + path + "'");
625
+ if (!files.length) {
626
+ throw new Error("cannot resolve path (or pattern) '" + path + "'");
627
+ }
592
628
  return files;
593
629
  }
594
630
  }
595
631
 
596
632
  try {
597
- var stat = fs.statSync(path);
598
- if (stat.isFile()) return path;
599
- }
600
- catch (ignored) {
633
+ var stat = statSync(path);
634
+ if (stat.isFile()) {
635
+ return path;
636
+ }
637
+ } catch (err) {
638
+ // ignore error
601
639
  return;
602
640
  }
603
641
 
604
- fs.readdirSync(path).forEach(function(file) {
642
+ readdirSync(path).forEach(function(file) {
605
643
  file = join(path, file);
606
644
  try {
607
- var stat = fs.statSync(file);
645
+ var stat = statSync(file);
608
646
  if (stat.isDirectory()) {
609
647
  if (recursive) {
610
648
  files = files.concat(lookupFiles(file, extensions, recursive));
611
649
  }
612
650
  return;
613
651
  }
652
+ } catch (err) {
653
+ // ignore error
654
+ return;
614
655
  }
615
- catch (ignored) {
656
+ if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') {
616
657
  return;
617
658
  }
618
- if (!stat.isFile() || !re.test(file) || basename(file)[0] === '.') return;
619
659
  files.push(file);
620
660
  });
621
661
 
@@ -643,62 +683,50 @@ exports.getError = function(err) {
643
683
  return err || exports.undefinedError();
644
684
  };
645
685
 
646
-
647
686
  /**
648
687
  * @summary
649
688
  * This Filter based on `mocha-clean` module.(see: `github.com/rstacruz/mocha-clean`)
650
689
  * @description
651
690
  * When invoking this function you get a filter function that get the Error.stack as an input,
652
691
  * and return a prettify output.
653
- * (i.e: strip Mocha, node_modules, bower and componentJS from stack trace).
692
+ * (i.e: strip Mocha and internal node functions from stack trace).
654
693
  * @returns {Function}
655
694
  */
656
-
657
695
  exports.stackTraceFilter = function() {
658
- var slash = '/'
659
- , is = typeof document === 'undefined'
660
- ? { node: true }
661
- : { browser: true }
662
- , cwd = is.node
696
+ // TODO: Replace with `process.browser`
697
+ var slash = '/';
698
+ var is = typeof document === 'undefined' ? { node: true } : { browser: true };
699
+ var cwd = is.node
663
700
  ? process.cwd() + slash
664
- : location.href.replace(/\/[^\/]*$/, '/');
701
+ : (typeof location === 'undefined' ? window.location : location).href.replace(/\/[^\/]*$/, '/');
665
702
 
666
- function isNodeModule (line) {
667
- return (~line.indexOf('node_modules'));
703
+ function isMochaInternal(line) {
704
+ return (~line.indexOf('node_modules' + slash + 'mocha' + slash))
705
+ || (~line.indexOf('components' + slash + 'mochajs' + slash))
706
+ || (~line.indexOf('components' + slash + 'mocha' + slash))
707
+ || (~line.indexOf(slash + 'mocha.js'));
668
708
  }
669
709
 
670
- function isMochaInternal (line) {
671
- return (~line.indexOf('node_modules' + slash + 'mocha')) ||
672
- (~line.indexOf('components' + slash + 'mochajs')) ||
673
- (~line.indexOf('components' + slash + 'mocha'));
674
- }
675
-
676
- // node_modules, bower, componentJS
677
- function isBrowserModule(line) {
678
- return (~line.indexOf('node_modules')) ||
679
- (~line.indexOf('components'));
680
- }
681
-
682
- function isNodeInternal (line) {
683
- return (~line.indexOf('(timers.js:')) ||
684
- (~line.indexOf('(events.js:')) ||
685
- (~line.indexOf('(node.js:')) ||
686
- (~line.indexOf('(module.js:')) ||
687
- (~line.indexOf('GeneratorFunctionPrototype.next (native)')) ||
688
- false
710
+ function isNodeInternal(line) {
711
+ return (~line.indexOf('(timers.js:'))
712
+ || (~line.indexOf('(events.js:'))
713
+ || (~line.indexOf('(node.js:'))
714
+ || (~line.indexOf('(module.js:'))
715
+ || (~line.indexOf('GeneratorFunctionPrototype.next (native)'))
716
+ || false;
689
717
  }
690
718
 
691
719
  return function(stack) {
692
720
  stack = stack.split('\n');
693
721
 
694
722
  stack = exports.reduce(stack, function(list, line) {
695
- if (is.node && (isNodeModule(line) ||
696
- isMochaInternal(line) ||
697
- isNodeInternal(line)))
723
+ if (isMochaInternal(line)) {
698
724
  return list;
725
+ }
699
726
 
700
- if (is.browser && (isBrowserModule(line)))
727
+ if (is.node && isNodeInternal(line)) {
701
728
  return list;
729
+ }
702
730
 
703
731
  // Clean up cwd(absolute)
704
732
  list.push(line.replace(cwd, ''));
@@ -706,5 +734,5 @@ exports.stackTraceFilter = function() {
706
734
  }, []);
707
735
 
708
736
  return stack.join('\n');
709
- }
710
- };
737
+ };
738
+ };