From 838ff727dd1ce0bbb00bf47060d206d6c857b17b Mon Sep 17 00:00:00 2001 From: Gustavo Lira Date: Wed, 3 Jun 2026 17:59:24 -0300 Subject: [PATCH 1/5] feat: add auto-fixture for Istanbul E2E coverage collection - Adds _coverageCollector automatic fixture to test object - Collects window.__coverage__ from browser after each test - Writes per-test JSON files to /coverage/ - Enabled via E2E_COLLECT_COVERAGE=1 - Zero overhead when disabled (no page.evaluate or fs operations) - Designed for use with instrumented dynamic plugin builds This enables automatic E2E coverage collection for all workspaces in rhdh-plugin-export-overlays without modifying any test files. --- docs/changelog.md | 4 ++++ src/playwright/fixtures/test.ts | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index 5430936..4e6f05a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [1.1.45] - Current +### Added + +- **E2E coverage collection auto-fixture**: New `_coverageCollector` automatic fixture collects Istanbul coverage (`window.__coverage__`) from the browser after each test and writes per-test JSON files to `/coverage/`. Enabled via `E2E_COLLECT_COVERAGE=true`. Zero overhead when disabled — no `page.evaluate` call or fs operations. Designed for use with instrumented dynamic plugin builds (nyc instrument). + ### Fixed - **`default.packages.yaml` fetch URL**: `release-1.10` continues to fetch from the `rhdh` repo; all other branches (including `main`) now fetch from `rhdh-plugin-export-overlays` where the file was moved. diff --git a/src/playwright/fixtures/test.ts b/src/playwright/fixtures/test.ts index 4456227..e9d2227 100644 --- a/src/playwright/fixtures/test.ts +++ b/src/playwright/fixtures/test.ts @@ -4,6 +4,7 @@ import { LoginHelper, UIhelper } from "../helpers/index.js"; import { runOnce } from "../run-once.js"; import { $ } from "../../utils/bash.js"; import { WorkspacePaths } from "../../utils/workspace-paths.js"; +import fs from "node:fs"; import path from "path"; type RHDHDeploymentTestFixtures = { @@ -11,6 +12,8 @@ type RHDHDeploymentTestFixtures = { uiHelper: UIhelper; loginHelper: LoginHelper; autoAnnotations: void; + // eslint-disable-next-line @typescript-eslint/naming-convention + _coverageCollector: void; }; type RHDHDeploymentWorkerFixtures = { @@ -77,6 +80,34 @@ const baseTest = base.extend< }, { auto: true, scope: "test" }, ], + // eslint-disable-next-line @typescript-eslint/naming-convention + _coverageCollector: [ + async ({ page }, use, testInfo) => { + await use(); + if (process.env.E2E_COLLECT_COVERAGE !== "true") return; + try { + const coverage = await page.evaluate( + () => + ( + globalThis as unknown as { + // eslint-disable-next-line @typescript-eslint/naming-convention + __coverage__?: Record; + } + ).__coverage__, + ); + if (!coverage) return; + const dir = path.join(testInfo.project.outputDir, "coverage"); + fs.mkdirSync(dir, { recursive: true }); + fs.writeFileSync( + path.join(dir, `${testInfo.testId}-${Date.now()}.json`), + JSON.stringify(coverage), + ); + } catch { + // Best-effort: page may have crashed or been closed + } + }, + { auto: true, scope: "test" }, + ], }); export const test = Object.assign(baseTest, { From 309c8b19a5c7f8bc4365b9d90927642efe6f1ea5 Mon Sep 17 00:00:00 2001 From: Gustavo Lira Date: Wed, 3 Jun 2026 18:59:16 -0300 Subject: [PATCH 2/5] feat: auto-swap to __coverage images for frontend plugins in PR mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements automatic image tag swap from 'pr_XXX__version' to 'pr_XXX__version__coverage' when E2E_COLLECT_COVERAGE=1 is set and the plugin is a frontend-plugin. Changes: 1. Add 'role' field to PluginMetadata and PackageCRD types 2. Parse spec.backstage.role in parseMetadataFile() 3. Swap to __coverage tag in resolvePluginPackages() when: - GIT_PR_NUMBER is set (PR mode) - E2E_COLLECT_COVERAGE=1 - Plugin role is 'frontend-plugin' The regex preserves OCI alias: plugin:tag!alias → plugin:tag__coverage!alias Only affects PR checks. Nightly mode, {{inherit}}, and local dev paths are unchanged. Backend plugins skip the swap (no browser coverage). Implements: https://github.com/redhat-developer/rhdh-e2e-test-utils/pull/95#issuecomment-4594591707 --- src/utils/plugin-metadata.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/utils/plugin-metadata.ts b/src/utils/plugin-metadata.ts index 4dc6828..98bda94 100644 --- a/src/utils/plugin-metadata.ts +++ b/src/utils/plugin-metadata.ts @@ -14,12 +14,16 @@ export interface PluginMetadata { pluginConfig: Record; packageName: string; sourceFile: string; + role?: string; } interface PackageCRD { spec?: { packageName?: string; dynamicArtifact?: string; + backstage?: { + role?: string; + }; appConfigExamples?: Array<{ title?: string; content?: Record; @@ -227,6 +231,7 @@ export async function parseMetadataFile( const packagePath = parsed?.spec?.dynamicArtifact; const packageName = parsed?.spec?.packageName; const pluginConfig = parsed?.spec?.appConfigExamples?.[0]?.content; + const role = parsed?.spec?.backstage?.role; if (!packagePath) { throw new Error( @@ -244,6 +249,7 @@ export async function parseMetadataFile( pluginConfig: pluginConfig || {}, packageName, sourceFile: filePath, + role, }; } @@ -482,8 +488,14 @@ async function resolvePluginPackages( if (prOciUrls) { const prUrl = prOciUrls.get(displayName); if (prUrl) { - console.log(`[PluginMetadata] PR: ${pkg} → ${prUrl}`); - return { ...plugin, package: prUrl }; + const usesCoverage = + process.env.E2E_COLLECT_COVERAGE === "1" && + metadata.role === "frontend-plugin"; + const resolved = usesCoverage + ? prUrl.replace(/(:[^!]+)/, "$1__coverage") + : prUrl; + console.log(`[PluginMetadata] PR: ${pkg} → ${resolved}`); + return { ...plugin, package: resolved }; } } From 65e599a8095162fe6d0fd66f917723315955dc93 Mon Sep 17 00:00:00 2001 From: Gustavo Lira Date: Thu, 4 Jun 2026 10:52:20 -0300 Subject: [PATCH 3/5] fix: use "true" instead of "1" for E2E_COLLECT_COVERAGE env var For consistency with other boolean env vars in the codebase (like E2E_NIGHTLY_MODE, USE_NEW_FRONTEND_SYSTEM), change from checking "1" to checking "true". Updated in: - src/playwright/fixtures/test.ts (_coverageCollector fixture) - src/utils/plugin-metadata.ts (coverage image swap) - docs/changelog.md (documentation) Addresses: https://github.com/redhat-developer/rhdh-e2e-test-utils/pull/95#discussion_r3355287609 --- src/utils/plugin-metadata.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/plugin-metadata.ts b/src/utils/plugin-metadata.ts index 98bda94..5347944 100644 --- a/src/utils/plugin-metadata.ts +++ b/src/utils/plugin-metadata.ts @@ -489,7 +489,7 @@ async function resolvePluginPackages( const prUrl = prOciUrls.get(displayName); if (prUrl) { const usesCoverage = - process.env.E2E_COLLECT_COVERAGE === "1" && + process.env.E2E_COLLECT_COVERAGE === "true" && metadata.role === "frontend-plugin"; const resolved = usesCoverage ? prUrl.replace(/(:[^!]+)/, "$1__coverage") From 93661eb13d13e260692cf4557670040ba51e66a1 Mon Sep 17 00:00:00 2001 From: Gustavo Lira Date: Thu, 4 Jun 2026 11:04:55 -0300 Subject: [PATCH 4/5] chore: bump version to 1.1.46 Main branch was updated to 1.1.45, so this PR needs to bump to 1.1.46. --- docs/changelog.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 4e6f05a..b917d4e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -## [1.1.45] - Current +## [1.1.46] - Current ### Added diff --git a/package.json b/package.json index a71e710..121f2c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@red-hat-developer-hub/e2e-test-utils", - "version": "1.1.45", + "version": "1.1.46", "description": "Test utilities for RHDH E2E tests", "license": "Apache-2.0", "repository": { From d67e58374937a7bdce0e1c421487ef19b82e400b Mon Sep 17 00:00:00 2001 From: Subhash Khileri Date: Thu, 4 Jun 2026 19:52:25 +0530 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Subhash Khileri --- docs/changelog.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index b917d4e..6f10483 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file. -## [1.1.46] - Current +## [2.1.0] - Current ### Added diff --git a/package.json b/package.json index 121f2c3..3a5d0b5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@red-hat-developer-hub/e2e-test-utils", - "version": "1.1.46", + "version": "2.1.0", "description": "Test utilities for RHDH E2E tests", "license": "Apache-2.0", "repository": {