Skip to content

Commit c9def14

Browse files
author
James Halliday
committedMay 2, 2013
no longer getting already closed errors by tracking the number of running tests
1 parent 365ceab commit c9def14

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed
 

‎lib/results.js

+10-13
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ module.exports = function (test) {
1616

1717
nextTick(function next () {
1818
var t = results.tests.shift();
19-
if (!t && results.subtests) return;
19+
if (!t && results.running) return;
2020
if (!t) return results.close();
21-
t.on('end', next);
2221
t.run();
2322
});
2423

@@ -31,13 +30,14 @@ function Results (stream) {
3130
this.pass = 0;
3231
this.stream = stream;
3332
this.tests = [];
34-
this.subtests = 0;
33+
this.running = 0;
3534
}
3635

3736
Results.prototype.push = function (t, parentT) {
3837
var self = this;
3938
var write = function (s) { self.stream.queue(s) };
4039
t.on('prerun', function () {
40+
self.running ++;
4141
write('# ' + t.name + '\n');
4242
});
4343
if (parentT) {
@@ -52,10 +52,9 @@ Results.prototype.push = function (t, parentT) {
5252
var subtests = 0;
5353
t.on('test', function (st) {
5454
subtests ++;
55-
self.subtests ++;
5655
st.on('end', function () {
56+
self.running --;
5757
subtests --;
58-
self.subtests --;
5958
if (subtests === 0 && !plan) t.emit('end');
6059
nextTick(function () { onend.call(t) });
6160
});
@@ -79,16 +78,14 @@ Results.prototype.push = function (t, parentT) {
7978
function onend () {
8079
if (this.ended) return;
8180
if (subtests !== 0) return;
82-
if (!plan && self.tests.length === 0) {
83-
nextTick(function () {
84-
if (!plan && self.tests.length === 0) {
85-
self.close();
86-
}
87-
});
81+
self.running --;
82+
83+
if (!self.running && self.tests.length === 0) {
84+
self.close();
8885
}
89-
else if (!plan && self.tests.length) {
86+
else if (!self.running) {
9087
var t = self.tests.shift();
91-
nextTick(function () { t.run() });
88+
t.run();
9289
}
9390
}
9491
};

0 commit comments

Comments
 (0)
Please sign in to comment.