-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Files required through node --eval
or node --require
do not get instrumented
#144
Comments
Bumping this so the issue does not get stale. |
Bumping again |
I can answer part of this bug, it's not possible for files required via The way that I know will work is if you have a module where sources are in As for |
I've marked this issue so the stale bot will not touch it anymore, but understand that no code fix is planned. The intent is to create a tutorial at istanbul.js.org for how to perform coverage testing of a |
I understand, thanks for explaining the reason behind this. I do think this is a limitation in the current hooking system that should be documented. A workaround I am doing which does not require an extra build step is to add a Another thing: I have seen that there has been some work in Istanbul towards offering |
Native V8 coverage can be processed by c8 in place of nyc, it only uses istanbul to generate reports. From what I can tell it doesn't yet support any kind of comment hints for disabling coverage. I'd assume that native v8 coverage would pick up on |
Yes exactly. Thanks for your help, I am going to close this issue as this probably won't be fixed. However thanks for checking it out. I am also going to delete the demo repository, please let me know if that is a problem. |
@ehmicky thanks for your patience but I have transferred this issue to our website repo so that it exists in the right place as a need to be documented. Feel free to unsubscribe from the thread if you don't want notifications on this any more. I have also forked your demo repository, so it should be fine to delete... though it doesn't do much harm to keep. Either way, thanks so much for that! |
Demo repository
Expected Behavior
Files required through
node --eval
ornode --require
should be instrumented.Observed Behavior
They do not get instrumented.
The demo repository contains two empty files
index.js
andother.js
.Running the file instrument it correctly:
Requiring it through
--eval
does not instrument it:Requiring it through
--require
does not instrument it:Forensic Information
Operating System: Ubuntu
18.04
Environment Information: node
v11.3.0
, npm6.4.1
, nyc13.1.0
Notes
nyc
has a--require
flag. However this only works whennode
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 runschildProcess.spawn()
using--require register.js
.I can work around the problem and avoid
--eval
or--require
by loading a file that firesrequire()
instead, but there might be other use cases that this limitation of nyc might impact.The text was updated successfully, but these errors were encountered: