-
Notifications
You must be signed in to change notification settings - Fork 94
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
Document how to use with puppeteer? #162
Comments
Puppeteer aggregates results that is returned from raw chrome dev tools protocol |
@stevenvachon, |
@bcoe then why are you creating this library, if not to replace nyc and/or the use of istanbul? |
Because they do two different things? Istanbul transpiles your source code into a form that collects test coverage, c8 turns on V8's built in test coverage and runs reports. It happens that puppeteer can be made to output coverage in the same form as V8, so some of the toolchain for processing these reports is shared. |
Ahoy ahoy 🦜 If anyone would like to know how to use |
I was able to get The code I wrote is as follows: await page.coverage.startJSCoverage({includeRawScriptCoverage: true});
// Do your tests...
const jsCoverage = await page.coverage.stopJSCoverage();
// Point to original .js files
const coverage = jsCoverage
.map(({rawScriptCoverage: it}) => ({
...it,
scriptId: String(it.scriptId),
url: it.url.replace(
new RegExp(`${ origin }(?<pathname>.*)`),
(...[, , , , { pathname }]) => `${
pathname.match(/^\/src/)
? process.cwd()
: path.resolve(dirPath, base)
}${ pathname.replace(/([#?].*)/, '')
.replace(/\//g, path.sep) }`,
})));
// Export coverage data
jsCoverage.forEach((it, idx) =>
fs.writeFileSync(
`${
process.env.NODE_V8_COVERAGE
}/coverage-${Date.now()}-${idx}.json`,
JSON.stringify({result: [it]})
)
); |
@queengooborg this is slick, we should document how to do this 😄 |
That would be great, yeah! I was thinking of submitting a PR to add it, but I wasn't sure where to add it -- any particular location you'd think would work best? |
@queengooborg we could add a |
IMO, it might be both |
Any updates on this? |
startJSCOverage does not seem to have this includeRawScriptCoverage: true |
Previously, with nyc, I was using puppeteer-to-istanbul, but now I'm not sure what to do. c8 needs to receive the reports from puppeteer somehow.
The text was updated successfully, but these errors were encountered: