feat: add auto-fixture for Istanbul E2E coverage collection#95
feat: add auto-fixture for Istanbul E2E coverage collection#95gustavolira wants to merge 4 commits into
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 |
- 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.
fad896f to
7f4e86c
Compare
Remove dead link to default.packages.yaml (404) in older changelog entry. The file was removed or never existed at that path in the rhdh repo. Fixes CI markdown-link-check failure.
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)
✅ Implemented Coverage Image SwapImplemented all changes requested in #95 (comment) Changes Made1. Added export interface PluginMetadata {
packagePath: string;
pluginConfig: Record<string, unknown>;
packageName: string;
sourceFile: string;
role?: string; // ← Added
}
interface PackageCRD {
spec?: {
packageName?: string;
dynamicArtifact?: string;
backstage?: { // ← Added
role?: string;
};
appConfigExamples?: Array<{...}>;
};
}2. Parse const role = parsed?.spec?.backstage?.role;
// ... in return:
return {
packagePath,
pluginConfig: pluginConfig || {},
packageName,
sourceFile: filePath,
role, // ← Added
};3. Implemented 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 };
}
}How It WorksWhen running E2E tests in PR mode with
ScopeOnly affects PR mode ( Commit: 82061d5 Ready for review! |
Co-authored-by: Subhash Khileri <subhashkhileri2@gmail.com>
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