Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only replace absolute -> relative paths for stack lines #2145

Merged
merged 2 commits into from
Mar 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the capture group for? Could this be simplified, e.g.

if (line.match(/:\d+:\d+$/)) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's actually not a capture group, those are escaped parenthesis. your suggestion would only work for stack lines without parenthesis around the file+position info, but according to the test/utils.js both seem to exist.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, didn't notice the escape characters :)

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