Skip to content

Commit

Permalink
Merge pull request #404 from nhamer/issue105
Browse files Browse the repository at this point in the history
[Fix]: only use one test runner for results, even if multiple streams are created

Fixes #105.
  • Loading branch information
ljharb committed Jan 28, 2019
2 parents fb548b3 + fa586b4 commit 614c4d0
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function Results () {
this._stream = through();
this.tests = [];
this._only = null;
this._isRunning = false;
}

Results.prototype.createStream = function (opts) {
Expand Down Expand Up @@ -65,14 +66,17 @@ Results.prototype.createStream = function (opts) {
self._stream.pipe(output);
}

nextTick(function next() {
var t;
while (t = getNextTest(self)) {
t.run();
if (!t.ended) return t.once('end', function(){ nextTick(next); });
}
self.emit('done');
});
if (!this._isRunning) {
this._isRunning = true;
nextTick(function next() {
var t;
while (t = getNextTest(self)) {
t.run();
if (!t.ended) return t.once('end', function(){ nextTick(next); });
}
self.emit('done');
});
}

return output;
};
Expand Down
31 changes: 31 additions & 0 deletions test/create_multiple_streams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var tape = require('../');

tape.test('createMultipleStreams', function(tt) {
tt.plan(2);

var th = tape.createHarness();
th.createStream()
th.createStream()

var testOneComplete = false;

th('test one', function (tht) {
tht.plan(1);
setTimeout( function() {
tht.pass();
testOneComplete = true;
}, 100);
});

th('test two', function (tht) {
tht.ok(testOneComplete, 'test 1 completed before test 2');
tht.end();
});

th.onFinish(function() {
tt.equal(th._results.count, 2, "harness test ran");
tt.equal(th._results.fail, 0, "harness test didn't fail");
});
});


0 comments on commit 614c4d0

Please sign in to comment.