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
Copy file name to clipboardExpand all lines: apps/site/pages/en/learn/test-runner/using-test-runner.md
+112
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,118 @@ Then for each setup, create a dedicated `setup` file (ensuring the base `setup.m
64
64
65
65
Each example below was taken from real-world projects; they may not be appropriate/applicable to yours, but each demonstrate general concepts that are broadly applicable.
66
66
67
+
## Dynamically generating test cases
68
+
69
+
Some times, you may want to dynamically generate test-cases. For instance, you want to test the same thing across a bunch of files. This is possible, albeit slightly arcane. You must use `test` (you cannot use `describe`) + `testContext.test`:
70
+
71
+
### Simple example
72
+
73
+
```js displayName="23.8.0 and later"
74
+
importassertfrom'node:assert/strict';
75
+
import { test } from'node:test';
76
+
77
+
import { detectOsInUserAgent } from'…';
78
+
79
+
constuserAgents= [
80
+
{ ua:/* … */, os:'WIN' },
81
+
// …
82
+
];
83
+
84
+
test('Detect OS via user-agent', { concurrency:true }, t=> {
> **Note**: Prior to version 23.8.0, the setup is quite different because `testContext.test` was not automatically awaited.
178
+
67
179
## ServiceWorker tests
68
180
69
181
[`ServiceWorkerGlobalScope`](https://developer.mozilla.org/docs/Web/API/ServiceWorkerGlobalScope) contains very specific APIs that don't exist in other environments, and some of its APIs are seemingly similar to others (ex `fetch`) but have augmented behaviour. You do not want these to spill into unrelated tests.
0 commit comments