Skip to content

Commit

Permalink
child ordering output is now correct
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 2, 2013
1 parent 8a80302 commit 5544d26
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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) {
Expand All @@ -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();
}
}
};
Expand Down

0 comments on commit 5544d26

Please sign in to comment.