Demo repository
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.
Demo repository
Expected Behavior
Files required through
node --evalornode --requireshould be instrumented.Observed Behavior
They do not get instrumented.
The demo repository contains two empty files
index.jsandother.js.Running the file instrument it correctly:
Requiring it through
--evaldoes not instrument it:Requiring it through
--requiredoes not instrument it:Forensic Information
Operating System: Ubuntu
18.04Environment Information: node
v11.3.0, npm6.4.1, nyc13.1.0Notes
nychas a--requireflag. However this only works whennodeis fired as the top-level command, not as a child process.For example I am testing a library that has a
register.jsfile that performs monkey patching on load (like@babel/registerdoes). 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 runschildProcess.spawn()using--require register.js.I can work around the problem and avoid
--evalor--requireby loading a file that firesrequire()instead, but there might be other use cases that this limitation of nyc might impact.