alicezetion 1.8.5 → 1.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. package/.cache/nix/binary-cache-v6.sqlite +0 -0
  2. package/.cache/nix/binary-cache-v6.sqlite-journal +0 -0
  3. package/.cache/replit/modules/nodejs-20:v25-20240206-fdbd396.res +1 -0
  4. package/.cache/replit/modules/replit:v4-20240206-fdbd396.res +1 -0
  5. package/.cache/replit/modules.stamp +0 -1
  6. package/.cache/replit/nix/env.json +1 -1
  7. package/.cache/typescript/5.3/node_modules/.package-lock.json +137 -0
  8. package/.cache/typescript/5.3/node_modules/@types/bluebird/LICENSE +21 -0
  9. package/.cache/typescript/5.3/node_modules/@types/bluebird/README.md +15 -0
  10. package/.cache/typescript/5.3/node_modules/@types/bluebird/index.d.ts +1365 -0
  11. package/.cache/typescript/5.3/node_modules/@types/bluebird/package.json +25 -0
  12. package/.cache/typescript/5.3/node_modules/@types/caseless/LICENSE +21 -0
  13. package/.cache/typescript/5.3/node_modules/@types/caseless/README.md +48 -0
  14. package/.cache/typescript/5.3/node_modules/@types/caseless/index.d.ts +29 -0
  15. package/.cache/typescript/5.3/node_modules/@types/caseless/package.json +35 -0
  16. package/.cache/typescript/5.3/node_modules/@types/cheerio/LICENSE +21 -0
  17. package/.cache/typescript/5.3/node_modules/@types/cheerio/README.md +15 -0
  18. package/.cache/typescript/5.3/node_modules/@types/cheerio/index.d.ts +318 -0
  19. package/.cache/typescript/5.3/node_modules/@types/cheerio/package.json +71 -0
  20. package/.cache/typescript/5.3/node_modules/@types/node/LICENSE +21 -0
  21. package/.cache/typescript/5.3/node_modules/@types/node/README.md +15 -0
  22. package/.cache/typescript/5.3/node_modules/@types/node/assert/strict.d.ts +8 -0
  23. package/.cache/typescript/5.3/node_modules/@types/node/assert.d.ts +996 -0
  24. package/.cache/typescript/5.3/node_modules/@types/node/async_hooks.d.ts +539 -0
  25. package/.cache/typescript/5.3/node_modules/@types/node/buffer.d.ts +2362 -0
  26. package/.cache/typescript/5.3/node_modules/@types/node/child_process.d.ts +1540 -0
  27. package/.cache/typescript/5.3/node_modules/@types/node/cluster.d.ts +432 -0
  28. package/.cache/typescript/5.3/node_modules/@types/node/console.d.ts +415 -0
  29. package/.cache/typescript/5.3/node_modules/@types/node/constants.d.ts +19 -0
  30. package/.cache/typescript/5.3/node_modules/@types/node/crypto.d.ts +4487 -0
  31. package/.cache/typescript/5.3/node_modules/@types/node/dgram.d.ts +596 -0
  32. package/.cache/typescript/5.3/node_modules/@types/node/diagnostics_channel.d.ts +545 -0
  33. package/.cache/typescript/5.3/node_modules/@types/node/dns/promises.d.ts +425 -0
  34. package/.cache/typescript/5.3/node_modules/@types/node/dns.d.ts +809 -0
  35. package/.cache/typescript/5.3/node_modules/@types/node/dom-events.d.ts +122 -0
  36. package/.cache/typescript/5.3/node_modules/@types/node/domain.d.ts +170 -0
  37. package/.cache/typescript/5.3/node_modules/@types/node/events.d.ts +879 -0
  38. package/.cache/typescript/5.3/node_modules/@types/node/fs/promises.d.ts +1239 -0
  39. package/.cache/typescript/5.3/node_modules/@types/node/fs.d.ts +4311 -0
  40. package/.cache/typescript/5.3/node_modules/@types/node/globals.d.ts +411 -0
  41. package/.cache/typescript/5.3/node_modules/@types/node/globals.global.d.ts +1 -0
  42. package/.cache/typescript/5.3/node_modules/@types/node/http.d.ts +1887 -0
  43. package/.cache/typescript/5.3/node_modules/@types/node/http2.d.ts +2382 -0
  44. package/.cache/typescript/5.3/node_modules/@types/node/https.d.ts +550 -0
  45. package/.cache/typescript/5.3/node_modules/@types/node/index.d.ts +88 -0
  46. package/.cache/typescript/5.3/node_modules/@types/node/inspector.d.ts +2747 -0
  47. package/.cache/typescript/5.3/node_modules/@types/node/module.d.ts +315 -0
  48. package/.cache/typescript/5.3/node_modules/@types/node/net.d.ts +949 -0
  49. package/.cache/typescript/5.3/node_modules/@types/node/os.d.ts +478 -0
  50. package/.cache/typescript/5.3/node_modules/@types/node/package.json +229 -0
  51. package/.cache/typescript/5.3/node_modules/@types/node/path.d.ts +191 -0
  52. package/.cache/typescript/5.3/node_modules/@types/node/perf_hooks.d.ts +645 -0
  53. package/.cache/typescript/5.3/node_modules/@types/node/process.d.ts +1561 -0
  54. package/.cache/typescript/5.3/node_modules/@types/node/punycode.d.ts +117 -0
  55. package/.cache/typescript/5.3/node_modules/@types/node/querystring.d.ts +141 -0
  56. package/.cache/typescript/5.3/node_modules/@types/node/readline/promises.d.ts +150 -0
  57. package/.cache/typescript/5.3/node_modules/@types/node/readline.d.ts +539 -0
  58. package/.cache/typescript/5.3/node_modules/@types/node/repl.d.ts +430 -0
  59. package/.cache/typescript/5.3/node_modules/@types/node/stream/consumers.d.ts +12 -0
  60. package/.cache/typescript/5.3/node_modules/@types/node/stream/promises.d.ts +83 -0
  61. package/.cache/typescript/5.3/node_modules/@types/node/stream/web.d.ts +366 -0
  62. package/.cache/typescript/5.3/node_modules/@types/node/stream.d.ts +1701 -0
  63. package/.cache/typescript/5.3/node_modules/@types/node/string_decoder.d.ts +67 -0
  64. package/.cache/typescript/5.3/node_modules/@types/node/test.d.ts +1465 -0
  65. package/.cache/typescript/5.3/node_modules/@types/node/timers/promises.d.ts +93 -0
  66. package/.cache/typescript/5.3/node_modules/@types/node/timers.d.ts +240 -0
  67. package/.cache/typescript/5.3/node_modules/@types/node/tls.d.ts +1210 -0
  68. package/.cache/typescript/5.3/node_modules/@types/node/trace_events.d.ts +182 -0
  69. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/assert/strict.d.ts +8 -0
  70. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/assert.d.ts +996 -0
  71. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/async_hooks.d.ts +539 -0
  72. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/buffer.d.ts +2362 -0
  73. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/child_process.d.ts +1540 -0
  74. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/cluster.d.ts +432 -0
  75. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/console.d.ts +415 -0
  76. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/constants.d.ts +19 -0
  77. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/crypto.d.ts +4487 -0
  78. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/dgram.d.ts +596 -0
  79. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +545 -0
  80. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/dns/promises.d.ts +425 -0
  81. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/dns.d.ts +809 -0
  82. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/dom-events.d.ts +122 -0
  83. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/domain.d.ts +170 -0
  84. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/events.d.ts +879 -0
  85. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/fs/promises.d.ts +1239 -0
  86. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/fs.d.ts +4311 -0
  87. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/globals.d.ts +411 -0
  88. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/globals.global.d.ts +1 -0
  89. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/http.d.ts +1887 -0
  90. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/http2.d.ts +2382 -0
  91. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/https.d.ts +550 -0
  92. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/index.d.ts +88 -0
  93. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/inspector.d.ts +2747 -0
  94. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/module.d.ts +315 -0
  95. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/net.d.ts +949 -0
  96. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/os.d.ts +478 -0
  97. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/path.d.ts +191 -0
  98. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/perf_hooks.d.ts +645 -0
  99. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/process.d.ts +1561 -0
  100. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/punycode.d.ts +117 -0
  101. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/querystring.d.ts +141 -0
  102. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/readline/promises.d.ts +150 -0
  103. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/readline.d.ts +539 -0
  104. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/repl.d.ts +430 -0
  105. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/stream/consumers.d.ts +12 -0
  106. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/stream/promises.d.ts +83 -0
  107. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/stream/web.d.ts +366 -0
  108. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/stream.d.ts +1701 -0
  109. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/string_decoder.d.ts +67 -0
  110. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/test.d.ts +1465 -0
  111. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/timers/promises.d.ts +93 -0
  112. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/timers.d.ts +240 -0
  113. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/tls.d.ts +1210 -0
  114. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/trace_events.d.ts +182 -0
  115. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/tty.d.ts +208 -0
  116. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/url.d.ts +927 -0
  117. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/util.d.ts +2183 -0
  118. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/v8.d.ts +635 -0
  119. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/vm.d.ts +903 -0
  120. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/wasi.d.ts +179 -0
  121. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/worker_threads.d.ts +691 -0
  122. package/.cache/typescript/5.3/node_modules/@types/node/ts4.8/zlib.d.ts +517 -0
  123. package/.cache/typescript/5.3/node_modules/@types/node/tty.d.ts +208 -0
  124. package/.cache/typescript/5.3/node_modules/@types/node/url.d.ts +927 -0
  125. package/.cache/typescript/5.3/node_modules/@types/node/util.d.ts +2183 -0
  126. package/.cache/typescript/5.3/node_modules/@types/node/v8.d.ts +635 -0
  127. package/.cache/typescript/5.3/node_modules/@types/node/vm.d.ts +903 -0
  128. package/.cache/typescript/5.3/node_modules/@types/node/wasi.d.ts +179 -0
  129. package/.cache/typescript/5.3/node_modules/@types/node/worker_threads.d.ts +691 -0
  130. package/.cache/typescript/5.3/node_modules/@types/node/zlib.d.ts +517 -0
  131. package/.cache/typescript/5.3/node_modules/@types/npmlog/LICENSE +21 -0
  132. package/.cache/typescript/5.3/node_modules/@types/npmlog/README.md +15 -0
  133. package/.cache/typescript/5.3/node_modules/@types/npmlog/index.d.ts +84 -0
  134. package/.cache/typescript/5.3/node_modules/@types/npmlog/package.json +32 -0
  135. package/.cache/typescript/5.3/node_modules/@types/request/LICENSE +21 -0
  136. package/.cache/typescript/5.3/node_modules/@types/request/README.md +15 -0
  137. package/.cache/typescript/5.3/node_modules/@types/request/index.d.ts +395 -0
  138. package/.cache/typescript/5.3/node_modules/@types/request/package.json +70 -0
  139. package/.cache/typescript/5.3/node_modules/@types/tough-cookie/LICENSE +21 -0
  140. package/.cache/typescript/5.3/node_modules/@types/tough-cookie/README.md +15 -0
  141. package/.cache/typescript/5.3/node_modules/@types/tough-cookie/index.d.ts +321 -0
  142. package/.cache/typescript/5.3/node_modules/@types/tough-cookie/package.json +35 -0
  143. package/.cache/typescript/5.3/node_modules/asynckit/LICENSE +21 -0
  144. package/.cache/typescript/5.3/node_modules/asynckit/README.md +233 -0
  145. package/.cache/typescript/5.3/node_modules/asynckit/bench.js +76 -0
  146. package/.cache/typescript/5.3/node_modules/asynckit/index.js +6 -0
  147. package/.cache/typescript/5.3/node_modules/asynckit/lib/abort.js +29 -0
  148. package/.cache/typescript/5.3/node_modules/asynckit/lib/async.js +34 -0
  149. package/.cache/typescript/5.3/node_modules/asynckit/lib/defer.js +26 -0
  150. package/.cache/typescript/5.3/node_modules/asynckit/lib/iterate.js +75 -0
  151. package/.cache/typescript/5.3/node_modules/asynckit/lib/readable_asynckit.js +91 -0
  152. package/.cache/typescript/5.3/node_modules/asynckit/lib/readable_parallel.js +25 -0
  153. package/.cache/typescript/5.3/node_modules/asynckit/lib/readable_serial.js +25 -0
  154. package/.cache/typescript/5.3/node_modules/asynckit/lib/readable_serial_ordered.js +29 -0
  155. package/.cache/typescript/5.3/node_modules/asynckit/lib/state.js +37 -0
  156. package/.cache/typescript/5.3/node_modules/asynckit/lib/streamify.js +141 -0
  157. package/.cache/typescript/5.3/node_modules/asynckit/lib/terminator.js +29 -0
  158. package/.cache/typescript/5.3/node_modules/asynckit/package.json +63 -0
  159. package/.cache/typescript/5.3/node_modules/asynckit/parallel.js +43 -0
  160. package/.cache/typescript/5.3/node_modules/asynckit/serial.js +17 -0
  161. package/.cache/typescript/5.3/node_modules/asynckit/serialOrdered.js +75 -0
  162. package/.cache/typescript/5.3/node_modules/asynckit/stream.js +21 -0
  163. package/.cache/typescript/5.3/node_modules/combined-stream/License +19 -0
  164. package/.cache/typescript/5.3/node_modules/combined-stream/Readme.md +138 -0
  165. package/.cache/typescript/5.3/node_modules/combined-stream/lib/combined_stream.js +208 -0
  166. package/.cache/typescript/5.3/node_modules/combined-stream/package.json +25 -0
  167. package/.cache/typescript/5.3/node_modules/combined-stream/yarn.lock +17 -0
  168. package/.cache/typescript/5.3/node_modules/delayed-stream/License +19 -0
  169. package/.cache/typescript/5.3/node_modules/delayed-stream/Makefile +7 -0
  170. package/.cache/typescript/5.3/node_modules/delayed-stream/Readme.md +141 -0
  171. package/.cache/typescript/5.3/node_modules/delayed-stream/lib/delayed_stream.js +107 -0
  172. package/.cache/typescript/5.3/node_modules/delayed-stream/package.json +27 -0
  173. package/.cache/typescript/5.3/node_modules/form-data/License +19 -0
  174. package/.cache/typescript/5.3/node_modules/form-data/README.md +350 -0
  175. package/.cache/typescript/5.3/node_modules/form-data/README.md.bak +350 -0
  176. package/.cache/typescript/5.3/node_modules/form-data/index.d.ts +51 -0
  177. package/.cache/typescript/5.3/node_modules/form-data/lib/browser.js +2 -0
  178. package/.cache/typescript/5.3/node_modules/form-data/lib/form_data.js +483 -0
  179. package/.cache/typescript/5.3/node_modules/form-data/lib/populate.js +10 -0
  180. package/.cache/typescript/5.3/node_modules/form-data/package.json +68 -0
  181. package/.cache/typescript/5.3/node_modules/mime-db/HISTORY.md +507 -0
  182. package/.cache/typescript/5.3/node_modules/mime-db/LICENSE +23 -0
  183. package/.cache/typescript/5.3/node_modules/mime-db/README.md +100 -0
  184. package/.cache/typescript/5.3/node_modules/mime-db/db.json +8519 -0
  185. package/.cache/typescript/5.3/node_modules/mime-db/index.js +12 -0
  186. package/.cache/typescript/5.3/node_modules/mime-db/package.json +60 -0
  187. package/.cache/typescript/5.3/node_modules/mime-types/HISTORY.md +397 -0
  188. package/.cache/typescript/5.3/node_modules/mime-types/LICENSE +23 -0
  189. package/.cache/typescript/5.3/node_modules/mime-types/README.md +113 -0
  190. package/.cache/typescript/5.3/node_modules/mime-types/index.js +188 -0
  191. package/.cache/typescript/5.3/node_modules/mime-types/package.json +44 -0
  192. package/.cache/typescript/5.3/node_modules/types-registry/README.md +2 -0
  193. package/.cache/typescript/5.3/node_modules/types-registry/index.json +1 -0
  194. package/.cache/typescript/5.3/node_modules/types-registry/package.json +20 -0
  195. package/.cache/typescript/5.3/node_modules/undici-types/README.md +6 -0
  196. package/.cache/typescript/5.3/node_modules/undici-types/agent.d.ts +31 -0
  197. package/.cache/typescript/5.3/node_modules/undici-types/api.d.ts +43 -0
  198. package/.cache/typescript/5.3/node_modules/undici-types/balanced-pool.d.ts +18 -0
  199. package/.cache/typescript/5.3/node_modules/undici-types/cache.d.ts +36 -0
  200. package/.cache/typescript/5.3/node_modules/undici-types/client.d.ts +97 -0
  201. package/.cache/typescript/5.3/node_modules/undici-types/connector.d.ts +34 -0
  202. package/.cache/typescript/5.3/node_modules/undici-types/content-type.d.ts +21 -0
  203. package/.cache/typescript/5.3/node_modules/undici-types/cookies.d.ts +28 -0
  204. package/.cache/typescript/5.3/node_modules/undici-types/diagnostics-channel.d.ts +67 -0
  205. package/.cache/typescript/5.3/node_modules/undici-types/dispatcher.d.ts +241 -0
  206. package/.cache/typescript/5.3/node_modules/undici-types/errors.d.ts +128 -0
  207. package/.cache/typescript/5.3/node_modules/undici-types/fetch.d.ts +209 -0
  208. package/.cache/typescript/5.3/node_modules/undici-types/file.d.ts +39 -0
  209. package/.cache/typescript/5.3/node_modules/undici-types/filereader.d.ts +54 -0
  210. package/.cache/typescript/5.3/node_modules/undici-types/formdata.d.ts +108 -0
  211. package/.cache/typescript/5.3/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  212. package/.cache/typescript/5.3/node_modules/undici-types/global-origin.d.ts +7 -0
  213. package/.cache/typescript/5.3/node_modules/undici-types/handlers.d.ts +9 -0
  214. package/.cache/typescript/5.3/node_modules/undici-types/header.d.ts +4 -0
  215. package/.cache/typescript/5.3/node_modules/undici-types/index.d.ts +63 -0
  216. package/.cache/typescript/5.3/node_modules/undici-types/interceptors.d.ts +5 -0
  217. package/.cache/typescript/5.3/node_modules/undici-types/mock-agent.d.ts +50 -0
  218. package/.cache/typescript/5.3/node_modules/undici-types/mock-client.d.ts +25 -0
  219. package/.cache/typescript/5.3/node_modules/undici-types/mock-errors.d.ts +12 -0
  220. package/.cache/typescript/5.3/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  221. package/.cache/typescript/5.3/node_modules/undici-types/mock-pool.d.ts +25 -0
  222. package/.cache/typescript/5.3/node_modules/undici-types/package.json +55 -0
  223. package/.cache/typescript/5.3/node_modules/undici-types/patch.d.ts +71 -0
  224. package/.cache/typescript/5.3/node_modules/undici-types/pool-stats.d.ts +19 -0
  225. package/.cache/typescript/5.3/node_modules/undici-types/pool.d.ts +28 -0
  226. package/.cache/typescript/5.3/node_modules/undici-types/proxy-agent.d.ts +30 -0
  227. package/.cache/typescript/5.3/node_modules/undici-types/readable.d.ts +61 -0
  228. package/.cache/typescript/5.3/node_modules/undici-types/webidl.d.ts +220 -0
  229. package/.cache/typescript/5.3/node_modules/undici-types/websocket.d.ts +131 -0
  230. package/.cache/typescript/5.3/package-lock.json +149 -0
  231. package/.cache/typescript/5.3/package.json +1 -0
  232. package/.replit +1 -0
  233. package/index.js +2 -0
  234. package/leiamnash/edit.js +59 -0
  235. package/leiamnash/token.js +112 -0
  236. package/package.json +1 -1
  237. package/utils.js +18 -2
  238. package/.cache/replit/__replit_disk_meta.json +0 -1
  239. package/replit.nix +0 -6
@@ -0,0 +1,1465 @@
1
+ /**
2
+ * The `node:test` module facilitates the creation of JavaScript tests.
3
+ * To access it:
4
+ *
5
+ * ```js
6
+ * import test from 'node:test';
7
+ * ```
8
+ *
9
+ * This module is only available under the `node:` scheme. The following will not
10
+ * work:
11
+ *
12
+ * ```js
13
+ * import test from 'test';
14
+ * ```
15
+ *
16
+ * Tests created via the `test` module consist of a single function that is
17
+ * processed in one of three ways:
18
+ *
19
+ * 1. A synchronous function that is considered failing if it throws an exception,
20
+ * and is considered passing otherwise.
21
+ * 2. A function that returns a `Promise` that is considered failing if the`Promise` rejects, and is considered passing if the `Promise` fulfills.
22
+ * 3. A function that receives a callback function. If the callback receives any
23
+ * truthy value as its first argument, the test is considered failing. If a
24
+ * falsy value is passed as the first argument to the callback, the test is
25
+ * considered passing. If the test function receives a callback function and
26
+ * also returns a `Promise`, the test will fail.
27
+ *
28
+ * The following example illustrates how tests are written using the`test` module.
29
+ *
30
+ * ```js
31
+ * test('synchronous passing test', (t) => {
32
+ * // This test passes because it does not throw an exception.
33
+ * assert.strictEqual(1, 1);
34
+ * });
35
+ *
36
+ * test('synchronous failing test', (t) => {
37
+ * // This test fails because it throws an exception.
38
+ * assert.strictEqual(1, 2);
39
+ * });
40
+ *
41
+ * test('asynchronous passing test', async (t) => {
42
+ * // This test passes because the Promise returned by the async
43
+ * // function is settled and not rejected.
44
+ * assert.strictEqual(1, 1);
45
+ * });
46
+ *
47
+ * test('asynchronous failing test', async (t) => {
48
+ * // This test fails because the Promise returned by the async
49
+ * // function is rejected.
50
+ * assert.strictEqual(1, 2);
51
+ * });
52
+ *
53
+ * test('failing test using Promises', (t) => {
54
+ * // Promises can be used directly as well.
55
+ * return new Promise((resolve, reject) => {
56
+ * setImmediate(() => {
57
+ * reject(new Error('this will cause the test to fail'));
58
+ * });
59
+ * });
60
+ * });
61
+ *
62
+ * test('callback passing test', (t, done) => {
63
+ * // done() is the callback function. When the setImmediate() runs, it invokes
64
+ * // done() with no arguments.
65
+ * setImmediate(done);
66
+ * });
67
+ *
68
+ * test('callback failing test', (t, done) => {
69
+ * // When the setImmediate() runs, done() is invoked with an Error object and
70
+ * // the test fails.
71
+ * setImmediate(() => {
72
+ * done(new Error('callback failure'));
73
+ * });
74
+ * });
75
+ * ```
76
+ *
77
+ * If any tests fail, the process exit code is set to `1`.
78
+ * @since v18.0.0, v16.17.0
79
+ * @see [source](https://github.com/nodejs/node/blob/v20.4.0/lib/test.js)
80
+ */
81
+ declare module "node:test" {
82
+ import { Readable } from "node:stream";
83
+ import { AsyncResource } from "node:async_hooks";
84
+ /**
85
+ * **Note:**`shard` is used to horizontally parallelize test running across
86
+ * machines or processes, ideal for large-scale executions across varied
87
+ * environments. It's incompatible with `watch` mode, tailored for rapid
88
+ * code iteration by automatically rerunning tests on file changes.
89
+ *
90
+ * ```js
91
+ * import { tap } from 'node:test/reporters';
92
+ * import { run } from 'node:test';
93
+ * import process from 'node:process';
94
+ * import path from 'node:path';
95
+ *
96
+ * run({ files: [path.resolve('./tests/test.js')] })
97
+ * .compose(tap)
98
+ * .pipe(process.stdout);
99
+ * ```
100
+ * @since v18.9.0, v16.19.0
101
+ * @param options Configuration options for running tests. The following properties are supported:
102
+ */
103
+ function run(options?: RunOptions): TestsStream;
104
+ /**
105
+ * The `test()` function is the value imported from the `test` module. Each
106
+ * invocation of this function results in reporting the test to the `TestsStream`.
107
+ *
108
+ * The `TestContext` object passed to the `fn` argument can be used to perform
109
+ * actions related to the current test. Examples include skipping the test, adding
110
+ * additional diagnostic information, or creating subtests.
111
+ *
112
+ * `test()` returns a `Promise` that fulfills once the test completes.
113
+ * if `test()` is called within a `describe()` block, it fulfills immediately.
114
+ * The return value can usually be discarded for top level tests.
115
+ * However, the return value from subtests should be used to prevent the parent
116
+ * test from finishing first and cancelling the subtest
117
+ * as shown in the following example.
118
+ *
119
+ * ```js
120
+ * test('top level test', async (t) => {
121
+ * // The setTimeout() in the following subtest would cause it to outlive its
122
+ * // parent test if 'await' is removed on the next line. Once the parent test
123
+ * // completes, it will cancel any outstanding subtests.
124
+ * await t.test('longer running subtest', async (t) => {
125
+ * return new Promise((resolve, reject) => {
126
+ * setTimeout(resolve, 1000);
127
+ * });
128
+ * });
129
+ * });
130
+ * ```
131
+ *
132
+ * The `timeout` option can be used to fail the test if it takes longer than`timeout` milliseconds to complete. However, it is not a reliable mechanism for
133
+ * canceling tests because a running test might block the application thread and
134
+ * thus prevent the scheduled cancellation.
135
+ * @since v18.0.0, v16.17.0
136
+ * @param [name='The name'] The name of the test, which is displayed when reporting test results.
137
+ * @param options Configuration options for the test. The following properties are supported:
138
+ * @param [fn='A no-op function'] The function under test. The first argument to this function is a {@link TestContext} object. If the test uses callbacks, the callback function is passed as the
139
+ * second argument.
140
+ * @return Fulfilled with `undefined` once the test completes, or immediately if the test runs within {@link describe}.
141
+ */
142
+ function test(name?: string, fn?: TestFn): Promise<void>;
143
+ function test(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
144
+ function test(options?: TestOptions, fn?: TestFn): Promise<void>;
145
+ function test(fn?: TestFn): Promise<void>;
146
+ namespace test {
147
+ export { after, afterEach, before, beforeEach, describe, it, mock, only, run, skip, test, todo };
148
+ }
149
+ /**
150
+ * The `describe()` function imported from the `node:test` module. Each
151
+ * invocation of this function results in the creation of a Subtest.
152
+ * After invocation of top level `describe` functions,
153
+ * all top level tests and suites will execute.
154
+ * @param [name='The name'] The name of the suite, which is displayed when reporting test results.
155
+ * @param options Configuration options for the suite. supports the same options as `test([name][, options][, fn])`.
156
+ * @param [fn='A no-op function'] The function under suite declaring all subtests and subsuites. The first argument to this function is a {@link SuiteContext} object.
157
+ * @return Immediately fulfilled with `undefined`.
158
+ */
159
+ function describe(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
160
+ function describe(name?: string, fn?: SuiteFn): Promise<void>;
161
+ function describe(options?: TestOptions, fn?: SuiteFn): Promise<void>;
162
+ function describe(fn?: SuiteFn): Promise<void>;
163
+ namespace describe {
164
+ /**
165
+ * Shorthand for skipping a suite, same as `describe([name], { skip: true }[, fn])`.
166
+ */
167
+ function skip(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
168
+ function skip(name?: string, fn?: SuiteFn): Promise<void>;
169
+ function skip(options?: TestOptions, fn?: SuiteFn): Promise<void>;
170
+ function skip(fn?: SuiteFn): Promise<void>;
171
+ /**
172
+ * Shorthand for marking a suite as `TODO`, same as `describe([name], { todo: true }[, fn])`.
173
+ */
174
+ function todo(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
175
+ function todo(name?: string, fn?: SuiteFn): Promise<void>;
176
+ function todo(options?: TestOptions, fn?: SuiteFn): Promise<void>;
177
+ function todo(fn?: SuiteFn): Promise<void>;
178
+ /**
179
+ * Shorthand for marking a suite as `only`, same as `describe([name], { only: true }[, fn])`.
180
+ * @since v18.15.0
181
+ */
182
+ function only(name?: string, options?: TestOptions, fn?: SuiteFn): Promise<void>;
183
+ function only(name?: string, fn?: SuiteFn): Promise<void>;
184
+ function only(options?: TestOptions, fn?: SuiteFn): Promise<void>;
185
+ function only(fn?: SuiteFn): Promise<void>;
186
+ }
187
+ /**
188
+ * Shorthand for `test()`.
189
+ *
190
+ * The `it()` function is imported from the `node:test` module.
191
+ * @since v18.6.0, v16.17.0
192
+ */
193
+ function it(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
194
+ function it(name?: string, fn?: TestFn): Promise<void>;
195
+ function it(options?: TestOptions, fn?: TestFn): Promise<void>;
196
+ function it(fn?: TestFn): Promise<void>;
197
+ namespace it {
198
+ /**
199
+ * Shorthand for skipping a test, same as `it([name], { skip: true }[, fn])`.
200
+ */
201
+ function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
202
+ function skip(name?: string, fn?: TestFn): Promise<void>;
203
+ function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
204
+ function skip(fn?: TestFn): Promise<void>;
205
+ /**
206
+ * Shorthand for marking a test as `TODO`, same as `it([name], { todo: true }[, fn])`.
207
+ */
208
+ function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
209
+ function todo(name?: string, fn?: TestFn): Promise<void>;
210
+ function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
211
+ function todo(fn?: TestFn): Promise<void>;
212
+ /**
213
+ * Shorthand for marking a test as `only`, same as `it([name], { only: true }[, fn])`.
214
+ * @since v18.15.0
215
+ */
216
+ function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
217
+ function only(name?: string, fn?: TestFn): Promise<void>;
218
+ function only(options?: TestOptions, fn?: TestFn): Promise<void>;
219
+ function only(fn?: TestFn): Promise<void>;
220
+ }
221
+ /**
222
+ * Shorthand for skipping a test, same as `test([name], { skip: true }[, fn])`.
223
+ * @since v20.2.0
224
+ */
225
+ function skip(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
226
+ function skip(name?: string, fn?: TestFn): Promise<void>;
227
+ function skip(options?: TestOptions, fn?: TestFn): Promise<void>;
228
+ function skip(fn?: TestFn): Promise<void>;
229
+ /**
230
+ * Shorthand for marking a test as `TODO`, same as `test([name], { todo: true }[, fn])`.
231
+ * @since v20.2.0
232
+ */
233
+ function todo(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
234
+ function todo(name?: string, fn?: TestFn): Promise<void>;
235
+ function todo(options?: TestOptions, fn?: TestFn): Promise<void>;
236
+ function todo(fn?: TestFn): Promise<void>;
237
+ /**
238
+ * Shorthand for marking a test as `only`, same as `test([name], { only: true }[, fn])`.
239
+ * @since v20.2.0
240
+ */
241
+ function only(name?: string, options?: TestOptions, fn?: TestFn): Promise<void>;
242
+ function only(name?: string, fn?: TestFn): Promise<void>;
243
+ function only(options?: TestOptions, fn?: TestFn): Promise<void>;
244
+ function only(fn?: TestFn): Promise<void>;
245
+ /**
246
+ * The type of a function under test. The first argument to this function is a
247
+ * {@link TestContext} object. If the test uses callbacks, the callback function is passed as
248
+ * the second argument.
249
+ */
250
+ type TestFn = (t: TestContext, done: (result?: any) => void) => void | Promise<void>;
251
+ /**
252
+ * The type of a function under Suite.
253
+ */
254
+ type SuiteFn = (s: SuiteContext) => void | Promise<void>;
255
+ interface TestShard {
256
+ /**
257
+ * A positive integer between 1 and `<total>` that specifies the index of the shard to run.
258
+ */
259
+ index: number;
260
+ /**
261
+ * A positive integer that specifies the total number of shards to split the test files to.
262
+ */
263
+ total: number;
264
+ }
265
+ interface RunOptions {
266
+ /**
267
+ * If a number is provided, then that many files would run in parallel.
268
+ * If truthy, it would run (number of cpu cores - 1) files in parallel.
269
+ * If falsy, it would only run one file at a time.
270
+ * If unspecified, subtests inherit this value from their parent.
271
+ * @default true
272
+ */
273
+ concurrency?: number | boolean | undefined;
274
+ /**
275
+ * An array containing the list of files to run.
276
+ * If unspecified, the test runner execution model will be used.
277
+ */
278
+ files?: readonly string[] | undefined;
279
+ /**
280
+ * Allows aborting an in-progress test execution.
281
+ * @default undefined
282
+ */
283
+ signal?: AbortSignal | undefined;
284
+ /**
285
+ * A number of milliseconds the test will fail after.
286
+ * If unspecified, subtests inherit this value from their parent.
287
+ * @default Infinity
288
+ */
289
+ timeout?: number | undefined;
290
+ /**
291
+ * Sets inspector port of test child process.
292
+ * If a nullish value is provided, each process gets its own port,
293
+ * incremented from the primary's `process.debugPort`.
294
+ */
295
+ inspectPort?: number | (() => number) | undefined;
296
+ /**
297
+ * That can be used to only run tests whose name matches the provided pattern.
298
+ * Test name patterns are interpreted as JavaScript regular expressions.
299
+ * For each test that is executed, any corresponding test hooks, such as `beforeEach()`, are also run.
300
+ */
301
+ testNamePatterns?: string | RegExp | string[] | RegExp[];
302
+ /**
303
+ * If truthy, the test context will only run tests that have the `only` option set
304
+ */
305
+ only?: boolean;
306
+ /**
307
+ * A function that accepts the TestsStream instance and can be used to setup listeners before any tests are run.
308
+ */
309
+ setup?: (root: Test) => void | Promise<void>;
310
+ /**
311
+ * Whether to run in watch mode or not.
312
+ * @default false
313
+ */
314
+ watch?: boolean | undefined;
315
+ /**
316
+ * Running tests in a specific shard.
317
+ * @default undefined
318
+ */
319
+ shard?: TestShard | undefined;
320
+ }
321
+ class Test extends AsyncResource {
322
+ concurrency: number;
323
+ nesting: number;
324
+ only: boolean;
325
+ reporter: TestsStream;
326
+ runOnlySubtests: boolean;
327
+ testNumber: number;
328
+ timeout: number | null;
329
+ }
330
+ /**
331
+ * A successful call to `run()` method will return a new `TestsStream` object, streaming a series of events representing the execution of the tests.`TestsStream` will emit events, in the
332
+ * order of the tests definition
333
+ * @since v18.9.0, v16.19.0
334
+ */
335
+ class TestsStream extends Readable implements NodeJS.ReadableStream {
336
+ addListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
337
+ addListener(event: "test:fail", listener: (data: TestFail) => void): this;
338
+ addListener(event: "test:pass", listener: (data: TestPass) => void): this;
339
+ addListener(event: "test:plan", listener: (data: TestPlan) => void): this;
340
+ addListener(event: "test:start", listener: (data: TestStart) => void): this;
341
+ addListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
342
+ addListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
343
+ addListener(event: string, listener: (...args: any[]) => void): this;
344
+ emit(event: "test:diagnostic", data: DiagnosticData): boolean;
345
+ emit(event: "test:fail", data: TestFail): boolean;
346
+ emit(event: "test:pass", data: TestPass): boolean;
347
+ emit(event: "test:plan", data: TestPlan): boolean;
348
+ emit(event: "test:start", data: TestStart): boolean;
349
+ emit(event: "test:stderr", data: TestStderr): boolean;
350
+ emit(event: "test:stdout", data: TestStdout): boolean;
351
+ emit(event: string | symbol, ...args: any[]): boolean;
352
+ on(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
353
+ on(event: "test:fail", listener: (data: TestFail) => void): this;
354
+ on(event: "test:pass", listener: (data: TestPass) => void): this;
355
+ on(event: "test:plan", listener: (data: TestPlan) => void): this;
356
+ on(event: "test:start", listener: (data: TestStart) => void): this;
357
+ on(event: "test:stderr", listener: (data: TestStderr) => void): this;
358
+ on(event: "test:stdout", listener: (data: TestStdout) => void): this;
359
+ on(event: string, listener: (...args: any[]) => void): this;
360
+ once(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
361
+ once(event: "test:fail", listener: (data: TestFail) => void): this;
362
+ once(event: "test:pass", listener: (data: TestPass) => void): this;
363
+ once(event: "test:plan", listener: (data: TestPlan) => void): this;
364
+ once(event: "test:start", listener: (data: TestStart) => void): this;
365
+ once(event: "test:stderr", listener: (data: TestStderr) => void): this;
366
+ once(event: "test:stdout", listener: (data: TestStdout) => void): this;
367
+ once(event: string, listener: (...args: any[]) => void): this;
368
+ prependListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
369
+ prependListener(event: "test:fail", listener: (data: TestFail) => void): this;
370
+ prependListener(event: "test:pass", listener: (data: TestPass) => void): this;
371
+ prependListener(event: "test:plan", listener: (data: TestPlan) => void): this;
372
+ prependListener(event: "test:start", listener: (data: TestStart) => void): this;
373
+ prependListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
374
+ prependListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
375
+ prependListener(event: string, listener: (...args: any[]) => void): this;
376
+ prependOnceListener(event: "test:diagnostic", listener: (data: DiagnosticData) => void): this;
377
+ prependOnceListener(event: "test:fail", listener: (data: TestFail) => void): this;
378
+ prependOnceListener(event: "test:pass", listener: (data: TestPass) => void): this;
379
+ prependOnceListener(event: "test:plan", listener: (data: TestPlan) => void): this;
380
+ prependOnceListener(event: "test:start", listener: (data: TestStart) => void): this;
381
+ prependOnceListener(event: "test:stderr", listener: (data: TestStderr) => void): this;
382
+ prependOnceListener(event: "test:stdout", listener: (data: TestStdout) => void): this;
383
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
384
+ }
385
+ /**
386
+ * An instance of `TestContext` is passed to each test function in order to
387
+ * interact with the test runner. However, the `TestContext` constructor is not
388
+ * exposed as part of the API.
389
+ * @since v18.0.0, v16.17.0
390
+ */
391
+ class TestContext {
392
+ /**
393
+ * This function is used to create a hook running before subtest of the current test.
394
+ * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
395
+ * the second argument. Default: A no-op function.
396
+ * @param options Configuration options for the hook.
397
+ * @since v20.1.0
398
+ */
399
+ before: typeof before;
400
+ /**
401
+ * This function is used to create a hook running before each subtest of the current test.
402
+ * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
403
+ * the second argument. Default: A no-op function.
404
+ * @param options Configuration options for the hook.
405
+ * @since v18.8.0
406
+ */
407
+ beforeEach: typeof beforeEach;
408
+ /**
409
+ * This function is used to create a hook that runs after the current test finishes.
410
+ * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
411
+ * the second argument. Default: A no-op function.
412
+ * @param options Configuration options for the hook.
413
+ * @since v18.13.0
414
+ */
415
+ after: typeof after;
416
+ /**
417
+ * This function is used to create a hook running after each subtest of the current test.
418
+ * @param fn The hook function. If the hook uses callbacks, the callback function is passed as
419
+ * the second argument. Default: A no-op function.
420
+ * @param options Configuration options for the hook.
421
+ * @since v18.8.0
422
+ */
423
+ afterEach: typeof afterEach;
424
+ /**
425
+ * This function is used to write diagnostics to the output. Any diagnostic
426
+ * information is included at the end of the test's results. This function does
427
+ * not return a value.
428
+ *
429
+ * ```js
430
+ * test('top level test', (t) => {
431
+ * t.diagnostic('A diagnostic message');
432
+ * });
433
+ * ```
434
+ * @since v18.0.0, v16.17.0
435
+ * @param message Message to be reported.
436
+ */
437
+ diagnostic(message: string): void;
438
+ /**
439
+ * The name of the test.
440
+ * @since v18.8.0, v16.18.0
441
+ */
442
+ readonly name: string;
443
+ /**
444
+ * If `shouldRunOnlyTests` is truthy, the test context will only run tests that
445
+ * have the `only` option set. Otherwise, all tests are run. If Node.js was not
446
+ * started with the `--test-only` command-line option, this function is a
447
+ * no-op.
448
+ *
449
+ * ```js
450
+ * test('top level test', (t) => {
451
+ * // The test context can be set to run subtests with the 'only' option.
452
+ * t.runOnly(true);
453
+ * return Promise.all([
454
+ * t.test('this subtest is now skipped'),
455
+ * t.test('this subtest is run', { only: true }),
456
+ * ]);
457
+ * });
458
+ * ```
459
+ * @since v18.0.0, v16.17.0
460
+ * @param shouldRunOnlyTests Whether or not to run `only` tests.
461
+ */
462
+ runOnly(shouldRunOnlyTests: boolean): void;
463
+ /**
464
+ * ```js
465
+ * test('top level test', async (t) => {
466
+ * await fetch('some/uri', { signal: t.signal });
467
+ * });
468
+ * ```
469
+ * @since v18.7.0, v16.17.0
470
+ */
471
+ readonly signal: AbortSignal;
472
+ /**
473
+ * This function causes the test's output to indicate the test as skipped. If`message` is provided, it is included in the output. Calling `skip()` does
474
+ * not terminate execution of the test function. This function does not return a
475
+ * value.
476
+ *
477
+ * ```js
478
+ * test('top level test', (t) => {
479
+ * // Make sure to return here as well if the test contains additional logic.
480
+ * t.skip('this is skipped');
481
+ * });
482
+ * ```
483
+ * @since v18.0.0, v16.17.0
484
+ * @param message Optional skip message.
485
+ */
486
+ skip(message?: string): void;
487
+ /**
488
+ * This function adds a `TODO` directive to the test's output. If `message` is
489
+ * provided, it is included in the output. Calling `todo()` does not terminate
490
+ * execution of the test function. This function does not return a value.
491
+ *
492
+ * ```js
493
+ * test('top level test', (t) => {
494
+ * // This test is marked as `TODO`
495
+ * t.todo('this is a todo');
496
+ * });
497
+ * ```
498
+ * @since v18.0.0, v16.17.0
499
+ * @param message Optional `TODO` message.
500
+ */
501
+ todo(message?: string): void;
502
+ /**
503
+ * This function is used to create subtests under the current test. This function behaves in
504
+ * the same fashion as the top level {@link test} function.
505
+ * @since v18.0.0
506
+ * @param name The name of the test, which is displayed when reporting test results.
507
+ * Default: The `name` property of fn, or `'<anonymous>'` if `fn` does not have a name.
508
+ * @param options Configuration options for the test
509
+ * @param fn The function under test. This first argument to this function is a
510
+ * {@link TestContext} object. If the test uses callbacks, the callback function is
511
+ * passed as the second argument. Default: A no-op function.
512
+ * @returns A {@link Promise} resolved with `undefined` once the test completes.
513
+ */
514
+ test: typeof test;
515
+ /**
516
+ * Each test provides its own MockTracker instance.
517
+ */
518
+ readonly mock: MockTracker;
519
+ }
520
+ /**
521
+ * An instance of `SuiteContext` is passed to each suite function in order to
522
+ * interact with the test runner. However, the `SuiteContext` constructor is not
523
+ * exposed as part of the API.
524
+ * @since v18.7.0, v16.17.0
525
+ */
526
+ class SuiteContext {
527
+ /**
528
+ * The name of the suite.
529
+ * @since v18.8.0, v16.18.0
530
+ */
531
+ readonly name: string;
532
+ /**
533
+ * Can be used to abort test subtasks when the test has been aborted.
534
+ * @since v18.7.0, v16.17.0
535
+ */
536
+ readonly signal: AbortSignal;
537
+ }
538
+ interface TestOptions {
539
+ /**
540
+ * If a number is provided, then that many tests would run in parallel.
541
+ * If truthy, it would run (number of cpu cores - 1) tests in parallel.
542
+ * For subtests, it will be `Infinity` tests in parallel.
543
+ * If falsy, it would only run one test at a time.
544
+ * If unspecified, subtests inherit this value from their parent.
545
+ * @default false
546
+ */
547
+ concurrency?: number | boolean | undefined;
548
+ /**
549
+ * If truthy, and the test context is configured to run `only` tests, then this test will be
550
+ * run. Otherwise, the test is skipped.
551
+ * @default false
552
+ */
553
+ only?: boolean | undefined;
554
+ /**
555
+ * Allows aborting an in-progress test.
556
+ * @since v18.8.0
557
+ */
558
+ signal?: AbortSignal | undefined;
559
+ /**
560
+ * If truthy, the test is skipped. If a string is provided, that string is displayed in the
561
+ * test results as the reason for skipping the test.
562
+ * @default false
563
+ */
564
+ skip?: boolean | string | undefined;
565
+ /**
566
+ * A number of milliseconds the test will fail after. If unspecified, subtests inherit this
567
+ * value from their parent.
568
+ * @default Infinity
569
+ * @since v18.7.0
570
+ */
571
+ timeout?: number | undefined;
572
+ /**
573
+ * If truthy, the test marked as `TODO`. If a string is provided, that string is displayed in
574
+ * the test results as the reason why the test is `TODO`.
575
+ * @default false
576
+ */
577
+ todo?: boolean | string | undefined;
578
+ }
579
+ /**
580
+ * This function is used to create a hook running before running a suite.
581
+ *
582
+ * ```js
583
+ * describe('tests', async () => {
584
+ * before(() => console.log('about to run some test'));
585
+ * it('is a subtest', () => {
586
+ * assert.ok('some relevant assertion here');
587
+ * });
588
+ * });
589
+ * ```
590
+ * @since v18.8.0, v16.18.0
591
+ * @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
592
+ * @param options Configuration options for the hook. The following properties are supported:
593
+ */
594
+ function before(fn?: HookFn, options?: HookOptions): void;
595
+ /**
596
+ * This function is used to create a hook running after running a suite.
597
+ *
598
+ * ```js
599
+ * describe('tests', async () => {
600
+ * after(() => console.log('finished running tests'));
601
+ * it('is a subtest', () => {
602
+ * assert.ok('some relevant assertion here');
603
+ * });
604
+ * });
605
+ * ```
606
+ * @since v18.8.0, v16.18.0
607
+ * @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
608
+ * @param options Configuration options for the hook. The following properties are supported:
609
+ */
610
+ function after(fn?: HookFn, options?: HookOptions): void;
611
+ /**
612
+ * This function is used to create a hook running
613
+ * before each subtest of the current suite.
614
+ *
615
+ * ```js
616
+ * describe('tests', async () => {
617
+ * beforeEach(() => console.log('about to run a test'));
618
+ * it('is a subtest', () => {
619
+ * assert.ok('some relevant assertion here');
620
+ * });
621
+ * });
622
+ * ```
623
+ * @since v18.8.0, v16.18.0
624
+ * @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
625
+ * @param options Configuration options for the hook. The following properties are supported:
626
+ */
627
+ function beforeEach(fn?: HookFn, options?: HookOptions): void;
628
+ /**
629
+ * This function is used to create a hook running
630
+ * after each subtest of the current test.
631
+ *
632
+ * ```js
633
+ * describe('tests', async () => {
634
+ * afterEach(() => console.log('finished running a test'));
635
+ * it('is a subtest', () => {
636
+ * assert.ok('some relevant assertion here');
637
+ * });
638
+ * });
639
+ * ```
640
+ * @since v18.8.0, v16.18.0
641
+ * @param [fn='A no-op function'] The hook function. If the hook uses callbacks, the callback function is passed as the second argument.
642
+ * @param options Configuration options for the hook. The following properties are supported:
643
+ */
644
+ function afterEach(fn?: HookFn, options?: HookOptions): void;
645
+ /**
646
+ * The hook function. If the hook uses callbacks, the callback function is passed as the
647
+ * second argument.
648
+ */
649
+ type HookFn = (s: SuiteContext, done: (result?: any) => void) => any;
650
+ /**
651
+ * Configuration options for hooks.
652
+ * @since v18.8.0
653
+ */
654
+ interface HookOptions {
655
+ /**
656
+ * Allows aborting an in-progress hook.
657
+ */
658
+ signal?: AbortSignal | undefined;
659
+ /**
660
+ * A number of milliseconds the hook will fail after. If unspecified, subtests inherit this
661
+ * value from their parent.
662
+ * @default Infinity
663
+ */
664
+ timeout?: number | undefined;
665
+ }
666
+ interface MockFunctionOptions {
667
+ /**
668
+ * The number of times that the mock will use the behavior of `implementation`.
669
+ * Once the mock function has been called `times` times,
670
+ * it will automatically restore the behavior of `original`.
671
+ * This value must be an integer greater than zero.
672
+ * @default Infinity
673
+ */
674
+ times?: number | undefined;
675
+ }
676
+ interface MockMethodOptions extends MockFunctionOptions {
677
+ /**
678
+ * If `true`, `object[methodName]` is treated as a getter.
679
+ * This option cannot be used with the `setter` option.
680
+ */
681
+ getter?: boolean | undefined;
682
+ /**
683
+ * If `true`, `object[methodName]` is treated as a setter.
684
+ * This option cannot be used with the `getter` option.
685
+ */
686
+ setter?: boolean | undefined;
687
+ }
688
+ type Mock<F extends Function> = F & {
689
+ mock: MockFunctionContext<F>;
690
+ };
691
+ type NoOpFunction = (...args: any[]) => undefined;
692
+ type FunctionPropertyNames<T> = {
693
+ [K in keyof T]: T[K] extends Function ? K : never;
694
+ }[keyof T];
695
+ /**
696
+ * The `MockTracker` class is used to manage mocking functionality. The test runner
697
+ * module provides a top level `mock` export which is a `MockTracker` instance.
698
+ * Each test also provides its own `MockTracker` instance via the test context's`mock` property.
699
+ * @since v19.1.0, v18.13.0
700
+ */
701
+ class MockTracker {
702
+ /**
703
+ * This function is used to create a mock function.
704
+ *
705
+ * The following example creates a mock function that increments a counter by one
706
+ * on each invocation. The `times` option is used to modify the mock behavior such
707
+ * that the first two invocations add two to the counter instead of one.
708
+ *
709
+ * ```js
710
+ * test('mocks a counting function', (t) => {
711
+ * let cnt = 0;
712
+ *
713
+ * function addOne() {
714
+ * cnt++;
715
+ * return cnt;
716
+ * }
717
+ *
718
+ * function addTwo() {
719
+ * cnt += 2;
720
+ * return cnt;
721
+ * }
722
+ *
723
+ * const fn = t.mock.fn(addOne, addTwo, { times: 2 });
724
+ *
725
+ * assert.strictEqual(fn(), 2);
726
+ * assert.strictEqual(fn(), 4);
727
+ * assert.strictEqual(fn(), 5);
728
+ * assert.strictEqual(fn(), 6);
729
+ * });
730
+ * ```
731
+ * @since v19.1.0, v18.13.0
732
+ * @param [original='A no-op function'] An optional function to create a mock on.
733
+ * @param implementation An optional function used as the mock implementation for `original`. This is useful for creating mocks that exhibit one behavior for a specified number of calls and
734
+ * then restore the behavior of `original`.
735
+ * @param options Optional configuration options for the mock function. The following properties are supported:
736
+ * @return The mocked function. The mocked function contains a special `mock` property, which is an instance of {@link MockFunctionContext}, and can be used for inspecting and changing the
737
+ * behavior of the mocked function.
738
+ */
739
+ fn<F extends Function = NoOpFunction>(original?: F, options?: MockFunctionOptions): Mock<F>;
740
+ fn<F extends Function = NoOpFunction, Implementation extends Function = F>(
741
+ original?: F,
742
+ implementation?: Implementation,
743
+ options?: MockFunctionOptions,
744
+ ): Mock<F | Implementation>;
745
+ /**
746
+ * This function is used to create a mock on an existing object method. The
747
+ * following example demonstrates how a mock is created on an existing object
748
+ * method.
749
+ *
750
+ * ```js
751
+ * test('spies on an object method', (t) => {
752
+ * const number = {
753
+ * value: 5,
754
+ * subtract(a) {
755
+ * return this.value - a;
756
+ * },
757
+ * };
758
+ *
759
+ * t.mock.method(number, 'subtract');
760
+ * assert.strictEqual(number.subtract.mock.calls.length, 0);
761
+ * assert.strictEqual(number.subtract(3), 2);
762
+ * assert.strictEqual(number.subtract.mock.calls.length, 1);
763
+ *
764
+ * const call = number.subtract.mock.calls[0];
765
+ *
766
+ * assert.deepStrictEqual(call.arguments, [3]);
767
+ * assert.strictEqual(call.result, 2);
768
+ * assert.strictEqual(call.error, undefined);
769
+ * assert.strictEqual(call.target, undefined);
770
+ * assert.strictEqual(call.this, number);
771
+ * });
772
+ * ```
773
+ * @since v19.1.0, v18.13.0
774
+ * @param object The object whose method is being mocked.
775
+ * @param methodName The identifier of the method on `object` to mock. If `object[methodName]` is not a function, an error is thrown.
776
+ * @param implementation An optional function used as the mock implementation for `object[methodName]`.
777
+ * @param options Optional configuration options for the mock method. The following properties are supported:
778
+ * @return The mocked method. The mocked method contains a special `mock` property, which is an instance of {@link MockFunctionContext}, and can be used for inspecting and changing the
779
+ * behavior of the mocked method.
780
+ */
781
+ method<
782
+ MockedObject extends object,
783
+ MethodName extends FunctionPropertyNames<MockedObject>,
784
+ >(
785
+ object: MockedObject,
786
+ methodName: MethodName,
787
+ options?: MockFunctionOptions,
788
+ ): MockedObject[MethodName] extends Function ? Mock<MockedObject[MethodName]>
789
+ : never;
790
+ method<
791
+ MockedObject extends object,
792
+ MethodName extends FunctionPropertyNames<MockedObject>,
793
+ Implementation extends Function,
794
+ >(
795
+ object: MockedObject,
796
+ methodName: MethodName,
797
+ implementation: Implementation,
798
+ options?: MockFunctionOptions,
799
+ ): MockedObject[MethodName] extends Function ? Mock<MockedObject[MethodName] | Implementation>
800
+ : never;
801
+ method<MockedObject extends object>(
802
+ object: MockedObject,
803
+ methodName: keyof MockedObject,
804
+ options: MockMethodOptions,
805
+ ): Mock<Function>;
806
+ method<MockedObject extends object>(
807
+ object: MockedObject,
808
+ methodName: keyof MockedObject,
809
+ implementation: Function,
810
+ options: MockMethodOptions,
811
+ ): Mock<Function>;
812
+
813
+ /**
814
+ * This function is syntax sugar for `MockTracker.method` with `options.getter`set to `true`.
815
+ * @since v19.3.0, v18.13.0
816
+ */
817
+ getter<
818
+ MockedObject extends object,
819
+ MethodName extends keyof MockedObject,
820
+ >(
821
+ object: MockedObject,
822
+ methodName: MethodName,
823
+ options?: MockFunctionOptions,
824
+ ): Mock<() => MockedObject[MethodName]>;
825
+ getter<
826
+ MockedObject extends object,
827
+ MethodName extends keyof MockedObject,
828
+ Implementation extends Function,
829
+ >(
830
+ object: MockedObject,
831
+ methodName: MethodName,
832
+ implementation?: Implementation,
833
+ options?: MockFunctionOptions,
834
+ ): Mock<(() => MockedObject[MethodName]) | Implementation>;
835
+ /**
836
+ * This function is syntax sugar for `MockTracker.method` with `options.setter`set to `true`.
837
+ * @since v19.3.0, v18.13.0
838
+ */
839
+ setter<
840
+ MockedObject extends object,
841
+ MethodName extends keyof MockedObject,
842
+ >(
843
+ object: MockedObject,
844
+ methodName: MethodName,
845
+ options?: MockFunctionOptions,
846
+ ): Mock<(value: MockedObject[MethodName]) => void>;
847
+ setter<
848
+ MockedObject extends object,
849
+ MethodName extends keyof MockedObject,
850
+ Implementation extends Function,
851
+ >(
852
+ object: MockedObject,
853
+ methodName: MethodName,
854
+ implementation?: Implementation,
855
+ options?: MockFunctionOptions,
856
+ ): Mock<((value: MockedObject[MethodName]) => void) | Implementation>;
857
+ /**
858
+ * This function restores the default behavior of all mocks that were previously
859
+ * 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
860
+ * used to reset their behavior or
861
+ * otherwise interact with them.
862
+ *
863
+ * After each test completes, this function is called on the test context's`MockTracker`. If the global `MockTracker` is used extensively, calling this
864
+ * function manually is recommended.
865
+ * @since v19.1.0, v18.13.0
866
+ */
867
+ reset(): void;
868
+ /**
869
+ * This function restores the default behavior of all mocks that were previously
870
+ * created by this `MockTracker`. Unlike `mock.reset()`, `mock.restoreAll()` does
871
+ * not disassociate the mocks from the `MockTracker` instance.
872
+ * @since v19.1.0, v18.13.0
873
+ */
874
+ restoreAll(): void;
875
+ timers: MockTimers;
876
+ }
877
+ const mock: MockTracker;
878
+ interface MockFunctionCall<
879
+ F extends Function,
880
+ ReturnType = F extends (...args: any) => infer T ? T
881
+ : F extends abstract new(...args: any) => infer T ? T
882
+ : unknown,
883
+ Args = F extends (...args: infer Y) => any ? Y
884
+ : F extends abstract new(...args: infer Y) => any ? Y
885
+ : unknown[],
886
+ > {
887
+ /**
888
+ * An array of the arguments passed to the mock function.
889
+ */
890
+ arguments: Args;
891
+ /**
892
+ * If the mocked function threw then this property contains the thrown value.
893
+ */
894
+ error: unknown | undefined;
895
+ /**
896
+ * The value returned by the mocked function.
897
+ *
898
+ * If the mocked function threw, it will be `undefined`.
899
+ */
900
+ result: ReturnType | undefined;
901
+ /**
902
+ * An `Error` object whose stack can be used to determine the callsite of the mocked function invocation.
903
+ */
904
+ stack: Error;
905
+ /**
906
+ * If the mocked function is a constructor, this field contains the class being constructed.
907
+ * Otherwise this will be `undefined`.
908
+ */
909
+ target: F extends abstract new(...args: any) => any ? F : undefined;
910
+ /**
911
+ * The mocked function's `this` value.
912
+ */
913
+ this: unknown;
914
+ }
915
+ /**
916
+ * The `MockFunctionContext` class is used to inspect or manipulate the behavior of
917
+ * mocks created via the `MockTracker` APIs.
918
+ * @since v19.1.0, v18.13.0
919
+ */
920
+ class MockFunctionContext<F extends Function> {
921
+ /**
922
+ * A getter that returns a copy of the internal array used to track calls to the
923
+ * mock. Each entry in the array is an object with the following properties.
924
+ * @since v19.1.0, v18.13.0
925
+ */
926
+ readonly calls: Array<MockFunctionCall<F>>;
927
+ /**
928
+ * This function returns the number of times that this mock has been invoked. This
929
+ * function is more efficient than checking `ctx.calls.length` because `ctx.calls`is a getter that creates a copy of the internal call tracking array.
930
+ * @since v19.1.0, v18.13.0
931
+ * @return The number of times that this mock has been invoked.
932
+ */
933
+ callCount(): number;
934
+ /**
935
+ * This function is used to change the behavior of an existing mock.
936
+ *
937
+ * The following example creates a mock function using `t.mock.fn()`, calls the
938
+ * mock function, and then changes the mock implementation to a different function.
939
+ *
940
+ * ```js
941
+ * test('changes a mock behavior', (t) => {
942
+ * let cnt = 0;
943
+ *
944
+ * function addOne() {
945
+ * cnt++;
946
+ * return cnt;
947
+ * }
948
+ *
949
+ * function addTwo() {
950
+ * cnt += 2;
951
+ * return cnt;
952
+ * }
953
+ *
954
+ * const fn = t.mock.fn(addOne);
955
+ *
956
+ * assert.strictEqual(fn(), 1);
957
+ * fn.mock.mockImplementation(addTwo);
958
+ * assert.strictEqual(fn(), 3);
959
+ * assert.strictEqual(fn(), 5);
960
+ * });
961
+ * ```
962
+ * @since v19.1.0, v18.13.0
963
+ * @param implementation The function to be used as the mock's new implementation.
964
+ */
965
+ mockImplementation(implementation: Function): void;
966
+ /**
967
+ * This function is used to change the behavior of an existing mock for a single
968
+ * invocation. Once invocation `onCall` has occurred, the mock will revert to
969
+ * whatever behavior it would have used had `mockImplementationOnce()` not been
970
+ * called.
971
+ *
972
+ * The following example creates a mock function using `t.mock.fn()`, calls the
973
+ * mock function, changes the mock implementation to a different function for the
974
+ * next invocation, and then resumes its previous behavior.
975
+ *
976
+ * ```js
977
+ * test('changes a mock behavior once', (t) => {
978
+ * let cnt = 0;
979
+ *
980
+ * function addOne() {
981
+ * cnt++;
982
+ * return cnt;
983
+ * }
984
+ *
985
+ * function addTwo() {
986
+ * cnt += 2;
987
+ * return cnt;
988
+ * }
989
+ *
990
+ * const fn = t.mock.fn(addOne);
991
+ *
992
+ * assert.strictEqual(fn(), 1);
993
+ * fn.mock.mockImplementationOnce(addTwo);
994
+ * assert.strictEqual(fn(), 3);
995
+ * assert.strictEqual(fn(), 4);
996
+ * });
997
+ * ```
998
+ * @since v19.1.0, v18.13.0
999
+ * @param implementation The function to be used as the mock's implementation for the invocation number specified by `onCall`.
1000
+ * @param onCall The invocation number that will use `implementation`. If the specified invocation has already occurred then an exception is thrown.
1001
+ */
1002
+ mockImplementationOnce(implementation: Function, onCall?: number): void;
1003
+ /**
1004
+ * Resets the call history of the mock function.
1005
+ * @since v19.3.0, v18.13.0
1006
+ */
1007
+ resetCalls(): void;
1008
+ /**
1009
+ * Resets the implementation of the mock function to its original behavior. The
1010
+ * mock can still be used after calling this function.
1011
+ * @since v19.1.0, v18.13.0
1012
+ */
1013
+ restore(): void;
1014
+ }
1015
+ type Timer = "setInterval" | "setTimeout" | "setImmediate" | "Date";
1016
+
1017
+ interface MockTimersOptions {
1018
+ apis: Timer[];
1019
+ now?: number | Date;
1020
+ }
1021
+ /**
1022
+ * Mocking timers is a technique commonly used in software testing to simulate and
1023
+ * control the behavior of timers, such as `setInterval` and `setTimeout`,
1024
+ * without actually waiting for the specified time intervals.
1025
+ *
1026
+ * The MockTimers API also allows for mocking of the `Date` constructor and
1027
+ * `setImmediate`/`clearImmediate` functions.
1028
+ *
1029
+ * The `MockTracker` provides a top-level `timers` export
1030
+ * which is a `MockTimers` instance.
1031
+ * @since v20.4.0
1032
+ * @experimental
1033
+ */
1034
+ class MockTimers {
1035
+ /**
1036
+ * Enables timer mocking for the specified timers.
1037
+ *
1038
+ * **Note:** When you enable mocking for a specific timer, its associated
1039
+ * clear function will also be implicitly mocked.
1040
+ *
1041
+ * **Note:** Mocking `Date` will affect the behavior of the mocked timers
1042
+ * as they use the same internal clock.
1043
+ *
1044
+ * Example usage without setting initial time:
1045
+ *
1046
+ * ```js
1047
+ * import { mock } from 'node:test';
1048
+ * mock.timers.enable({ apis: ['setInterval', 'Date'], now: 1234 });
1049
+ * ```
1050
+ *
1051
+ * The above example enables mocking for the `Date` constructor, `setInterval` timer and
1052
+ * implicitly mocks the `clearInterval` function. Only the `Date` constructor from `globalThis`,
1053
+ * `setInterval` and `clearInterval` functions from `node:timers`,`node:timers/promises`, and `globalThis` will be mocked.
1054
+ *
1055
+ * Example usage with initial time set
1056
+ *
1057
+ * ```js
1058
+ * import { mock } from 'node:test';
1059
+ * mock.timers.enable({ apis: ['Date'], now: 1000 });
1060
+ * ```
1061
+ *
1062
+ * Example usage with initial Date object as time set
1063
+ *
1064
+ * ```js
1065
+ * import { mock } from 'node:test';
1066
+ * mock.timers.enable({ apis: ['Date'], now: new Date() });
1067
+ * ```
1068
+ *
1069
+ * Alternatively, if you call `mock.timers.enable()` without any parameters:
1070
+ *
1071
+ * All timers (`'setInterval'`, `'clearInterval'`, `'Date'`, `'setImmediate'`, `'clearImmediate'`, `'setTimeout'`, and `'clearTimeout'`)
1072
+ * will be mocked.
1073
+ *
1074
+ * The `setInterval`, `clearInterval`, `setTimeout`, and `clearTimeout` functions from `node:timers`, `node:timers/promises`,
1075
+ * and `globalThis` will be mocked.
1076
+ * The `Date` constructor from `globalThis` will be mocked.
1077
+ *
1078
+ * If there is no initial epoch set, the initial date will be based on 0 in the Unix epoch. This is `January 1st, 1970, 00:00:00 UTC`. You can set an initial date by passing a now property to the `.enable()` method. This value will be used as the initial date for the mocked Date object. It can either be a positive integer, or another Date object.
1079
+ * @since v20.4.0
1080
+ */
1081
+ enable(options?: MockTimersOptions): void;
1082
+ /**
1083
+ * You can use the `.setTime()` method to manually move the mocked date to another time. This method only accepts a positive integer.
1084
+ * Note: This method will execute any mocked timers that are in the past from the new time.
1085
+ * In the below example we are setting a new time for the mocked date.
1086
+ * ```js
1087
+ * import assert from 'node:assert';
1088
+ * import { test } from 'node:test';
1089
+ * test('sets the time of a date object', (context) => {
1090
+ * // Optionally choose what to mock
1091
+ * context.mock.timers.enable({ apis: ['Date'], now: 100 });
1092
+ * assert.strictEqual(Date.now(), 100);
1093
+ * // Advance in time will also advance the date
1094
+ * context.mock.timers.setTime(1000);
1095
+ * context.mock.timers.tick(200);
1096
+ * assert.strictEqual(Date.now(), 1200);
1097
+ * });
1098
+ * ```
1099
+ */
1100
+ setTime(time: number): void;
1101
+ /**
1102
+ * This function restores the default behavior of all mocks that were previously
1103
+ * created by this `MockTimers` instance and disassociates the mocks
1104
+ * from the `MockTracker` instance.
1105
+ *
1106
+ * **Note:** After each test completes, this function is called on
1107
+ * the test context's `MockTracker`.
1108
+ *
1109
+ * ```js
1110
+ * import { mock } from 'node:test';
1111
+ * mock.timers.reset();
1112
+ * ```
1113
+ * @since v20.4.0
1114
+ */
1115
+ reset(): void;
1116
+ /**
1117
+ * Advances time for all mocked timers.
1118
+ *
1119
+ * **Note:** This diverges from how `setTimeout` in Node.js behaves and accepts
1120
+ * only positive numbers. In Node.js, `setTimeout` with negative numbers is
1121
+ * only supported for web compatibility reasons.
1122
+ *
1123
+ * The following example mocks a `setTimeout` function and
1124
+ * by using `.tick` advances in
1125
+ * time triggering all pending timers.
1126
+ *
1127
+ * ```js
1128
+ * import assert from 'node:assert';
1129
+ * import { test } from 'node:test';
1130
+ *
1131
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
1132
+ * const fn = context.mock.fn();
1133
+ *
1134
+ * context.mock.timers.enable({ apis: ['setTimeout'] });
1135
+ *
1136
+ * setTimeout(fn, 9999);
1137
+ *
1138
+ * assert.strictEqual(fn.mock.callCount(), 0);
1139
+ *
1140
+ * // Advance in time
1141
+ * context.mock.timers.tick(9999);
1142
+ *
1143
+ * assert.strictEqual(fn.mock.callCount(), 1);
1144
+ * });
1145
+ * ```
1146
+ *
1147
+ * Alternativelly, the `.tick` function can be called many times
1148
+ *
1149
+ * ```js
1150
+ * import assert from 'node:assert';
1151
+ * import { test } from 'node:test';
1152
+ *
1153
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
1154
+ * const fn = context.mock.fn();
1155
+ * context.mock.timers.enable({ apis: ['setTimeout'] });
1156
+ * const nineSecs = 9000;
1157
+ * setTimeout(fn, nineSecs);
1158
+ *
1159
+ * const twoSeconds = 3000;
1160
+ * context.mock.timers.tick(twoSeconds);
1161
+ * context.mock.timers.tick(twoSeconds);
1162
+ * context.mock.timers.tick(twoSeconds);
1163
+ *
1164
+ * assert.strictEqual(fn.mock.callCount(), 1);
1165
+ * });
1166
+ * ```
1167
+ *
1168
+ * Advancing time using `.tick` will also advance the time for any `Date` object
1169
+ * created after the mock was enabled (if `Date` was also set to be mocked).
1170
+ *
1171
+ * ```js
1172
+ * import assert from 'node:assert';
1173
+ * import { test } from 'node:test';
1174
+ *
1175
+ * test('mocks setTimeout to be executed synchronously without having to actually wait for it', (context) => {
1176
+ * const fn = context.mock.fn();
1177
+ *
1178
+ * context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
1179
+ * setTimeout(fn, 9999);
1180
+ *
1181
+ * assert.strictEqual(fn.mock.callCount(), 0);
1182
+ * assert.strictEqual(Date.now(), 0);
1183
+ *
1184
+ * // Advance in time
1185
+ * context.mock.timers.tick(9999);
1186
+ * assert.strictEqual(fn.mock.callCount(), 1);
1187
+ * assert.strictEqual(Date.now(), 9999);
1188
+ * });
1189
+ * ```
1190
+ * @since v20.4.0
1191
+ */
1192
+ tick(milliseconds: number): void;
1193
+ /**
1194
+ * Triggers all pending mocked timers immediately. If the `Date` object is also
1195
+ * mocked, it will also advance the `Date` object to the furthest timer's time.
1196
+ *
1197
+ * The example below triggers all pending timers immediately,
1198
+ * causing them to execute without any delay.
1199
+ *
1200
+ * ```js
1201
+ * import assert from 'node:assert';
1202
+ * import { test } from 'node:test';
1203
+ *
1204
+ * test('runAll functions following the given order', (context) => {
1205
+ * context.mock.timers.enable({ apis: ['setTimeout', 'Date'] });
1206
+ * const results = [];
1207
+ * setTimeout(() => results.push(1), 9999);
1208
+ *
1209
+ * // Notice that if both timers have the same timeout,
1210
+ * // the order of execution is guaranteed
1211
+ * setTimeout(() => results.push(3), 8888);
1212
+ * setTimeout(() => results.push(2), 8888);
1213
+ *
1214
+ * assert.deepStrictEqual(results, []);
1215
+ *
1216
+ * context.mock.timers.runAll();
1217
+ * assert.deepStrictEqual(results, [3, 2, 1]);
1218
+ * // The Date object is also advanced to the furthest timer's time
1219
+ * assert.strictEqual(Date.now(), 9999);
1220
+ * });
1221
+ * ```
1222
+ *
1223
+ * **Note:** The `runAll()` function is specifically designed for
1224
+ * triggering timers in the context of timer mocking.
1225
+ * It does not have any effect on real-time system
1226
+ * clocks or actual timers outside of the mocking environment.
1227
+ * @since v20.4.0
1228
+ */
1229
+ runAll(): void;
1230
+ /**
1231
+ * Calls {@link MockTimers.reset()}.
1232
+ */
1233
+ [Symbol.dispose](): void;
1234
+ }
1235
+ export {
1236
+ after,
1237
+ afterEach,
1238
+ before,
1239
+ beforeEach,
1240
+ describe,
1241
+ it,
1242
+ Mock,
1243
+ mock,
1244
+ only,
1245
+ run,
1246
+ skip,
1247
+ test,
1248
+ test as default,
1249
+ todo,
1250
+ };
1251
+ }
1252
+
1253
+ interface TestLocationInfo {
1254
+ /**
1255
+ * The column number where the test is defined, or
1256
+ * `undefined` if the test was run through the REPL.
1257
+ */
1258
+ column?: number;
1259
+ /**
1260
+ * The path of the test file, `undefined` if test is not ran through a file.
1261
+ */
1262
+ file?: string;
1263
+ /**
1264
+ * The line number where the test is defined, or
1265
+ * `undefined` if the test was run through the REPL.
1266
+ */
1267
+ line?: number;
1268
+ }
1269
+ interface DiagnosticData extends TestLocationInfo {
1270
+ /**
1271
+ * The diagnostic message.
1272
+ */
1273
+ message: string;
1274
+ /**
1275
+ * The nesting level of the test.
1276
+ */
1277
+ nesting: number;
1278
+ }
1279
+ interface TestFail extends TestLocationInfo {
1280
+ /**
1281
+ * Additional execution metadata.
1282
+ */
1283
+ details: {
1284
+ /**
1285
+ * The duration of the test in milliseconds.
1286
+ */
1287
+ duration_ms: number;
1288
+ /**
1289
+ * The error thrown by the test.
1290
+ */
1291
+ error: Error;
1292
+ /**
1293
+ * The type of the test, used to denote whether this is a suite.
1294
+ * @since 20.0.0, 19.9.0, 18.17.0
1295
+ */
1296
+ type?: "suite";
1297
+ };
1298
+ /**
1299
+ * The test name.
1300
+ */
1301
+ name: string;
1302
+ /**
1303
+ * The nesting level of the test.
1304
+ */
1305
+ nesting: number;
1306
+ /**
1307
+ * The ordinal number of the test.
1308
+ */
1309
+ testNumber: number;
1310
+ /**
1311
+ * Present if `context.todo` is called.
1312
+ */
1313
+ todo?: string | boolean;
1314
+ /**
1315
+ * Present if `context.skip` is called.
1316
+ */
1317
+ skip?: string | boolean;
1318
+ }
1319
+ interface TestPass extends TestLocationInfo {
1320
+ /**
1321
+ * Additional execution metadata.
1322
+ */
1323
+ details: {
1324
+ /**
1325
+ * The duration of the test in milliseconds.
1326
+ */
1327
+ duration_ms: number;
1328
+ /**
1329
+ * The type of the test, used to denote whether this is a suite.
1330
+ * @since 20.0.0, 19.9.0, 18.17.0
1331
+ */
1332
+ type?: "suite";
1333
+ };
1334
+ /**
1335
+ * The test name.
1336
+ */
1337
+ name: string;
1338
+ /**
1339
+ * The nesting level of the test.
1340
+ */
1341
+ nesting: number;
1342
+ /**
1343
+ * The ordinal number of the test.
1344
+ */
1345
+ testNumber: number;
1346
+ /**
1347
+ * Present if `context.todo` is called.
1348
+ */
1349
+ todo?: string | boolean;
1350
+ /**
1351
+ * Present if `context.skip` is called.
1352
+ */
1353
+ skip?: string | boolean;
1354
+ }
1355
+ interface TestPlan extends TestLocationInfo {
1356
+ /**
1357
+ * The nesting level of the test.
1358
+ */
1359
+ nesting: number;
1360
+ /**
1361
+ * The number of subtests that have ran.
1362
+ */
1363
+ count: number;
1364
+ }
1365
+ interface TestStart extends TestLocationInfo {
1366
+ /**
1367
+ * The test name.
1368
+ */
1369
+ name: string;
1370
+ /**
1371
+ * The nesting level of the test.
1372
+ */
1373
+ nesting: number;
1374
+ }
1375
+ interface TestStderr extends TestLocationInfo {
1376
+ /**
1377
+ * The message written to `stderr`
1378
+ */
1379
+ message: string;
1380
+ }
1381
+ interface TestStdout extends TestLocationInfo {
1382
+ /**
1383
+ * The message written to `stdout`
1384
+ */
1385
+ message: string;
1386
+ }
1387
+ interface TestEnqueue extends TestLocationInfo {
1388
+ /**
1389
+ * The test name
1390
+ */
1391
+ name: string;
1392
+ /**
1393
+ * The nesting level of the test.
1394
+ */
1395
+ nesting: number;
1396
+ }
1397
+ interface TestDequeue extends TestLocationInfo {
1398
+ /**
1399
+ * The test name
1400
+ */
1401
+ name: string;
1402
+ /**
1403
+ * The nesting level of the test.
1404
+ */
1405
+ nesting: number;
1406
+ }
1407
+
1408
+ /**
1409
+ * The `node:test/reporters` module exposes the builtin-reporters for `node:test`.
1410
+ * To access it:
1411
+ *
1412
+ * ```js
1413
+ * import test from 'node:test/reporters';
1414
+ * ```
1415
+ *
1416
+ * This module is only available under the `node:` scheme. The following will not
1417
+ * work:
1418
+ *
1419
+ * ```js
1420
+ * import test from 'test/reporters';
1421
+ * ```
1422
+ * @since v19.9.0
1423
+ * @see [source](https://github.com/nodejs/node/blob/v20.2.0/lib/test/reporters.js)
1424
+ */
1425
+ declare module "node:test/reporters" {
1426
+ import { Transform, TransformOptions } from "node:stream";
1427
+
1428
+ type TestEvent =
1429
+ | { type: "test:diagnostic"; data: DiagnosticData }
1430
+ | { type: "test:fail"; data: TestFail }
1431
+ | { type: "test:pass"; data: TestPass }
1432
+ | { type: "test:plan"; data: TestPlan }
1433
+ | { type: "test:start"; data: TestStart }
1434
+ | { type: "test:stderr"; data: TestStderr }
1435
+ | { type: "test:stdout"; data: TestStdout }
1436
+ | { type: "test:enqueue"; data: TestEnqueue }
1437
+ | { type: "test:dequeue"; data: TestDequeue }
1438
+ | { type: "test:watch:drained" };
1439
+ type TestEventGenerator = AsyncGenerator<TestEvent, void>;
1440
+
1441
+ /**
1442
+ * The `dot` reporter outputs the test results in a compact format,
1443
+ * where each passing test is represented by a `.`,
1444
+ * and each failing test is represented by a `X`.
1445
+ */
1446
+ function dot(source: TestEventGenerator): AsyncGenerator<"\n" | "." | "X", void>;
1447
+ /**
1448
+ * The `tap` reporter outputs the test results in the [TAP](https://testanything.org/) format.
1449
+ */
1450
+ function tap(source: TestEventGenerator): AsyncGenerator<string, void>;
1451
+ /**
1452
+ * The `spec` reporter outputs the test results in a human-readable format.
1453
+ */
1454
+ class Spec extends Transform {
1455
+ constructor();
1456
+ }
1457
+ /**
1458
+ * The `junit` reporter outputs test results in a jUnit XML format
1459
+ */
1460
+ function junit(source: TestEventGenerator): AsyncGenerator<string, void>;
1461
+ class Lcov extends Transform {
1462
+ constructor(opts?: TransformOptions);
1463
+ }
1464
+ export { dot, junit, Lcov as lcov, Spec as spec, tap, TestEvent };
1465
+ }