Skip to content

Commit af37305

Browse files
committed
use stack-utils for nicer stack traces.
1 parent 3fdb6fc commit af37305

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

lib/beautify-stack.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
'use strict';
22

3-
function beautifyStack(stack) {
4-
var re = /(?:^(?! {4}at\b).{6})|(?:\((?:[A-Z]:)?(?:[\\\/](?:(?!node_modules[\\\/]ava[\\\/])[^:\\\/])+)+:\d+:\d+\))/;
5-
var found = false;
3+
var StackUtils = require('stack-utils');
4+
var debug = require('debug')('ava');
5+
6+
var stackUtils = new StackUtils({
7+
internals: debug.enabled ? [] : StackUtils.nodeInternals().concat([
8+
/\/ava\/(?:lib\/)?[\w-]+\.js:\d+:\d+\)?$/,
9+
/\/node_modules\/(?:bluebird|empower-core)\//
10+
])
11+
});
612

7-
return stack.split('\n').filter(function (line) {
8-
var relevant = re.test(line);
9-
found = found || relevant;
10-
return !found || relevant;
13+
function beautifyStack(stack) {
14+
return stack.split('\n')[0] + '\n' + stackUtils.clean(stack).split('\n').map(function (s) {
15+
return ' ' + s;
1116
}).join('\n');
1217
}
1318

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"serialize-error": "^1.1.0",
121121
"set-immediate-shim": "^1.0.1",
122122
"source-map-support": "^0.4.0",
123+
"stack-utils": "^0.3.0",
123124
"strip-bom": "^2.0.0",
124125
"time-require": "^0.1.2",
125126
"unique-temp-dir": "^1.0.0",

test/reporters/mini.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ test('results with passing tests and rejections', function (t) {
129129
t.is(output[2], '');
130130
t.is(output[3], ' ' + chalk.red('1. Unhandled Rejection'));
131131
t.match(output[4], /Error: failure/);
132-
t.match(output[5], /Test\.test/);
132+
t.match(output[5], /test\/reporters\/mini\.js/);
133133
t.end();
134134
});
135135

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

@@ -174,6 +174,6 @@ test('results with errors', function (t) {
174174
t.is(output[2], ' ' + chalk.red('1. failed'));
175175
t.match(output[3], /failure/);
176176
t.match(output[4], /Error: failure/);
177-
t.match(output[5], /Test\.test/);
177+
t.match(output[5], /test\/reporters\/mini\.js/);
178178
t.end();
179179
});

test/reporters/verbose.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ test('uncaught exception', function (t) {
115115

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

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

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

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

0 commit comments

Comments
 (0)