Skip to content

Commit

Permalink
send the end event properly
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Nov 25, 2012
1 parent 7948e2e commit 46fb0a1
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ Test.prototype.comment = function (msg) {
this.result('\n' + msg.trim());
};

Test.prototype.result = function (res) {
var self = this;
self.emit('result', res);
if (self._plan === self.assertCount) {
process.nextTick(function () {
if (!self.ended) self.end();
});
}
};

Test.prototype.plan = function (n) {
this._plan = n;
};
Expand All @@ -36,9 +26,11 @@ Test.prototype.end = function () {
};

Test.prototype._assert = function assert (ok, opts) {
var self = this;
var extra = opts.extra || {};

var res = {
id : this.assertCount ++,
id : self.assertCount ++,
ok : Boolean(ok),
skip : defined(extra.skip, opts.skip),
name : defined(extra.message, opts.message, '(unnamed assert)'),
Expand All @@ -50,7 +42,14 @@ Test.prototype._assert = function assert (ok, opts) {
if (!ok) {
res.error = defined(extra.error, opts.error, new Error(res.name));
}
this.emit('result', res);

self.emit('result', res);

if (self._plan === self.assertCount) {
process.nextTick(function () {
if (!self.ended) self.end();
});
}
};

Test.prototype.fail = function (msg, extra) {
Expand Down

0 comments on commit 46fb0a1

Please sign in to comment.