Skip to content

fix: coverage report with Istanbul instrumented code #2940

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/two-poems-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/test-runner-playwright': patch
---

Fixes coverage report collecting test coverage whenever the coverage is executed, not just when using the native instrumentation.
9 changes: 6 additions & 3 deletions packages/test-runner-playwright/src/PlaywrightLauncherPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class PlaywrightLauncherPage {
public playwrightContext: BrowserContext;
public playwrightPage: Page;
private nativeInstrumentationEnabledOnPage = false;
private collectCoverage = false;

constructor(
config: TestRunnerCoreConfig,
Expand All @@ -27,6 +28,8 @@ export class PlaywrightLauncherPage {
}

async runSession(url: string, coverage: boolean) {
this.collectCoverage = coverage;

if (
coverage &&
this.product === 'chromium' &&
Expand All @@ -44,7 +47,7 @@ export class PlaywrightLauncherPage {
}

async stopSession(): Promise<SessionResult> {
const testCoverage = this.nativeInstrumentationEnabledOnPage
const testCoverage = this.collectCoverage
? await this.collectTestCoverage(this.config, this.testFiles)
: undefined;

Expand Down Expand Up @@ -77,8 +80,8 @@ export class PlaywrightLauncherPage {
if (config.coverageConfig?.nativeInstrumentation === false) {
throw new Error(
'Coverage is enabled with nativeInstrumentation disabled. ' +
'Expected coverage provided in the browser as a global __coverage__ variable.' +
'Use a plugin like babel-plugin-istanbul to generate the coverage, or enable native instrumentation.',
'Expected coverage provided in the browser as a global __coverage__ variable.' +
'Use a plugin like babel-plugin-istanbul to generate the coverage, or enable native instrumentation.',
);
}

Expand Down
Loading