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.

[feat] module api for intergrators

See original GitHub issue

Im integrating code coverage into Bazel: https://github.com/bazelbuild/rules_nodejs However, rather than reimplementing the internal logic we see in this lib it would be great if there was a public facing API that could be used by downstream integrators.

For this kind of integration the main functionality needed

  • gathering coverage (without child process/forking)
  • producing machine readable reports (in this case we’re after lcov)
  • merging reports between projects that might have overlapping coverage

A code example of the api we’re after might look like this

const c8 = require('c8');

c8.collectCoverage({reporters: ['text-summary', 'lcov']});
jasmine.execute();
const reports = await c8.completeCoverage();

const textSummaryReport = reports.find(r => r.type = 'text-summary');
console.log(textSummaryReport);

cons lcovReport = reports.find(r => r.type = 'lcov');
fs.writeFileSync('to/some/location', lcovReport);
// or maybe merge/process it in some other way

Some important points here:

  • The lib should not do any IO
  • The lib should not require environment variables to collect coverage

I’d be happy to contribute to this design or implementation if needed. Let me know if this is something we’d like to do with this lib

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
SimenBcommented, Jun 22, 2019

I opened up https://github.com/istanbuljs/v8-to-istanbul/issues/33. By using that, and copying some istanbul-lib-* code from Report.js in this repo, I was able to make it work in Jest 🎉

The part I copied from c8:

const map = libCoverage.createCoverageMap({});

v8CoverageResult.forEach(res => map.merge(res));

const context = libReport.createContext({
  dir: globalConfig.coverageDirectory,
});

const tree = libReport.summarizers.pkg(map);

tree.visit(reports.create('html'), context);

Not too much. So I don’t think we necessarily need to put any more code in c8 - making v8-to-istanbul support not talking to the FS seems to cover it?


The inspector API abstraction I put together: https://github.com/SimenB/jest/blob/917efc3398577c205f33c1c2f9a1aeabfaad6f7d/packages/jest-coverage/src/index.ts

Usage:

const v8CoverageInstrumenter = new CoverageInstrumenter();

await v8CoverageInstrumenter.startInstrumenting();

// do your work that you want instrumented here

const v8CoverageResult = await v8CoverageInstrumenter.stopInstrumenting();

Note that this does not at all have to live in Jest, it was just easiest for me when doing this work to have it there. It might live in the istanbul org, maybe?


Results in this: image

(this is just require('typescript'))

1reaction
bcoecommented, Jun 18, 2019

@Toxicable @SimenB might be worth moving this feature request to Node.js? could imagine this being possible with a signal, not sure what signal.

Read more comments on GitHub >

github_iconTop Results From Across the Web

v8 Coverage for integrators · Issue #28283 · nodejs/node
[feat] module api for intergrators bcoe/c8#116 ... the title v8 Coverage for intergrators v8 Coverage for integrators on Jun 18, 2019.
Read more >
Module integration helpers | Entity API
The entity API provides some useful defaults for integrating with rules and for providing Entity property information.
Read more >
Plugins - API Builder v5
Plugins are regular node modules that are included in your API Builder project's package.json file. API Builder detects plugins by searching for installed ......
Read more >
Become an API Integrator - Learn Interactively
Application Programmable Interface (API) is a software intermediary that allows two applications ... Module 1. Integrate Auth0 with Java Servlet Application.
Read more >
APi Systems Integrators | Western States Fire Protection
APi Systems Integrators is a premier special systems integrator, encompassing five states. Our highly talented engineering staff designs projects from scratch ...
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