-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
v8 Coverage for integrators #28283
Comments
IIUC the feature request that actually applies here is the ability to turn on coverage at run time and write out the reports at some time other than right before exiting? That should be possible with two bindings. However off the top my head, we need to notify (at least) the (subsequently spawned) child processes about the change of coverage directory after the API is invoked. One option might be to set |
Yeah I think that would solve our problem here, thanks for summing that up. I'm not sure what you mean by the spawned child process in this situation though. |
I think @joyeecheung is talking about child processes being spawned by the script being profiled. In the linked issue @bcoe says that working with the inspector API is problematic but it's not clear to me what the difficulties are. I'm inclined to say no change to Node is necessary because all the building blocks already exist:
|
@bnoordhuis old issues on the
@Toxicable is the problem that you want to collect coverage for an application before it exits? I'm not fully understanding why running Node.js with an environment variable is a blocker. |
@SimenB brings up the need for "running tests in watch mode", which I think means you'd want coverage before the process exits? In this case, I wonder could you run the script with |
@bnoordhuis see my post here: bcoe/c8#116 (comment) Using the inspector API is not as accurate as the env var. Running with If I can run with
Yes - I'd like to print the coverage after each run. The process might be running for hours (I've had it going for the 8 hours I'm at work multiple times without ever exiting it). I'd also like to clear collected coverage before kicking off a new run |
@bcoe Being able to gather and process the report in memory, without touching the FS is the high level thing I want here So possibly some API such as
|
@bcoe Apropos (1), calling W.r.t. (2) and cc @SimenB: start the inspector like this to get block coverage: const options = {callCount: true, detailed: true};
session.post('Profiler.startPreciseCoverage', options, () => { /* ... */ }); As far as I'm aware that works fine (at least with Node.js master) with an already running isolate. If it doesn't, I'd like to know what exactly doesn't work. Is that sufficient? Is anything else needed? |
I agree with @bnoordhuis that this can be done with using the inspector protocol directly. If the request is to get user land coverage on demand, then none of those issues apply here. I don't really see why it can't be done with the inspector module directly? |
Didn't know about those options! I'll test it out and report back. It would be nice with a cleaner api, but that should be very much possible to build in userland |
@joyeecheung @bnoordhuis if we could pull it off without too much trouble, I think it would be a somewhat cleaner API if someone could trigger the existing inspector session we have open and tell it to dump its coverage. My thinking is, then @SimenB or @Toxicable could start their process with NODE_V8_COVERAGE set... my gut is that this does have a few benefits from a simplicity point of view: you don't need a second inspector session, you piggyback off the one already running; you ensure coverage was enabled before any of your applications dependencies load; the upstream library doesn't need to speak the inspector API. I'm not quite sure what the mechanism would be for triggering a dump ... maybe if you have If we're not open to adding this to Node.js, I think that it's a great candidate for a userland module that @SimenB, @Toxicable, and myself could hopefully share for our use-cases. |
For Jest's use case, it's very explicit when we load user code, so we don't need any coverage guarantee about "library code". As long as More than happy to figure out some abstraction for collecting the coverage in user land that can be shared, sounds like a great goal. |
This also isn't a concern for us. @bcoe With that in mind, do you think
But just to ensure anyone integrating it downstream dosen't have to have this conversation again |
Adding the options worked an absolute treat - I get the same numbers as if starting the node process with EDIT: btw, the docs state that worker_threads are not supported (https://nodejs.org/api/cli.html#cli_node_v8_coverage_dir) - is that a limitation of the env var or |
Oh actually, there is one API I'm missing - getting instrumentation data for an uncovered file. |
@SimenB, @Toxicable let's move this conversation to c8 and/or v8-to-istanbul, as from conversations we've been having it sounds like the inspector API is working like a charm 👍 |
This is derived from the conversations had here: bcoe/c8#116
Is your feature request related to a problem? Please describe.
The problem is with intergrating V8 coverage into downstream systems such as test runners or processes which run nodejs programs.
Describe the solution you'd like
The most ideal solution would be something like
However it's my understanding that this approach wouldn't work very well since internally the
collectCoverage
would have to activate covergae via the inspector api which isn't the best.bcoe/c8#116 (comment)
With that in mind another approach is using the
NODE_V8_COVERAGE=/some/dir
env var.However an issue came accross with this one where we need to somehow signal Nodejs to write out the coverage file since we need to process it in in the same process.
bcoe/c8#116 (comment)
Describe alternatives you've considered
The two points above
The text was updated successfully, but these errors were encountered: