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