Skip to content
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

Use stack-utils for nicer stack traces. #418

Merged
merged 1 commit into from
Jan 14, 2016
Merged
Show file tree
Hide file tree
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
19 changes: 12 additions & 7 deletions lib/beautify-stack.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
'use strict';

function beautifyStack(stack) {
var re = /(?:^(?! {4}at\b).{6})|(?:\((?:[A-Z]:)?(?:[\\\/](?:(?!node_modules[\\\/]ava[\\\/])[^:\\\/])+)+:\d+:\d+\))/;
var found = false;
var StackUtils = require('stack-utils');
var debug = require('debug')('ava');

var stackUtils = new StackUtils({
internals: debug.enabled ? [] : StackUtils.nodeInternals().concat([
/\/ava\/(?:lib\/)?[\w-]+\.js:\d+:\d+\)?$/,
/\/node_modules\/(?:bluebird|empower-core)\//
])
});

return stack.split('\n').filter(function (line) {
var relevant = re.test(line);
found = found || relevant;
return !found || relevant;
function beautifyStack(stack) {
return stack.split('\n')[0] + '\n' + stackUtils.clean(stack).split('\n').map(function (s) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Why is the first line not indented? And why do we need to manually indent it? Shouldn't stack-utils do that for us?

Copy link
Contributor

Choose a reason for hiding this comment

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

See tapjs/stack-utils#2 (comment), if I'm not mistaken

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. Whitespace at the beginning of any multi-line string makes the yaml output much harder to read. stack-utils trims whitespace from the first line.

I guess we could add an indent option to stack-utils.

Copy link
Member

Choose a reason for hiding this comment

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

I guess we could add an indent option to stack-utils.

👍 Can you open an issue on stack-utils so we don't forget to simplify this?

return ' ' + s;
}).join('\n');
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"serialize-error": "^1.1.0",
"set-immediate-shim": "^1.0.1",
"source-map-support": "^0.4.0",
"stack-utils": "^0.3.0",
"strip-bom": "^2.0.0",
"time-require": "^0.1.2",
"unique-temp-dir": "^1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ test('results with passing tests and rejections', function (t) {
t.is(output[2], '');
t.is(output[3], ' ' + chalk.red('1. Unhandled Rejection'));
t.match(output[4], /Error: failure/);
t.match(output[5], /Test\.test/);
t.match(output[5], /test\/reporters\/mini\.js/);
t.end();
});

Expand All @@ -152,7 +152,7 @@ test('results with passing tests and exceptions', function (t) {
t.is(output[2], '');
t.is(output[3], ' ' + chalk.red('1. Uncaught Exception'));
t.match(output[4], /Error: failure/);
t.match(output[5], /Test\.test/);
t.match(output[5], /test\/reporters\/mini\.js/);
t.end();
});

Expand All @@ -174,6 +174,6 @@ test('results with errors', function (t) {
t.is(output[2], ' ' + chalk.red('1. failed'));
t.match(output[3], /failure/);
t.match(output[4], /Error: failure/);
t.match(output[5], /Test\.test/);
t.match(output[5], /test\/reporters\/mini\.js/);
t.end();
});
6 changes: 3 additions & 3 deletions test/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ test('uncaught exception', function (t) {

t.is(output[0], chalk.red('Uncaught Exception: test.js'));
t.match(output[1], /Error: Unexpected token/);
t.match(output[2], /at Test\.test/);
t.match(output[2], /test\/reporters\/verbose\.js/);
t.end();
});

Expand All @@ -130,7 +130,7 @@ test('unhandled rejection', function (t) {

t.is(output[0], chalk.red('Unhandled Rejection: test.js'));
t.match(output[1], /Error: Unexpected token/);
t.match(output[2], /at Test\.test/);
t.match(output[2], /test\/reporters\/verbose\.js/);
t.end();
});

Expand Down Expand Up @@ -248,7 +248,7 @@ test('results with errors', function (t) {
t.is(output[1], ' ' + chalk.red('1 test failed'));
t.is(output[3], ' ' + chalk.red('1. fail'));
t.match(output[4], /Error: error message/);
t.match(output[5], /Test\.test/);
t.match(output[5], /test\/reporters\/verbose\.js/);
t.end();
});

Expand Down