istanbuljs / istanbuljs/test-exclude

`options.cwd` should use the canonical pathname

Open
#36 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
10
Forks
18
PR merge metrics
No merged PRs in 30d

Description

`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:

```js
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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing TextExclude.shouldInstrument(filename), focusing on the comparison between options.cwd and filename when options.relativePath is true. Check how fs.realpath() can canonicalize both paths, then verify that equivalent symlinked paths are treated as inside the configured cwd; the payload does not name a test file to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
testing-qa, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.