Skip to content
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

Collect coverage reports from electron tests #3885

Open
Irev-Dev opened this issue Sep 14, 2024 · 0 comments
Open

Collect coverage reports from electron tests #3885

Irev-Dev opened this issue Sep 14, 2024 · 0 comments
Labels
dev Issues related to development of the app.

Comments

@Irev-Dev
Copy link
Collaborator

Irev-Dev commented Sep 14, 2024

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?

@Irev-Dev Irev-Dev added the dev Issues related to development of the app. label Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev Issues related to development of the app.
Projects
None yet
Development

No branches or pull requests

1 participant