diff --git a/lib/results.js b/lib/results.js index 18d6a5d6..6c39d4f7 100644 --- a/lib/results.js +++ b/lib/results.js @@ -47,9 +47,9 @@ Results.prototype.push = function (t) { t.on('test', function (st) { subtests ++; st.on('end', function () { - nextTick(function () { - if (--subtests === 0 && !plan) t.emit('end'); - }); + subtests --; + if (subtests === 0 && !plan) t.emit('end'); + onend(); }); self.push(st); }); @@ -66,13 +66,15 @@ Results.prototype.push = function (t) { else self.fail ++ }); - t.on('end', function () { + t.on('end', onend); + + function onend () { nextTick(function () { - if (subtests === 0) return; + if (subtests !== 0) return; if (self.tests.length === 0) self.close(); else self.tests.shift().run(); }); - }); + } }; Results.prototype.close = function () {