question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
bcoecommented, Mar 19, 2022

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.

1reaction
bcoecommented, Mar 16, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Retrieve global variable after running jest programatically #7421
The stryker-jest-runner communicates the global coverage object back to Stryker; Stryker runs mutation testing using the perTest coverage ...
Read more >
Configuring Jest
The configuration file should simply export an object: ... If globs or paths are specified alongside global , coverage data for matching ...
Read more >
List all js global variables used by site (not all defined!)
You will have a list of unused variables (global and then local to each function). Now run Object.keys(window); in the console and compare ......
Read more >
dotnet-coverage code coverage tool - .NET CLI - Microsoft Learn
Learn how to install and use the dotnet-coverage CLI tool to collect code coverage data of a running process.
Read more >
How to Idiomatically Use Global Variables in Rust - SitePoint
Use an external library for easy runtime initialized globals: lazy_static / once_cell; Implement your own runtime initialization: std::sync:: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found