Runtime global __coverage__ object
See original GitHub issue- Version: 16.13.0
- Platform: Darwin apples-MacBook-Pro.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:21 PDT 2021; root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64
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
).
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
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.
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:
https://github.com/puppeteer/puppeteer/pull/6454