You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shared RHDH deployment across all tests in a worker.
19
+
Shared RHDH deployment across all tests in a worker. Wrap expensive setup in `test.runOnce` to avoid re-deploying when workers restart after test failures.
Executes `fn` exactly once per test run, even across worker restarts. Returns `true` if executed, `false` if skipped. Useful for expensive or persistent operations (deployments, database seeding, service provisioning) that should not repeat after a worker restart.
92
+
93
+
| Parameter | Type | Description |
94
+
|-----------|------|-------------|
95
+
|`key`|`string`| Unique identifier for this operation |
96
+
|`fn`|`() => Promise<void> \| void`| Function to execute once |
97
+
98
+
```typescript
99
+
test.beforeAll(async ({ rhdh }) => {
100
+
awaittest.runOnce("my-deploy", async () => {
101
+
awaitrhdh.configure({ auth: "keycloak" });
102
+
awaitrhdh.deploy();
103
+
});
104
+
});
105
+
```
106
+
107
+
See [Playwright Fixtures — `test.runOnce`](/guide/core-concepts/playwright-fixtures#test-runonce-—-execute-a-function-once-per-test-run) for detailed usage and examples.
Copy file name to clipboardExpand all lines: docs/changelog.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,17 @@
2
2
3
3
All notable changes to this project will be documented in this file.
4
4
5
-
## [1.1.13] - Current
5
+
## [1.1.14] - Current
6
+
7
+
### Added
8
+
-**`test.runOnce(key, fn)`**: Execute a function exactly once per test run, even across worker restarts. Prevents re-running expensive operations (deployments, service provisioning, data seeding) when Playwright creates new workers after test failures.
9
+
-**Teardown reporter**: Built-in Playwright reporter that automatically deletes Kubernetes namespaces after all tests complete. Active only in CI (`process.env.CI`).
10
+
-**`registerTeardownNamespace(projectName, namespace)`**: Register custom namespaces for automatic cleanup. Import from `@red-hat-developer-hub/e2e-test-utils/teardown`.
11
+
12
+
### Changed
13
+
- Namespace cleanup moved from worker fixture to teardown reporter to prevent premature deletion on test failures.
## `test.runOnce` — Execute a Function Once Per Test Run
158
158
159
-
In CI environments (when `CI` environment variable is set):
159
+
Playwright's `beforeAll` runs once **per worker**, not once per test run. When a test fails, Playwright kills the worker and creates a new one for remaining tests — causing `beforeAll` to run again. For operations that are expensive or produce persistent side effects, this leads to unnecessary re-execution.
160
160
161
-
- Namespaces are automatically deleted after tests complete
162
-
- Prevents resource accumulation on shared clusters
161
+
`test.runOnce` ensures a function executes **exactly once per test run**, even across worker restarts:
In CI environments (`CI` environment variable is set), namespaces are automatically deleted after all tests complete. This is handled by a built-in **teardown reporter** that:
216
+
217
+
1. Runs in the main Playwright process (survives worker restarts)
218
+
2. Waits for **all tests** in a project to finish
219
+
3. Deletes the namespace matching the project name
220
+
221
+
### Default Behavior
222
+
223
+
No configuration needed. The namespace is derived from your project name:
224
+
225
+
```typescript
226
+
// playwright.config.ts
227
+
projects: [
228
+
{ name: "tech-radar" }, // Namespace "tech-radar" deleted after all tests
229
+
{ name: "catalog" }, // Namespace "catalog" deleted after all tests
230
+
]
231
+
```
232
+
233
+
### Custom Namespaces
234
+
235
+
If you deploy to a namespace that differs from the project name, register it for cleanup:
This permanently deletes all resources in the namespace. In CI, this happens automatically.
181
+
You typically don't need to call this manually. In CI, the built-in teardown reporter automatically deletes namespaces after all tests complete. See [Namespace Cleanup](/guide/core-concepts/playwright-fixtures#namespace-cleanup-teardown).
180
182
:::
181
183
182
184
## Properties
@@ -259,21 +261,23 @@ import { test } from "@red-hat-developer-hub/e2e-test-utils/test";
0 commit comments