Skip to content

Commit 838ff72

Browse files
committed
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 <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.
1 parent 93d7ff2 commit 838ff72

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

docs/changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
## [1.1.45] - Current
66

7+
### Added
8+
9+
- **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 `<outputDir>/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).
10+
711
### Fixed
812

913
- **`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.

src/playwright/fixtures/test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import { LoginHelper, UIhelper } from "../helpers/index.js";
44
import { runOnce } from "../run-once.js";
55
import { $ } from "../../utils/bash.js";
66
import { WorkspacePaths } from "../../utils/workspace-paths.js";
7+
import fs from "node:fs";
78
import path from "path";
89

910
type RHDHDeploymentTestFixtures = {
1011
rhdh: RHDHDeployment;
1112
uiHelper: UIhelper;
1213
loginHelper: LoginHelper;
1314
autoAnnotations: void;
15+
// eslint-disable-next-line @typescript-eslint/naming-convention
16+
_coverageCollector: void;
1417
};
1518

1619
type RHDHDeploymentWorkerFixtures = {
@@ -77,6 +80,34 @@ const baseTest = base.extend<
7780
},
7881
{ auto: true, scope: "test" },
7982
],
83+
// eslint-disable-next-line @typescript-eslint/naming-convention
84+
_coverageCollector: [
85+
async ({ page }, use, testInfo) => {
86+
await use();
87+
if (process.env.E2E_COLLECT_COVERAGE !== "true") return;
88+
try {
89+
const coverage = await page.evaluate(
90+
() =>
91+
(
92+
globalThis as unknown as {
93+
// eslint-disable-next-line @typescript-eslint/naming-convention
94+
__coverage__?: Record<string, unknown>;
95+
}
96+
).__coverage__,
97+
);
98+
if (!coverage) return;
99+
const dir = path.join(testInfo.project.outputDir, "coverage");
100+
fs.mkdirSync(dir, { recursive: true });
101+
fs.writeFileSync(
102+
path.join(dir, `${testInfo.testId}-${Date.now()}.json`),
103+
JSON.stringify(coverage),
104+
);
105+
} catch {
106+
// Best-effort: page may have crashed or been closed
107+
}
108+
},
109+
{ auto: true, scope: "test" },
110+
],
80111
});
81112

82113
export const test = Object.assign(baseTest, {

0 commit comments

Comments
 (0)