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

Persist paths in stack trace which have cwd as infix #3244

Merged
merged 1 commit into from Mar 5, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/utils.js
Expand Up @@ -597,7 +597,7 @@ exports.stackTraceFilter = function () {

// Clean up cwd(absolute)
if (/\(?.+:\d+:\d+\)?$/.test(line)) {
line = line.replace(cwd, '');
line = line.replace('(' + cwd, '(');
Copy link
Member

Choose a reason for hiding this comment

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

by using escape-string-regexp, @ScottFreeCode meant do this:

line = line.replace(require('escape-string-regexp')(cwd), '');

Does that not work?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, that doesn't.

In this case, escape-string-regexp change nothing on the path. (I didn't check it with escape-string-regexp on Windows)

> var cwd = '/Users/outsideris/github/mocha/';
undefined
> require('escape-string-regexp')(cwd)
'/Users/outsideris/github/mocha/'

So, line = line.replace(require('escape-string-regexp')(cwd), ''); will change at foo (/www/Users/outsideris/github/mocha/foo/index.js:13:226) to at foo (/wwwfoo/index.js:13:226).
It resolves nothing here and results same as before I change it.

}

list.push(line);
Expand Down
17 changes: 17 additions & 0 deletions test/node-unit/stack-trace-filter.spec.js
Expand Up @@ -88,6 +88,23 @@ describe('stackTraceFilter()', function () {
expect(filter(stack.join('\n')))
.to.equal(expected.join('\n'));
});

it('should not replace absolute path which has cwd as infix', function () {
var stack = [
'Error: /www' + process.cwd() + '/bla.js has a problem',
'at foo (/www' + 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: /www' + process.cwd() + '/bla.js has a problem',
'at foo (/www' + process.cwd() + '/foo/index.js:13:226)',
'at bar (/usr/local/dev/own/tmp/node_modules/bluebird/js/main/promise.js:11:26)'
];

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

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