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
+34Lines changed: 34 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,6 +64,40 @@ 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`) + `await testContext.test`:
t.test(`Ensure fields are properly set: ${pjson.name}`, () => {
89
+
assert.partialDeepStrictEqual(pjson.keywords, [
90
+
'node.js',
91
+
'sliced bread',
92
+
]);
93
+
})
94
+
);
95
+
96
+
// Allow the cases to run concurrently.
97
+
awaitPromise.allSettled(cases);
98
+
});
99
+
```
100
+
67
101
## ServiceWorker tests
68
102
69
103
[`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