Skip to content

Commit 614c4d0

Browse files
authored
Merge pull request #404 from nhamer/issue105
[Fix]: only use one test runner for results, even if multiple streams are created Fixes #105.
2 parents fb548b3 + fa586b4 commit 614c4d0

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed

lib/results.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function Results () {
2424
this._stream = through();
2525
this.tests = [];
2626
this._only = null;
27+
this._isRunning = false;
2728
}
2829

2930
Results.prototype.createStream = function (opts) {
@@ -65,14 +66,17 @@ Results.prototype.createStream = function (opts) {
6566
self._stream.pipe(output);
6667
}
6768

68-
nextTick(function next() {
69-
var t;
70-
while (t = getNextTest(self)) {
71-
t.run();
72-
if (!t.ended) return t.once('end', function(){ nextTick(next); });
73-
}
74-
self.emit('done');
75-
});
69+
if (!this._isRunning) {
70+
this._isRunning = true;
71+
nextTick(function next() {
72+
var t;
73+
while (t = getNextTest(self)) {
74+
t.run();
75+
if (!t.ended) return t.once('end', function(){ nextTick(next); });
76+
}
77+
self.emit('done');
78+
});
79+
}
7680

7781
return output;
7882
};

test/create_multiple_streams.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
var tape = require('../');
2+
3+
tape.test('createMultipleStreams', function(tt) {
4+
tt.plan(2);
5+
6+
var th = tape.createHarness();
7+
th.createStream()
8+
th.createStream()
9+
10+
var testOneComplete = false;
11+
12+
th('test one', function (tht) {
13+
tht.plan(1);
14+
setTimeout( function() {
15+
tht.pass();
16+
testOneComplete = true;
17+
}, 100);
18+
});
19+
20+
th('test two', function (tht) {
21+
tht.ok(testOneComplete, 'test 1 completed before test 2');
22+
tht.end();
23+
});
24+
25+
th.onFinish(function() {
26+
tt.equal(th._results.count, 2, "harness test ran");
27+
tt.equal(th._results.fail, 0, "harness test didn't fail");
28+
});
29+
});
30+
31+

0 commit comments

Comments
 (0)