Skip to content

Shorten the plan stack. #482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand All @@ -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 () {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just put all this logic in the internal API?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that would add an extra line to the stack (one we don't need).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just remove it, but this works too.

this._test.plan(ct, obj.stack);
};

// Getters
[
'assertCount',
Expand Down