@types/node 20.19.25 → 24.10.4

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 (79) hide show
  1. {node v20.19 → node v24.10}/README.md +3 -3
  2. node v24.10/assert/strict.d.ts +111 -0
  3. {node v20.19 → node v24.10}/assert.d.ts +150 -97
  4. {node v20.19 → node v24.10}/async_hooks.d.ts +27 -9
  5. {node v20.19 → node v24.10}/buffer.buffer.d.ts +2 -1
  6. {node v20.19 → node v24.10}/buffer.d.ts +6 -8
  7. {node v20.19 → node v24.10}/child_process.d.ts +11 -10
  8. {node v20.19 → node v24.10}/cluster.d.ts +16 -15
  9. {node v20.19 → node v24.10}/console.d.ts +19 -18
  10. {node v20.19 → node v24.10}/crypto.d.ts +1120 -293
  11. {node v20.19 → node v24.10}/dgram.d.ts +5 -2
  12. {node v20.19 → node v24.10}/diagnostics_channel.d.ts +1 -3
  13. {node v20.19 → node v24.10}/dns/promises.d.ts +30 -6
  14. {node v20.19 → node v24.10}/dns.d.ts +69 -17
  15. {node v20.19 → node v24.10}/domain.d.ts +1 -1
  16. {node v20.19 → node v24.10}/events.d.ts +1 -2
  17. {node v20.19 → node v24.10}/fs/promises.d.ts +85 -38
  18. {node v20.19 → node v24.10}/fs.d.ts +387 -48
  19. {node v20.19 → node v24.10}/globals.d.ts +2 -4
  20. {node v20.19 → node v24.10}/globals.typedarray.d.ts +3 -0
  21. {node v20.19 → node v24.10}/http.d.ts +90 -5
  22. {node v20.19 → node v24.10}/http2.d.ts +166 -41
  23. {node v20.19 → node v24.10}/https.d.ts +4 -3
  24. {node v20.19 → node v24.10}/index.d.ts +13 -5
  25. node v24.10/inspector.d.ts +277 -0
  26. {node v20.19 → node v24.10}/inspector.generated.d.ts +1096 -829
  27. {node v20.19 → node v24.10}/module.d.ts +403 -48
  28. {node v20.19 → node v24.10}/net.d.ts +62 -20
  29. {node v20.19 → node v24.10}/os.d.ts +8 -7
  30. {node v20.19 → node v24.10}/package.json +18 -3
  31. {node v20.19 → node v24.10}/path.d.ts +3 -3
  32. {node v20.19 → node v24.10}/perf_hooks.d.ts +37 -16
  33. {node v20.19 → node v24.10}/process.d.ts +138 -16
  34. {node v20.19 → node v24.10}/punycode.d.ts +1 -1
  35. {node v20.19 → node v24.10}/querystring.d.ts +1 -1
  36. {node v20.19 → node v24.10}/readline/promises.d.ts +0 -1
  37. {node v20.19 → node v24.10}/readline.d.ts +19 -14
  38. {node v20.19 → node v24.10}/repl.d.ts +25 -17
  39. {node v20.19 → node v24.10}/sea.d.ts +11 -2
  40. node v24.10/sqlite.d.ts +937 -0
  41. {node v20.19 → node v24.10}/stream/web.d.ts +85 -45
  42. {node v20.19 → node v24.10}/stream.d.ts +36 -28
  43. {node v20.19 → node v24.10}/string_decoder.d.ts +1 -1
  44. {node v20.19 → node v24.10}/test.d.ts +587 -35
  45. {node v20.19 → node v24.10}/timers/promises.d.ts +1 -1
  46. {node v20.19 → node v24.10}/timers.d.ts +4 -5
  47. {node v20.19 → node v24.10}/tls.d.ts +62 -48
  48. {node v20.19 → node v24.10}/trace_events.d.ts +6 -6
  49. node v24.10/ts5.6/compatibility/float16array.d.ts +71 -0
  50. {node v20.19 → node v24.10}/ts5.6/globals.typedarray.d.ts +2 -0
  51. {node v20.19 → node v24.10}/ts5.6/index.d.ts +15 -5
  52. node v24.10/ts5.7/compatibility/float16array.d.ts +72 -0
  53. node v24.10/ts5.7/index.d.ts +103 -0
  54. {node v20.19 → node v24.10}/tty.d.ts +1 -1
  55. {node v20.19 → node v24.10}/url.d.ts +128 -35
  56. {node v20.19 → node v24.10}/util.d.ts +384 -390
  57. {node v20.19 → node v24.10}/v8.d.ts +175 -32
  58. {node v20.19 → node v24.10}/vm.d.ts +246 -67
  59. {node v20.19 → node v24.10}/wasi.d.ts +23 -2
  60. node v24.10/web-globals/crypto.d.ts +32 -0
  61. {node v20.19 → node v24.10}/web-globals/fetch.d.ts +4 -0
  62. node v24.10/web-globals/navigator.d.ts +25 -0
  63. node v24.10/web-globals/storage.d.ts +24 -0
  64. node v24.10/web-globals/streams.d.ts +22 -0
  65. {node v20.19 → node v24.10}/worker_threads.d.ts +205 -24
  66. {node v20.19 → node v24.10}/zlib.d.ts +185 -44
  67. node v20.19/assert/strict.d.ts +0 -8
  68. node v20.19/compatibility/disposable.d.ts +0 -16
  69. node v20.19/compatibility/index.d.ts +0 -9
  70. node v20.19/compatibility/indexable.d.ts +0 -20
  71. {node v20.19 → node v24.10}/LICENSE +0 -0
  72. {node v20.19 → node v24.10}/compatibility/iterators.d.ts +0 -0
  73. {node v20.19 → node v24.10}/constants.d.ts +0 -0
  74. {node v20.19 → node v24.10}/stream/consumers.d.ts +0 -0
  75. {node v20.19 → node v24.10}/stream/promises.d.ts +0 -0
  76. {node v20.19 → node v24.10}/ts5.6/buffer.buffer.d.ts +0 -0
  77. {node v20.19 → node v24.10}/web-globals/abortcontroller.d.ts +0 -0
  78. {node v20.19 → node v24.10}/web-globals/domexception.d.ts +0 -0
  79. {node v20.19 → node v24.10}/web-globals/events.d.ts +0 -0
@@ -10,7 +10,7 @@
10
10
  * work:
11
11
  *
12
12
  * ```js
13
- * import test from 'test';
13
+ * import test from 'node:test';
14
14
  * ```
15
15
  *
16
16
  * Tests created via the `test` module consist of a single function that is
@@ -76,7 +76,7 @@
76
76
  *
77
77
  * If any tests fail, the process exit code is set to `1`.
78
78
  * @since v18.0.0, v16.17.0
79
- * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/test.js)
79
+ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/test.js)
80
80
  */
81
81
  declare module "node:test" {
82
82
  import { AssertMethodNames } from "node:assert";
@@ -240,9 +240,17 @@ declare module "node:test" {
240
240
  * @default false
241
241
  */
242
242
  concurrency?: number | boolean | undefined;
243
+ /**
244
+ * Specifies the current working directory to be used by the test runner.
245
+ * Serves as the base path for resolving files according to the
246
+ * [test runner execution model](https://nodejs.org/docs/latest-v24.x/api/test.html#test-runner-execution-model).
247
+ * @since v23.0.0
248
+ * @default process.cwd()
249
+ */
250
+ cwd?: string | undefined;
243
251
  /**
244
252
  * An array containing the list of files to run. If omitted, files are run according to the
245
- * [test runner execution model](https://nodejs.org/docs/latest-v20.x/api/test.html#test-runner-execution-model).
253
+ * [test runner execution model](https://nodejs.org/docs/latest-v24.x/api/test.html#test-runner-execution-model).
246
254
  */
247
255
  files?: readonly string[] | undefined;
248
256
  /**
@@ -252,13 +260,31 @@ declare module "node:test" {
252
260
  * @default false
253
261
  */
254
262
  forceExit?: boolean | undefined;
263
+ /**
264
+ * An array containing the list of glob patterns to match test files.
265
+ * This option cannot be used together with `files`. If omitted, files are run according to the
266
+ * [test runner execution model](https://nodejs.org/docs/latest-v24.x/api/test.html#test-runner-execution-model).
267
+ * @since v22.6.0
268
+ */
269
+ globPatterns?: readonly string[] | undefined;
255
270
  /**
256
271
  * Sets inspector port of test child process.
257
- * If a nullish value is provided, each process gets its own port,
258
- * incremented from the primary's `process.debugPort`.
272
+ * This can be a number, or a function that takes no arguments and returns a
273
+ * number. If a nullish value is provided, each process gets its own port,
274
+ * incremented from the primary's `process.debugPort`. This option is ignored
275
+ * if the `isolation` option is set to `'none'` as no child processes are
276
+ * spawned.
259
277
  * @default undefined
260
278
  */
261
279
  inspectPort?: number | (() => number) | undefined;
280
+ /**
281
+ * Configures the type of test isolation. If set to
282
+ * `'process'`, each test file is run in a separate child process. If set to
283
+ * `'none'`, all test files run in the current process.
284
+ * @default 'process'
285
+ * @since v22.8.0
286
+ */
287
+ isolation?: "process" | "none" | undefined;
262
288
  /**
263
289
  * If truthy, the test context will only run tests that have the `only` option set
264
290
  */
@@ -268,6 +294,20 @@ declare module "node:test" {
268
294
  * @default undefined
269
295
  */
270
296
  setup?: ((reporter: TestsStream) => void | Promise<void>) | undefined;
297
+ /**
298
+ * An array of CLI flags to pass to the `node` executable when
299
+ * spawning the subprocesses. This option has no effect when `isolation` is `'none`'.
300
+ * @since v22.10.0
301
+ * @default []
302
+ */
303
+ execArgv?: readonly string[] | undefined;
304
+ /**
305
+ * An array of CLI flags to pass to each test file when spawning the
306
+ * subprocesses. This option has no effect when `isolation` is `'none'`.
307
+ * @since v22.10.0
308
+ * @default []
309
+ */
310
+ argv?: readonly string[] | undefined;
271
311
  /**
272
312
  * Allows aborting an in-progress test execution.
273
313
  */
@@ -278,6 +318,15 @@ declare module "node:test" {
278
318
  * @default undefined
279
319
  */
280
320
  testNamePatterns?: string | RegExp | ReadonlyArray<string | RegExp> | undefined;
321
+ /**
322
+ * A String, RegExp or a RegExp Array, that can be used to exclude running tests whose
323
+ * name matches the provided pattern. Test name patterns are interpreted as JavaScript
324
+ * regular expressions. For each test that is executed, any corresponding test hooks,
325
+ * such as `beforeEach()`, are also run.
326
+ * @default undefined
327
+ * @since v22.1.0
328
+ */
329
+ testSkipPatterns?: string | RegExp | ReadonlyArray<string | RegExp> | undefined;
281
330
  /**
282
331
  * The number of milliseconds after which the test execution will fail.
283
332
  * If unspecified, subtests inherit this value from their parent.
@@ -294,6 +343,60 @@ declare module "node:test" {
294
343
  * @default undefined
295
344
  */
296
345
  shard?: TestShard | undefined;
346
+ /**
347
+ * A file path where the test runner will
348
+ * store the state of the tests to allow rerunning only the failed tests on a next run.
349
+ * @since v24.7.0
350
+ * @default undefined
351
+ */
352
+ rerunFailuresFilePath?: string | undefined;
353
+ /**
354
+ * enable [code coverage](https://nodejs.org/docs/latest-v24.x/api/test.html#collecting-code-coverage) collection.
355
+ * @since v22.10.0
356
+ * @default false
357
+ */
358
+ coverage?: boolean | undefined;
359
+ /**
360
+ * Excludes specific files from code coverage
361
+ * using a glob pattern, which can match both absolute and relative file paths.
362
+ * This property is only applicable when `coverage` was set to `true`.
363
+ * If both `coverageExcludeGlobs` and `coverageIncludeGlobs` are provided,
364
+ * files must meet **both** criteria to be included in the coverage report.
365
+ * @since v22.10.0
366
+ * @default undefined
367
+ */
368
+ coverageExcludeGlobs?: string | readonly string[] | undefined;
369
+ /**
370
+ * Includes specific files in code coverage
371
+ * using a glob pattern, which can match both absolute and relative file paths.
372
+ * This property is only applicable when `coverage` was set to `true`.
373
+ * If both `coverageExcludeGlobs` and `coverageIncludeGlobs` are provided,
374
+ * files must meet **both** criteria to be included in the coverage report.
375
+ * @since v22.10.0
376
+ * @default undefined
377
+ */
378
+ coverageIncludeGlobs?: string | readonly string[] | undefined;
379
+ /**
380
+ * Require a minimum percent of covered lines. If code
381
+ * coverage does not reach the threshold specified, the process will exit with code `1`.
382
+ * @since v22.10.0
383
+ * @default 0
384
+ */
385
+ lineCoverage?: number | undefined;
386
+ /**
387
+ * Require a minimum percent of covered branches. If code
388
+ * coverage does not reach the threshold specified, the process will exit with code `1`.
389
+ * @since v22.10.0
390
+ * @default 0
391
+ */
392
+ branchCoverage?: number | undefined;
393
+ /**
394
+ * Require a minimum percent of covered functions. If code
395
+ * coverage does not reach the threshold specified, the process will exit with code `1`.
396
+ * @since v22.10.0
397
+ * @default 0
398
+ */
399
+ functionCoverage?: number | undefined;
297
400
  }
298
401
  /**
299
402
  * A successful call to `run()` will return a new `TestsStream` object, streaming a series of events representing the execution of the tests.
@@ -313,7 +416,9 @@ declare module "node:test" {
313
416
  addListener(event: "test:start", listener: (data: EventData.TestStart) => void): this;
314
417
  addListener(event: "test:stderr", listener: (data: EventData.TestStderr) => void): this;
315
418
  addListener(event: "test:stdout", listener: (data: EventData.TestStdout) => void): this;
419
+ addListener(event: "test:summary", listener: (data: EventData.TestSummary) => void): this;
316
420
  addListener(event: "test:watch:drained", listener: () => void): this;
421
+ addListener(event: "test:watch:restarted", listener: () => void): this;
317
422
  addListener(event: string, listener: (...args: any[]) => void): this;
318
423
  emit(event: "test:coverage", data: EventData.TestCoverage): boolean;
319
424
  emit(event: "test:complete", data: EventData.TestComplete): boolean;
@@ -326,7 +431,9 @@ declare module "node:test" {
326
431
  emit(event: "test:start", data: EventData.TestStart): boolean;
327
432
  emit(event: "test:stderr", data: EventData.TestStderr): boolean;
328
433
  emit(event: "test:stdout", data: EventData.TestStdout): boolean;
434
+ emit(event: "test:summary", data: EventData.TestSummary): boolean;
329
435
  emit(event: "test:watch:drained"): boolean;
436
+ emit(event: "test:watch:restarted"): boolean;
330
437
  emit(event: string | symbol, ...args: any[]): boolean;
331
438
  on(event: "test:coverage", listener: (data: EventData.TestCoverage) => void): this;
332
439
  on(event: "test:complete", listener: (data: EventData.TestComplete) => void): this;
@@ -339,7 +446,9 @@ declare module "node:test" {
339
446
  on(event: "test:start", listener: (data: EventData.TestStart) => void): this;
340
447
  on(event: "test:stderr", listener: (data: EventData.TestStderr) => void): this;
341
448
  on(event: "test:stdout", listener: (data: EventData.TestStdout) => void): this;
449
+ on(event: "test:summary", listener: (data: EventData.TestSummary) => void): this;
342
450
  on(event: "test:watch:drained", listener: () => void): this;
451
+ on(event: "test:watch:restarted", listener: () => void): this;
343
452
  on(event: string, listener: (...args: any[]) => void): this;
344
453
  once(event: "test:coverage", listener: (data: EventData.TestCoverage) => void): this;
345
454
  once(event: "test:complete", listener: (data: EventData.TestComplete) => void): this;
@@ -352,7 +461,9 @@ declare module "node:test" {
352
461
  once(event: "test:start", listener: (data: EventData.TestStart) => void): this;
353
462
  once(event: "test:stderr", listener: (data: EventData.TestStderr) => void): this;
354
463
  once(event: "test:stdout", listener: (data: EventData.TestStdout) => void): this;
464
+ once(event: "test:summary", listener: (data: EventData.TestSummary) => void): this;
355
465
  once(event: "test:watch:drained", listener: () => void): this;
466
+ once(event: "test:watch:restarted", listener: () => void): this;
356
467
  once(event: string, listener: (...args: any[]) => void): this;
357
468
  prependListener(event: "test:coverage", listener: (data: EventData.TestCoverage) => void): this;
358
469
  prependListener(event: "test:complete", listener: (data: EventData.TestComplete) => void): this;
@@ -365,7 +476,9 @@ declare module "node:test" {
365
476
  prependListener(event: "test:start", listener: (data: EventData.TestStart) => void): this;
366
477
  prependListener(event: "test:stderr", listener: (data: EventData.TestStderr) => void): this;
367
478
  prependListener(event: "test:stdout", listener: (data: EventData.TestStdout) => void): this;
479
+ prependListener(event: "test:summary", listener: (data: EventData.TestSummary) => void): this;
368
480
  prependListener(event: "test:watch:drained", listener: () => void): this;
481
+ prependListener(event: "test:watch:restarted", listener: () => void): this;
369
482
  prependListener(event: string, listener: (...args: any[]) => void): this;
370
483
  prependOnceListener(event: "test:coverage", listener: (data: EventData.TestCoverage) => void): this;
371
484
  prependOnceListener(event: "test:complete", listener: (data: EventData.TestComplete) => void): this;
@@ -378,7 +491,9 @@ declare module "node:test" {
378
491
  prependOnceListener(event: "test:start", listener: (data: EventData.TestStart) => void): this;
379
492
  prependOnceListener(event: "test:stderr", listener: (data: EventData.TestStderr) => void): this;
380
493
  prependOnceListener(event: "test:stdout", listener: (data: EventData.TestStdout) => void): this;
494
+ prependOnceListener(event: "test:summary", listener: (data: EventData.TestSummary) => void): this;
381
495
  prependOnceListener(event: "test:watch:drained", listener: () => void): this;
496
+ prependOnceListener(event: "test:watch:restarted", listener: () => void): this;
382
497
  prependOnceListener(event: string, listener: (...args: any[]) => void): this;
383
498
  }
384
499
  namespace EventData {
@@ -409,6 +524,14 @@ declare module "node:test" {
409
524
  * The nesting level of the test.
410
525
  */
411
526
  nesting: number;
527
+ /**
528
+ * The severity level of the diagnostic message.
529
+ * Possible values are:
530
+ * * `'info'`: Informational messages.
531
+ * * `'warn'`: Warnings.
532
+ * * `'error'`: Errors.
533
+ */
534
+ level: "info" | "warn" | "error";
412
535
  }
413
536
  interface TestCoverage {
414
537
  /**
@@ -503,6 +626,25 @@ declare module "node:test" {
503
626
  count: number;
504
627
  }>;
505
628
  }>;
629
+ /**
630
+ * An object containing whether or not the coverage for
631
+ * each coverage type.
632
+ * @since v22.9.0
633
+ */
634
+ thresholds: {
635
+ /**
636
+ * The function coverage threshold.
637
+ */
638
+ function: number;
639
+ /**
640
+ * The branch coverage threshold.
641
+ */
642
+ branch: number;
643
+ /**
644
+ * The line coverage threshold.
645
+ */
646
+ line: number;
647
+ };
506
648
  /**
507
649
  * An object containing a summary of coverage for all files.
508
650
  */
@@ -576,7 +718,7 @@ declare module "node:test" {
576
718
  /**
577
719
  * The type of the test, used to denote whether this is a suite.
578
720
  */
579
- type?: "suite";
721
+ type?: "suite" | "test";
580
722
  };
581
723
  /**
582
724
  * The test name.
@@ -608,6 +750,11 @@ declare module "node:test" {
608
750
  * The nesting level of the test.
609
751
  */
610
752
  nesting: number;
753
+ /**
754
+ * The test type. Either `'suite'` or `'test'`.
755
+ * @since v22.15.0
756
+ */
757
+ type: "suite" | "test";
611
758
  }
612
759
  interface TestEnqueue extends LocationInfo {
613
760
  /**
@@ -618,6 +765,11 @@ declare module "node:test" {
618
765
  * The nesting level of the test.
619
766
  */
620
767
  nesting: number;
768
+ /**
769
+ * The test type. Either `'suite'` or `'test'`.
770
+ * @since v22.15.0
771
+ */
772
+ type: "suite" | "test";
621
773
  }
622
774
  interface TestFail extends LocationInfo {
623
775
  /**
@@ -636,7 +788,13 @@ declare module "node:test" {
636
788
  * The type of the test, used to denote whether this is a suite.
637
789
  * @since v20.0.0, v19.9.0, v18.17.0
638
790
  */
639
- type?: "suite";
791
+ type?: "suite" | "test";
792
+ /**
793
+ * The attempt number of the test run,
794
+ * present only when using the `--test-rerun-failures` flag.
795
+ * @since v24.7.0
796
+ */
797
+ attempt?: number;
640
798
  };
641
799
  /**
642
800
  * The test name.
@@ -672,7 +830,19 @@ declare module "node:test" {
672
830
  * The type of the test, used to denote whether this is a suite.
673
831
  * @since 20.0.0, 19.9.0, 18.17.0
674
832
  */
675
- type?: "suite";
833
+ type?: "suite" | "test";
834
+ /**
835
+ * The attempt number of the test run,
836
+ * present only when using the `--test-rerun-failures` flag.
837
+ * @since v24.7.0
838
+ */
839
+ attempt?: number;
840
+ /**
841
+ * The attempt number the test passed on,
842
+ * present only when using the `--test-rerun-failures` flag.
843
+ * @since v24.7.0
844
+ */
845
+ passed_on_attempt?: number;
676
846
  };
677
847
  /**
678
848
  * The test name.
@@ -735,6 +905,57 @@ declare module "node:test" {
735
905
  */
736
906
  message: string;
737
907
  }
908
+ interface TestSummary {
909
+ /**
910
+ * An object containing the counts of various test results.
911
+ */
912
+ counts: {
913
+ /**
914
+ * The total number of cancelled tests.
915
+ */
916
+ cancelled: number;
917
+ /**
918
+ * The total number of passed tests.
919
+ */
920
+ passed: number;
921
+ /**
922
+ * The total number of skipped tests.
923
+ */
924
+ skipped: number;
925
+ /**
926
+ * The total number of suites run.
927
+ */
928
+ suites: number;
929
+ /**
930
+ * The total number of tests run, excluding suites.
931
+ */
932
+ tests: number;
933
+ /**
934
+ * The total number of TODO tests.
935
+ */
936
+ todo: number;
937
+ /**
938
+ * The total number of top level tests and suites.
939
+ */
940
+ topLevel: number;
941
+ };
942
+ /**
943
+ * The duration of the test run in milliseconds.
944
+ */
945
+ duration_ms: number;
946
+ /**
947
+ * The path of the test file that generated the
948
+ * summary. If the summary corresponds to multiple files, this value is
949
+ * `undefined`.
950
+ */
951
+ file: string | undefined;
952
+ /**
953
+ * Indicates whether or not the test run is considered
954
+ * successful or not. If any error condition occurs, such as a failing test or
955
+ * unmet coverage threshold, this value will be set to `false`.
956
+ */
957
+ success: boolean;
958
+ }
738
959
  }
739
960
  /**
740
961
  * An instance of `TestContext` is passed to each test function in order to
@@ -763,9 +984,10 @@ declare module "node:test" {
763
984
  * t.assert.deepStrictEqual(actual, expected); // Error: 't' needs an explicit type annotation.
764
985
  * });
765
986
  * ```
766
- * @since v20.15.0
987
+ * @since v22.2.0, v20.15.0
767
988
  */
768
989
  readonly assert: TestContextAssert;
990
+ readonly attempt: number;
769
991
  /**
770
992
  * This function is used to create a hook running before subtest of the current test.
771
993
  * @param fn The hook function. The first argument to this function is a `TestContext` object.
@@ -812,9 +1034,15 @@ declare module "node:test" {
812
1034
  * @param message Message to be reported.
813
1035
  */
814
1036
  diagnostic(message: string): void;
1037
+ /**
1038
+ * The absolute path of the test file that created the current test. If a test file imports
1039
+ * additional modules that generate tests, the imported tests will return the path of the root test file.
1040
+ * @since v22.6.0
1041
+ */
1042
+ readonly filePath: string | undefined;
815
1043
  /**
816
1044
  * The name of the test and each of its ancestors, separated by `>`.
817
- * @since v20.16.0
1045
+ * @since v22.3.0
818
1046
  */
819
1047
  readonly fullName: string;
820
1048
  /**
@@ -823,11 +1051,12 @@ declare module "node:test" {
823
1051
  */
824
1052
  readonly name: string;
825
1053
  /**
826
- * Used to set the number of assertions and subtests that are expected to run within the test.
827
- * If the number of assertions and subtests that run does not match the expected count, the test will fail.
1054
+ * This function is used to set the number of assertions and subtests that are expected to run
1055
+ * within the test. If the number of assertions and subtests that run does not match the
1056
+ * expected count, the test will fail.
1057
+ *
1058
+ * > Note: To make sure assertions are tracked, `t.assert` must be used instead of `assert` directly.
828
1059
  *
829
- * To make sure assertions are tracked, the assert functions on `context.assert` must be used,
830
- * instead of importing from the `node:assert` module.
831
1060
  * ```js
832
1061
  * test('top level test', (t) => {
833
1062
  * t.plan(2);
@@ -836,7 +1065,9 @@ declare module "node:test" {
836
1065
  * });
837
1066
  * ```
838
1067
  *
839
- * When working with asynchronous code, the `plan` function can be used to ensure that the correct number of assertions are run:
1068
+ * When working with asynchronous code, the `plan` function can be used to ensure that the
1069
+ * correct number of assertions are run:
1070
+ *
840
1071
  * ```js
841
1072
  * test('planning with streams', (t, done) => {
842
1073
  * function* generate() {
@@ -850,14 +1081,35 @@ declare module "node:test" {
850
1081
  * stream.on('data', (chunk) => {
851
1082
  * t.assert.strictEqual(chunk, expected.shift());
852
1083
  * });
1084
+ *
853
1085
  * stream.on('end', () => {
854
1086
  * done();
855
1087
  * });
856
1088
  * });
857
1089
  * ```
858
- * @since v20.15.0
1090
+ *
1091
+ * When using the `wait` option, you can control how long the test will wait for the expected assertions.
1092
+ * For example, setting a maximum wait time ensures that the test will wait for asynchronous assertions
1093
+ * to complete within the specified timeframe:
1094
+ *
1095
+ * ```js
1096
+ * test('plan with wait: 2000 waits for async assertions', (t) => {
1097
+ * t.plan(1, { wait: 2000 }); // Waits for up to 2 seconds for the assertion to complete.
1098
+ *
1099
+ * const asyncActivity = () => {
1100
+ * setTimeout(() => {
1101
+ * * t.assert.ok(true, 'Async assertion completed within the wait time');
1102
+ * }, 1000); // Completes after 1 second, within the 2-second wait time.
1103
+ * };
1104
+ *
1105
+ * asyncActivity(); // The test will pass because the assertion is completed in time.
1106
+ * });
1107
+ * ```
1108
+ *
1109
+ * Note: If a `wait` timeout is specified, it begins counting down only after the test function finishes executing.
1110
+ * @since v22.2.0
859
1111
  */
860
- plan(count: number): void;
1112
+ plan(count: number, options?: TestContextPlanOptions): void;
861
1113
  /**
862
1114
  * If `shouldRunOnlyTests` is truthy, the test context will only run tests that
863
1115
  * have the `only` option set. Otherwise, all tests are run. If Node.js was not
@@ -929,12 +1181,116 @@ declare module "node:test" {
929
1181
  * @returns A {@link Promise} resolved with `undefined` once the test completes.
930
1182
  */
931
1183
  test: typeof test;
1184
+ /**
1185
+ * This method polls a `condition` function until that function either returns
1186
+ * successfully or the operation times out.
1187
+ * @since v22.14.0
1188
+ * @param condition An assertion function that is invoked
1189
+ * periodically until it completes successfully or the defined polling timeout
1190
+ * elapses. Successful completion is defined as not throwing or rejecting. This
1191
+ * function does not accept any arguments, and is allowed to return any value.
1192
+ * @param options An optional configuration object for the polling operation.
1193
+ * @returns Fulfilled with the value returned by `condition`.
1194
+ */
1195
+ waitFor<T>(condition: () => T, options?: TestContextWaitForOptions): Promise<Awaited<T>>;
932
1196
  /**
933
1197
  * Each test provides its own MockTracker instance.
934
1198
  */
935
1199
  readonly mock: MockTracker;
936
1200
  }
937
- interface TestContextAssert extends Pick<typeof import("assert"), AssertMethodNames> {}
1201
+ interface TestContextAssert extends Pick<typeof import("assert"), AssertMethodNames> {
1202
+ /**
1203
+ * This function serializes `value` and writes it to the file specified by `path`.
1204
+ *
1205
+ * ```js
1206
+ * test('snapshot test with default serialization', (t) => {
1207
+ * t.assert.fileSnapshot({ value1: 1, value2: 2 }, './snapshots/snapshot.json');
1208
+ * });
1209
+ * ```
1210
+ *
1211
+ * This function differs from `context.assert.snapshot()` in the following ways:
1212
+ *
1213
+ * * The snapshot file path is explicitly provided by the user.
1214
+ * * Each snapshot file is limited to a single snapshot value.
1215
+ * * No additional escaping is performed by the test runner.
1216
+ *
1217
+ * These differences allow snapshot files to better support features such as syntax
1218
+ * highlighting.
1219
+ * @since v22.14.0
1220
+ * @param value A value to serialize to a string. If Node.js was started with
1221
+ * the [`--test-update-snapshots`](https://nodejs.org/docs/latest-v24.x/api/cli.html#--test-update-snapshots)
1222
+ * flag, the serialized value is written to
1223
+ * `path`. Otherwise, the serialized value is compared to the contents of the
1224
+ * existing snapshot file.
1225
+ * @param path The file where the serialized `value` is written.
1226
+ * @param options Optional configuration options.
1227
+ */
1228
+ fileSnapshot(value: any, path: string, options?: AssertSnapshotOptions): void;
1229
+ /**
1230
+ * This function implements assertions for snapshot testing.
1231
+ * ```js
1232
+ * test('snapshot test with default serialization', (t) => {
1233
+ * t.assert.snapshot({ value1: 1, value2: 2 });
1234
+ * });
1235
+ *
1236
+ * test('snapshot test with custom serialization', (t) => {
1237
+ * t.assert.snapshot({ value3: 3, value4: 4 }, {
1238
+ * serializers: [(value) => JSON.stringify(value)]
1239
+ * });
1240
+ * });
1241
+ * ```
1242
+ * @since v22.3.0
1243
+ * @param value A value to serialize to a string. If Node.js was started with
1244
+ * the [`--test-update-snapshots`](https://nodejs.org/docs/latest-v24.x/api/cli.html#--test-update-snapshots)
1245
+ * flag, the serialized value is written to
1246
+ * the snapshot file. Otherwise, the serialized value is compared to the
1247
+ * corresponding value in the existing snapshot file.
1248
+ */
1249
+ snapshot(value: any, options?: AssertSnapshotOptions): void;
1250
+ /**
1251
+ * A custom assertion function registered with `assert.register()`.
1252
+ */
1253
+ [name: string]: (...args: any[]) => void;
1254
+ }
1255
+ interface AssertSnapshotOptions {
1256
+ /**
1257
+ * An array of synchronous functions used to serialize `value` into a string.
1258
+ * `value` is passed as the only argument to the first serializer function.
1259
+ * The return value of each serializer is passed as input to the next serializer.
1260
+ * Once all serializers have run, the resulting value is coerced to a string.
1261
+ *
1262
+ * If no serializers are provided, the test runner's default serializers are used.
1263
+ */
1264
+ serializers?: ReadonlyArray<(value: any) => any> | undefined;
1265
+ }
1266
+ interface TestContextPlanOptions {
1267
+ /**
1268
+ * The wait time for the plan:
1269
+ * * If `true`, the plan waits indefinitely for all assertions and subtests to run.
1270
+ * * If `false`, the plan performs an immediate check after the test function completes,
1271
+ * without waiting for any pending assertions or subtests.
1272
+ * Any assertions or subtests that complete after this check will not be counted towards the plan.
1273
+ * * If a number, it specifies the maximum wait time in milliseconds
1274
+ * before timing out while waiting for expected assertions and subtests to be matched.
1275
+ * If the timeout is reached, the test will fail.
1276
+ * @default false
1277
+ */
1278
+ wait?: boolean | number | undefined;
1279
+ }
1280
+ interface TestContextWaitForOptions {
1281
+ /**
1282
+ * The number of milliseconds to wait after an unsuccessful
1283
+ * invocation of `condition` before trying again.
1284
+ * @default 50
1285
+ */
1286
+ interval?: number | undefined;
1287
+ /**
1288
+ * The poll timeout in milliseconds. If `condition` has not
1289
+ * succeeded by the time this elapses, an error occurs.
1290
+ * @default 1000
1291
+ */
1292
+ timeout?: number | undefined;
1293
+ }
938
1294
  /**
939
1295
  * An instance of `SuiteContext` is passed to each suite function in order to
940
1296
  * interact with the test runner. However, the `SuiteContext` constructor is not
@@ -942,6 +1298,12 @@ declare module "node:test" {
942
1298
  * @since v18.7.0, v16.17.0
943
1299
  */
944
1300
  interface SuiteContext {
1301
+ /**
1302
+ * The absolute path of the test file that created the current suite. If a test file imports
1303
+ * additional modules that generate suites, the imported suites will return the path of the root test file.
1304
+ * @since v22.6.0
1305
+ */
1306
+ readonly filePath: string | undefined;
945
1307
  /**
946
1308
  * The name of the suite.
947
1309
  * @since v18.8.0, v16.18.0
@@ -998,7 +1360,7 @@ declare module "node:test" {
998
1360
  * If the number of assertions run in the test does not match the number
999
1361
  * specified in the plan, the test will fail.
1000
1362
  * @default undefined
1001
- * @since v20.15.0
1363
+ * @since v22.2.0
1002
1364
  */
1003
1365
  plan?: number | undefined;
1004
1366
  }
@@ -1307,16 +1669,89 @@ declare module "node:test" {
1307
1669
  options?: MockFunctionOptions,
1308
1670
  ): Mock<((value: MockedObject[MethodName]) => void) | Implementation>;
1309
1671
  /**
1310
- * This function is used to mock the exports of ECMAScript modules, CommonJS modules, and Node.js builtin modules.
1311
- * Any references to the original module prior to mocking are not impacted.
1672
+ * This function is used to mock the exports of ECMAScript modules, CommonJS modules, JSON modules, and
1673
+ * Node.js builtin modules. Any references to the original module prior to mocking are not impacted. In
1674
+ * order to enable module mocking, Node.js must be started with the
1675
+ * [`--experimental-test-module-mocks`](https://nodejs.org/docs/latest-v24.x/api/cli.html#--experimental-test-module-mocks)
1676
+ * command-line flag.
1677
+ *
1678
+ * The following example demonstrates how a mock is created for a module.
1679
+ *
1680
+ * ```js
1681
+ * test('mocks a builtin module in both module systems', async (t) => {
1682
+ * // Create a mock of 'node:readline' with a named export named 'fn', which
1683
+ * // does not exist in the original 'node:readline' module.
1684
+ * const mock = t.mock.module('node:readline', {
1685
+ * namedExports: { fn() { return 42; } },
1686
+ * });
1312
1687
  *
1313
- * Only available through the [--experimental-test-module-mocks](https://nodejs.org/api/cli.html#--experimental-test-module-mocks) flag.
1314
- * @since v20.18.0
1688
+ * let esmImpl = await import('node:readline');
1689
+ * let cjsImpl = require('node:readline');
1690
+ *
1691
+ * // cursorTo() is an export of the original 'node:readline' module.
1692
+ * assert.strictEqual(esmImpl.cursorTo, undefined);
1693
+ * assert.strictEqual(cjsImpl.cursorTo, undefined);
1694
+ * assert.strictEqual(esmImpl.fn(), 42);
1695
+ * assert.strictEqual(cjsImpl.fn(), 42);
1696
+ *
1697
+ * mock.restore();
1698
+ *
1699
+ * // The mock is restored, so the original builtin module is returned.
1700
+ * esmImpl = await import('node:readline');
1701
+ * cjsImpl = require('node:readline');
1702
+ *
1703
+ * assert.strictEqual(typeof esmImpl.cursorTo, 'function');
1704
+ * assert.strictEqual(typeof cjsImpl.cursorTo, 'function');
1705
+ * assert.strictEqual(esmImpl.fn, undefined);
1706
+ * assert.strictEqual(cjsImpl.fn, undefined);
1707
+ * });
1708
+ * ```
1709
+ * @since v22.3.0
1315
1710
  * @experimental
1316
1711
  * @param specifier A string identifying the module to mock.
1317
1712
  * @param options Optional configuration options for the mock module.
1318
1713
  */
1319
1714
  module(specifier: string, options?: MockModuleOptions): MockModuleContext;
1715
+ /**
1716
+ * Creates a mock for a property value on an object. This allows you to track and control access to a specific property,
1717
+ * including how many times it is read (getter) or written (setter), and to restore the original value after mocking.
1718
+ *
1719
+ * ```js
1720
+ * test('mocks a property value', (t) => {
1721
+ * const obj = { foo: 42 };
1722
+ * const prop = t.mock.property(obj, 'foo', 100);
1723
+ *
1724
+ * assert.strictEqual(obj.foo, 100);
1725
+ * assert.strictEqual(prop.mock.accessCount(), 1);
1726
+ * assert.strictEqual(prop.mock.accesses[0].type, 'get');
1727
+ * assert.strictEqual(prop.mock.accesses[0].value, 100);
1728
+ *
1729
+ * obj.foo = 200;
1730
+ * assert.strictEqual(prop.mock.accessCount(), 2);
1731
+ * assert.strictEqual(prop.mock.accesses[1].type, 'set');
1732
+ * assert.strictEqual(prop.mock.accesses[1].value, 200);
1733
+ *
1734
+ * prop.mock.restore();
1735
+ * assert.strictEqual(obj.foo, 42);
1736
+ * });
1737
+ * ```
1738
+ * @since v24.3.0
1739
+ * @param object The object whose value is being mocked.
1740
+ * @param propertyName The identifier of the property on `object` to mock.
1741
+ * @param value An optional value used as the mock value
1742
+ * for `object[propertyName]`. **Default:** The original property value.
1743
+ * @returns A proxy to the mocked object. The mocked object contains a
1744
+ * special `mock` property, which is an instance of [`MockPropertyContext`][], and
1745
+ * can be used for inspecting and changing the behavior of the mocked property.
1746
+ */
1747
+ property<
1748
+ MockedObject extends object,
1749
+ PropertyName extends keyof MockedObject,
1750
+ >(
1751
+ object: MockedObject,
1752
+ property: PropertyName,
1753
+ value?: MockedObject[PropertyName],
1754
+ ): MockedObject & { mock: MockPropertyContext<MockedObject[PropertyName]> };
1320
1755
  /**
1321
1756
  * This function restores the default behavior of all mocks that were previously
1322
1757
  * created by this `MockTracker` and disassociates the mocks from the `MockTracker` instance. Once disassociated, the mocks can still be used, but the `MockTracker` instance can no longer be
@@ -1476,13 +1911,77 @@ declare module "node:test" {
1476
1911
  restore(): void;
1477
1912
  }
1478
1913
  /**
1479
- * @since v20.18.0
1914
+ * @since v22.3.0
1480
1915
  * @experimental
1481
1916
  */
1482
1917
  interface MockModuleContext {
1483
1918
  /**
1484
1919
  * Resets the implementation of the mock module.
1485
- * @since v20.18.0
1920
+ * @since v22.3.0
1921
+ */
1922
+ restore(): void;
1923
+ }
1924
+ /**
1925
+ * @since v24.3.0
1926
+ */
1927
+ class MockPropertyContext<PropertyType = any> {
1928
+ /**
1929
+ * A getter that returns a copy of the internal array used to track accesses (get/set) to
1930
+ * the mocked property. Each entry in the array is an object with the following properties:
1931
+ */
1932
+ readonly accesses: Array<{
1933
+ type: "get" | "set";
1934
+ value: PropertyType;
1935
+ stack: Error;
1936
+ }>;
1937
+ /**
1938
+ * This function returns the number of times that the property was accessed.
1939
+ * This function is more efficient than checking `ctx.accesses.length` because
1940
+ * `ctx.accesses` is a getter that creates a copy of the internal access tracking array.
1941
+ * @returns The number of times that the property was accessed (read or written).
1942
+ */
1943
+ accessCount(): number;
1944
+ /**
1945
+ * This function is used to change the value returned by the mocked property getter.
1946
+ * @param value The new value to be set as the mocked property value.
1947
+ */
1948
+ mockImplementation(value: PropertyType): void;
1949
+ /**
1950
+ * This function is used to change the behavior of an existing mock for a single
1951
+ * invocation. Once invocation `onAccess` has occurred, the mock will revert to
1952
+ * whatever behavior it would have used had `mockImplementationOnce()` not been
1953
+ * called.
1954
+ *
1955
+ * The following example creates a mock function using `t.mock.property()`, calls the
1956
+ * mock property, changes the mock implementation to a different value for the
1957
+ * next invocation, and then resumes its previous behavior.
1958
+ *
1959
+ * ```js
1960
+ * test('changes a mock behavior once', (t) => {
1961
+ * const obj = { foo: 1 };
1962
+ *
1963
+ * const prop = t.mock.property(obj, 'foo', 5);
1964
+ *
1965
+ * assert.strictEqual(obj.foo, 5);
1966
+ * prop.mock.mockImplementationOnce(25);
1967
+ * assert.strictEqual(obj.foo, 25);
1968
+ * assert.strictEqual(obj.foo, 5);
1969
+ * });
1970
+ * ```
1971
+ * @param value The value to be used as the mock's
1972
+ * implementation for the invocation number specified by `onAccess`.
1973
+ * @param onAccess The invocation number that will use `value`. If
1974
+ * the specified invocation has already occurred then an exception is thrown.
1975
+ * **Default:** The number of the next invocation.
1976
+ */
1977
+ mockImplementationOnce(value: PropertyType, onAccess?: number): void;
1978
+ /**
1979
+ * Resets the access history of the mocked property.
1980
+ */
1981
+ resetAccesses(): void;
1982
+ /**
1983
+ * Resets the implementation of the mock property to its original behavior. The
1984
+ * mock can still be used after calling this function.
1486
1985
  */
1487
1986
  restore(): void;
1488
1987
  }
@@ -1501,7 +2000,6 @@ declare module "node:test" {
1501
2000
  * The `MockTracker` provides a top-level `timers` export
1502
2001
  * which is a `MockTimers` instance.
1503
2002
  * @since v20.4.0
1504
- * @experimental
1505
2003
  */
1506
2004
  interface MockTimers {
1507
2005
  /**
@@ -1706,6 +2204,52 @@ declare module "node:test" {
1706
2204
  */
1707
2205
  [Symbol.dispose](): void;
1708
2206
  }
2207
+ /**
2208
+ * An object whose methods are used to configure available assertions on the
2209
+ * `TestContext` objects in the current process. The methods from `node:assert`
2210
+ * and snapshot testing functions are available by default.
2211
+ *
2212
+ * It is possible to apply the same configuration to all files by placing common
2213
+ * configuration code in a module
2214
+ * preloaded with `--require` or `--import`.
2215
+ * @since v22.14.0
2216
+ */
2217
+ namespace assert {
2218
+ /**
2219
+ * Defines a new assertion function with the provided name and function. If an
2220
+ * assertion already exists with the same name, it is overwritten.
2221
+ * @since v22.14.0
2222
+ */
2223
+ function register(name: string, fn: (this: TestContext, ...args: any[]) => void): void;
2224
+ }
2225
+ /**
2226
+ * @since v22.3.0
2227
+ */
2228
+ namespace snapshot {
2229
+ /**
2230
+ * This function is used to customize the default serialization mechanism used by the test runner.
2231
+ *
2232
+ * By default, the test runner performs serialization by calling `JSON.stringify(value, null, 2)` on the provided value.
2233
+ * `JSON.stringify()` does have limitations regarding circular structures and supported data types.
2234
+ * If a more robust serialization mechanism is required, this function should be used to specify a list of custom serializers.
2235
+ *
2236
+ * Serializers are called in order, with the output of the previous serializer passed as input to the next.
2237
+ * The final result must be a string value.
2238
+ * @since v22.3.0
2239
+ * @param serializers An array of synchronous functions used as the default serializers for snapshot tests.
2240
+ */
2241
+ function setDefaultSnapshotSerializers(serializers: ReadonlyArray<(value: any) => any>): void;
2242
+ /**
2243
+ * This function is used to set a custom resolver for the location of the snapshot file used for snapshot testing.
2244
+ * By default, the snapshot filename is the same as the entry point filename with `.snapshot` appended.
2245
+ * @since v22.3.0
2246
+ * @param fn A function used to compute the location of the snapshot file.
2247
+ * The function receives the path of the test file as its only argument. If the
2248
+ * test is not associated with a file (for example in the REPL), the input is
2249
+ * undefined. `fn()` must return a string specifying the location of the snapshot file.
2250
+ */
2251
+ function setResolveSnapshotPath(fn: (path: string | undefined) => string): void;
2252
+ }
1709
2253
  }
1710
2254
  type FunctionPropertyNames<T> = {
1711
2255
  [K in keyof T]: T[K] extends Function ? K : never;
@@ -1725,10 +2269,10 @@ declare module "node:test" {
1725
2269
  * work:
1726
2270
  *
1727
2271
  * ```js
1728
- * import test from 'test/reporters';
2272
+ * import test from 'node:test/reporters';
1729
2273
  * ```
1730
2274
  * @since v19.9.0
1731
- * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/test/reporters.js)
2275
+ * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/test/reporters.js)
1732
2276
  */
1733
2277
  declare module "node:test/reporters" {
1734
2278
  import { Transform, TransformOptions } from "node:stream";
@@ -1746,9 +2290,16 @@ declare module "node:test/reporters" {
1746
2290
  | { type: "test:start"; data: EventData.TestStart }
1747
2291
  | { type: "test:stderr"; data: EventData.TestStderr }
1748
2292
  | { type: "test:stdout"; data: EventData.TestStdout }
1749
- | { type: "test:watch:drained"; data: undefined };
2293
+ | { type: "test:summary"; data: EventData.TestSummary }
2294
+ | { type: "test:watch:drained"; data: undefined }
2295
+ | { type: "test:watch:restarted"; data: undefined };
1750
2296
  type TestEventGenerator = AsyncGenerator<TestEvent, void>;
1751
2297
 
2298
+ interface ReporterConstructorWrapper<T extends new(...args: any[]) => Transform> {
2299
+ new(...args: ConstructorParameters<T>): InstanceType<T>;
2300
+ (...args: ConstructorParameters<T>): InstanceType<T>;
2301
+ }
2302
+
1752
2303
  /**
1753
2304
  * The `dot` reporter outputs the test results in a compact format,
1754
2305
  * where each passing test is represented by a `.`,
@@ -1761,13 +2312,14 @@ declare module "node:test/reporters" {
1761
2312
  * @since v20.0.0
1762
2313
  */
1763
2314
  function tap(source: TestEventGenerator): AsyncGenerator<string, void>;
2315
+ class SpecReporter extends Transform {
2316
+ constructor();
2317
+ }
1764
2318
  /**
1765
2319
  * The `spec` reporter outputs the test results in a human-readable format.
1766
2320
  * @since v20.0.0
1767
2321
  */
1768
- class SpecReporter extends Transform {
1769
- constructor();
1770
- }
2322
+ const spec: ReporterConstructorWrapper<typeof SpecReporter>;
1771
2323
  /**
1772
2324
  * The `junit` reporter outputs test results in a jUnit XML format.
1773
2325
  * @since v21.0.0
@@ -1778,10 +2330,10 @@ declare module "node:test/reporters" {
1778
2330
  }
1779
2331
  /**
1780
2332
  * The `lcov` reporter outputs test coverage when used with the
1781
- * [`--experimental-test-coverage`](https://nodejs.org/docs/latest-v20.x/api/cli.html#--experimental-test-coverage) flag.
2333
+ * [`--experimental-test-coverage`](https://nodejs.org/docs/latest-v24.x/api/cli.html#--experimental-test-coverage) flag.
1782
2334
  * @since v22.0.0
1783
2335
  */
1784
- const lcov: LcovReporter;
2336
+ const lcov: ReporterConstructorWrapper<typeof LcovReporter>;
1785
2337
 
1786
- export { dot, junit, lcov, SpecReporter as spec, tap, TestEvent };
2338
+ export { dot, junit, lcov, spec, tap, TestEvent };
1787
2339
  }