Skip to content

Replacing current working directory in stack trace message not always working as intended. #3093

Closed

Description

I had the following test fail when running npm test in a docker container where I had mounting the mocha source at /local.
https://github.com/mochajs/mocha/blob/master/test/unit/runner.spec.js#L406

The issue is here.

line = line.replace(cwd, '');

The replace call, causes '/usr/local/dev' to be changed to '/usrdev/, and the string comparison fails in the assert.

I imagine you would have to do a fancier regex replacement to get this to work correctly. In practice this might not be a huge issue since users tend to be in /home/username/path which should be reasonably unique.

However, I can imagine a situation where some files being stored at /tmp/<random_string>/home/username/path/filename or a similar location would occur in a stack trace message and be replaced to /tmp/<random_string>/filename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions