Skip to content

options.cwd should use the canonical pathname #36

@ehmicky

Description

@ehmicky

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions