From efea8ead803e988f2dc9c24a41161c7d5d7f3ed2 Mon Sep 17 00:00:00 2001 From: Andy Weiss Date: Fri, 9 Aug 2024 17:21:29 -0400 Subject: [PATCH] Allow for Instanbul coverage with Playwright This makes the PlaywrightLauncherPage function similarly to the ChromeLauncher where we attempt to load the coverage from the browser and return that if availble during the stopSession method. Currently the Playwright launcher breaks early if the native instrumentation is not enabled. We changed to using the Playwright launcher and were suprised that our coverage stopped working even though we are using the babel istanbul plugin which worked when we were using the ChromeLauncher. --- .changeset/tidy-knives-agree.md | 5 +++++ .../test-runner-playwright/src/PlaywrightLauncherPage.ts | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/tidy-knives-agree.md diff --git a/.changeset/tidy-knives-agree.md b/.changeset/tidy-knives-agree.md new file mode 100644 index 000000000..5e91490a6 --- /dev/null +++ b/.changeset/tidy-knives-agree.md @@ -0,0 +1,5 @@ +--- +'@web/test-runner-playwright': patch +--- + +Support browser generated coverage without native instrumentation diff --git a/packages/test-runner-playwright/src/PlaywrightLauncherPage.ts b/packages/test-runner-playwright/src/PlaywrightLauncherPage.ts index fa4de283a..98dd3e84a 100644 --- a/packages/test-runner-playwright/src/PlaywrightLauncherPage.ts +++ b/packages/test-runner-playwright/src/PlaywrightLauncherPage.ts @@ -44,9 +44,7 @@ export class PlaywrightLauncherPage { } async stopSession(): Promise { - const testCoverage = this.nativeInstrumentationEnabledOnPage - ? await this.collectTestCoverage(this.config, this.testFiles) - : undefined; + const testCoverage = await this.collectTestCoverage(this.config, this.testFiles); // navigate to an empty page to kill any running code on the page, stopping timers and // breaking a potential endless reload loop @@ -82,6 +80,10 @@ export class PlaywrightLauncherPage { ); } + if (!this.nativeInstrumentationEnabledOnPage) { + return undefined; + } + // get native coverage from playwright let coverage: V8Coverage[]; if (this.product === 'chromium') {