Skip to content

Commit

Permalink
Runner: use more efficient method to build list of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Jan 21, 2016
1 parent ea551c7 commit 4e23943
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function Runner(opts) {
this.results = [];
this.tests = [];
this.testsByType = {};
this.hasExclusive = false;
}

util.inherits(Runner, EventEmitter);
Expand All @@ -67,6 +68,9 @@ Runner.prototype._addTest = function (test) {
var type = test.metadata.type;
var tests = this.testsByType[type] || (this.testsByType[type] = []);
tests.push(test);
if (test.metadata.exclusive) {
this.hasExclusive = true;
}
};

Runner.prototype._runTestWithHooks = function (test) {
Expand Down Expand Up @@ -144,33 +148,24 @@ Runner.prototype._addTestResult = function (test) {
Runner.prototype.run = function () {
var self = this;

var hasExclusive = this.select({
exclusive: true,
skipped: false,
type: 'test'
}).length > 0;

var serial = this.select({
exclusive: hasExclusive,
serial: true,
type: 'test'
});

var concurrent = this.select({
exclusive: hasExclusive,
serial: false,
type: 'test'
});
var serial = [];
var concurrent = [];
var skipCount = 0;

var skipped = this.select({
type: 'test',
skipped: true
});
this.testsByType.test.forEach(function (test) {
var metadata = test.metadata;
if (metadata.exclusive === this.hasExclusive) {
(metadata.serial ? serial : concurrent).push(test);
if (metadata.skipped) {
skipCount++;
}
}
}, this);

var stats = this.stats = {
failCount: 0,
passCount: 0,
testCount: serial.length + concurrent.length - skipped.length
testCount: serial.length + concurrent.length - skipCount
};

return eachSeries(this.select({type: 'before'}), this._runTest, this)
Expand Down

0 comments on commit 4e23943

Please sign in to comment.