From 341c84b7e26f1110f2dbf1ebaeb6bc806cf941fc Mon Sep 17 00:00:00 2001 From: James Talmage Date: Thu, 28 Jan 2016 23:36:17 -0500 Subject: [PATCH] Shorten the plan stack. For performance improvements. --- lib/test.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/test.js b/lib/test.js index ca571a9a0..18636c972 100644 --- a/lib/test.js +++ b/lib/test.js @@ -77,7 +77,7 @@ Test.prototype._setAssertError = function (err) { this.assertError = err; }; -Test.prototype.plan = function (count) { +Test.prototype.plan = function (count, planStack) { if (typeof count !== 'number') { throw new TypeError('Expected a number'); } @@ -86,7 +86,7 @@ Test.prototype.plan = function (count) { // in case the `planCount` doesn't match `assertCount, // we need the stack of this function to throw with a useful stack - this.planStack = new Error().stack; + this.planStack = planStack; }; Test.prototype._run = function () { @@ -265,7 +265,6 @@ Test.prototype._publicApi = function () { function PublicApi(test) { this._test = test; - this.plan = test.plan.bind(test); this.skip = new SkipApi(test); } @@ -303,6 +302,15 @@ PublicApi.prototype = enhanceAssert({ onError: onAssertionEvent }); +PublicApi.prototype.plan = function plan(ct) { + var limitBefore = Error.stackTraceLimit; + Error.stackTraceLimit = 1; + var obj = {}; + Error.captureStackTrace(obj, plan); + Error.stackTraceLimit = limitBefore; + this._test.plan(ct, obj.stack); +}; + // Getters [ 'assertCount',