From 83b72ed8d8ed9cd3df010036c8561ce385ba5c46 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 7 Mar 2016 09:53:36 +0100 Subject: [PATCH 1/2] test/utils: Add "absolute -> relative paths" test --- test/utils.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/utils.js b/test/utils.js index fcbb87c008..31af2cb218 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: failed' + , '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: failed' + , '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() { From dc365082896d431f4586da8c2c01a73506a280b5 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 7 Mar 2016 10:03:57 +0100 Subject: [PATCH 2/2] lib/utils: Only replace absolute -> relative paths for stack lines the stack can include the error message which might contain paths that should not be replaced --- lib/utils.js | 6 +++++- test/utils.js | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 7c3a8b6620..77f6495c75 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 31af2cb218..6cebc5ab68 100644 --- a/test/utils.js +++ b/test/utils.js @@ -119,11 +119,11 @@ describe('utils', function() { }); it('should replace absolute with relative paths', function() { - var stack = ['Error: failed' + 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: failed' + 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)'];