mocha 5.1.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/bin/_mocha +82 -36
- 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 +7 -7
- package/lib/hook.js +5 -16
- package/lib/interfaces/bdd.js +12 -13
- package/lib/interfaces/common.js +18 -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 +56 -57
- package/lib/ms.js +7 -5
- package/lib/pending.js +1 -5
- package/lib/reporters/base.js +91 -63
- package/lib/reporters/doc.js +16 -8
- package/lib/reporters/dot.js +7 -7
- package/lib/reporters/html.js +74 -40
- package/lib/reporters/json-stream.js +7 -7
- package/lib/reporters/json.js +21 -19
- package/lib/reporters/landing.js +7 -7
- package/lib/reporters/list.js +9 -9
- package/lib/reporters/markdown.js +11 -11
- package/lib/reporters/min.js +2 -2
- package/lib/reporters/nyan.js +24 -24
- package/lib/reporters/progress.js +6 -6
- package/lib/reporters/spec.js +12 -10
- package/lib/reporters/tap.js +8 -8
- package/lib/reporters/xunit.js +41 -23
- package/lib/runnable.js +64 -62
- package/lib/runner.js +99 -78
- package/lib/suite.js +39 -33
- package/lib/test.js +9 -13
- package/lib/utils.js +131 -85
- package/mocha.js +1556 -1064
- package/package.json +32 -19
- package/images/error.png +0 -0
- package/images/ok.png +0 -0
package/lib/runner.js
CHANGED
|
@@ -63,7 +63,7 @@ module.exports = Runner;
|
|
|
63
63
|
* @param {boolean} [delay] Whether or not to delay execution of root suite
|
|
64
64
|
* until ready.
|
|
65
65
|
*/
|
|
66
|
-
function Runner
|
|
66
|
+
function Runner(suite, delay) {
|
|
67
67
|
var self = this;
|
|
68
68
|
this._globals = [];
|
|
69
69
|
this._abort = false;
|
|
@@ -72,10 +72,10 @@ function Runner (suite, delay) {
|
|
|
72
72
|
this.started = false;
|
|
73
73
|
this.total = suite.total();
|
|
74
74
|
this.failures = 0;
|
|
75
|
-
this.on('test end', function
|
|
75
|
+
this.on('test end', function(test) {
|
|
76
76
|
self.checkGlobals(test);
|
|
77
77
|
});
|
|
78
|
-
this.on('hook end', function
|
|
78
|
+
this.on('hook end', function(hook) {
|
|
79
79
|
self.checkGlobals(hook);
|
|
80
80
|
});
|
|
81
81
|
this._defaultGrep = /.*/;
|
|
@@ -107,7 +107,7 @@ inherits(Runner, EventEmitter);
|
|
|
107
107
|
* @param {boolean} invert
|
|
108
108
|
* @return {Runner} Runner instance.
|
|
109
109
|
*/
|
|
110
|
-
Runner.prototype.grep = function
|
|
110
|
+
Runner.prototype.grep = function(re, invert) {
|
|
111
111
|
debug('grep %s', re);
|
|
112
112
|
this._grep = re;
|
|
113
113
|
this._invert = invert;
|
|
@@ -125,11 +125,11 @@ Runner.prototype.grep = function (re, invert) {
|
|
|
125
125
|
* @param {Suite} suite
|
|
126
126
|
* @return {number}
|
|
127
127
|
*/
|
|
128
|
-
Runner.prototype.grepTotal = function
|
|
128
|
+
Runner.prototype.grepTotal = function(suite) {
|
|
129
129
|
var self = this;
|
|
130
130
|
var total = 0;
|
|
131
131
|
|
|
132
|
-
suite.eachTest(function
|
|
132
|
+
suite.eachTest(function(test) {
|
|
133
133
|
var match = self._grep.test(test.fullTitle());
|
|
134
134
|
if (self._invert) {
|
|
135
135
|
match = !match;
|
|
@@ -148,7 +148,7 @@ Runner.prototype.grepTotal = function (suite) {
|
|
|
148
148
|
* @return {Array}
|
|
149
149
|
* @api private
|
|
150
150
|
*/
|
|
151
|
-
Runner.prototype.globalProps = function
|
|
151
|
+
Runner.prototype.globalProps = function() {
|
|
152
152
|
var props = Object.keys(global);
|
|
153
153
|
|
|
154
154
|
// non-enumerables
|
|
@@ -171,7 +171,7 @@ Runner.prototype.globalProps = function () {
|
|
|
171
171
|
* @param {Array} arr
|
|
172
172
|
* @return {Runner} Runner instance.
|
|
173
173
|
*/
|
|
174
|
-
Runner.prototype.globals = function
|
|
174
|
+
Runner.prototype.globals = function(arr) {
|
|
175
175
|
if (!arguments.length) {
|
|
176
176
|
return this._globals;
|
|
177
177
|
}
|
|
@@ -185,7 +185,7 @@ Runner.prototype.globals = function (arr) {
|
|
|
185
185
|
*
|
|
186
186
|
* @api private
|
|
187
187
|
*/
|
|
188
|
-
Runner.prototype.checkGlobals = function
|
|
188
|
+
Runner.prototype.checkGlobals = function(test) {
|
|
189
189
|
if (this.ignoreLeaks) {
|
|
190
190
|
return;
|
|
191
191
|
}
|
|
@@ -207,7 +207,10 @@ Runner.prototype.checkGlobals = function (test) {
|
|
|
207
207
|
this._globals = this._globals.concat(leaks);
|
|
208
208
|
|
|
209
209
|
if (leaks.length > 1) {
|
|
210
|
-
this.fail(
|
|
210
|
+
this.fail(
|
|
211
|
+
test,
|
|
212
|
+
new Error('global leaks detected: ' + leaks.join(', ') + '')
|
|
213
|
+
);
|
|
211
214
|
} else if (leaks.length) {
|
|
212
215
|
this.fail(test, new Error('global leak detected: ' + leaks[0]));
|
|
213
216
|
}
|
|
@@ -220,7 +223,7 @@ Runner.prototype.checkGlobals = function (test) {
|
|
|
220
223
|
* @param {Test} test
|
|
221
224
|
* @param {Error} err
|
|
222
225
|
*/
|
|
223
|
-
Runner.prototype.fail = function
|
|
226
|
+
Runner.prototype.fail = function(test, err) {
|
|
224
227
|
if (test.isPending()) {
|
|
225
228
|
return;
|
|
226
229
|
}
|
|
@@ -229,18 +232,26 @@ Runner.prototype.fail = function (test, err) {
|
|
|
229
232
|
test.state = 'failed';
|
|
230
233
|
|
|
231
234
|
if (!(err instanceof Error || (err && typeof err.message === 'string'))) {
|
|
232
|
-
err = new Error(
|
|
235
|
+
err = new Error(
|
|
236
|
+
'the ' +
|
|
237
|
+
type(err) +
|
|
238
|
+
' ' +
|
|
239
|
+
stringify(err) +
|
|
240
|
+
' was thrown, throw an Error :)'
|
|
241
|
+
);
|
|
233
242
|
}
|
|
234
243
|
|
|
235
244
|
try {
|
|
236
|
-
err.stack =
|
|
237
|
-
? err.stack
|
|
238
|
-
|
|
239
|
-
} catch (ignored) {
|
|
245
|
+
err.stack =
|
|
246
|
+
this.fullStackTrace || !err.stack ? err.stack : stackFilter(err.stack);
|
|
247
|
+
} catch (ignore) {
|
|
240
248
|
// some environments do not take kindly to monkeying with the stack
|
|
241
249
|
}
|
|
242
250
|
|
|
243
251
|
this.emit('fail', test, err);
|
|
252
|
+
if (this.suite.bail()) {
|
|
253
|
+
this.emit('end');
|
|
254
|
+
}
|
|
244
255
|
};
|
|
245
256
|
|
|
246
257
|
/**
|
|
@@ -263,15 +274,13 @@ Runner.prototype.fail = function (test, err) {
|
|
|
263
274
|
* @param {Hook} hook
|
|
264
275
|
* @param {Error} err
|
|
265
276
|
*/
|
|
266
|
-
Runner.prototype.failHook = function
|
|
277
|
+
Runner.prototype.failHook = function(hook, err) {
|
|
267
278
|
if (hook.ctx && hook.ctx.currentTest) {
|
|
268
279
|
hook.originalTitle = hook.originalTitle || hook.title;
|
|
269
|
-
hook.title =
|
|
280
|
+
hook.title =
|
|
281
|
+
hook.originalTitle + ' for "' + hook.ctx.currentTest.title + '"';
|
|
270
282
|
}
|
|
271
283
|
|
|
272
|
-
if (this.suite.bail()) {
|
|
273
|
-
this.emit('end');
|
|
274
|
-
}
|
|
275
284
|
this.fail(hook, err);
|
|
276
285
|
};
|
|
277
286
|
|
|
@@ -283,12 +292,12 @@ Runner.prototype.failHook = function (hook, err) {
|
|
|
283
292
|
* @param {Function} fn
|
|
284
293
|
*/
|
|
285
294
|
|
|
286
|
-
Runner.prototype.hook = function
|
|
295
|
+
Runner.prototype.hook = function(name, fn) {
|
|
287
296
|
var suite = this.suite;
|
|
288
297
|
var hooks = suite['_' + name];
|
|
289
298
|
var self = this;
|
|
290
299
|
|
|
291
|
-
function next
|
|
300
|
+
function next(i) {
|
|
292
301
|
var hook = hooks[i];
|
|
293
302
|
if (!hook) {
|
|
294
303
|
return fn();
|
|
@@ -300,12 +309,12 @@ Runner.prototype.hook = function (name, fn) {
|
|
|
300
309
|
self.emit('hook', hook);
|
|
301
310
|
|
|
302
311
|
if (!hook.listeners('error').length) {
|
|
303
|
-
hook.on('error', function
|
|
312
|
+
hook.on('error', function(err) {
|
|
304
313
|
self.failHook(hook, err);
|
|
305
314
|
});
|
|
306
315
|
}
|
|
307
316
|
|
|
308
|
-
hook.run(function
|
|
317
|
+
hook.run(function(err) {
|
|
309
318
|
var testError = hook.error();
|
|
310
319
|
if (testError) {
|
|
311
320
|
self.fail(self.test, testError);
|
|
@@ -315,7 +324,7 @@ Runner.prototype.hook = function (name, fn) {
|
|
|
315
324
|
if (name === 'beforeEach' || name === 'afterEach') {
|
|
316
325
|
self.test.pending = true;
|
|
317
326
|
} else {
|
|
318
|
-
suite.tests.forEach(function
|
|
327
|
+
suite.tests.forEach(function(test) {
|
|
319
328
|
test.pending = true;
|
|
320
329
|
});
|
|
321
330
|
// a pending hook won't be executed twice.
|
|
@@ -334,7 +343,7 @@ Runner.prototype.hook = function (name, fn) {
|
|
|
334
343
|
});
|
|
335
344
|
}
|
|
336
345
|
|
|
337
|
-
Runner.immediately(function
|
|
346
|
+
Runner.immediately(function() {
|
|
338
347
|
next(0);
|
|
339
348
|
});
|
|
340
349
|
};
|
|
@@ -348,11 +357,11 @@ Runner.prototype.hook = function (name, fn) {
|
|
|
348
357
|
* @param {Array} suites
|
|
349
358
|
* @param {Function} fn
|
|
350
359
|
*/
|
|
351
|
-
Runner.prototype.hooks = function
|
|
360
|
+
Runner.prototype.hooks = function(name, suites, fn) {
|
|
352
361
|
var self = this;
|
|
353
362
|
var orig = this.suite;
|
|
354
363
|
|
|
355
|
-
function next
|
|
364
|
+
function next(suite) {
|
|
356
365
|
self.suite = suite;
|
|
357
366
|
|
|
358
367
|
if (!suite) {
|
|
@@ -360,7 +369,7 @@ Runner.prototype.hooks = function (name, suites, fn) {
|
|
|
360
369
|
return fn();
|
|
361
370
|
}
|
|
362
371
|
|
|
363
|
-
self.hook(name, function
|
|
372
|
+
self.hook(name, function(err) {
|
|
364
373
|
if (err) {
|
|
365
374
|
var errSuite = self.suite;
|
|
366
375
|
self.suite = orig;
|
|
@@ -381,7 +390,7 @@ Runner.prototype.hooks = function (name, suites, fn) {
|
|
|
381
390
|
* @param {Function} fn
|
|
382
391
|
* @api private
|
|
383
392
|
*/
|
|
384
|
-
Runner.prototype.hookUp = function
|
|
393
|
+
Runner.prototype.hookUp = function(name, fn) {
|
|
385
394
|
var suites = [this.suite].concat(this.parents()).reverse();
|
|
386
395
|
this.hooks(name, suites, fn);
|
|
387
396
|
};
|
|
@@ -393,7 +402,7 @@ Runner.prototype.hookUp = function (name, fn) {
|
|
|
393
402
|
* @param {Function} fn
|
|
394
403
|
* @api private
|
|
395
404
|
*/
|
|
396
|
-
Runner.prototype.hookDown = function
|
|
405
|
+
Runner.prototype.hookDown = function(name, fn) {
|
|
397
406
|
var suites = [this.suite].concat(this.parents());
|
|
398
407
|
this.hooks(name, suites, fn);
|
|
399
408
|
};
|
|
@@ -405,7 +414,7 @@ Runner.prototype.hookDown = function (name, fn) {
|
|
|
405
414
|
* @return {Array}
|
|
406
415
|
* @api private
|
|
407
416
|
*/
|
|
408
|
-
Runner.prototype.parents = function
|
|
417
|
+
Runner.prototype.parents = function() {
|
|
409
418
|
var suite = this.suite;
|
|
410
419
|
var suites = [];
|
|
411
420
|
while (suite.parent) {
|
|
@@ -421,7 +430,7 @@ Runner.prototype.parents = function () {
|
|
|
421
430
|
* @param {Function} fn
|
|
422
431
|
* @api private
|
|
423
432
|
*/
|
|
424
|
-
Runner.prototype.runTest = function
|
|
433
|
+
Runner.prototype.runTest = function(fn) {
|
|
425
434
|
var self = this;
|
|
426
435
|
var test = this.test;
|
|
427
436
|
|
|
@@ -435,7 +444,7 @@ Runner.prototype.runTest = function (fn) {
|
|
|
435
444
|
if (this.asyncOnly) {
|
|
436
445
|
test.asyncOnly = true;
|
|
437
446
|
}
|
|
438
|
-
test.on('error', function
|
|
447
|
+
test.on('error', function(err) {
|
|
439
448
|
self.fail(test, err);
|
|
440
449
|
});
|
|
441
450
|
if (this.allowUncaught) {
|
|
@@ -456,12 +465,12 @@ Runner.prototype.runTest = function (fn) {
|
|
|
456
465
|
* @param {Suite} suite
|
|
457
466
|
* @param {Function} fn
|
|
458
467
|
*/
|
|
459
|
-
Runner.prototype.runTests = function
|
|
468
|
+
Runner.prototype.runTests = function(suite, fn) {
|
|
460
469
|
var self = this;
|
|
461
470
|
var tests = suite.tests.slice();
|
|
462
471
|
var test;
|
|
463
472
|
|
|
464
|
-
function hookErr
|
|
473
|
+
function hookErr(_, errSuite, after) {
|
|
465
474
|
// before/after Each hook for errSuite failed:
|
|
466
475
|
var orig = self.suite;
|
|
467
476
|
|
|
@@ -471,7 +480,7 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
471
480
|
|
|
472
481
|
if (self.suite) {
|
|
473
482
|
// call hookUp afterEach
|
|
474
|
-
self.hookUp('afterEach', function
|
|
483
|
+
self.hookUp('afterEach', function(err2, errSuite2) {
|
|
475
484
|
self.suite = orig;
|
|
476
485
|
// some hooks may fail even now
|
|
477
486
|
if (err2) {
|
|
@@ -487,7 +496,7 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
487
496
|
}
|
|
488
497
|
}
|
|
489
498
|
|
|
490
|
-
function next
|
|
499
|
+
function next(err, errSuite) {
|
|
491
500
|
// if we bail after first err
|
|
492
501
|
if (self.failures && suite._bail) {
|
|
493
502
|
return fn();
|
|
@@ -544,8 +553,8 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
544
553
|
}
|
|
545
554
|
|
|
546
555
|
// execute test and hook(s)
|
|
547
|
-
self.emit('test', self.test = test);
|
|
548
|
-
self.hookDown('beforeEach', function
|
|
556
|
+
self.emit('test', (self.test = test));
|
|
557
|
+
self.hookDown('beforeEach', function(err, errSuite) {
|
|
549
558
|
if (test.isPending()) {
|
|
550
559
|
if (self.forbidPending) {
|
|
551
560
|
test.isPending = alwaysFalse;
|
|
@@ -561,7 +570,7 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
561
570
|
return hookErr(err, errSuite, false);
|
|
562
571
|
}
|
|
563
572
|
self.currentRunnable = self.test;
|
|
564
|
-
self.runTest(function
|
|
573
|
+
self.runTest(function(err) {
|
|
565
574
|
test = self.test;
|
|
566
575
|
if (err) {
|
|
567
576
|
var retry = test.currentRetry();
|
|
@@ -603,7 +612,7 @@ Runner.prototype.runTests = function (suite, fn) {
|
|
|
603
612
|
next();
|
|
604
613
|
};
|
|
605
614
|
|
|
606
|
-
function alwaysFalse
|
|
615
|
+
function alwaysFalse() {
|
|
607
616
|
return false;
|
|
608
617
|
}
|
|
609
618
|
|
|
@@ -614,7 +623,7 @@ function alwaysFalse () {
|
|
|
614
623
|
* @param {Suite} suite
|
|
615
624
|
* @param {Function} fn
|
|
616
625
|
*/
|
|
617
|
-
Runner.prototype.runSuite = function
|
|
626
|
+
Runner.prototype.runSuite = function(suite, fn) {
|
|
618
627
|
var i = 0;
|
|
619
628
|
var self = this;
|
|
620
629
|
var total = this.grepTotal(suite);
|
|
@@ -626,9 +635,9 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
626
635
|
return fn();
|
|
627
636
|
}
|
|
628
637
|
|
|
629
|
-
this.emit('suite', this.suite = suite);
|
|
638
|
+
this.emit('suite', (this.suite = suite));
|
|
630
639
|
|
|
631
|
-
function next
|
|
640
|
+
function next(errSuite) {
|
|
632
641
|
if (errSuite) {
|
|
633
642
|
// current suite failed on a hook from errSuite
|
|
634
643
|
if (errSuite === suite) {
|
|
@@ -654,7 +663,7 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
654
663
|
// huge recursive loop and thus a maximum call stack error.
|
|
655
664
|
// See comment in `this.runTests()` for more information.
|
|
656
665
|
if (self._grep !== self._defaultGrep) {
|
|
657
|
-
Runner.immediately(function
|
|
666
|
+
Runner.immediately(function() {
|
|
658
667
|
self.runSuite(curr, next);
|
|
659
668
|
});
|
|
660
669
|
} else {
|
|
@@ -662,7 +671,7 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
662
671
|
}
|
|
663
672
|
}
|
|
664
673
|
|
|
665
|
-
function done
|
|
674
|
+
function done(errSuite) {
|
|
666
675
|
self.suite = suite;
|
|
667
676
|
self.nextSuite = next;
|
|
668
677
|
|
|
@@ -676,7 +685,7 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
676
685
|
// remove reference to test
|
|
677
686
|
delete self.test;
|
|
678
687
|
|
|
679
|
-
self.hook('afterAll', function
|
|
688
|
+
self.hook('afterAll', function() {
|
|
680
689
|
self.emit('suite end', suite);
|
|
681
690
|
fn(errSuite);
|
|
682
691
|
});
|
|
@@ -685,7 +694,7 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
685
694
|
|
|
686
695
|
this.nextSuite = next;
|
|
687
696
|
|
|
688
|
-
this.hook('beforeAll', function
|
|
697
|
+
this.hook('beforeAll', function(err) {
|
|
689
698
|
if (err) {
|
|
690
699
|
return done();
|
|
691
700
|
}
|
|
@@ -699,11 +708,17 @@ Runner.prototype.runSuite = function (suite, fn) {
|
|
|
699
708
|
* @param {Error} err
|
|
700
709
|
* @api private
|
|
701
710
|
*/
|
|
702
|
-
Runner.prototype.uncaught = function
|
|
711
|
+
Runner.prototype.uncaught = function(err) {
|
|
703
712
|
if (err) {
|
|
704
|
-
debug(
|
|
705
|
-
|
|
706
|
-
|
|
713
|
+
debug(
|
|
714
|
+
'uncaught exception %s',
|
|
715
|
+
err ===
|
|
716
|
+
function() {
|
|
717
|
+
return this;
|
|
718
|
+
}.call(err)
|
|
719
|
+
? err.message || err
|
|
720
|
+
: err
|
|
721
|
+
);
|
|
707
722
|
} else {
|
|
708
723
|
debug('uncaught undefined exception');
|
|
709
724
|
err = undefinedError();
|
|
@@ -776,8 +791,8 @@ Runner.prototype.uncaught = function (err) {
|
|
|
776
791
|
*
|
|
777
792
|
* @param {Suite} suite
|
|
778
793
|
*/
|
|
779
|
-
function cleanSuiteReferences
|
|
780
|
-
function cleanArrReferences
|
|
794
|
+
function cleanSuiteReferences(suite) {
|
|
795
|
+
function cleanArrReferences(arr) {
|
|
781
796
|
for (var i = 0; i < arr.length; i++) {
|
|
782
797
|
delete arr[i].fn;
|
|
783
798
|
}
|
|
@@ -814,24 +829,24 @@ function cleanSuiteReferences (suite) {
|
|
|
814
829
|
* @param {Function} fn
|
|
815
830
|
* @return {Runner} Runner instance.
|
|
816
831
|
*/
|
|
817
|
-
Runner.prototype.run = function
|
|
832
|
+
Runner.prototype.run = function(fn) {
|
|
818
833
|
var self = this;
|
|
819
834
|
var rootSuite = this.suite;
|
|
820
835
|
|
|
821
|
-
fn = fn || function
|
|
836
|
+
fn = fn || function() {};
|
|
822
837
|
|
|
823
|
-
function uncaught
|
|
838
|
+
function uncaught(err) {
|
|
824
839
|
self.uncaught(err);
|
|
825
840
|
}
|
|
826
841
|
|
|
827
|
-
function start
|
|
842
|
+
function start() {
|
|
828
843
|
// If there is an `only` filter
|
|
829
844
|
if (hasOnly(rootSuite)) {
|
|
830
845
|
filterOnly(rootSuite);
|
|
831
846
|
}
|
|
832
847
|
self.started = true;
|
|
833
848
|
self.emit('start');
|
|
834
|
-
self.runSuite(rootSuite, function
|
|
849
|
+
self.runSuite(rootSuite, function() {
|
|
835
850
|
debug('finished running');
|
|
836
851
|
self.emit('end');
|
|
837
852
|
});
|
|
@@ -843,7 +858,7 @@ Runner.prototype.run = function (fn) {
|
|
|
843
858
|
this.on('suite end', cleanSuiteReferences);
|
|
844
859
|
|
|
845
860
|
// callback
|
|
846
|
-
this.on('end', function
|
|
861
|
+
this.on('end', function() {
|
|
847
862
|
debug('end');
|
|
848
863
|
process.removeListener('uncaughtException', uncaught);
|
|
849
864
|
fn(self.failures);
|
|
@@ -872,7 +887,7 @@ Runner.prototype.run = function (fn) {
|
|
|
872
887
|
* @api public
|
|
873
888
|
* @return {Runner} Runner instance.
|
|
874
889
|
*/
|
|
875
|
-
Runner.prototype.abort = function
|
|
890
|
+
Runner.prototype.abort = function() {
|
|
876
891
|
debug('aborting');
|
|
877
892
|
this._abort = true;
|
|
878
893
|
|
|
@@ -886,7 +901,7 @@ Runner.prototype.abort = function () {
|
|
|
886
901
|
* @returns {Boolean}
|
|
887
902
|
* @api private
|
|
888
903
|
*/
|
|
889
|
-
function filterOnly
|
|
904
|
+
function filterOnly(suite) {
|
|
890
905
|
if (suite._onlyTests.length) {
|
|
891
906
|
// If the suite contains `only` tests, run those and ignore any nested suites.
|
|
892
907
|
suite.tests = suite._onlyTests;
|
|
@@ -894,7 +909,7 @@ function filterOnly (suite) {
|
|
|
894
909
|
} else {
|
|
895
910
|
// Otherwise, do not run any of the tests in this suite.
|
|
896
911
|
suite.tests = [];
|
|
897
|
-
suite._onlySuites.forEach(function
|
|
912
|
+
suite._onlySuites.forEach(function(onlySuite) {
|
|
898
913
|
// If there are other `only` tests/suites nested in the current `only` suite, then filter that `only` suite.
|
|
899
914
|
// Otherwise, all of the tests on this `only` suite should be run, so don't filter it.
|
|
900
915
|
if (hasOnly(onlySuite)) {
|
|
@@ -902,8 +917,10 @@ function filterOnly (suite) {
|
|
|
902
917
|
}
|
|
903
918
|
});
|
|
904
919
|
// Run the `only` suites, as well as any other suites that have `only` tests/suites as descendants.
|
|
905
|
-
suite.suites = suite.suites.filter(function
|
|
906
|
-
return
|
|
920
|
+
suite.suites = suite.suites.filter(function(childSuite) {
|
|
921
|
+
return (
|
|
922
|
+
suite._onlySuites.indexOf(childSuite) !== -1 || filterOnly(childSuite)
|
|
923
|
+
);
|
|
907
924
|
});
|
|
908
925
|
}
|
|
909
926
|
// Keep the suite only if there is something to run
|
|
@@ -917,8 +934,12 @@ function filterOnly (suite) {
|
|
|
917
934
|
* @returns {Boolean}
|
|
918
935
|
* @api private
|
|
919
936
|
*/
|
|
920
|
-
function hasOnly
|
|
921
|
-
return
|
|
937
|
+
function hasOnly(suite) {
|
|
938
|
+
return (
|
|
939
|
+
suite._onlyTests.length ||
|
|
940
|
+
suite._onlySuites.length ||
|
|
941
|
+
suite.suites.some(hasOnly)
|
|
942
|
+
);
|
|
922
943
|
}
|
|
923
944
|
|
|
924
945
|
/**
|
|
@@ -929,8 +950,8 @@ function hasOnly (suite) {
|
|
|
929
950
|
* @param {Array} globals
|
|
930
951
|
* @return {Array}
|
|
931
952
|
*/
|
|
932
|
-
function filterLeaks
|
|
933
|
-
return globals.filter(function
|
|
953
|
+
function filterLeaks(ok, globals) {
|
|
954
|
+
return globals.filter(function(key) {
|
|
934
955
|
// Firefox and Chrome exposes iframes as index inside the window object
|
|
935
956
|
if (/^\d+/.test(key)) {
|
|
936
957
|
return false;
|
|
@@ -939,13 +960,13 @@ function filterLeaks (ok, globals) {
|
|
|
939
960
|
// in firefox
|
|
940
961
|
// if runner runs in an iframe, this iframe's window.getInterface method
|
|
941
962
|
// not init at first it is assigned in some seconds
|
|
942
|
-
if (global.navigator &&
|
|
963
|
+
if (global.navigator && /^getInterface/.test(key)) {
|
|
943
964
|
return false;
|
|
944
965
|
}
|
|
945
966
|
|
|
946
967
|
// an iframe could be approached by window[iframeIndex]
|
|
947
968
|
// in ie6,7,8 and opera, iframeIndex is enumerable, this could cause leak
|
|
948
|
-
if (global.navigator &&
|
|
969
|
+
if (global.navigator && /^\d+/.test(key)) {
|
|
949
970
|
return false;
|
|
950
971
|
}
|
|
951
972
|
|
|
@@ -954,7 +975,7 @@ function filterLeaks (ok, globals) {
|
|
|
954
975
|
return false;
|
|
955
976
|
}
|
|
956
977
|
|
|
957
|
-
var matched = ok.filter(function
|
|
978
|
+
var matched = ok.filter(function(ok) {
|
|
958
979
|
if (~ok.indexOf('*')) {
|
|
959
980
|
return key.indexOf(ok.split('*')[0]) === 0;
|
|
960
981
|
}
|
|
@@ -970,16 +991,16 @@ function filterLeaks (ok, globals) {
|
|
|
970
991
|
* @return {Array}
|
|
971
992
|
* @api private
|
|
972
993
|
*/
|
|
973
|
-
function extraGlobals
|
|
994
|
+
function extraGlobals() {
|
|
974
995
|
if (typeof process === 'object' && typeof process.version === 'string') {
|
|
975
996
|
var parts = process.version.split('.');
|
|
976
|
-
var nodeVersion = parts.reduce(function
|
|
977
|
-
return a << 8 | v;
|
|
997
|
+
var nodeVersion = parts.reduce(function(a, v) {
|
|
998
|
+
return (a << 8) | v;
|
|
978
999
|
});
|
|
979
1000
|
|
|
980
1001
|
// 'errno' was renamed to process._errno in v0.9.11.
|
|
981
1002
|
|
|
982
|
-
if (nodeVersion <
|
|
1003
|
+
if (nodeVersion < 0x00090b) {
|
|
983
1004
|
return ['errno'];
|
|
984
1005
|
}
|
|
985
1006
|
}
|