diff --git a/lib/beautify-stack.js b/lib/beautify-stack.js index c26316cc4..d524d4a97 100644 --- a/lib/beautify-stack.js +++ b/lib/beautify-stack.js @@ -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; } @@ -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)