@types/node 18.19.22 → 18.19.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. node v18.19/README.md +1 -1
  2. node v18.19/package.json +3 -10
  3. node v18.19/ts4.8/assert/strict.d.ts +0 -8
  4. node v18.19/ts4.8/assert.d.ts +0 -985
  5. node v18.19/ts4.8/async_hooks.d.ts +0 -522
  6. node v18.19/ts4.8/buffer.d.ts +0 -2353
  7. node v18.19/ts4.8/child_process.d.ts +0 -1544
  8. node v18.19/ts4.8/cluster.d.ts +0 -432
  9. node v18.19/ts4.8/console.d.ts +0 -412
  10. node v18.19/ts4.8/constants.d.ts +0 -19
  11. node v18.19/ts4.8/crypto.d.ts +0 -4457
  12. node v18.19/ts4.8/dgram.d.ts +0 -596
  13. node v18.19/ts4.8/diagnostics_channel.d.ts +0 -546
  14. node v18.19/ts4.8/dns/promises.d.ts +0 -381
  15. node v18.19/ts4.8/dns.d.ts +0 -809
  16. node v18.19/ts4.8/dom-events.d.ts +0 -122
  17. node v18.19/ts4.8/domain.d.ts +0 -170
  18. node v18.19/ts4.8/events.d.ts +0 -819
  19. node v18.19/ts4.8/fs/promises.d.ts +0 -1205
  20. node v18.19/ts4.8/fs.d.ts +0 -4231
  21. node v18.19/ts4.8/globals.d.ts +0 -377
  22. node v18.19/ts4.8/globals.global.d.ts +0 -1
  23. node v18.19/ts4.8/http.d.ts +0 -1803
  24. node v18.19/ts4.8/http2.d.ts +0 -2386
  25. node v18.19/ts4.8/https.d.ts +0 -544
  26. node v18.19/ts4.8/index.d.ts +0 -88
  27. node v18.19/ts4.8/inspector.d.ts +0 -2739
  28. node v18.19/ts4.8/module.d.ts +0 -298
  29. node v18.19/ts4.8/net.d.ts +0 -918
  30. node v18.19/ts4.8/os.d.ts +0 -473
  31. node v18.19/ts4.8/path.d.ts +0 -191
  32. node v18.19/ts4.8/perf_hooks.d.ts +0 -626
  33. node v18.19/ts4.8/process.d.ts +0 -1548
  34. node v18.19/ts4.8/punycode.d.ts +0 -117
  35. node v18.19/ts4.8/querystring.d.ts +0 -141
  36. node v18.19/ts4.8/readline/promises.d.ts +0 -143
  37. node v18.19/ts4.8/readline.d.ts +0 -666
  38. node v18.19/ts4.8/repl.d.ts +0 -430
  39. node v18.19/ts4.8/stream/consumers.d.ts +0 -12
  40. node v18.19/ts4.8/stream/promises.d.ts +0 -83
  41. node v18.19/ts4.8/stream/web.d.ts +0 -352
  42. node v18.19/ts4.8/stream.d.ts +0 -1731
  43. node v18.19/ts4.8/string_decoder.d.ts +0 -67
  44. node v18.19/ts4.8/test.d.ts +0 -1113
  45. node v18.19/ts4.8/timers/promises.d.ts +0 -93
  46. node v18.19/ts4.8/timers.d.ts +0 -126
  47. node v18.19/ts4.8/tls.d.ts +0 -1203
  48. node v18.19/ts4.8/trace_events.d.ts +0 -171
  49. node v18.19/ts4.8/tty.d.ts +0 -206
  50. node v18.19/ts4.8/url.d.ts +0 -954
  51. node v18.19/ts4.8/util.d.ts +0 -2075
  52. node v18.19/ts4.8/v8.d.ts +0 -753
  53. node v18.19/ts4.8/vm.d.ts +0 -667
  54. node v18.19/ts4.8/wasi.d.ts +0 -158
  55. node v18.19/ts4.8/worker_threads.d.ts +0 -692
  56. node v18.19/ts4.8/zlib.d.ts +0 -517
@@ -1,1113 +0,0 @@
1
- /**
2
- * The `node:test` module provides a standalone testing module.
3
- * @see [source](https://github.com/nodejs/node/blob/v18.x/lib/test.js)
4
- */
5
- declare module "node:test" {
6
- import { AsyncResource } from "node:async_hooks";
7
- /**
8
- * Programmatically start the test runner.
9
- * @since v18.9.0
10
- * @param options Configuration options for running tests.
11
- * @returns A {@link TestsStream} that emits events about the test execution.
12
- */
13
- function run(options?: RunOptions): TestsStream;
14
- /**
15
- * The `test()` function is the value imported from the test module. Each invocation of this
16
- * function results in reporting the test to the {@link TestsStream}.
17
- *
18
- * The {@link TestContext} object passed to the fn argument can be used to perform actions
19
- * related to the current test. Examples include skipping the test, adding additional
20
- * diagnostic information, or creating subtests.
21
- *
22
- * `test()` returns a {@link Promise} that resolves once the test completes. The return value
23
- * can usually be discarded for top level tests. However, the return value from subtests should
24
- * be used to prevent the parent test from finishing first and cancelling the subtest as shown
25
- * in the following example.
26
- *
27
- * ```js
28
- * test('top level test', async (t) => {
29
- * // The setTimeout() in the following subtest would cause it to outlive its
30
- * // parent test if 'await' is removed on the next line. Once the parent test
31
- * // completes, it will cancel any outstanding subtests.
32
- * await t.test('longer running subtest', async (t) => {
33
- * return new Promise((resolve, reject) => {
34
- * setTimeout(resolve, 1000);
35
- * });
36
- * });
37
- * });
38
- * ```
39
- * @since v18.0.0
40
- * @param name The name of the test, which is displayed when reporting test results.
41
- * Default: The `name` property of fn, or `'<anonymous>'` if `fn` does not have a name.
42
- * @param options Configuration options for the test
43
- * @param fn The function under test. The first argument to this function is a
44
- * {@link TestContext} object. If the test uses callbacks, the callback function is
45
- * passed as the second argument. Default: A no-op function.
46
- * @returns A {@link Promise} resolved with `undefined` once the test completes.
47
- */
48
- function test(name?: string, fn?: TestFn): Promise<void>;
49
- function test(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
50
- function test(options?: TestOptions, fn?: TestFn): Promise<void>;
51
- function test(fn?: TestFn): Promise<void>;
52
- namespace test {
53
- export { after, afterEach, before, beforeEach, describe, it, mock, only, run, skip, test, todo };
54
- }
55
- /**
56
- * @since v18.6.0
57
- * @param name The name of the suite, which is displayed when reporting suite results.
58
- * Default: The `name` property of fn, or `'<anonymous>'` if `fn` does not have a name.
59
- * @param options Configuration options for the suite
60
- * @param fn The function under suite. Default: A no-op function.
61
- */
62
- function describe(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
63
- function describe(name?: string, fn?: SuiteFn): Promise<void>;
64
- function describe(options?: TestOptions, fn?: SuiteFn): Promise<void>;
65
- function describe(fn?: SuiteFn): Promise<void>;
66
- namespace describe {
67
- /**
68
- * Shorthand for skipping a suite, same as `describe([name], { skip: true }[, fn])`.
69
- */
70
- function skip(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
71
- function skip(name?: string, fn?: SuiteFn): Promise<void>;
72
- function skip(options?: TestOptions, fn?: SuiteFn): Promise<void>;
73
- function skip(fn?: SuiteFn): Promise<void>;
74
- /**
75
- * Shorthand for marking a suite as `TODO`, same as `describe([name], { todo: true }[, fn])`.
76
- */
77
- function todo(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
78
- function todo(name?: string, fn?: SuiteFn): Promise<void>;
79
- function todo(options?: TestOptions, fn?: SuiteFn): Promise<void>;
80
- function todo(fn?: SuiteFn): Promise<void>;
81
- /**
82
- * Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
83
- * @since v18.15.0
84
- */
85
- function only(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
86
- function only(name?: string, fn?: SuiteFn): Promise<void>;
87
- function only(options?: TestOptions, fn?: SuiteFn): Promise<void>;
88
- function only(fn?: SuiteFn): Promise<void>;
89
- }
90
-
91
- /**
92
- * @since v18.6.0
93
- * @param name The name of the test, which is displayed when reporting test results.
94
- * Default: The `name` property of fn, or `'<anonymous>'` if `fn` does not have a name.
95
- * @param options Configuration options for the test
96
- * @param fn The function under test. If the test uses callbacks, the callback function is
97
- * passed as the second argument. Default: A no-op function.
98
- */
99
- function it(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
100
- function it(name?: string, fn?: TestFn): Promise<void>;
101
- function it(options?: TestOptions, fn?: TestFn): Promise<void>;
102
- function it(fn?: TestFn): Promise<void>;
103
- namespace it {
104
- /**
105
- * Shorthand for skipping a test, same as `it([name], { skip: true }[, fn])`.
106
- */
107
- function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
108
- function skip(name?: string, fn?: TestFn): Promise<void>;
109
- function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
110
- function skip(fn?: TestFn): Promise<void>;
111
- /**
112
- * Shorthand for marking a test as `TODO`, same as `it([name], { todo: true }[, fn])`.
113
- */
114
- function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
115
- function todo(name?: string, fn?: TestFn): Promise<void>;
116
- function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
117
- function todo(fn?: TestFn): Promise<void>;
118
- /**
119
- * Shorthand for marking a test as `only`, same as `it([name], { only: true }[, fn])`.
120
- * @since v18.15.0
121
- */
122
- function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
123
- function only(name?: string, fn?: TestFn): Promise<void>;
124
- function only(options?: TestOptions, fn?: TestFn): Promise<void>;
125
- function only(fn?: TestFn): Promise<void>;
126
- }
127
- /**
128
- * Shorthand for skipping a test, same as `test([name], { skip: true }[, fn])`.
129
- * @since v18.17.0
130
- */
131
- function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
132
- function skip(name?: string, fn?: TestFn): Promise<void>;
133
- function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
134
- function skip(fn?: TestFn): Promise<void>;
135
- /**
136
- * Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`.
137
- * @since v18.17.0
138
- */
139
- function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
140
- function todo(name?: string, fn?: TestFn): Promise<void>;
141
- function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
142
- function todo(fn?: TestFn): Promise<void>;
143
- /**
144
- * Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`.
145
- * @since v18.17.0
146
- */
147
- function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
148
- function only(name?: string, fn?: TestFn): Promise<void>;
149
- function only(options?: TestOptions, fn?: TestFn): Promise<void>;
150
- function only(fn?: TestFn): Promise<void>;
151
- /**
152
- * The type of a function under test. The first argument to this function is a
153
- * {@link TestContext} object. If the test uses callbacks, the callback function is passed as
154
- * the second argument.
155
- */
156
- type TestFn = (t: TestContext, done: (result?: any) => void) => any;
157
- /**
158
- * The type of a function under Suite.
159
- */
160
- type SuiteFn = (s: SuiteContext) => void | Promise<void>;
161
- interface TestShard {
162
- /**
163
- * A positive integer between 1 and `<total>` that specifies the index of the shard to run.
164
- */
165
- index: number;
166
- /**
167
- * A positive integer that specifies the total number of shards to split the test files to.
168
- */
169
- total: number;
170
- }
171
- interface RunOptions {
172
- /**
173
- * If a number is provided, then that many files would run in parallel.
174
- * If truthy, it would run (number of cpu cores - 1) files in parallel.
175
- * If falsy, it would only run one file at a time.
176
- * If unspecified, subtests inherit this value from their parent.
177
- * @default true
178
- */
179
- concurrency?: number | boolean | undefined;
180
- /**
181
- * An array containing the list of files to run.
182
- * If unspecified, the test runner execution model will be used.
183
- */
184
- files?: readonly string[] | undefined;
185
- /**
186
- * Allows aborting an in-progress test execution.
187
- * @default undefined
188
- */
189
- signal?: AbortSignal | undefined;
190
- /**
191
- * A number of milliseconds the test will fail after.
192
- * If unspecified, subtests inherit this value from their parent.
193
- * @default Infinity
194
- */
195
- timeout?: number | undefined;
196
- /**
197
- * Sets inspector port of test child process.
198
- * If a nullish value is provided, each process gets its own port,
199
- * incremented from the primary's `process.debugPort`.
200
- */
201
- inspectPort?: number | (() => number) | undefined;
202
- /**
203
- * That can be used to only run tests whose name matches the provided pattern.
204
- * Test name patterns are interpreted as JavaScript regular expressions.
205
- * For each test that is executed, any corresponding test hooks, such as `beforeEach()`, are also run.
206
- */
207
- testNamePatterns?: string | RegExp | string[] | RegExp[];
208
- /**
209
- * If truthy, the test context will only run tests that have the `only` option set
210
- * @since v18.19.0
211
- */
212
- only?: boolean;
213
- /**
214
- * A function that accepts the TestsStream instance and can be used to setup listeners before any tests are run.
215
- */
216
- setup?: (root: Test) => void | Promise<void>;
217
- /**
218
- * Whether to run in watch mode or not.
219
- * @default false
220
- */
221
- watch?: boolean | undefined;
222
- /**
223
- * Running tests in a specific shard.
224
- * @since v18.19.0
225
- * @default undefined
226
- */
227
- shard?: TestShard | undefined;
228
- }
229
- class Test extends AsyncResource {
230
- concurrency: number;
231
- nesting: number;
232
- only: boolean;
233
- reporter: TestsStream;
234
- runOnlySubtests: boolean;
235
- testNumber: number;
236
- timeout: number | null;
237
- }
238
-
239
- /**
240
- * A successful call of the `run()` method will return a new `TestsStream` object,
241
- * streaming a series of events representing the execution of the tests.
242
- * `TestsStream` will emit events in the order of the tests' definitions.
243
- * @since v18.9.0
244
- */
245
- interface TestsStream extends NodeJS.ReadableStream {
246
- addListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
247
- addListener(event: "test:fail", listener: (data: TestFail) => void): this;
248
- addListener(event: "test:pass", listener: (data: TestPass) => void): this;
249
- addListener(event: "test:plan", listener: (data: TestPlan) => void): this;
250
- addListener(event: "test:start", listener: (data: TestStart) => void): this;
251
- addListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
252
- addListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
253
- addListener(event: string, listener: (...args: any[]) => void): this;
254
- emit(event: "test:diagnostic", data: DiagnosticData): boolean;
255
- emit(event: "test:fail", data: TestFail): boolean;
256
- emit(event: "test:pass", data: TestPass): boolean;
257
- emit(event: "test:plan", data: TestPlan): boolean;
258
- emit(event: "test:start", data: TestStart): boolean;
259
- emit(event: "test:stderr", data: TestStderr): boolean;
260
- emit(event: "test:stdout", data: TestStdout): boolean;
261
- emit(event: string | symbol, ...args: any[]): boolean;
262
- on(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
263
- on(event: "test:fail", listener: (data: TestFail) => void): this;
264
- on(event: "test:pass", listener: (data: TestPass) => void): this;
265
- on(event: "test:plan", listener: (data: TestPlan) => void): this;
266
- on(event: "test:start", listener: (data: TestStart) => void): this;
267
- on(event: "test:stderr", listener: (data: TestStderr) => void): this;
268
- on(event: "test:stdout", listener: (data: TestStdout) => void): this;
269
- on(event: string, listener: (...args: any[]) => void): this;
270
- once(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
271
- once(event: "test:fail", listener: (data: TestFail) => void): this;
272
- once(event: "test:pass", listener: (data: TestPass) => void): this;
273
- once(event: "test:plan", listener: (data: TestPlan) => void): this;
274
- once(event: "test:start", listener: (data: TestStart) => void): this;
275
- once(event: "test:stderr", listener: (data: TestStderr) => void): this;
276
- once(event: "test:stdout", listener: (data: TestStdout) => void): this;
277
- once(event: string, listener: (...args: any[]) => void): this;
278
- prependListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
279
- prependListener(event: "test:fail", listener: (data: TestFail) => void): this;
280
- prependListener(event: "test:pass", listener: (data: TestPass) => void): this;
281
- prependListener(event: "test:plan", listener: (data: TestPlan) => void): this;
282
- prependListener(event: "test:start", listener: (data: TestStart) => void): this;
283
- prependListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
284
- prependListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
285
- prependListener(event: string, listener: (...args: any[]) => void): this;
286
- prependOnceListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
287
- prependOnceListener(event: "test:fail", listener: (data: TestFail) => void): this;
288
- prependOnceListener(event: "test:pass", listener: (data: TestPass) => void): this;
289
- prependOnceListener(event: "test:plan", listener: (data: TestPlan) => void): this;
290
- prependOnceListener(event: "test:start", listener: (data: TestStart) => void): this;
291
- prependOnceListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
292
- prependOnceListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
293
- prependOnceListener(event: string, listener: (...args: any[]) => void): this;
294
- }
295
-
296
- /**
297
- * An instance of `TestContext` is passed to each test function in order to interact with the
298
- * test runner. However, the `TestContext` constructor is not exposed as part of the API.
299
- * @since v18.0.0
300
- */
301
- interface TestContext {
302
- /**
303
- * This function is used to create a hook running before subtest of the current test.
304
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
305
- * the second argument. Default: A no-op function.
306
- * @param options Configuration options for the hook.
307
- * @since v18.17.0
308
- */
309
- before: typeof before;
310
-
311
- /**
312
- * This function is used to create a hook running before each subtest of the current test.
313
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
314
- * the second argument. Default: A no-op function.
315
- * @param options Configuration options for the hook.
316
- * @since v18.8.0
317
- */
318
- beforeEach: typeof beforeEach;
319
-
320
- /**
321
- * This function is used to create a hook that runs after the current test finishes.
322
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
323
- * the second argument. Default: A no-op function.
324
- * @param options Configuration options for the hook.
325
- * @since v18.13.0
326
- */
327
- after: typeof after;
328
-
329
- /**
330
- * This function is used to create a hook running after each subtest of the current test.
331
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
332
- * the second argument. Default: A no-op function.
333
- * @param options Configuration options for the hook.
334
- * @since v18.8.0
335
- */
336
- afterEach: typeof afterEach;
337
-
338
- /**
339
- * This function is used to write diagnostics to the output. Any diagnostic information is
340
- * included at the end of the test's results. This function does not return a value.
341
- * @param message Message to be reported.
342
- * @since v18.0.0
343
- */
344
- diagnostic(message: string): void;
345
-
346
- /**
347
- * The name of the test.
348
- * @since v18.8.0
349
- */
350
- readonly name: string;
351
-
352
- /**
353
- * If `shouldRunOnlyTests` is truthy, the test context will only run tests that have the `only`
354
- * option set. Otherwise, all tests are run. If Node.js was not started with the `--test-only`
355
- * command-line option, this function is a no-op.
356
- * @param shouldRunOnlyTests Whether or not to run `only` tests.
357
- * @since v18.0.0
358
- */
359
- runOnly(shouldRunOnlyTests: boolean): void;
360
-
361
- /**
362
- * Can be used to abort test subtasks when the test has been aborted.
363
- * @since v18.7.0
364
- */
365
- readonly signal: AbortSignal;
366
-
367
- /**
368
- * This function causes the test's output to indicate the test as skipped. If `message` is
369
- * provided, it is included in the output. Calling `skip()` does not terminate execution of
370
- * the test function. This function does not return a value.
371
- * @param message Optional skip message.
372
- * @since v18.0.0
373
- */
374
- skip(message?: string): void;
375
-
376
- /**
377
- * This function adds a `TODO` directive to the test's output. If `message` is provided, it is
378
- * included in the output. Calling `todo()` does not terminate execution of the test
379
- * function. This function does not return a value.
380
- * @param message Optional `TODO` message.
381
- * @since v18.0.0
382
- */
383
- todo(message?: string): void;
384
-
385
- /**
386
- * This function is used to create subtests under the current test. This function behaves in
387
- * the same fashion as the top level {@link test} function.
388
- * @since v18.0.0
389
- * @param name The name of the test, which is displayed when reporting test results.
390
- * Default: The `name` property of fn, or `'<anonymous>'` if `fn` does not have a name.
391
- * @param options Configuration options for the test
392
- * @param fn The function under test. This first argument to this function is a
393
- * {@link TestContext} object. If the test uses callbacks, the callback function is
394
- * passed as the second argument. Default: A no-op function.
395
- * @returns A {@link Promise} resolved with `undefined` once the test completes.
396
- */
397
- test: typeof test;
398
- /**
399
- * Each test provides its own MockTracker instance.
400
- */
401
- readonly mock: MockTracker;
402
- }
403
-
404
- /**
405
- * An instance of `SuiteContext` is passed to each suite function in order to
406
- * interact with the test runner. However, the `SuiteContext` constructor is not
407
- * exposed as part of the API.
408
- * @since v18.7.0, v16.17.0
409
- */
410
- class SuiteContext {
411
- /**
412
- * The name of the suite.
413
- * @since v18.8.0, v16.18.0
414
- */
415
- readonly name: string;
416
- /**
417
- * Can be used to abort test subtasks when the test has been aborted.
418
- * @since v18.7.0, v16.17.0
419
- */
420
- readonly signal: AbortSignal;
421
- }
422
- interface TestOptions {
423
- /**
424
- * If a number is provided, then that many tests would run in parallel.
425
- * If truthy, it would run (number of cpu cores - 1) tests in parallel.
426
- * For subtests, it will be `Infinity` tests in parallel.
427
- * If falsy, it would only run one test at a time.
428
- * If unspecified, subtests inherit this value from their parent.
429
- * @default false
430
- */
431
- concurrency?: number | boolean | undefined;
432
-
433
- /**
434
- * If truthy, and the test context is configured to run `only` tests, then this test will be
435
- * run. Otherwise, the test is skipped.
436
- * @default false
437
- */
438
- only?: boolean | undefined;
439
-
440
- /**
441
- * Allows aborting an in-progress test.
442
- * @since v18.8.0
443
- */
444
- signal?: AbortSignal | undefined;
445
-
446
- /**
447
- * If truthy, the test is skipped. If a string is provided, that string is displayed in the
448
- * test results as the reason for skipping the test.
449
- * @default false
450
- */
451
- skip?: boolean | string | undefined;
452
-
453
- /**
454
- * A number of milliseconds the test will fail after. If unspecified, subtests inherit this
455
- * value from their parent.
456
- * @default Infinity
457
- * @since v18.7.0
458
- */
459
- timeout?: number | undefined;
460
-
461
- /**
462
- * If truthy, the test marked as `TODO`. If a string is provided, that string is displayed in
463
- * the test results as the reason why the test is `TODO`.
464
- * @default false
465
- */
466
- todo?: boolean | string | undefined;
467
- }
468
-
469
- /**
470
- * This function is used to create a hook running before running a suite.
471
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
472
- * the second argument. Default: A no-op function.
473
- * @param options Configuration options for the hook.
474
- * @since v18.8.0
475
- */
476
- function before(fn?: HookFn, options?: HookOptions): void;
477
-
478
- /**
479
- * This function is used to create a hook running after running a suite.
480
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
481
- * the second argument. Default: A no-op function.
482
- * @param options Configuration options for the hook.
483
- * @since v18.8.0
484
- */
485
- function after(fn?: HookFn, options?: HookOptions): void;
486
-
487
- /**
488
- * This function is used to create a hook running before each subtest of the current suite.
489
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
490
- * the second argument. Default: A no-op function.
491
- * @param options Configuration options for the hook.
492
- * @since v18.8.0
493
- */
494
- function beforeEach(fn?: HookFn, options?: HookOptions): void;
495
-
496
- /**
497
- * This function is used to create a hook running after each subtest of the current test.
498
- * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
499
- * the second argument. Default: A no-op function.
500
- * @param options Configuration options for the hook.
501
- * @since v18.8.0
502
- */
503
- function afterEach(fn?: HookFn, options?: HookOptions): void;
504
-
505
- /**
506
- * The hook function. If the hook uses callbacks, the callback function is passed as the
507
- * second argument.
508
- */
509
- type HookFn = (s: SuiteContext, done: (result?: any) => void) => any;
510
-
511
- /**
512
- * Configuration options for hooks.
513
- * @since v18.8.0
514
- */
515
- interface HookOptions {
516
- /**
517
- * Allows aborting an in-progress hook.
518
- */
519
- signal?: AbortSignal | undefined;
520
-
521
- /**
522
- * A number of milliseconds the hook will fail after. If unspecified, subtests inherit this
523
- * value from their parent.
524
- * @default Infinity
525
- */
526
- timeout?: number | undefined;
527
- }
528
-
529
- interface MockFunctionOptions {
530
- /**
531
- * The number of times that the mock will use the behavior of `implementation`.
532
- * Once the mock function has been called `times` times,
533
- * it will automatically restore the behavior of `original`.
534
- * This value must be an integer greater than zero.
535
- * @default Infinity
536
- */
537
- times?: number | undefined;
538
- }
539
-
540
- interface MockMethodOptions extends MockFunctionOptions {
541
- /**
542
- * If `true`, `object[methodName]` is treated as a getter.
543
- * This option cannot be used with the `setter` option.
544
- */
545
- getter?: boolean | undefined;
546
-
547
- /**
548
- * If `true`, `object[methodName]` is treated as a setter.
549
- * This option cannot be used with the `getter` option.
550
- */
551
- setter?: boolean | undefined;
552
- }
553
-
554
- type Mock<F extends Function> = F & {
555
- mock: MockFunctionContext<F>;
556
- };
557
-
558
- type NoOpFunction = (...args: any[]) => undefined;
559
-
560
- type FunctionPropertyNames<T> = {
561
- [K in keyof T]: T[K] extends Function ? K : never;
562
- }[keyof T];
563
-
564
- interface MockTracker {
565
- /**
566
- * This function is used to create a mock function.
567
- * @param original An optional function to create a mock on.
568
- * @param implementation An optional function used as the mock implementation for `original`.
569
- * This is useful for creating mocks that exhibit one behavior for a specified number of calls and then restore the behavior of `original`.
570
- * @param options Optional configuration options for the mock function.
571
- */
572
- fn<F extends Function = NoOpFunction>(original?: F, options?: MockFunctionOptions): Mock<F>;
573
- fn<F extends Function = NoOpFunction, Implementation extends Function = F>(
574
- original?: F,
575
- implementation?: Implementation,
576
- options?: MockFunctionOptions,
577
- ): Mock<F | Implementation>;
578
- /**
579
- * This function is used to create a mock on an existing object method.
580
- * @param object The object whose method is being mocked.
581
- * @param methodName The identifier of the method on `object` to mock. If `object[methodName]` is not a function, an error is thrown.
582
- * @param implementation An optional function used as the mock implementation for `object[methodName]`.
583
- * @param options Optional configuration options for the mock method.
584
- */
585
- method<
586
- MockedObject extends object,
587
- MethodName extends FunctionPropertyNames<MockedObject>,
588
- >(
589
- object: MockedObject,
590
- methodName: MethodName,
591
- options?: MockFunctionOptions,
592
- ): MockedObject[MethodName] extends Function ? Mock<MockedObject[MethodName]>
593
- : never;
594
- method<
595
- MockedObject extends object,
596
- MethodName extends FunctionPropertyNames<MockedObject>,
597
- Implementation extends Function,
598
- >(
599
- object: MockedObject,
600
- methodName: MethodName,
601
- implementation: Implementation,
602
- options?: MockFunctionOptions,
603
- ): MockedObject[MethodName] extends Function ? Mock<MockedObject[MethodName] | Implementation>
604
- : never;
605
- method<MockedObject extends object>(
606
- object: MockedObject,
607
- methodName: keyof MockedObject,
608
- options: MockMethodOptions,
609
- ): Mock<Function>;
610
- method<MockedObject extends object>(
611
- object: MockedObject,
612
- methodName: keyof MockedObject,
613
- implementation: Function,
614
- options: MockMethodOptions,
615
- ): Mock<Function>;
616
- /**
617
- * This function is syntax sugar for {@link MockTracker.method} with `options.getter` set to `true`.
618
- */
619
- getter<
620
- MockedObject extends object,
621
- MethodName extends keyof MockedObject,
622
- >(
623
- object: MockedObject,
624
- methodName: MethodName,
625
- options?: MockFunctionOptions,
626
- ): Mock<() => MockedObject[MethodName]>;
627
- getter<
628
- MockedObject extends object,
629
- MethodName extends keyof MockedObject,
630
- Implementation extends Function,
631
- >(
632
- object: MockedObject,
633
- methodName: MethodName,
634
- implementation?: Implementation,
635
- options?: MockFunctionOptions,
636
- ): Mock<(() => MockedObject[MethodName]) | Implementation>;
637
- /**
638
- * This function is syntax sugar for {@link MockTracker.method} with `options.setter` set to `true`.
639
- */
640
- setter<
641
- MockedObject extends object,
642
- MethodName extends keyof MockedObject,
643
- >(
644
- object: MockedObject,
645
- methodName: MethodName,
646
- options?: MockFunctionOptions,
647
- ): Mock<(value: MockedObject[MethodName]) => void>;
648
- setter<
649
- MockedObject extends object,
650
- MethodName extends keyof MockedObject,
651
- Implementation extends Function,
652
- >(
653
- object: MockedObject,
654
- methodName: MethodName,
655
- implementation?: Implementation,
656
- options?: MockFunctionOptions,
657
- ): Mock<((value: MockedObject[MethodName]) => void) | Implementation>;
658
- /**
659
- * This function restores the default behavior of all mocks that were previously created by this `MockTracker`
660
- * and disassociates the mocks from the `MockTracker` instance. Once disassociated, the mocks can still be used,
661
- * but the `MockTracker` instance can no longer be used to reset their behavior or otherwise interact with them.
662
- *
663
- * After each test completes, this function is called on the test context's `MockTracker`.
664
- * If the global `MockTracker` is used extensively, calling this function manually is recommended.
665
- */
666
- reset(): void;
667
- /**
668
- * This function restores the default behavior of all mocks that were previously created by this `MockTracker`.
669
- * Unlike `mock.reset()`, `mock.restoreAll()` does not disassociate the mocks from the `MockTracker` instance.
670
- */
671
- restoreAll(): void;
672
- timers: MockTimers;
673
- }
674
-
675
- const mock: MockTracker;
676
-
677
- interface MockFunctionCall<
678
- F extends Function,
679
- ReturnType = F extends (...args: any) => infer T ? T
680
- : F extends abstract new(...args: any) => infer T ? T
681
- : unknown,
682
- Args = F extends (...args: infer Y) => any ? Y
683
- : F extends abstract new(...args: infer Y) => any ? Y
684
- : unknown[],
685
- > {
686
- /**
687
- * An array of the arguments passed to the mock function.
688
- */
689
- arguments: Args;
690
- /**
691
- * If the mocked function threw then this property contains the thrown value.
692
- */
693
- error: unknown | undefined;
694
- /**
695
- * The value returned by the mocked function.
696
- *
697
- * If the mocked function threw, it will be `undefined`.
698
- */
699
- result: ReturnType | undefined;
700
- /**
701
- * An `Error` object whose stack can be used to determine the callsite of the mocked function invocation.
702
- */
703
- stack: Error;
704
- /**
705
- * If the mocked function is a constructor, this field contains the class being constructed.
706
- * Otherwise this will be `undefined`.
707
- */
708
- target: F extends abstract new(...args: any) => any ? F : undefined;
709
- /**
710
- * The mocked function's `this` value.
711
- */
712
- this: unknown;
713
- }
714
-
715
- interface MockFunctionContext<F extends Function> {
716
- /**
717
- * A getter that returns a copy of the internal array used to track calls to the mock.
718
- */
719
- readonly calls: Array<MockFunctionCall<F>>;
720
-
721
- /**
722
- * This function returns the number of times that this mock has been invoked.
723
- * This function is more efficient than checking `ctx.calls.length`
724
- * because `ctx.calls` is a getter that creates a copy of the internal call tracking array.
725
- */
726
- callCount(): number;
727
-
728
- /**
729
- * This function is used to change the behavior of an existing mock.
730
- * @param implementation The function to be used as the mock's new implementation.
731
- */
732
- mockImplementation(implementation: Function): void;
733
-
734
- /**
735
- * This function is used to change the behavior of an existing mock for a single invocation.
736
- * Once invocation `onCall` has occurred, the mock will revert to whatever behavior
737
- * it would have used had `mockImplementationOnce()` not been called.
738
- * @param implementation The function to be used as the mock's implementation for the invocation number specified by `onCall`.
739
- * @param onCall The invocation number that will use `implementation`.
740
- * If the specified invocation has already occurred then an exception is thrown.
741
- */
742
- mockImplementationOnce(implementation: Function, onCall?: number): void;
743
-
744
- /**
745
- * Resets the call history of the mock function.
746
- */
747
- resetCalls(): void;
748
-
749
- /**
750
- * Resets the implementation of the mock function to its original behavior.
751
- * The mock can still be used after calling this function.
752
- */
753
- restore(): void;
754
- }
755
- type Timer = "setInterval" | "clearInterval" | "setTimeout" | "clearTimeout";
756
- /**
757
- * Mocking timers is a technique commonly used in software testing to simulate and
758
- * control the behavior of timers, such as `setInterval` and `setTimeout`,
759
- * without actually waiting for the specified time intervals.
760
- *
761
- * The `MockTracker` provides a top-level `timers` export
762
- * which is a `MockTimers` instance.
763
- * @since v18.19.0
764
- * @experimental
765
- */
766
- class MockTimers {
767
- /**
768
- * Enables timer mocking for the specified timers.
769
- *
770
- * **Note:** When you enable mocking for a specific timer, its associated
771
- * clear function will also be implicitly mocked.
772
- *
773
- * Example usage:
774
- *
775
- * ```js
776
- * import { mock } from 'node:test';
777
- * mock.timers.enable(['setInterval']);
778
- * ```
779
- *
780
- * The above example enables mocking for the `setInterval` timer and
781
- * implicitly mocks the `clearInterval` function. Only the `setInterval`and `clearInterval` functions from `node:timers`,`node:timers/promises`, and`globalThis` will be mocked.
782
- *
783
- * Alternatively, if you call `mock.timers.enable()` without any parameters:
784
- *
785
- * All timers (`'setInterval'`, `'clearInterval'`, `'setTimeout'`, and `'clearTimeout'`)
786
- * will be mocked. The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout`functions from `node:timers`, `node:timers/promises`,
787
- * and `globalThis` will be mocked.
788
- * @since v18.19.0
789
- */
790
- enable(timers?: Timer[]): void;
791
- /**
792
- * This function restores the default behavior of all mocks that were previously
793
- * created by this `MockTimers` instance and disassociates the mocks
794
- * from the `MockTracker` instance.
795
- *
796
- * **Note:** After each test completes, this function is called on
797
- * the test context's `MockTracker`.
798
- *
799
- * ```js
800
- * import { mock } from 'node:test';
801
- * mock.timers.reset();
802
- * ```
803
- * @since v18.19.0
804
- */
805
- reset(): void;
806
- /**
807
- * Advances time for all mocked timers.
808
- *
809
- * **Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
810
- * only positive numbers. In Node.js, `setTimeout` with negative numbers is
811
- * only supported for web compatibility reasons.
812
- *
813
- * The following example mocks a `setTimeout` function and
814
- * by using `.tick` advances in
815
- * time triggering all pending timers.
816
- *
817
- * ```js
818
- * import assert from 'node:assert';
819
- * import { test } from 'node:test';
820
- *
821
- * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
822
- * const fn = context.mock.fn();
823
- *
824
- * context.mock.timers.enable(['setTimeout']);
825
- *
826
- * setTimeout(fn, 9999);
827
- *
828
- * assert.strictEqual(fn.mock.callCount(), 0);
829
- *
830
- * // Advance in time
831
- * context.mock.timers.tick(9999);
832
- *
833
- * assert.strictEqual(fn.mock.callCount(), 1);
834
- * });
835
- * ```
836
- *
837
- * Alternativelly, the `.tick` function can be called many times
838
- *
839
- * ```js
840
- * import assert from 'node:assert';
841
- * import { test } from 'node:test';
842
- *
843
- * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
844
- * const fn = context.mock.fn();
845
- * context.mock.timers.enable(['setTimeout']);
846
- * const nineSecs = 9000;
847
- * setTimeout(fn, nineSecs);
848
- *
849
- * const twoSeconds = 3000;
850
- * context.mock.timers.tick(twoSeconds);
851
- * context.mock.timers.tick(twoSeconds);
852
- * context.mock.timers.tick(twoSeconds);
853
- *
854
- * assert.strictEqual(fn.mock.callCount(), 1);
855
- * });
856
- * ```
857
- * @since v18.19.0
858
- */
859
- tick(milliseconds: number): void;
860
- /**
861
- * Triggers all pending mocked timers immediately.
862
- *
863
- * The example below triggers all pending timers immediately,
864
- * causing them to execute without any delay.
865
- *
866
- * ```js
867
- * import assert from 'node:assert';
868
- * import { test } from 'node:test';
869
- *
870
- * test('runAll functions following the given order', (context) => {
871
- * context.mock.timers.enable(['setTimeout']);
872
- * const results = [];
873
- * setTimeout(() => results.push(1), 9999);
874
- *
875
- * // Notice that if both timers have the same timeout,
876
- * // the order of execution is guaranteed
877
- * setTimeout(() => results.push(3), 8888);
878
- * setTimeout(() => results.push(2), 8888);
879
- *
880
- * assert.deepStrictEqual(results, []);
881
- *
882
- * context.mock.timers.runAll();
883
- *
884
- * assert.deepStrictEqual(results, [3, 2, 1]);
885
- * });
886
- * ```
887
- *
888
- * **Note:** The `runAll()` function is specifically designed for
889
- * triggering timers in the context of timer mocking.
890
- * It does not have any effect on real-time system
891
- * clocks or actual timers outside of the mocking environment.
892
- * @since v18.19.0
893
- */
894
- runAll(): void;
895
- /**
896
- * Calls {@link MockTimers.reset()}.
897
- */
898
- [Symbol.dispose](): void;
899
- }
900
-
901
- export { after, afterEach, before, beforeEach, describe, it, mock, run, test, test as default };
902
- }
903
-
904
- interface TestLocationInfo {
905
- /**
906
- * The column number where the test is defined, or
907
- * `undefined` if the test was run through the REPL.
908
- */
909
- column?: number;
910
- /**
911
- * The path of the test file, `undefined` if test is not ran through a file.
912
- */
913
- file?: string;
914
- /**
915
- * The line number where the test is defined, or
916
- * `undefined` if the test was run through the REPL.
917
- */
918
- line?: number;
919
- }
920
- interface DiagnosticData extends TestLocationInfo {
921
- /**
922
- * The diagnostic message.
923
- */
924
- message: string;
925
- /**
926
- * The nesting level of the test.
927
- */
928
- nesting: number;
929
- }
930
- interface TestFail extends TestLocationInfo {
931
- /**
932
- * Additional execution metadata.
933
- */
934
- details: {
935
- /**
936
- * The duration of the test in milliseconds.
937
- */
938
- duration_ms: number;
939
- /**
940
- * The error thrown by the test.
941
- */
942
- error: Error;
943
- /**
944
- * The type of the test, used to denote whether this is a suite.
945
- * @since 18.17.0
946
- */
947
- type?: "suite";
948
- };
949
- /**
950
- * The test name.
951
- */
952
- name: string;
953
- /**
954
- * The nesting level of the test.
955
- */
956
- nesting: number;
957
- /**
958
- * The ordinal number of the test.
959
- */
960
- testNumber: number;
961
- /**
962
- * Present if `context.todo` is called.
963
- */
964
- todo?: string | boolean;
965
- /**
966
- * Present if `context.skip` is called.
967
- */
968
- skip?: string | boolean;
969
- }
970
- interface TestPass extends TestLocationInfo {
971
- /**
972
- * Additional execution metadata.
973
- */
974
- details: {
975
- /**
976
- * The duration of the test in milliseconds.
977
- */
978
- duration_ms: number;
979
- /**
980
- * The type of the test, used to denote whether this is a suite.
981
- * @since 18.17.0
982
- */
983
- type?: "suite";
984
- };
985
- /**
986
- * The test name.
987
- */
988
- name: string;
989
- /**
990
- * The nesting level of the test.
991
- */
992
- nesting: number;
993
- /**
994
- * The ordinal number of the test.
995
- */
996
- testNumber: number;
997
- /**
998
- * Present if `context.todo` is called.
999
- */
1000
- todo?: string | boolean;
1001
- /**
1002
- * Present if `context.skip` is called.
1003
- */
1004
- skip?: string | boolean;
1005
- }
1006
- interface TestPlan extends TestLocationInfo {
1007
- /**
1008
- * The nesting level of the test.
1009
- */
1010
- nesting: number;
1011
- /**
1012
- * The number of subtests that have ran.
1013
- */
1014
- count: number;
1015
- }
1016
- interface TestStart extends TestLocationInfo {
1017
- /**
1018
- * The test name.
1019
- */
1020
- name: string;
1021
- /**
1022
- * The nesting level of the test.
1023
- */
1024
- nesting: number;
1025
- }
1026
- interface TestStderr extends TestLocationInfo {
1027
- /**
1028
- * The message written to `stderr`
1029
- */
1030
- message: string;
1031
- }
1032
- interface TestStdout extends TestLocationInfo {
1033
- /**
1034
- * The message written to `stdout`
1035
- */
1036
- message: string;
1037
- }
1038
- interface TestEnqueue extends TestLocationInfo {
1039
- /**
1040
- * The test name
1041
- */
1042
- name: string;
1043
- /**
1044
- * The nesting level of the test.
1045
- */
1046
- nesting: number;
1047
- }
1048
- interface TestDequeue extends TestLocationInfo {
1049
- /**
1050
- * The test name
1051
- */
1052
- name: string;
1053
- /**
1054
- * The nesting level of the test.
1055
- */
1056
- nesting: number;
1057
- }
1058
-
1059
- /**
1060
- * The `node:test/reporters` module exposes the builtin-reporters for `node:test`.
1061
- * To access it:
1062
- *
1063
- * ```js
1064
- * import test from 'node:test/reporters';
1065
- * ```
1066
- *
1067
- * This module is only available under the `node:` scheme. The following will not
1068
- * work:
1069
- *
1070
- * ```js
1071
- * import test from 'test/reporters';
1072
- * ```
1073
- * @since v18.17.0
1074
- * @see [source](https://github.com/nodejs/node/blob/v18.17.0/lib/test/reporters.js)
1075
- */
1076
- declare module "node:test/reporters" {
1077
- import { Transform } from "node:stream";
1078
-
1079
- type TestEvent =
1080
- | { type: "test:diagnostic"; data: DiagnosticData }
1081
- | { type: "test:fail"; data: TestFail }
1082
- | { type: "test:pass"; data: TestPass }
1083
- | { type: "test:plan"; data: TestPlan }
1084
- | { type: "test:start"; data: TestStart }
1085
- | { type: "test:stderr"; data: TestStderr }
1086
- | { type: "test:stdout"; data: TestStdout }
1087
- | { type: "test:enqueue"; data: TestEnqueue }
1088
- | { type: "test:dequeue"; data: TestDequeue }
1089
- | { type: "test:watch:drained" };
1090
- type TestEventGenerator = AsyncGenerator<TestEvent, void>;
1091
-
1092
- /**
1093
- * The `dot` reporter outputs the test results in a compact format,
1094
- * where each passing test is represented by a `.`,
1095
- * and each failing test is represented by a `X`.
1096
- */
1097
- function dot(source: TestEventGenerator): AsyncGenerator<"\n" | "." | "X", void>;
1098
- /**
1099
- * The `tap` reporter outputs the test results in the [TAP](https://testanything.org/) format.
1100
- */
1101
- function tap(source: TestEventGenerator): AsyncGenerator<string, void>;
1102
- /**
1103
- * The `spec` reporter outputs the test results in a human-readable format.
1104
- */
1105
- class Spec extends Transform {
1106
- constructor();
1107
- }
1108
- /**
1109
- * The `junit` reporter outputs test results in a jUnit XML format
1110
- */
1111
- function junit(source: TestEventGenerator): AsyncGenerator<string, void>;
1112
- export { dot, junit, Spec as spec, tap, TestEvent };
1113
- }