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