Skip to content

Commit 26bcab0

Browse files
committed
temp fix for Node.js internal stack traces showing
With Node.js 6 and up. See: sindresorhus/clean-stack@e26cacd#diff-1dd241c4cd3fd1dd89c570cee98b79ddR50
1 parent 2d04763 commit 26bcab0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/beautify-stack.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
var StackUtils = require('stack-utils');
33
var debug = require('debug')('ava');
44

5+
//-----------
6+
// embedded `clean-stack` module (because it requires Node.js 4)
7+
var extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/;
8+
var pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/babel-polyfill\/.*)?\w+)\.js:\d+:\d+)|native)/;
9+
10+
var cleanStack = function (stack) {
11+
return stack.replace(/\\/g, '/').split('\n').filter(function (x) {
12+
var pathMatches = x.match(extractPathRegex);
13+
if (pathMatches === null || !pathMatches[1]) {
14+
return true;
15+
}
16+
17+
return !pathRegex.test(pathMatches[1]);
18+
}).filter(function (x) {
19+
return x.trim() !== '';
20+
}).join('\n');
21+
};
22+
//-----------
23+
524
function indent(str) {
625
return ' ' + str;
726
}
@@ -25,6 +44,10 @@ module.exports = function (stack) {
2544
return '';
2645
}
2746

47+
// workaround for https://github.com/tapjs/stack-utils/issues/14
48+
// TODO: fix it in `stack-utils`
49+
stack = cleanStack(stack);
50+
2851
var title = stack.split('\n')[0];
2952
var lines = stackUtils
3053
.clean(stack)

0 commit comments

Comments
 (0)