Skip to content

Commit

Permalink
wip - only-modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage committed Nov 17, 2015
1 parent 2d36b51 commit 4568347
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 26 additions & 10 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ function Runner(opts) {

this.results = [];

this.stats = {
failCount: 0,
testCount: 0
};

this.tests = {
concurrent: [],
serial: [],
Expand All @@ -43,12 +38,10 @@ util.inherits(Runner, EventEmitter);
module.exports = Runner;

Runner.prototype.addTest = function (title, cb) {
this.stats.testCount++;
this.tests.concurrent.push(new Test(title, cb));
};

Runner.prototype.addSerialTest = function (title, cb) {
this.stats.testCount++;
this.tests.serial.push(new Test(title, cb));
};

Expand Down Expand Up @@ -182,12 +175,35 @@ Runner.prototype._addTestResult = function (test) {
this.emit('test', props);
};

function isExclusive(test) {
return test.exclusive;
}

function isUnskipped(test) {
return !test.skip;
}

Runner.prototype.run = function () {
var self = this;
var tests = this.tests;
var stats = this.stats;
var serial = tests.serial;
var concurrent = tests.concurrent;
var hasExclusive = tests.concurrent.some(isExclusive) || tests.serial.some(isExclusive);
if (hasExclusive) {
serial = serial.filter(isExclusive);
concurrent = concurrent.filter(isExclusive);
} else {
serial = serial.filter(isUnskipped);
concurrent = concurrent.filter(isUnskipped);
}

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

// Runner is executed directly in tests, in that case process.send() == undefined
// TODO (jamestalmage): We do not have a failCount yet. Why are we sending now?
if (process.send) {
process.send({
name: 'stats',
Expand All @@ -203,10 +219,10 @@ Runner.prototype.run = function () {
}
})
.then(function () {
return self.serial(tests.serial);
return self.serial(serial);
})
.then(function () {
return self.concurrent(tests.concurrent);
return self.concurrent(concurrent);
})
.then(function () {
return eachSeries(tests.after, self._runTest.bind(self));
Expand Down
4 changes: 2 additions & 2 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ test('returns new instance of runner without "new"', function (t) {
test('runner.addTest adds a new test', function (t) {
var runner = new Runner();
runner.addTest(mockTitle, noop);
t.equal(runner.stats.testCount, 1);
// t.equal(runner.stats.testCount, 1);
t.equal(runner.tests.concurrent.length, 1);
t.ok(runner.tests.concurrent[0] instanceof Test);
t.end();
Expand All @@ -23,7 +23,7 @@ test('runner.addTest adds a new test', function (t) {
test('runner.addSerialTest adds a new serial test', function (t) {
var runner = new Runner();
runner.addSerialTest(mockTitle, noop);
t.equal(runner.stats.testCount, 1);
// t.equal(runner.stats.testCount, 1);
t.equal(runner.tests.serial.length, 1);
t.ok(runner.tests.serial[0] instanceof Test);
t.end();
Expand Down

0 comments on commit 4568347

Please sign in to comment.