Skip to content

Show only the useful lines of stack trace - fixes #22 #29

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var chalk = require('chalk');
var figures = require('figures');
var Squeak = require('squeak');
var plur = require('plur');
var path = require('path');
var Runner = require('./lib/runner');
var log = new Squeak({separator: ' '});
var runner = new Runner();
Expand Down Expand Up @@ -36,6 +37,18 @@ function stack(results) {

i++;

// Don't print the full stack but the only useful line showing
// the actual test file stack
var dir = path.dirname(module.parent.filename);
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for my thickness, but what is this actually doing? I mean, what is the intent? Isn't it just filtering out anything that's not in the project directory? What is this improving/fixing?

In an edge case, what happens if I require() something outside of my immediate project directory? It will be dropped, too.

Copy link
Author

Choose a reason for hiding this comment

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

This is fixing the issue defined here.

It doesn't necessarily have to show the stack for your required modules, users are least concerned with how the error was generated in the module they are using, they're mostly interested in how their code causes an error, afterall they are testing their own code, not their modules.

It's about defaults, what most people prefer, users usually prefer simplicity, and if they really want the full stack, we can provide an option for that (--full-stack as you said).


var split = (result.error.stack || '').split('\n');
var related = split.filter(function (line) {
return line.indexOf(dir) > -1;
});

var beautiful = result.error.message + '\n' + related.join('\n');
result.error.stack = beautiful;

log.writelpad(chalk.red(i + '.', result.title));
log.writelpad(chalk.red(result.error.stack));
log.write();
Expand Down
12 changes: 7 additions & 5 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ Test.prototype.plan = function (count) {
}

this.planCount = count;
// in case the planCount doesnt match assertCount, we need the stack of this
// function to throw with a useful stack
this.planStack = new Error().stack;
};

Test.prototype.skip = function () {
Expand All @@ -75,8 +78,7 @@ Test.prototype.run = function (cb) {
this.assertError = new assert.AssertionError({
actual: err,
message: 'Promise rejected → ' + err,
operator: 'promise',
stackStartFunction: this
operator: 'promise'
});

this.exit();
Expand All @@ -103,10 +105,10 @@ Test.prototype.exit = function () {
actual: this.assertCount,
expected: this.planCount,
message: 'Assertion count does not match planned',
operator: 'plan',
// TODO: find out why it doesn't show any stack
stackStartFunction: this.fn
operator: 'plan'
});

this.assertError.stack = this.planStack;
}

if (!this.ended) {
Expand Down