diff --git a/lib/results.js b/lib/results.js index af63ef6b..961ffde3 100644 --- a/lib/results.js +++ b/lib/results.js @@ -20,9 +20,8 @@ module.exports = function () { nextTick(function next () { var t = getNextTest(results); - if (!t && results.running) return; - if (!t) return results.close(); - t.run(); + if (t) t.run(); + else results.close(); }); return output; @@ -34,52 +33,26 @@ function Results (stream) { this.pass = 0; this.stream = stream; this.tests = []; - this.running = 0; } -Results.prototype.push = function (t, parentT) { +Results.prototype.push = function (t) { + var self = this; + self.tests.push(t); + self._watch(t); + t.once('end', function () { + var nt = getNextTest(self); + if (nt) nt.run(); + else self.close(); + }); +}; + +Results.prototype._watch = function (t) { var self = this; var write = function (s) { self.stream.queue(s) }; t.once('prerun', function () { - if (self.only && self.only !== t.name && !parentT) { - var nt = getNextTest(self); - if (nt) nt.run() - else self.close(); - return; - } - - self.running ++; write('# ' + t.name + '\n'); }); - if (parentT) { - var ix = self.tests.indexOf(parentT); - if (ix >= 0) self.tests.splice(ix, 0, t); - } - else self.tests.push(t); - - var plan; - 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) { - if (plan === undefined) st.run(); - else nextTick(function () { - st.run(); - }); - } - }); - + t.on('result', function (res) { if (typeof res === 'string') { write('# ' + res + '\n'); @@ -91,27 +64,9 @@ Results.prototype.push = function (t, parentT) { if (res.ok) self.pass ++ else self.fail ++ }); - - t.once('end', function () { - if (t._skip) { - var nt = getNextTest(self); - if (nt) nt.run(); - else self.close(); - return; - } - - self.running --; - if (subtests !== 0) return; - - if (self.running === 0 && self.tests.length) { - var nt = getNextTest(self); - if (nt) nt.run(); - else self.close(); - } - else if (self.running === 0) { - self.close(); - } - }); + + t.on('test', function (st) { self._watch(st) }); + t.on('next', function (st) { st.run() }); }; Results.prototype.close = function () { diff --git a/lib/test.js b/lib/test.js index 435c39f2..c53abb5a 100644 --- a/lib/test.js +++ b/lib/test.js @@ -79,6 +79,7 @@ Test.prototype.end = function () { if (this._progeny.length) { var t = this._progeny.shift(); t.on('end', function () { self.end() }); + this.emit('next', t); return; }