Accept coverage info, collected from the browser
See original GitHub issueI’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:
- Created 2 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
@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 withv8-to-istanbul
?So, by changing all urls to
file://
withel.url = el.url.replace(/^https?:\/\//, 'file:///')
, wrapping the results from browser with{ result : ... }
, using--allowExternal
and applying this small patch tolib/report.js
: https://github.com/canonic-epicure/c8/commit/0ed7994cec03ab10052f9c974971a789a256e064I was able to receive decently looking report:
Sources are not shown of course:
This makes me positive its overall doable.