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.
- package/CHANGELOG.md +119 -9
- package/bin/_mocha +90 -35
- package/bin/options.js +14 -8
- package/browser-entry.js +20 -16
- package/lib/browser/progress.js +8 -8
- package/lib/browser/tty.js +2 -2
- package/lib/context.js +11 -9
- package/lib/hook.js +7 -9
- package/lib/interfaces/bdd.js +12 -13
- package/lib/interfaces/common.js +20 -15
- package/lib/interfaces/exports.js +2 -7
- package/lib/interfaces/qunit.js +6 -10
- package/lib/interfaces/tdd.js +7 -11
- package/lib/mocha.js +94 -54
- package/lib/ms.js +12 -6
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +102 -64
- package/lib/reporters/doc.js +23 -9
- package/lib/reporters/dot.js +14 -8
- package/lib/reporters/html.js +81 -41
- package/lib/reporters/json-stream.js +16 -9
- package/lib/reporters/json.js +47 -12
- package/lib/reporters/json.js.orig +128 -0
- package/lib/reporters/landing.js +14 -8
- package/lib/reporters/list.js +16 -10
- package/lib/reporters/markdown.js +18 -12
- package/lib/reporters/min.js +9 -3
- package/lib/reporters/nyan.js +31 -25
- package/lib/reporters/progress.js +13 -7
- package/lib/reporters/spec.js +19 -11
- package/lib/reporters/tap.js +15 -9
- package/lib/reporters/xunit.js +48 -24
- package/lib/runnable.js +88 -66
- package/lib/runner.js +117 -90
- package/lib/suite.js +76 -63
- package/lib/test.js +9 -13
- package/lib/utils.js +137 -85
- package/mocha.js +1914 -1162
- package/package.json +462 -299
- package/CHANGELOG.md.orig +0 -1736
- package/README.md.orig +0 -132
- package/bin/.eslintrc.yml +0 -3
- package/images/error.png +0 -0
- package/images/ok.png +0 -0
- package/lib/browser/.eslintrc.yml +0 -4
package/lib/runner.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @module Runner
|
|
5
|
+
*/
|
|
3
6
|
/**
|
|
4
7
|
* Module dependencies.
|
|
5
8
|
*/
|
|
6
|
-
|
|
7
9
|
var EventEmitter = require('events').EventEmitter;
|
|
8
10
|
var Pending = require('./pending');
|
|
9
11
|
var utils = require('./utils');
|
|
@@ -37,7 +39,7 @@ var globals = [
|
|
|
37
39
|
module.exports = Runner;
|
|
38
40
|
|
|
39
41
|
/**
|
|
40
|
-
* Initialize a `Runner` for the given `suite`.
|
|
42
|
+
* Initialize a `Runner` for the given `suite`. Derived from [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter)
|
|
41
43
|
*
|
|
42
44
|
* Events:
|
|
43
45
|
*
|
|
@@ -53,12 +55,15 @@ module.exports = Runner;
|
|
|
53
55
|
* - `fail` (test, err) test failed
|
|
54
56
|
* - `pending` (test) test pending
|
|
55
57
|
*
|
|
58
|
+
* @memberof Mocha
|
|
59
|
+
* @public
|
|
60
|
+
* @class
|
|
56
61
|
* @api public
|
|
57
|
-
* @param {Suite} suite Root suite
|
|
62
|
+
* @param {Suite} [suite] Root suite
|
|
58
63
|
* @param {boolean} [delay] Whether or not to delay execution of root suite
|
|
59
64
|
* until ready.
|
|
60
65
|
*/
|
|
61
|
-
function Runner
|
|
66
|
+
function Runner(suite, delay) {
|
|
62
67
|
var self = this;
|
|
63
68
|
this._globals = [];
|
|
64
69
|
this._abort = false;
|
|
@@ -67,10 +72,10 @@ function Runner (suite, delay) {
|
|
|
67
72
|
this.started = false;
|
|
68
73
|
this.total = suite.total();
|
|
69
74
|
this.failures = 0;
|
|
70
|
-
this.on('test end', function
|
|
75
|
+
this.on('test end', function(test) {
|
|
71
76
|
self.checkGlobals(test);
|
|
72
77
|
});
|
|
73
|
-
this.on('hook end', function
|
|
78
|
+
this.on('hook end', function(hook) {
|
|
74
79
|
self.checkGlobals(hook);
|
|
75
80
|
});
|
|
76
81
|
this._defaultGrep = /.*/;
|
|
@@ -95,15 +100,14 @@ inherits(Runner, EventEmitter);
|
|
|
95
100
|
* Run tests with full titles matching `re`. Updates runner.total
|
|
96
101
|
* with number of tests matched.
|
|
97
102
|
*
|
|
98
|
-
* @param {RegExp} re
|
|
99
|
-
* @param {Boolean} invert
|
|
100
|
-
* @return {Runner} for chaining
|
|
101
103
|
* @api public
|
|
104
|
+
* @public
|
|
105
|
+
* @memberof Mocha.Runner
|
|
102
106
|
* @param {RegExp} re
|
|
103
107
|
* @param {boolean} invert
|
|
104
108
|
* @return {Runner} Runner instance.
|
|
105
109
|
*/
|
|
106
|
-
Runner.prototype.grep = function
|
|
110
|
+
Runner.prototype.grep = function(re, invert) {
|
|
107
111
|
debug('grep %s', re);
|
|
108
112
|
this._grep = re;
|
|
109
113
|
this._invert = invert;
|
|
@@ -115,17 +119,17 @@ Runner.prototype.grep = function (re, invert) {
|
|
|
115
119
|
* Returns the number of tests matching the grep search for the
|
|
116
120
|
* given suite.
|
|
117
121
|
*
|
|
118
|
-
* @
|
|
119
|
-
* @return {Number}
|
|
122
|
+
* @memberof Mocha.Runner
|
|
120
123
|
* @api public
|
|
124
|
+
* @public
|
|
121
125
|
* @param {Suite} suite
|
|
122
126
|
* @return {number}
|
|
123
127
|
*/
|
|
124
|
-
Runner.prototype.grepTotal = function
|
|
128
|
+
Runner.prototype.grepTotal = function(suite) {
|
|
125
129
|
var self = this;
|
|
126
130
|
var total = 0;
|
|
127
131
|
|
|
128
|
-
suite.eachTest(function
|
|
132
|
+
suite.eachTest(function(test) {
|
|
129
133
|
var match = self._grep.test(test.fullTitle());
|
|
130
134
|
if (self._invert) {
|
|
131
135
|
match = !match;
|
|
@@ -144,7 +148,7 @@ Runner.prototype.grepTotal = function (suite) {
|
|
|
144
148
|
* @return {Array}
|
|
145
149
|
* @api private
|
|
146
150
|
*/
|
|
147
|
-
Runner.prototype.globalProps = function
|
|
151
|
+
Runner.prototype.globalProps = function() {
|
|
148
152
|
var props = Object.keys(global);
|
|
149
153
|
|
|
150
154
|
// non-enumerables
|
|
@@ -161,13 +165,13 @@ Runner.prototype.globalProps = function () {
|
|
|
161
165
|
/**
|
|
162
166
|
* Allow the given `arr` of globals.
|
|
163
167
|
*
|
|
164
|
-
* @param {Array} arr
|
|
165
|
-
* @return {Runner} for chaining
|
|
166
168
|
* @api public
|
|
169
|
+
* @public
|
|
170
|
+
* @memberof Mocha.Runner
|
|
167
171
|
* @param {Array} arr
|
|
168
172
|
* @return {Runner} Runner instance.
|
|
169
173
|
*/
|
|
170
|
-
Runner.prototype.globals = function
|
|
174
|
+
Runner.prototype.globals = function(arr) {
|
|
171
175
|
if (!arguments.length) {
|
|
172
176
|
return this._globals;
|
|
173
177
|
}
|
|
@@ -181,7 +185,7 @@ Runner.prototype.globals = function (arr) {
|
|
|
181
185
|
*
|
|
182
186
|
* @api private
|
|
183
187
|
*/
|
|
184
|
-
Runner.prototype.checkGlobals = function
|
|
188
|
+
Runner.prototype.checkGlobals = function(test) {
|
|
185
189
|
if (this.ignoreLeaks) {
|
|
186
190
|
return;
|
|
187
191
|
}
|
|
@@ -203,7 +207,10 @@ Runner.prototype.checkGlobals = function (test) {
|
|
|
203
207
|
this._globals = this._globals.concat(leaks);
|
|
204
208
|
|
|
205
209
|
if (leaks.length > 1) {
|
|
206
|
-
this.fail(
|
|
210
|
+
this.fail(
|
|
211
|
+
test,
|
|
212
|
+
new Error('global leaks detected: ' + leaks.join(', ') + '')
|
|
213
|
+
);
|
|
207
214
|
} else if (leaks.length) {
|
|
208
215
|
this.fail(test, new Error('global leak detected: ' + leaks[0]));
|
|
209
216
|
}
|
|
@@ -216,7 +223,7 @@ Runner.prototype.checkGlobals = function (test) {
|
|
|
216
223
|
* @param {Test} test
|
|
217
224
|
* @param {Error} err
|
|
218
225
|
*/
|
|
219
|
-
Runner.prototype.fail = function
|
|
226
|
+
Runner.prototype.fail = function(test, err) {
|
|
220
227
|
if (test.isPending()) {
|
|
221
228
|
return;
|
|
222
229
|
}
|
|
@@ -225,18 +232,26 @@ Runner.prototype.fail = function (test, err) {
|
|
|
225
232
|
test.state = 'failed';
|
|
226
233
|
|
|
227
234
|
if (!(err instanceof Error || (err && typeof err.message === 'string'))) {
|
|
228
|
-
err = new Error(
|
|
235
|
+
err = new Error(
|
|
236
|
+
'the ' +
|
|
237
|
+
type(err) +
|
|
238
|
+
' ' +
|
|
239
|
+
stringify(err) +
|
|
240
|
+
' was thrown, throw an Error :)'
|
|
241
|
+
);
|
|
229
242
|
}
|
|
230
243
|
|
|
231
244
|
try {
|
|
232
|
-
err.stack =
|
|
233
|
-
? err.stack
|
|
234
|
-
|
|
235
|
-
} catch (ignored) {
|
|
245
|
+
err.stack =
|
|
246
|
+
this.fullStackTrace || !err.stack ? err.stack : stackFilter(err.stack);
|
|
247
|
+
} catch (ignore) {
|
|
236
248
|
// some environments do not take kindly to monkeying with the stack
|
|
237
249
|
}
|
|
238
250
|
|
|
239
251
|
this.emit('fail', test, err);
|
|
252
|
+
if (this.suite.bail()) {
|
|
253
|
+
this.emit('end');
|
|
254
|
+
}
|
|
240
255
|
};
|
|
241
256
|
|
|
242
257
|
/**
|
|
@@ -259,16 +274,14 @@ Runner.prototype.fail = function (test, err) {
|
|
|
259
274
|
* @param {Hook} hook
|
|
260
275
|
* @param {Error} err
|
|
261
276
|
*/
|
|
262
|
-
Runner.prototype.failHook = function
|
|
277
|
+
Runner.prototype.failHook = function(hook, err) {
|
|
263
278
|
if (hook.ctx && hook.ctx.currentTest) {
|
|
264
279
|
hook.originalTitle = hook.originalTitle || hook.title;
|
|
265
|
-
hook.title =
|
|
280
|
+
hook.title =
|
|
281
|
+
hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
|
|
266
282
|
}
|
|
267
283
|
|
|
268
284
|
this.fail(hook, err);
|
|
269
|
-
if (this.suite.bail()) {
|
|
270
|
-
this.emit('end');
|
|
271
|
-
}
|
|
272
285
|
};
|
|
273
286
|
|
|
274
287
|
/**
|
|
@@ -279,12 +292,12 @@ Runner.prototype.failHook = function (hook, err) {
|
|
|
279
292
|
* @param {Function} fn
|
|
280
293
|
*/
|
|
281
294
|
|
|
282
|
-
Runner.prototype.hook = function
|
|
295
|
+
Runner.prototype.hook = function(name, fn) {
|
|
283
296
|
var suite = this.suite;
|
|
284
297
|
var hooks = suite['_' + name];
|
|
285
298
|
var self = this;
|
|
286
299
|
|
|
287
|
-
function next
|
|
300
|
+
function next(i) {
|
|
288
301
|
var hook = hooks[i];
|
|
289
302
|
if (!hook) {
|
|
290
303
|
return fn();
|
|
@@ -296,12 +309,12 @@ Runner.prototype.hook = function (name, fn) {
|
|
|
296
309
|
self.emit('hook', hook);
|
|
297
310
|
|
|
298
311
|
if (!hook.listeners('error').length) {
|
|
299
|
-
hook.on('error', function
|
|
312
|
+
hook.on('error', function(err) {
|
|
300
313
|
self.failHook(hook, err);
|
|
301
314
|
});
|
|
302
315
|
}
|
|
303
316
|
|
|
304
|
-
hook.run(function
|
|
317
|
+
hook.run(function(err) {
|
|
305
318
|
var testError = hook.error();
|
|
306
319
|
if (testError) {
|
|
307
320
|
self.fail(self.test, testError);
|
|
@@ -311,7 +324,7 @@ Runner.prototype.hook = function (name, fn) {
|
|
|
311
324
|
if (name === 'beforeEach' || name === 'afterEach') {
|
|
312
325
|
self.test.pending = true;
|
|
313
326
|
} else {
|
|
314
|
-
suite.tests.forEach(function
|
|
327
|
+
suite.tests.forEach(function(test) {
|
|
315
328
|
test.pending = true;
|
|
316
329
|
});
|
|
317
330
|
// a pending hook won't be executed twice.
|
|
@@ -330,7 +343,7 @@ Runner.prototype.hook = function (name, fn) {
|
|
|
330
343
|
});
|
|
331
344
|
}
|
|
332
345
|
|
|
333
|
-
Runner.immediately(function
|
|
346
|
+
Runner.immediately(function() {
|
|
334
347
|
next(0);
|
|
335
348
|
});
|
|
336
349
|
};
|
|
@@ -344,11 +357,11 @@ Runner.prototype.hook = function (name, fn) {
|
|
|
344
357
|
* @param {Array} suites
|
|
345
358
|
* @param {Function} fn
|
|
346
359
|
*/
|
|
347
|
-
Runner.prototype.hooks = function
|
|
360
|
+
Runner.prototype.hooks = function(name, suites, fn) {
|
|
348
361
|
var self = this;
|
|
349
362
|
var orig = this.suite;
|
|
350
363
|
|
|
351
|
-
function next
|
|
364
|
+
function next(suite) {
|
|
352
365
|
self.suite = suite;
|
|
353
366
|
|
|
354
367
|
if (!suite) {
|
|
@@ -356,7 +369,7 @@ Runner.prototype.hooks = function (name, suites, fn) {
|
|
|
356
369
|
return fn();
|
|
357
370
|
}
|
|
358
371
|
|
|
359
|
-
self.hook(name, function
|
|
372
|
+
self.hook(name, function(err) {
|
|
360
373
|
if (err) {
|
|
361
374
|
var errSuite = self.suite;
|
|
362
375
|
self.suite = orig;
|
|
@@ -377,7 +390,7 @@ Runner.prototype.hooks = function (name, suites, fn) {
|
|
|
377
390
|
* @param {Function} fn
|
|
378
391
|
* @api private
|
|
379
392
|
*/
|
|
380
|
-
Runner.prototype.hookUp = function
|
|
393
|
+
Runner.prototype.hookUp = function(name, fn) {
|
|
381
394
|
var suites = [this.suite].concat(this.parents()).reverse();
|
|
382
395
|
this.hooks(name, suites, fn);
|
|
383
396
|
};
|
|
@@ -389,7 +402,7 @@ Runner.prototype.hookUp = function (name, fn) {
|
|
|
389
402
|
* @param {Function} fn
|
|
390
403
|
* @api private
|
|
391
404
|
*/
|
|
392
|
-
Runner.prototype.hookDown = function
|
|
405
|
+
Runner.prototype.hookDown = function(name, fn) {
|
|
393
406
|
var suites = [this.suite].concat(this.parents());
|
|
394
407
|
this.hooks(name, suites, fn);
|
|
395
408
|
};
|
|
@@ -401,7 +414,7 @@ Runner.prototype.hookDown = function (name, fn) {
|
|
|
401
414
|
* @return {Array}
|
|
402
415
|
* @api private
|
|
403
416
|
*/
|
|
404
|
-
Runner.prototype.parents = function
|
|
417
|
+
Runner.prototype.parents = function() {
|
|
405
418
|
var suite = this.suite;
|
|
406
419
|
var suites = [];
|
|
407
420
|
while (suite.parent) {
|
|
@@ -417,7 +430,7 @@ Runner.prototype.parents = function () {
|
|
|
417
430
|
* @param {Function} fn
|
|
418
431
|
* @api private
|
|
419
432
|
*/
|
|
420
|
-
Runner.prototype.runTest = function
|
|
433
|
+
Runner.prototype.runTest = function(fn) {
|
|
421
434
|
var self = this;
|
|
422
435
|
var test = this.test;
|
|
423
436
|
|
|
@@ -431,7 +444,7 @@ Runner.prototype.runTest = function (fn) {
|
|
|
431
444
|
if (this.asyncOnly) {
|
|
432
445
|
test.asyncOnly = true;
|
|
433
446
|
}
|
|
434
|
-
test.on('error', function
|
|
447
|
+
test.on('error', function(err) {
|
|
435
448
|
self.fail(test, err);
|
|
436
449
|
});
|
|
437
450
|
if (this.allowUncaught) {
|
|
@@ -452,12 +465,12 @@ Runner.prototype.runTest = function (fn) {
|
|
|
452
465
|
* @param {Suite} suite
|
|
453
466
|
* @param {Function} fn
|
|
454
467
|
*/
|
|
455
|
-
Runner.prototype.runTests = function
|
|
468
|
+
Runner.prototype.runTests = function(suite, fn) {
|
|
456
469
|
var self = this;
|
|
457
470
|
var tests = suite.tests.slice();
|
|
458
471
|
var test;
|
|
459
472
|
|
|
460
|
-
function hookErr
|
|
473
|
+
function hookErr(_, errSuite, after) {
|
|
461
474
|
// before/after Each hook for errSuite failed:
|
|
462
475
|
var orig = self.suite;
|
|
463
476
|
|
|
@@ -467,7 +480,7 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
467
480
|
|
|
468
481
|
if (self.suite) {
|
|
469
482
|
// call hookUp afterEach
|
|
470
|
-
self.hookUp('afterEach', function
|
|
483
|
+
self.hookUp('afterEach', function(err2, errSuite2) {
|
|
471
484
|
self.suite = orig;
|
|
472
485
|
// some hooks may fail even now
|
|
473
486
|
if (err2) {
|
|
@@ -483,7 +496,7 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
483
496
|
}
|
|
484
497
|
}
|
|
485
498
|
|
|
486
|
-
function next
|
|
499
|
+
function next(err, errSuite) {
|
|
487
500
|
// if we bail after first err
|
|
488
501
|
if (self.failures && suite._bail) {
|
|
489
502
|
return fn();
|
|
@@ -540,8 +553,8 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
540
553
|
}
|
|
541
554
|
|
|
542
555
|
// execute test and hook(s)
|
|
543
|
-
self.emit('test', self.test = test);
|
|
544
|
-
self.hookDown('beforeEach', function
|
|
556
|
+
self.emit('test', (self.test = test));
|
|
557
|
+
self.hookDown('beforeEach', function(err, errSuite) {
|
|
545
558
|
if (test.isPending()) {
|
|
546
559
|
if (self.forbidPending) {
|
|
547
560
|
test.isPending = alwaysFalse;
|
|
@@ -557,7 +570,7 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
557
570
|
return hookErr(err, errSuite, false);
|
|
558
571
|
}
|
|
559
572
|
self.currentRunnable = self.test;
|
|
560
|
-
self.runTest(function
|
|
573
|
+
self.runTest(function(err) {
|
|
561
574
|
test = self.test;
|
|
562
575
|
if (err) {
|
|
563
576
|
var retry = test.currentRetry();
|
|
@@ -599,7 +612,7 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
599
612
|
next();
|
|
600
613
|
};
|
|
601
614
|
|
|
602
|
-
function alwaysFalse
|
|
615
|
+
function alwaysFalse() {
|
|
603
616
|
return false;
|
|
604
617
|
}
|
|
605
618
|
|
|
@@ -610,7 +623,7 @@ function alwaysFalse () {
|
|
|
610
623
|
* @param {Suite} suite
|
|
611
624
|
* @param {Function} fn
|
|
612
625
|
*/
|
|
613
|
-
Runner.prototype.runSuite = function
|
|
626
|
+
Runner.prototype.runSuite = function(suite, fn) {
|
|
614
627
|
var i = 0;
|
|
615
628
|
var self = this;
|
|
616
629
|
var total = this.grepTotal(suite);
|
|
@@ -622,9 +635,9 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
622
635
|
return fn();
|
|
623
636
|
}
|
|
624
637
|
|
|
625
|
-
this.emit('suite', this.suite = suite);
|
|
638
|
+
this.emit('suite', (this.suite = suite));
|
|
626
639
|
|
|
627
|
-
function next
|
|
640
|
+
function next(errSuite) {
|
|
628
641
|
if (errSuite) {
|
|
629
642
|
// current suite failed on a hook from errSuite
|
|
630
643
|
if (errSuite === suite) {
|
|
@@ -650,7 +663,7 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
650
663
|
// huge recursive loop and thus a maximum call stack error.
|
|
651
664
|
// See comment in `this.runTests()` for more information.
|
|
652
665
|
if (self._grep !== self._defaultGrep) {
|
|
653
|
-
Runner.immediately(function
|
|
666
|
+
Runner.immediately(function() {
|
|
654
667
|
self.runSuite(curr, next);
|
|
655
668
|
});
|
|
656
669
|
} else {
|
|
@@ -658,7 +671,7 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
658
671
|
}
|
|
659
672
|
}
|
|
660
673
|
|
|
661
|
-
function done
|
|
674
|
+
function done(errSuite) {
|
|
662
675
|
self.suite = suite;
|
|
663
676
|
self.nextSuite = next;
|
|
664
677
|
|
|
@@ -672,7 +685,7 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
672
685
|
// remove reference to test
|
|
673
686
|
delete self.test;
|
|
674
687
|
|
|
675
|
-
self.hook('afterAll', function
|
|
688
|
+
self.hook('afterAll', function() {
|
|
676
689
|
self.emit('suite end', suite);
|
|
677
690
|
fn(errSuite);
|
|
678
691
|
});
|
|
@@ -681,7 +694,7 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
681
694
|
|
|
682
695
|
this.nextSuite = next;
|
|
683
696
|
|
|
684
|
-
this.hook('beforeAll', function
|
|
697
|
+
this.hook('beforeAll', function(err) {
|
|
685
698
|
if (err) {
|
|
686
699
|
return done();
|
|
687
700
|
}
|
|
@@ -695,11 +708,17 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
695
708
|
* @param {Error} err
|
|
696
709
|
* @api private
|
|
697
710
|
*/
|
|
698
|
-
Runner.prototype.uncaught = function
|
|
711
|
+
Runner.prototype.uncaught = function(err) {
|
|
699
712
|
if (err) {
|
|
700
|
-
debug(
|
|
701
|
-
|
|
702
|
-
|
|
713
|
+
debug(
|
|
714
|
+
'uncaught exception %s',
|
|
715
|
+
err ===
|
|
716
|
+
function() {
|
|
717
|
+
return this;
|
|
718
|
+
}.call(err)
|
|
719
|
+
? err.message || err
|
|
720
|
+
: err
|
|
721
|
+
);
|
|
703
722
|
} else {
|
|
704
723
|
debug('uncaught undefined exception');
|
|
705
724
|
err = undefinedError();
|
|
@@ -772,8 +791,8 @@ Runner.prototype.uncaught = function (err) {
|
|
|
772
791
|
*
|
|
773
792
|
* @param {Suite} suite
|
|
774
793
|
*/
|
|
775
|
-
function cleanSuiteReferences
|
|
776
|
-
function cleanArrReferences
|
|
794
|
+
function cleanSuiteReferences(suite) {
|
|
795
|
+
function cleanArrReferences(arr) {
|
|
777
796
|
for (var i = 0; i < arr.length; i++) {
|
|
778
797
|
delete arr[i].fn;
|
|
779
798
|
}
|
|
@@ -804,30 +823,30 @@ function cleanSuiteReferences (suite) {
|
|
|
804
823
|
* Run the root suite and invoke `fn(failures)`
|
|
805
824
|
* on completion.
|
|
806
825
|
*
|
|
807
|
-
* @param {Function} fn
|
|
808
|
-
* @return {Runner} for chaining
|
|
809
826
|
* @api public
|
|
827
|
+
* @public
|
|
828
|
+
* @memberof Mocha.Runner
|
|
810
829
|
* @param {Function} fn
|
|
811
830
|
* @return {Runner} Runner instance.
|
|
812
831
|
*/
|
|
813
|
-
Runner.prototype.run = function
|
|
832
|
+
Runner.prototype.run = function(fn) {
|
|
814
833
|
var self = this;
|
|
815
834
|
var rootSuite = this.suite;
|
|
816
835
|
|
|
817
|
-
fn = fn || function
|
|
836
|
+
fn = fn || function() {};
|
|
818
837
|
|
|
819
|
-
function uncaught
|
|
838
|
+
function uncaught(err) {
|
|
820
839
|
self.uncaught(err);
|
|
821
840
|
}
|
|
822
841
|
|
|
823
|
-
function start
|
|
842
|
+
function start() {
|
|
824
843
|
// If there is an `only` filter
|
|
825
844
|
if (hasOnly(rootSuite)) {
|
|
826
845
|
filterOnly(rootSuite);
|
|
827
846
|
}
|
|
828
847
|
self.started = true;
|
|
829
848
|
self.emit('start');
|
|
830
|
-
self.runSuite(rootSuite, function
|
|
849
|
+
self.runSuite(rootSuite, function() {
|
|
831
850
|
debug('finished running');
|
|
832
851
|
self.emit('end');
|
|
833
852
|
});
|
|
@@ -839,7 +858,7 @@ Runner.prototype.run = function (fn) {
|
|
|
839
858
|
this.on('suite end', cleanSuiteReferences);
|
|
840
859
|
|
|
841
860
|
// callback
|
|
842
|
-
this.on('end', function
|
|
861
|
+
this.on('end', function() {
|
|
843
862
|
debug('end');
|
|
844
863
|
process.removeListener('uncaughtException', uncaught);
|
|
845
864
|
fn(self.failures);
|
|
@@ -863,10 +882,12 @@ Runner.prototype.run = function (fn) {
|
|
|
863
882
|
/**
|
|
864
883
|
* Cleanly abort execution.
|
|
865
884
|
*
|
|
885
|
+
* @memberof Mocha.Runner
|
|
886
|
+
* @public
|
|
866
887
|
* @api public
|
|
867
888
|
* @return {Runner} Runner instance.
|
|
868
889
|
*/
|
|
869
|
-
Runner.prototype.abort = function
|
|
890
|
+
Runner.prototype.abort = function() {
|
|
870
891
|
debug('aborting');
|
|
871
892
|
this._abort = true;
|
|
872
893
|
|
|
@@ -880,7 +901,7 @@ Runner.prototype.abort = function () {
|
|
|
880
901
|
* @returns {Boolean}
|
|
881
902
|
* @api private
|
|
882
903
|
*/
|
|
883
|
-
function filterOnly
|
|
904
|
+
function filterOnly(suite) {
|
|
884
905
|
if (suite._onlyTests.length) {
|
|
885
906
|
// If the suite contains `only` tests, run those and ignore any nested suites.
|
|
886
907
|
suite.tests = suite._onlyTests;
|
|
@@ -888,7 +909,7 @@ function filterOnly (suite) {
|
|
|
888
909
|
} else {
|
|
889
910
|
// Otherwise, do not run any of the tests in this suite.
|
|
890
911
|
suite.tests = [];
|
|
891
|
-
suite._onlySuites.forEach(function
|
|
912
|
+
suite._onlySuites.forEach(function(onlySuite) {
|
|
892
913
|
// If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
|
|
893
914
|
// Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
|
|
894
915
|
if (hasOnly(onlySuite)) {
|
|
@@ -896,8 +917,10 @@ function filterOnly (suite) {
|
|
|
896
917
|
}
|
|
897
918
|
});
|
|
898
919
|
// Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
|
|
899
|
-
suite.suites = suite.suites.filter(function
|
|
900
|
-
return
|
|
920
|
+
suite.suites = suite.suites.filter(function(childSuite) {
|
|
921
|
+
return (
|
|
922
|
+
suite._onlySuites.indexOf(childSuite) !== -1 || filterOnly(childSuite)
|
|
923
|
+
);
|
|
901
924
|
});
|
|
902
925
|
}
|
|
903
926
|
// Keep the suite only if there is something to run
|
|
@@ -911,8 +934,12 @@ function filterOnly (suite) {
|
|
|
911
934
|
* @returns {Boolean}
|
|
912
935
|
* @api private
|
|
913
936
|
*/
|
|
914
|
-
function hasOnly
|
|
915
|
-
return
|
|
937
|
+
function hasOnly(suite) {
|
|
938
|
+
return (
|
|
939
|
+
suite._onlyTests.length ||
|
|
940
|
+
suite._onlySuites.length ||
|
|
941
|
+
suite.suites.some(hasOnly)
|
|
942
|
+
);
|
|
916
943
|
}
|
|
917
944
|
|
|
918
945
|
/**
|
|
@@ -923,8 +950,8 @@ function hasOnly (suite) {
|
|
|
923
950
|
* @param {Array} globals
|
|
924
951
|
* @return {Array}
|
|
925
952
|
*/
|
|
926
|
-
function filterLeaks
|
|
927
|
-
return globals.filter(function
|
|
953
|
+
function filterLeaks(ok, globals) {
|
|
954
|
+
return globals.filter(function(key) {
|
|
928
955
|
// Firefox and Chrome exposes iframes as index inside the window object
|
|
929
956
|
if (/^\d+/.test(key)) {
|
|
930
957
|
return false;
|
|
@@ -933,13 +960,13 @@ function filterLeaks (ok, globals) {
|
|
|
933
960
|
// in firefox
|
|
934
961
|
// if runner runs in an iframe, this iframe's window.getInterface method
|
|
935
962
|
// not init at first it is assigned in some seconds
|
|
936
|
-
if (global.navigator &&
|
|
963
|
+
if (global.navigator && /^getInterface/.test(key)) {
|
|
937
964
|
return false;
|
|
938
965
|
}
|
|
939
966
|
|
|
940
967
|
// an iframe could be approached by window[iframeIndex]
|
|
941
968
|
// in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
|
|
942
|
-
if (global.navigator &&
|
|
969
|
+
if (global.navigator && /^\d+/.test(key)) {
|
|
943
970
|
return false;
|
|
944
971
|
}
|
|
945
972
|
|
|
@@ -948,7 +975,7 @@ function filterLeaks (ok, globals) {
|
|
|
948
975
|
return false;
|
|
949
976
|
}
|
|
950
977
|
|
|
951
|
-
var matched = ok.filter(function
|
|
978
|
+
var matched = ok.filter(function(ok) {
|
|
952
979
|
if (~ok.indexOf('*')) {
|
|
953
980
|
return key.indexOf(ok.split('*')[0]) === 0;
|
|
954
981
|
}
|
|
@@ -964,16 +991,16 @@ function filterLeaks (ok, globals) {
|
|
|
964
991
|
* @return {Array}
|
|
965
992
|
* @api private
|
|
966
993
|
*/
|
|
967
|
-
function extraGlobals
|
|
994
|
+
function extraGlobals() {
|
|
968
995
|
if (typeof process === 'object' && typeof process.version === 'string') {
|
|
969
996
|
var parts = process.version.split('.');
|
|
970
|
-
var nodeVersion = parts.reduce(function
|
|
971
|
-
return a << 8 | v;
|
|
997
|
+
var nodeVersion = parts.reduce(function(a, v) {
|
|
998
|
+
return (a << 8) | v;
|
|
972
999
|
});
|
|
973
1000
|
|
|
974
1001
|
// 'errno' was renamed to process._errno in v0.9.11.
|
|
975
1002
|
|
|
976
|
-
if (nodeVersion <
|
|
1003
|
+
if (nodeVersion < 0x00090b) {
|
|
977
1004
|
return ['errno'];
|
|
978
1005
|
}
|
|
979
1006
|
}
|