From fbe4b951cb6c6cc4f0e9e3ae4a57b123dd82c0fb Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 29 Jan 2019 23:19:13 -0800 Subject: [PATCH] [Refactor] Avoid adding a new observable method to the API. --- lib/test.js | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/lib/test.js b/lib/test.js index a7f18397..93ddbf68 100644 --- a/lib/test.js +++ b/lib/test.js @@ -39,6 +39,21 @@ var getTestArgs = function (name_, opts_, cb_) { return { name: name, opts: opts, cb: cb }; }; +var runProgeny = function () { + var self = this; + if (this._progeny.length) { + var t = this._progeny.shift(); + t.on('end', function () { runProgeny.call(self) }); + nextTick(function () { + t.run(); + }); + return; + } + if (this.calledEnd || this._plan) { + this._end(); + } +}; + function Test (name_, opts_, cb_) { if (! (this instanceof Test)) { return new Test(name_, opts_, cb_); @@ -107,7 +122,7 @@ Test.prototype.test = function (name, opts, cb) { }); if (!this._pendingAsserts()) { - this._runProgeny(); + runProgeny.call(this); } }; @@ -123,14 +138,14 @@ Test.prototype.plan = function (n) { this.emit('plan', n); }; -Test.prototype.timeoutAfter = function(ms) { +Test.prototype.timeoutAfter = function (ms) { if (!ms) throw new Error('timeoutAfter requires a timespan'); var self = this; - var timeout = safeSetTimeout(function() { + var timeout = safeSetTimeout(function () { self.fail('test timed out after ' + ms + 'ms'); self.end(); }, ms); - this.once('end', function() { + this.once('end', function () { safeClearTimeout(timeout); }); } @@ -144,7 +159,7 @@ Test.prototype.end = function (err) { this.fail('.end() called twice'); } this.calledEnd = true; - this._runProgeny(); + runProgeny.call(this); }; Test.prototype._end = function (err) { @@ -160,21 +175,6 @@ Test.prototype._end = function (err) { this.ended = true; }; -Test.prototype._runProgeny = function () { - var self = this; - if (this._progeny.length) { - var t = this._progeny.shift(); - t.on('end', function () { self._runProgeny() }); - nextTick(function() { - t.run(); - }); - return; - } - if(this.calledEnd || this._plan) { - this._end(); - } -}; - Test.prototype._exit = function () { if (this._plan !== undefined && !this._planError && this.assertCount !== this._plan) { @@ -296,7 +296,7 @@ Test.prototype._assert = function assert (ok, opts) { if (extra.exiting) { self._end(); } else { - self._runProgeny(); + runProgeny.call(self); } }