Skip to content

Commit cb10cd1

Browse files
committed
fix: coverage report with instrumented code
1 parent 29f73c5 commit cb10cd1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.changeset/two-poems-learn.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@web/test-runner-playwright': patch
3+
---
4+
5+
Fixes coverage report collecting test coverage whenever the coverage is executed, not just when using the native instrumentation.

packages/test-runner-playwright/src/PlaywrightLauncherPage.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export class PlaywrightLauncherPage {
1111
public playwrightContext: BrowserContext;
1212
public playwrightPage: Page;
1313
private nativeInstrumentationEnabledOnPage = false;
14+
private collectCoverage = false;
1415

1516
constructor(
1617
config: TestRunnerCoreConfig,
@@ -27,6 +28,8 @@ export class PlaywrightLauncherPage {
2728
}
2829

2930
async runSession(url: string, coverage: boolean) {
31+
this.collectCoverage = coverage;
32+
3033
if (
3134
coverage &&
3235
this.product === 'chromium' &&
@@ -44,7 +47,7 @@ export class PlaywrightLauncherPage {
4447
}
4548

4649
async stopSession(): Promise<SessionResult> {
47-
const testCoverage = this.nativeInstrumentationEnabledOnPage
50+
const testCoverage = this.collectCoverage
4851
? await this.collectTestCoverage(this.config, this.testFiles)
4952
: undefined;
5053

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

0 commit comments

Comments
 (0)