Skip to content

Commit 9740c65

Browse files
fixup!: re-organise examples
1 parent 0844518 commit 9740c65

1 file changed

Lines changed: 26 additions & 24 deletions

File tree

apps/site/pages/en/learn/test-runner/using-test-runner.md

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,47 +68,49 @@ Each example below was taken from real-world projects; they may not be appropria
6868

6969
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`:
7070

71-
```js displayName="simple example (prior to 23.8.0)"
71+
### Simple example
72+
73+
```js displayName="23.8.0 and later"
7274
import assert from 'node:assert/strict';
7375
import { test } from 'node:test';
7476

7577
import { detectOsInUserAgent } from '';
7678

7779
const userAgents = [
78-
{ ua: '', os: 'WIN' },
80+
{ ua: /**/, os: 'WIN' },
7981
//
8082
];
8183

82-
test('Detect OS via user-agent', { concurrency: true }, async t => {
83-
const cases = userAgents.map(({ os, ua }) => {
84+
test('Detect OS via user-agent', { concurrency: true }, t => {
85+
for (const { os, ua } from userAgents) {
8486
t.test(ua, () => assert.equal(detectOsInUserAgent(ua), os));
85-
});
86-
87-
await Promise.allSettled(cases);
87+
}
8888
});
8989
```
9090

91-
```js displayName="simple example (23.8.0 and later)"
91+
```js displayName="prior to 23.8.0"
9292
import assert from 'node:assert/strict';
9393
import { test } from 'node:test';
9494

9595
import { detectOsInUserAgent } from '';
9696

9797
const userAgents = [
98-
{ ua: /**/, os: 'WIN' },
98+
{ ua: '', os: 'WIN' },
9999
//
100100
];
101101

102-
test('Detect OS via user-agent', { concurrency: true }, t => {
103-
for (const { os, ua } from userAgents) {
102+
test('Detect OS via user-agent', { concurrency: true }, async t => {
103+
const cases = userAgents.map(({ os, ua }) => {
104104
t.test(ua, () => assert.equal(detectOsInUserAgent(ua), os));
105-
}
105+
});
106+
107+
await Promise.allSettled(cases);
106108
});
107109
```
108110

109-
<!-- separate groups -->
111+
### Advanced example
110112

111-
```js displayName="Advanced example (prior to 23.8.0)"
113+
```js displayName="23.8.0 and later"
112114
import assert from 'node:assert/strict';
113115
import { test } from 'node:test';
114116

@@ -119,19 +121,16 @@ const requiredKeywords = ['node.js', 'sliced bread'];
119121
test('Check package.jsons', { concurrency: true }, async t => {
120122
const pjsons = await getWorkspacePJSONs();
121123

122-
const cases = pjsons.map(pjson =>
124+
for (const pjson of pjsons) {
123125
// ⚠️ `t.test`, NOT `test`
124126
t.test(`Ensure fields are properly set: ${pjson.name}`, () => {
125127
assert.partialDeepStrictEqual(pjson.keywords, requiredKeywords);
126-
})
127-
);
128-
129-
// Allow the cases to run concurrently.
130-
await Promise.allSettled(cases);
128+
});
129+
}
131130
});
132131
```
133132

134-
```js displayName="Advanced example (23.8.0 and later)"
133+
```js displayName="prior to 23.8.0"
135134
import assert from 'node:assert/strict';
136135
import { test } from 'node:test';
137136

@@ -142,12 +141,15 @@ const requiredKeywords = ['node.js', 'sliced bread'];
142141
test('Check package.jsons', { concurrency: true }, async t => {
143142
const pjsons = await getWorkspacePJSONs();
144143

145-
for (const pjson of pjsons) {
144+
const cases = pjsons.map(pjson =>
146145
// ⚠️ `t.test`, NOT `test`
147146
t.test(`Ensure fields are properly set: ${pjson.name}`, () => {
148147
assert.partialDeepStrictEqual(pjson.keywords, requiredKeywords);
149-
});
150-
}
148+
})
149+
);
150+
151+
// Allow the cases to run concurrently.
152+
await Promise.allSettled(cases);
151153
});
152154
```
153155

0 commit comments

Comments
 (0)