Skip to content

Commit 770c7c7

Browse files
BridgeARaddaleax
authored andcommitted
test: improve the test common documentation
PR-URL: nodejs#14148 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Timothy Gu <[email protected]>
1 parent d7a1637 commit 770c7c7

File tree

1 file changed

+90
-71
lines changed

1 file changed

+90
-71
lines changed

test/common/README.md

Lines changed: 90 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ The `common` module is used by tests for consistency across repeated
1313
tasks.
1414

1515
### allowGlobals(...whitelist)
16-
* `whitelist` [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) Array of Globals
17-
* return [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
16+
* `whitelist` [&lt;Array>] Array of Globals
17+
* return [&lt;Array>]
1818

1919
Takes `whitelist` and concats that with predefined `knownGlobals`.
2020

2121
### arrayStream
2222
A stream to push an array into a REPL
2323

2424
### busyLoop(time)
25-
* `time` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
25+
* `time` [&lt;Number>]
2626

2727
Blocks for `time` amount of time.
2828

@@ -41,177 +41,185 @@ no unexpected rejections occur, because currently they result in silent
4141
failures.
4242

4343
### ddCommand(filename, kilobytes)
44-
* return [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
44+
* return [&lt;Object>]
4545

4646
Platform normalizes the `dd` command
4747

4848
### enoughTestMem
49-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
49+
* return [&lt;Boolean>]
5050

5151
Check if there is more than 1gb of total memory.
5252

53-
### expectsError(settings)
54-
* `settings` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
53+
### expectsError([fn, ]settings[, exact])
54+
* `fn` [&lt;Function>]
55+
* `settings` [&lt;Object>]
5556
with the following optional properties:
56-
* `code` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
57+
* `code` [&lt;String>]
5758
expected error must have this value for its `code` property
58-
* `type` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
59+
* `type` [&lt;Function>]
5960
expected error must be an instance of `type`
60-
* `message` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
61-
or [&lt;RegExp>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
61+
* `message` [&lt;String>]
62+
or [&lt;RegExp>]
6263
if a string is provided for `message`, expected error must have it for its
6364
`message` property; if a regular expression is provided for `message`, the
6465
regular expression must match the `message` property of the expected error
66+
* `exact` [&lt;Number>] default = 1
6567

6668
* return function suitable for use as a validation function passed as the second
67-
argument to `assert.throws()`
69+
argument to e.g. `assert.throws()`. If the returned function has not been
70+
called exactly `exact` number of times when the test is complete, then the
71+
test will fail.
72+
73+
If `fn` is provided, it will be passed to `assert.throws` as first argument.
6874

6975
The expected error should be [subclassed by the `internal/errors` module](https://github.com/nodejs/node/blob/master/doc/guides/using-internal-errors.md#api).
7076

7177
### expectWarning(name, expected)
72-
* `name` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
73-
* `expected` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) | [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
78+
* `name` [&lt;String>]
79+
* `expected` [&lt;String>] | [&lt;Array>]
7480

7581
Tests whether `name` and `expected` are part of a raised warning.
7682

7783
### fileExists(pathname)
78-
* pathname [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
79-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
84+
* pathname [&lt;String>]
85+
* return [&lt;Boolean>]
8086

8187
Checks if `pathname` exists
8288

8389
### fixturesDir
84-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
90+
* return [&lt;String>]
8591

8692
Path to the 'fixtures' directory.
8793

8894
### getArrayBufferViews(buf)
89-
* `buf` [&lt;Buffer>](https://nodejs.org/api/buffer.html#buffer_class_buffer)
90-
* return [&lt;ArrayBufferView&#91;&#93;>](https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView)
95+
* `buf` [&lt;Buffer>]
96+
* return [&lt;ArrayBufferView&#91;&#93;>]
9197

9298
Returns an instance of all possible `ArrayBufferView`s of the provided Buffer.
9399

94100
### globalCheck
95-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
101+
* return [&lt;Boolean>]
96102

97103
Turn this off if the test should not check for global leaks.
98104

99105
### hasCrypto
100-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
106+
* return [&lt;Boolean>]
101107

102108
Checks for 'openssl'.
103109

104110
### hasFipsCrypto
105-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
111+
* return [&lt;Boolean>]
106112

107113
Checks `hasCrypto` and `crypto` with fips.
108114

109115
### hasIntl
110-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
116+
* return [&lt;Boolean>]
111117

112118
Checks if [internationalization] is supported.
113119

114120
### hasSmallICU
115-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
121+
* return [&lt;Boolean>]
116122

117123
Checks `hasIntl` and `small-icu` is supported.
118124

119125
### hasIPv6
120-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
126+
* return [&lt;Boolean>]
121127

122128
Checks whether `IPv6` is supported on this platform.
123129

124130
### hasMultiLocalhost
125-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
131+
* return [&lt;Boolean>]
126132

127133
Checks if there are multiple localhosts available.
128134

129135
### hijackStderr(listener)
130-
* `listener` [&lt;Function>][MDN-Function]: a listener with a single parameter called `data`.
136+
* `listener` [&lt;Function>]: a listener with a single parameter
137+
called `data`.
131138

132139
Eavesdrop to `process.stderr.write` calls. Once `process.stderr.write` is
133140
called, `listener` will also be called and the `data` of `write` function will
134141
be passed to `listener`. What's more, `process.stderr.writeTimes` is a count of
135142
the number of calls.
136143

137144
### hijackStdout(listener)
138-
* `listener` [&lt;Function>][MDN-Function]: a listener with a single parameter called `data`.
145+
* `listener` [&lt;Function>]: a listener with a single parameter
146+
called `data`.
139147

140148
Eavesdrop to `process.stdout.write` calls. Once `process.stdout.write` is
141149
called, `listener` will also be called and the `data` of `write` function will
142150
be passed to `listener`. What's more, `process.stdout.writeTimes` is a count of
143151
the number of calls.
144152

145153
### inFreeBSDJail
146-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
154+
* return [&lt;Boolean>]
147155

148156
Checks whether free BSD Jail is true or false.
149157

150158
### isAIX
151-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
159+
* return [&lt;Boolean>]
152160

153161
Platform check for Advanced Interactive eXecutive (AIX).
154162

155163
### isAlive(pid)
156-
* `pid` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
157-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
164+
* `pid` [&lt;Number>]
165+
* return [&lt;Boolean>]
158166

159167
Attempts to 'kill' `pid`
160168

161169
### isFreeBSD
162-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
170+
* return [&lt;Boolean>]
163171

164172
Platform check for Free BSD.
165173

166174
### isLinux
167-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
175+
* return [&lt;Boolean>]
168176

169177
Platform check for Linux.
170178

171179
### isLinuxPPCBE
172-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
180+
* return [&lt;Boolean>]
173181

174182
Platform check for Linux on PowerPC.
175183

176184
### isOSX
177-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
185+
* return [&lt;Boolean>]
178186

179187
Platform check for macOS.
180188

181189
### isSunOS
182-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
190+
* return [&lt;Boolean>]
183191

184192
Platform check for SunOS.
185193

186194
### isWindows
187-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
195+
* return [&lt;Boolean>]
188196

189197
Platform check for Windows.
190198

191199
### isWOW64
192-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
200+
* return [&lt;Boolean>]
193201

194202
Platform check for Windows 32-bit on Windows 64-bit.
195203

196204
### leakedGlobals
197-
* return [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
205+
* return [&lt;Array>]
198206

199207
Checks whether any globals are not on the `knownGlobals` list.
200208

201209
### localhostIPv4
202-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
210+
* return [&lt;String>]
203211

204212
Gets IP of localhost
205213

206214
### localIPv6Hosts
207-
* return [&lt;Array>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
215+
* return [&lt;Array>]
208216

209217
Array of IPV6 hosts.
210218

211219
### mustCall([fn][, exact])
212-
* `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = () => {}
213-
* `exact` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
214-
* return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
220+
* `fn` [&lt;Function>] default = () => {}
221+
* `exact` [&lt;Number>] default = 1
222+
* return [&lt;Function>]
215223

216224
Returns a function that calls `fn`. If the returned function has not been called
217225
exactly `expected` number of times when the test is complete, then the test will
@@ -220,9 +228,9 @@ fail.
220228
If `fn` is not provided, an empty function will be used.
221229

222230
### mustCallAtLeast([fn][, minimum])
223-
* `fn` [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) default = () => {}
224-
* `minimum` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = 1
225-
* return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
231+
* `fn` [&lt;Function>] default = () => {}
232+
* `minimum` [&lt;Number>] default = 1
233+
* return [&lt;Function>]
226234

227235
Returns a function that calls `fn`. If the returned function has not been called
228236
at least `minimum` number of times when the test is complete, then the test will
@@ -231,46 +239,49 @@ fail.
231239
If `fn` is not provided, an empty function will be used.
232240

233241
### mustNotCall([msg])
234-
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type) default = 'function should not have been called'
235-
* return [&lt;Function>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)
242+
* `msg` [&lt;String>] default = 'function should not have been called'
243+
* return [&lt;Function>]
236244

237-
Returns a function that triggers an `AssertionError` if it is invoked. `msg` is used as the error message for the `AssertionError`.
245+
Returns a function that triggers an `AssertionError` if it is invoked. `msg` is
246+
used as the error message for the `AssertionError`.
238247

239248
### nodeProcessAborted(exitCode, signal)
240-
* `exitCode` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
241-
* `signal` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
242-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
249+
* `exitCode` [&lt;Number>]
250+
* `signal` [&lt;String>]
251+
* return [&lt;Boolean>]
243252

244-
Returns `true` if the exit code `exitCode` and/or signal name `signal` represent the exit code and/or signal name of a node process that aborted, `false` otherwise.
253+
Returns `true` if the exit code `exitCode` and/or signal name `signal` represent
254+
the exit code and/or signal name of a node process that aborted, `false`
255+
otherwise.
245256

246257
### opensslCli
247-
* return [&lt;Boolean>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type)
258+
* return [&lt;Boolean>]
248259

249260
Checks whether 'opensslCli' is supported.
250261

251262
### platformTimeout(ms)
252-
* `ms` [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
253-
* return [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type)
263+
* `ms` [&lt;Number>]
264+
* return [&lt;Number>]
254265

255266
Platform normalizes timeout.
256267

257268
### PIPE
258-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
269+
* return [&lt;String>]
259270

260271
Path to the test sock.
261272

262273
### PORT
263-
* return [&lt;Number>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type) default = `12346`
274+
* return [&lt;Number>] default = `12346`
264275

265276
Port tests are running on.
266277

267278
### printSkipMessage(msg)
268-
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
279+
* `msg` [&lt;String>]
269280

270281
Logs '1..0 # Skipped: ' + `msg`
271282

272283
### refreshTmpDir
273-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
284+
* return [&lt;String>]
274285

275286
Deletes the 'tmp' dir and recreates it
276287

@@ -283,34 +294,34 @@ Restore the original `process.stderr.write`.
283294
Restore the original `process.stdout.write`.
284295

285296
### rootDir
286-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
297+
* return [&lt;String>]
287298

288299
Path to the 'root' directory. either `/` or `c:\\` (windows)
289300

290301
### skip(msg)
291-
* `msg` [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
302+
* `msg` [&lt;String>]
292303

293304
Logs '1..0 # Skipped: ' + `msg` and exits with exit code `0`.
294305

295306
### spawnPwd(options)
296-
* `options` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
297-
* return [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
307+
* `options` [&lt;Object>]
308+
* return [&lt;Object>]
298309

299310
Platform normalizes the `pwd` command.
300311

301312
### spawnSyncPwd(options)
302-
* `options` [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
303-
* return [&lt;Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
313+
* `options` [&lt;Object>]
314+
* return [&lt;Object>]
304315

305316
Synchronous version of `spawnPwd`.
306317

307318
### tmpDir
308-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
319+
* return [&lt;String>]
309320

310321
The realpath of the 'tmp' directory.
311322

312323
### tmpDirName
313-
* return [&lt;String>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type)
324+
* return [&lt;String>]
314325

315326
Name of the temp directory used by tests.
316327

@@ -323,5 +334,13 @@ Node.js
323334
implementation with tests from
324335
[W3C Web Platform Tests](https://github.com/w3c/web-platform-tests).
325336

326-
[MDN-Function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Normal_objects_and_functions
337+
[&lt;Array>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
338+
[&lt;ArrayBufferView&#91;&#93;>]: https://developer.mozilla.org/en-US/docs/Web/API/ArrayBufferView
339+
[&lt;Boolean>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type
340+
[&lt;Buffer>]: https://nodejs.org/api/buffer.html#buffer_class_buffer
341+
[&lt;Function>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function
342+
[&lt;Number>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type
343+
[&lt;Object>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object
344+
[&lt;RegExp>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
345+
[&lt;String>]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type
327346
[internationalization]: https://github.com/nodejs/node/wiki/Intl

0 commit comments

Comments
 (0)