-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept coverage info, collected from the browser #339
Comments
Hm.. It seems there's a fundamental assumption, that coverage info comes from the terminal process ( |
So, by changing all urls to I was able to receive decently looking report: Sources are not shown of course: This makes me positive its overall doable. |
@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 |
Yes, would need to generalize the
Probably. I'm open for suggestions and ideas. The thing is, it seems istanbul reports also assumes that all urls are file-system. So one would need to tweak them as well. In theory, if the "generalized Right now I was able to workaround w/o patching
and also
Also need to enable If you think its a sane feature request, I'm ready to contribute all the necessary code (after we come up with a plan). |
Updating Istanbul reports to not assume file system paths might be a good starting point. I think the reports most likely to make this assumption would be the HTML reports, which actually load files off disk I believe 🤔
I think this sounds like a reasonable requests, users often ask how to handle browser coverage with c8, and there hasn't ever been a good answer. With regards to coming up with a plan, perhaps a good starting point would be to draft a markdown RFC with a rough plan. |
Ok, I'll be preparing one gradually. Will let you know. |
I was able to use the raw script coverage generated by puppeteer together with // enable collecting JavaScript code coverage with raw coverage
await page.coverage.startJSCoverage({
resetOnNavigation: false,
includeRawScriptCoverage: true
})
// load one or more pages and run tests in them
...
// collect JavaScript code coverage
const coverage = await page.coverage.stopJSCoverage()
// extract raw script coverage with URLs replaced with absolute paths
const urlBase = 'http://localhost:5000/'
const cwd = process.cwd()
const result = coverage.map(({ rawScriptCoverage }) => {
rawScriptCoverage.url = rawScriptCoverage.url.replace(urlBase, cwd)
return rawScriptCoverage
})
// write the coverage like c8 expects it
await mkdir('coverage/tmp', { recursive: true })
await writeFile(`coverage/tmp/out.json`, JSON.stringify({ result })) If you want to evaluate the coverage with |
Hello ! I'm trying to get c8 to report coverage from Nightwatch.js From what I understand in this issue, what's missing is the sourcemap from url to local files. First of all, should I create a new ticket for that ? What would be the best way to get that sourcemap ? I'm thinking of two ways, either I listen to Debugger.scriptParsed events from devtools-protocol, and use the sourceMapURL to match the scriptId (looks like I'm out of luck SeleniumHQ/selenium#10804). Or I can download the bundles from Does this looks like a good way to get usage coverage ? Am I missing something ? any tips ? Thanks! |
@Cactusbone, aren't the source maps in the file system together with the bundled assets? You shouldn't need to fetch them using the browser devtools protocol. I use the code above to catch code coverage in the source files, with the help of the source maps: Sources:
Build output:
Test run:
Configuration in
Coverage check:
( |
@prantlf Thanks a lot ! This is what I was missing :) Since we're not storing either the bundles nor the sources on the filesystem, It wasn't working for me (and the |
Yes, it works ! I had to save both the bundles and its map at the root of the projet, and add the bundles to my However, with or without excludeAfterRemap, I get 100% coverage of way too many files (just like the issue you opened about and from the code, it's not possible, for example with a single passage in a function containing a if/else statement, I get both the if and the else paths covered |
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:
Chromium's format:
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-coverageI'm willing to contribute a PR normalizing this format difference when generating a report, would you accept it and may be provide some guidance?
The text was updated successfully, but these errors were encountered: