istanbuljs / istanbuljs/istanbuljs.github.io
Files required through `node --eval` or `node --require` do not get instrumented
- Dominant language
- JavaScript
- Stars
- 25
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Description
[Demo repository](https://github.com/ehmicky/nyc-bug-two)
## Expected Behavior
Files required through `node --eval` or `node --require` should be instrumented.
## Observed Behavior
They do not get instrumented.
The demo repository contains two empty files `index.js` and `other.js`.
Running the file instrument it correctly:
```
$ nyc node index.js
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
index.js | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
```
Requiring it through `--eval` does not instrument it:
```
$ nyc node -e 'require("./index")'
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
```
Requiring it through `--require` does not instrument it:
```
$ nyc node -r ./index.js other.js
----------|----------|----------|----------|----------|-------------------|
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s |
----------|----------|----------|----------|----------|-------------------|
All files | 0 | 0 | 0 | 0 | |
other.js | 0 | 0 | 0 | 0 | |
----------|----------|----------|----------|----------|-------------------|
```
## Forensic Information
*Operating System*: Ubuntu `18.04`
*Environment Information*: node `v11.3.0`, npm `6.4.1`, nyc `13.1.0`
## Notes
`nyc` has a `--require` flag. However this only works when `node` is fired as the top-level command, not as a child process.
For example I am testing a library that has a `register.js` file that performs monkey patching on load (like `@babel/register` does). The only way to test it without polluting the global environment of the other tests is to run it as a child process. I.e. my unit test runs `childProcess.spawn()` using `--require register.js`.
I can work around the problem and avoid `--eval` or `--require` by loading a file that fires `require()` instead, but there might be other use cases that this limitation of nyc might impact.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the commands in the linked demo repository with its index.js and other.js files, using node --eval and node --require. Trace how nyc handles these Node entry points and compare the coverage output with the direct node index.js case. Done means the required files appear in the instrumentation report for both invocation forms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- testing-qa, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100