diff --git a/lib/utils.js b/lib/utils.js index 427915eae1..1ec27085fd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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; }, []); diff --git a/test/utils.js b/test/utils.js index fcbb87c008..6cebc5ab68 100644 --- a/test/utils.js +++ b/test/utils.js @@ -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() {