Skip to content

Commit 5544d26

Browse files
author
James Halliday
committed
child ordering output is now correct
1 parent 8a80302 commit 5544d26

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/results.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function Results (stream) {
3636
Results.prototype.push = function (t, parentT) {
3737
var self = this;
3838
var write = function (s) { self.stream.queue(s) };
39-
t.on('prerun', function () {
39+
t.once('prerun', function () {
4040
self.running ++;
4141
write('# ' + t.name + '\n');
4242
});
@@ -50,13 +50,18 @@ Results.prototype.push = function (t, parentT) {
5050
t.on('plan', function (n) { plan = n });
5151

5252
var subtests = 0;
53+
5354
t.on('test', function (st) {
5455
subtests ++;
5556
st.on('end', function () {
5657
subtests --;
58+
if (subtests === 1) nextTick(function () { st.run() });
59+
else if (subtests === 0 && !t.ended) {
60+
t.end();
61+
}
5762
});
5863
self.push(st, t);
59-
if (subtests === 1) nextTick(function () { st.run() });
64+
if (subtests === 1) st.run();
6065
});
6166

6267
t.on('result', function (res) {
@@ -70,19 +75,18 @@ Results.prototype.push = function (t, parentT) {
7075
if (res.ok) self.pass ++
7176
else self.fail ++
7277
});
73-
t.on('end', onend);
78+
t.once('end', onend);
7479

7580
function onend () {
76-
if (this.ended) return;
77-
if (subtests !== 0) return;
7881
self.running --;
82+
if (subtests !== 0) return;
7983

80-
if (self.running === 0 && self.tests.length === 0) {
81-
self.close();
84+
if (self.running === 0 && self.tests.length) {
85+
var nt = self.tests.shift();
86+
nt.run();
8287
}
8388
else if (self.running === 0) {
84-
var t = self.tests.shift();
85-
t.run();
89+
self.close();
8690
}
8791
}
8892
};

0 commit comments

Comments
 (0)