diff --git a/lib/results.js b/lib/results.js index eeca57fa..eefc8a8d 100644 --- a/lib/results.js +++ b/lib/results.js @@ -36,7 +36,7 @@ function Results (stream) { Results.prototype.push = function (t, parentT) { var self = this; var write = function (s) { self.stream.queue(s) }; - t.on('prerun', function () { + t.once('prerun', function () { self.running ++; write('# ' + t.name + '\n'); }); @@ -50,13 +50,18 @@ Results.prototype.push = function (t, parentT) { t.on('plan', function (n) { plan = n }); var subtests = 0; + t.on('test', function (st) { subtests ++; st.on('end', function () { subtests --; + if (subtests === 1) nextTick(function () { st.run() }); + else if (subtests === 0 && !t.ended) { + t.end(); + } }); self.push(st, t); - if (subtests === 1) nextTick(function () { st.run() }); + if (subtests === 1) st.run(); }); t.on('result', function (res) { @@ -70,19 +75,18 @@ Results.prototype.push = function (t, parentT) { if (res.ok) self.pass ++ else self.fail ++ }); - t.on('end', onend); + t.once('end', onend); function onend () { - if (this.ended) return; - if (subtests !== 0) return; self.running --; + if (subtests !== 0) return; - if (self.running === 0 && self.tests.length === 0) { - self.close(); + if (self.running === 0 && self.tests.length) { + var nt = self.tests.shift(); + nt.run(); } else if (self.running === 0) { - var t = self.tests.shift(); - t.run(); + self.close(); } } };