Skip to content

Commit

Permalink
temp fix for Node.js internal stack traces showing
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 16, 2016
1 parent 2d04763 commit 26bcab0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/beautify-stack.js
Expand Up @@ -2,6 +2,25 @@
var StackUtils = require('stack-utils');
var debug = require('debug')('ava');

//-----------
// embedded `clean-stack` module (because it requires Node.js 4)
var extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/;
var pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/babel-polyfill\/.*)?\w+)\.js:\d+:\d+)|native)/;

var cleanStack = function (stack) {
return stack.replace(/\\/g, '/').split('\n').filter(function (x) {
var pathMatches = x.match(extractPathRegex);
if (pathMatches === null || !pathMatches[1]) {
return true;
}

return !pathRegex.test(pathMatches[1]);
}).filter(function (x) {
return x.trim() !== '';
}).join('\n');
};
//-----------

function indent(str) {
return ' ' + str;
}
Expand All @@ -25,6 +44,10 @@ module.exports = function (stack) {
return '';
}

// workaround for https://github.com/tapjs/stack-utils/issues/14
// TODO: fix it in `stack-utils`
stack = cleanStack(stack);

var title = stack.split('\n')[0];
var lines = stackUtils
.clean(stack)
Expand Down

0 comments on commit 26bcab0

Please sign in to comment.