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

options.cwd should use the canonical pathname #36

Open
ehmicky opened this issue Nov 30, 2018 · 0 comments
Open

options.cwd should use the canonical pathname #36

ehmicky opened this issue Nov 30, 2018 · 0 comments

Comments

@ehmicky
Copy link

ehmicky commented Nov 30, 2018

TextExclude.shouldInstrument(filename) returns false when options.relativePath is true and filename is not inside options.cwd.

However:

  • when options.cwd is a symlink and is passed with its symlink unresolved
  • but filename resolves the symlink (through fs.realpath() for example)
  • then shouldInstrument() will return false even though it should return true.

This is likely to happen since:

  • the filename passed by nyc always has symlinks resolved because that's how module._compile() works
  • however nyc user might pass a options.cwd that has an unresolved symlink.

Real-life example: running the following on Travis on Mac OS:

const os = require('os');
const execa = require('execa');

const cwd = os.tmpdir();
await execa.shell(`nyc --cwd ${cwd}`)

Travis Mac OS environment:

  • returns /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T with os.tmpdir()
  • but this directory is a symlink for /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T
  • as a consequence all filename passed to testExclude.shouldInstrument() will start with /private/var/..., while options.cwd() will start with /var/..., even though it's the same folder.

One possible solution would be to run fs.realpath() on both filename and options.cwd() before comparing them.

@coreyfarrell coreyfarrell transferred this issue from istanbuljs/istanbuljs Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant