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.

Accept coverage info, collected from the browser

See original GitHub issue

I’m developing a cross-platform testing tool, which can run tests in browsers, Node and Deno: https://siesta.works

I’m trying to promote c8 as a recommended code coverage tool for it. It seems to work well for the Node.js tests.

However, if I collect coverage objects from the Chromium web pages, c8 does not recognize them as such. This is because Chromium’s coverage object seems to have different format from Node’s.

Node’s format:

{
    "result": [{
        "scriptId": "7",
        "url": "file:///home/nickolay/workspace/siesta-workspace/siesta-monorepo/packages/siesta/bin/siesta.js",
        ...
    }],
    "source-map-cache": {
        "file:///home/nickolay/workspace/siesta-workspace/siesta-monorepo/node_modules/.pnpm/@web+dev-server@0.1.24_rollup@2.58.0/node_modules/@web/dev-server/dist/index.js": {
            "lineLengths": [13, 62, 137, 51, 133, 54, 127, 61, 148, 57, 130, 65, 142, 33],
        },

Chromium’s format:

[
    {
        "scriptId": "32",
        "url": "http://localhost:8000/browser.js",
        ...
        "source": "..."
    }
]

So browser’s format includes “raw” sources and does not contain the results property. Data from browser is collected with Playwright: https://playwright.dev/docs/api/class-coverage

I’m willing to contribute a PR normalizing this format difference when generating a report, would you accept it and may be provide some guidance?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
bcoecommented, Dec 25, 2021

@canonic-epicure this seems like a great feature request.

I think the logic might end up complicated enough for resolving URLs, and making it fit into the assumptions made by c8, that we should probably add a new helper, something like ./lib/util/chrome-to-v8.js, which would spit out a file that then works with v8-to-istanbul?

2reactions
canonic-epicurecommented, Dec 23, 2021

So, by changing all urls to file:// with el.url = el.url.replace(/^https?:\/\//, 'file:///'), wrapping the results from browser with { result : ... }, using --allowExternal and applying this small patch to lib/report.js: https://github.com/canonic-epicure/c8/commit/0ed7994cec03ab10052f9c974971a789a256e064

I was able to receive decently looking report: image

Sources are not shown of course: image

This makes me positive its overall doable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Internet Safety: Understanding Browser Tracking - GCFGlobal
Learn all about browser tracking and better understand how tracking browser history works in this free Internet safety lesson.
Read more >
How to protect your online data from insurance companies
Life insurance companies, for example, take a very conservative approach ... or small text files in your Web browser that store information.
Read more >
Cover Your Tracks
It provides you with an overview of your browser's most unique and identifying characteristics. Only anonymous data will be collected through this site....
Read more >
Online Digital Service Tools | Travelers Insurance
In CA, quotes for all products must be obtained through a local independent agent. The information on this site is general in nature....
Read more >
Health Insurance Marketplace® Privacy Policy
If you agree to use MFA, we collect your phone number or your email address. We use this information to send a code...
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