Skip to content

Commit 46fb0a1

Browse files
author
James Halliday
committed
send the end event properly
1 parent 7948e2e commit 46fb0a1

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

lib/test.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,6 @@ Test.prototype.comment = function (msg) {
1616
this.result('\n' + msg.trim());
1717
};
1818

19-
Test.prototype.result = function (res) {
20-
var self = this;
21-
self.emit('result', res);
22-
if (self._plan === self.assertCount) {
23-
process.nextTick(function () {
24-
if (!self.ended) self.end();
25-
});
26-
}
27-
};
28-
2919
Test.prototype.plan = function (n) {
3020
this._plan = n;
3121
};
@@ -36,9 +26,11 @@ Test.prototype.end = function () {
3626
};
3727

3828
Test.prototype._assert = function assert (ok, opts) {
29+
var self = this;
3930
var extra = opts.extra || {};
31+
4032
var res = {
41-
id : this.assertCount ++,
33+
id : self.assertCount ++,
4234
ok : Boolean(ok),
4335
skip : defined(extra.skip, opts.skip),
4436
name : defined(extra.message, opts.message, '(unnamed assert)'),
@@ -50,7 +42,14 @@ Test.prototype._assert = function assert (ok, opts) {
5042
if (!ok) {
5143
res.error = defined(extra.error, opts.error, new Error(res.name));
5244
}
53-
this.emit('result', res);
45+
46+
self.emit('result', res);
47+
48+
if (self._plan === self.assertCount) {
49+
process.nextTick(function () {
50+
if (!self.ended) self.end();
51+
});
52+
}
5453
};
5554

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

0 commit comments

Comments
 (0)