Skip to content

Commit

Permalink
Merge pull request mochajs#2145 from Turbo87/fix-stack-filter
Browse files Browse the repository at this point in the history
Only replace absolute -> relative paths for stack lines
  • Loading branch information
danielstjules committed Mar 21, 2016
2 parents 00d6469 + dc36508 commit 4301caa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,11 @@ exports.stackTraceFilter = function() {
}

// Clean up cwd(absolute)
list.push(line.replace(cwd, ''));
if (/\(?.+:\d+:\d+\)?$/.test(line)) {
line = line.replace(cwd, '');
}

list.push(line);
return list;
}, []);

Expand Down
12 changes: 12 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ describe('utils', function() {
, 'at next (file:///.../components/mochajs/mocha/2.1.0/mocha.js:4817:14)'];
filter(stack.join('\n')).should.equal(stack.slice(0,7).join('\n'));
});

it('should replace absolute with relative paths', function() {
var stack = ['Error: ' + process.cwd() + '/bla.js has a problem'
, 'at foo (' + process.cwd() + '/foo/index.js:13:226)'
, 'at bar (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:11:26)'];

var expected = ['Error: ' + process.cwd() + '/bla.js has a problem'
, 'at foo (foo/index.js:13:226)'
, 'at bar (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:11:26)'];

filter(stack.join('\n')).should.equal(expected.join('\n'));
});
});

describe('on browser', function() {
Expand Down

0 comments on commit 4301caa

Please sign in to comment.