Collect coverage reports from electron tests
Opened this issue · 0 comments
Irev-Dev commented
In our test setup we have the following block.
if (process.env.GENERATE_PLAYWRIGHT_COVERAGE) {
await context.addInitScript(() =>
window.addEventListener('beforeunload', () =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).collectIstanbulCoverage(
JSON.stringify((window as any).__coverage__)
)
)
)
const istanbulCLIOutput = join(process.cwd(), '.nyc_output')
await fsp.mkdir(istanbulCLIOutput, { recursive: true })
await context.exposeFunction(
'collectIstanbulCoverage',
(coverageJSON: string) => {
if (coverageJSON) {
fs.writeFileSync(
join(istanbulCLIOutput, `playwright_coverage_${uuidv4()}.json`),
coverageJSON
)
}
}
)
}
Which than allows
await activePage.evaluate(() =>
(window as any).collectIstanbulCoverage(
JSON.stringify((window as any).__coverage__)
)
)
To run to collect coverage in the test tear down. However we get "window.collectIstanbulCoverage
is not a function" errors in electron. as far as I could see there was no obvious work around from google, or why the exposeFunction isn't working in an electron context, so for now we have GENERATE_PLAYWRIGHT_COVERAGE: false
for the electron tests.
Maybe using the electron specific exposeInMainWorld
could be a work around?