diff --git a/lib/results.js b/lib/results.js index af6ae188..8aca786e 100644 --- a/lib/results.js +++ b/lib/results.js @@ -16,8 +16,9 @@ module.exports = function (test) { nextTick(function next () { var t = results.tests.shift(); + if (!t && results.subtests) return; if (!t) return results.close(); - t.on('end', function () { nextTick(next) }); + t.on('end', next); t.run(); }); @@ -30,6 +31,7 @@ function Results (stream) { this.pass = 0; this.stream = stream; this.tests = []; + this.subtests = 0; } Results.prototype.push = function (t, parentT) { @@ -50,8 +52,10 @@ Results.prototype.push = function (t, parentT) { var subtests = 0; t.on('test', function (st) { subtests ++; + self.subtests ++; st.on('end', function () { subtests --; + self.subtests --; if (subtests === 0 && !plan) t.emit('end'); nextTick(function () { onend.call(t) }); });