Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #105: only use one test runner for results, even if multiple streams are created #404

Merged
merged 2 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});
});