Skip to content

Commit

Permalink
fixed for the two example
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed May 1, 2013
1 parent 6252fd2 commit 0ac88b8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
18 changes: 18 additions & 0 deletions example/two.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var test = require('../');

test('one', function (t) {
t.plan(2);
t.ok(true);
setTimeout(function () {
t.equal(1+3, 4);
}, 100);
});

test('two', function (t) {
t.plan(3);
t.equal(5, 2+3);
setTimeout(function () {
t.equal('a'.charCodeAt(0), 97);
t.ok(true);
}, 50);
});
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ function createHarness (conf_) {
})(t);

results.push(t);
nextTick(function () { t.run() });
return t;
};
test.stream = results;
Expand Down
33 changes: 23 additions & 10 deletions lib/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ module.exports = function (test) {
}
first = false;
};
nextTick(function next () {
var t = results.tests.shift();
if (!t) return results.close();
t.on('end', function () { nextTick(next) });
t.run();
});

return output;
};

Expand All @@ -33,12 +40,17 @@ function Results (stream) {
this.tests = [];
}

Results.prototype.push = function (t) {
Results.prototype.push = function (t, parentT) {
var self = this;
var write = function (s) { self.stream.queue(s) };
t.on('run', function () {
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 });
Expand All @@ -51,7 +63,8 @@ Results.prototype.push = function (t) {
if (subtests === 0 && !plan) t.emit('end');
onend();
});
self.push(st);
self.push(st, t);
if (subtests === 1) st.run();
});

t.on('result', function (res) {
Expand All @@ -65,15 +78,15 @@ Results.prototype.push = function (t) {
if (res.ok) self.pass ++
else self.fail ++
});

t.on('end', onend);

function onend () {
nextTick(function () {
if (subtests !== 0) return;
if (self.tests.length === 0) self.close();
else self.tests.shift().run();
});
if (subtests !== 0) return;
if (!plan && self.tests.length === 0) self.close();
else if (!plan && self.tests.length) {
var t = self.tests.shift();
nextTick(function () { t.run() });
};
}
};

Expand Down Expand Up @@ -128,7 +141,7 @@ function encodeResult (res, count) {
output += inner + lines[i] + '\n';
}
}

output += outer + '...\n';
return output;
}
Expand All @@ -150,6 +163,6 @@ function getSerialize () {
if (found) ret = '[Circular]'
else seen.push(value)
}
return ret
return ret;
};
}

0 comments on commit 0ac88b8

Please sign in to comment.