Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

All notable changes to this project will be documented in this file.

## [1.1.38] - Current
## [1.1.39] - 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 `<outputDir>/coverage/`. Enabled via `E2E_COLLECT_COVERAGE=1`. Zero overhead when disabled — no `page.evaluate` call or fs operations. Designed for use with instrumented dynamic plugin builds (nyc instrument).

## [1.1.38]

### Added

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@red-hat-developer-hub/e2e-test-utils",
"version": "1.1.38",
"version": "1.1.39",
"description": "Test utilities for RHDH E2E tests",
"license": "Apache-2.0",
"repository": {
Expand Down
31 changes: 31 additions & 0 deletions src/playwright/fixtures/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ 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 = {
rhdh: RHDHDeployment;
uiHelper: UIhelper;
loginHelper: LoginHelper;
autoAnnotations: void;
// eslint-disable-next-line @typescript-eslint/naming-convention
_coverageCollector: void;
};
Comment thread
gustavolira marked this conversation as resolved.

type RHDHDeploymentWorkerFixtures = {
Expand Down Expand Up @@ -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 !== "1") return;
try {
const coverage = await page.evaluate(
() =>
(
globalThis as unknown as {
// eslint-disable-next-line @typescript-eslint/naming-convention
__coverage__?: Record<string, unknown>;
}
).__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, {
Expand Down
Loading