feat: add auto-fixture for Istanbul E2E coverage collection#95
Conversation
949accb to
9e471cd
Compare
3f9569d to
9cc5a5a
Compare
|
Hey, here's what needs to change in Everything is in 1. Add
interface PackageCRD {
spec?: {
packageName?: string;
dynamicArtifact?: string;
backstage?: {
role?: string;
};
appConfigExamples?: Array<{ ... }>;
};
}
export interface PluginMetadata {
packagePath: string;
pluginConfig: Record<string, unknown>;
packageName: string;
sourceFile: string;
role?: string;
}2. Parse the role in Just read it from the parsed YAML and include in the return: const role = parsed?.spec?.backstage?.role;
// ... in the return:
return { packagePath, pluginConfig: pluginConfig || {}, packageName, sourceFile: filePath, role };3. The actual swap — in This is the existing PR branch that already only runs when if (prOciUrls) {
const prUrl = prOciUrls.get(displayName);
if (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 };
}
}That regex appends That's it — only affects PR checks, only when |
fad896f to
7f4e86c
Compare
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: redhat-developer#95 (comment)
| _coverageCollector: [ | ||
| async ({ page }, use, testInfo) => { | ||
| await use(); | ||
| if (process.env.E2E_COLLECT_COVERAGE !== "1") return; |
There was a problem hiding this comment.
Mostly a consistency nit, but other boolean value environment variables in the codebase seem to prefer "true" rather than 1 (like here), though then there's also this check against either. I'm sure this isn't something that will be toggled a lot.
- Adds _coverageCollector automatic fixture to test object - Collects window.__coverage__ from browser after each test - Writes per-test JSON files to <outputDir>/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.
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: redhat-developer#95 (comment)
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: redhat-developer#95 (comment)
b3a6710 to
65e599a
Compare
Main branch was updated to 1.1.45, so this PR needs to bump to 1.1.46.
Co-authored-by: Subhash Khileri <subhashkhileri2@gmail.com>
Version 2.1.0 includes the automatic __coverage image swap logic from PR redhat-developer/rhdh-e2e-test-utils#95 (merged 2026-06-04). Changes: - Auto-fixture _coverageCollector that collects window.__coverage__ - Automatic swap to __coverage images when E2E_COLLECT_COVERAGE=true and plugin role is frontend-plugin This enables E2E coverage collection to work end-to-end.
Version 2.1.0 includes the automatic __coverage image swap logic from PR redhat-developer/rhdh-e2e-test-utils#95 (merged 2026-06-04). Changes: - Auto-fixture _coverageCollector that collects window.__coverage__ - Automatic swap to __coverage images when E2E_COLLECT_COVERAGE=true and plugin role is frontend-plugin This enables E2E coverage collection to work end-to-end.
Summary
_coverageCollectorauto-fixture to the sharedtestobject that automatically collectswindow.__coverage__from the browser after each testE2E_COLLECT_COVERAGE=1— zero overhead when disabled (nopage.evaluate, no fs operations)coverage/istanbul/(configurable viaCOVERAGE_OUTPUT_DIR)Why
The rhdh-plugin-export-overlays repo builds Istanbul-instrumented dynamic plugins and runs E2E tests against them. The instrumented plugins populate
window.__coverage__in the browser, but nothing collects it today.Since all 18 workspace test files import
testfrom@red-hat-developer-hub/e2e-test-utils/test, adding an auto-fixture here gives every test automatic coverage collection without modifying any test file.How it works
Design decisions
auto: true— runs for every test without test file changesscope: "test"— collects per-test, not per-workerawait use()first — teardown runs AFTER the test but BEFOREpagecloses (Playwright tears down in reverse dependency order)try/catchwith empty catch — best-effort; if the page crashed or plugin wasn't instrumented, silently skip_prefix — Playwright convention for internal auto-fixturesnode:fsand existingpathimportRelated PRs
Test plan
yarn buildsucceedsyarn typecheckpassesE2E_COLLECT_COVERAGE=1and an instrumented plugin: JSON files appear incoverage/istanbul/E2E_COLLECT_COVERAGE: no JSON files, no performance impact🤖 Generated with Claude Code