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
Runtime global __coverage__ object #376
Comments
c8 does not have a global coverage object, it is dumping coverage information that is stored in the V8 JavaScript engine to disk. One option you might look at is using puppeteer to get the coverage information you are looking for: |
I'm actually looking to get runtime coverage for my backend NodeJS API, and want to query it from a different service.
Is it possible to read it from the running node process (the one being instrumented) and expose it without waiting for the process to exit? Would something like reading the temp-directory and passing it to https://github.com/istanbuljs/v8-to-istanbul work, or are the reports usable only once the process exits? |
You can use the inspector protocol in the Node.js process to grab the V8 coverage: https://github.com/tapjs/processinfo/blob/main/lib/register-coverage.cjs You can then process this information with c8. |
I'll try a small PoC and post here how it goes |
@bcoe It works pretty well, Thanks! This is the current script I have for reference: Any comments on the script would be appreciated. |
Background
I'm currently instrumenting my backend Typescript code using
nyc
for getting code coverage for our Cypress E2E test suite (docs). And I would like to move to c8.My current setup involves creating an api route (that is only enabled for NODE_ENV=test) that just returns the
global.__coverage__
object so that cypress can collect at the end of the tests, merge with client side coverage and generate a single report.Problem
AFAIK, c8 doesn't have runtime coverage information available like
nyc
and instead outputs it as a report. Could we add a flag to enable exposing the coverage at runtime also as a global or a method exposed by the module?Might be related to #339 but kind of like a reverse approach: we merge c8 coverage with browser collected coverage (using
babel-plugin-istanbul
).The text was updated successfully, but these errors were encountered: