From 46fb0a1e5b305d07ffaf1c464325356c269fb5fe Mon Sep 17 00:00:00 2001 From: James Halliday Date: Sun, 25 Nov 2012 06:05:11 -0800 Subject: [PATCH] send the end event properly --- lib/test.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/test.js b/lib/test.js index 49f8b1c5..4e58a126 100644 --- a/lib/test.js +++ b/lib/test.js @@ -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; }; @@ -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)'), @@ -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) {