Skip to content

Commit

Permalink
no longer getting already closed errors by tracking the number of run…
Browse files Browse the repository at this point in the history
…ning tests
  • Loading branch information
James Halliday committed May 2, 2013
1 parent 365ceab commit c9def14
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ module.exports = function (test) {

nextTick(function next () {
var t = results.tests.shift();
if (!t && results.subtests) return;
if (!t && results.running) return;
if (!t) return results.close();
t.on('end', next);
t.run();
});

Expand All @@ -31,13 +30,14 @@ function Results (stream) {
this.pass = 0;
this.stream = stream;
this.tests = [];
this.subtests = 0;
this.running = 0;
}

Results.prototype.push = function (t, parentT) {
var self = this;
var write = function (s) { self.stream.queue(s) };
t.on('prerun', function () {
self.running ++;
write('# ' + t.name + '\n');
});
if (parentT) {
Expand All @@ -52,10 +52,9 @@ Results.prototype.push = function (t, parentT) {
var subtests = 0;
t.on('test', function (st) {
subtests ++;
self.subtests ++;
st.on('end', function () {
self.running --;
subtests --;
self.subtests --;
if (subtests === 0 && !plan) t.emit('end');
nextTick(function () { onend.call(t) });
});
Expand All @@ -79,16 +78,14 @@ Results.prototype.push = function (t, parentT) {
function onend () {
if (this.ended) return;
if (subtests !== 0) return;
if (!plan && self.tests.length === 0) {
nextTick(function () {
if (!plan && self.tests.length === 0) {
self.close();
}
});
self.running --;

if (!self.running && self.tests.length === 0) {
self.close();
}
else if (!plan && self.tests.length) {
else if (!self.running) {
var t = self.tests.shift();
nextTick(function () { t.run() });
t.run();
}
}
};
Expand Down

0 comments on commit c9def14

Please sign in to comment.