veryfront 0.1.324 → 0.1.327

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 (277) hide show
  1. package/esm/cli/commands/extension/init-command.js +2 -2
  2. package/esm/cli/commands/extension/validate-command.js +1 -1
  3. package/esm/deno.d.ts +7 -0
  4. package/esm/deno.js +8 -1
  5. package/esm/deps/esm.sh/react-dom@19.2.4/client.d.ts +2 -0
  6. package/esm/deps/esm.sh/react-dom@19.2.4/client.d.ts.map +1 -0
  7. package/esm/deps/esm.sh/react-dom@19.2.4/client.js +5 -0
  8. package/esm/deps/esm.sh/scheduler@^0.27.0.d.ts +2 -0
  9. package/esm/deps/esm.sh/scheduler@^0.27.0.d.ts.map +1 -0
  10. package/esm/deps/esm.sh/scheduler@^0.27.0.js +3 -0
  11. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts +30 -0
  12. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.d.ts.map +1 -0
  13. package/esm/deps/jsr.io/@std/assert/1.0.19/almost_equals.js +47 -0
  14. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts +29 -0
  15. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.d.ts.map +1 -0
  16. package/esm/deps/jsr.io/@std/assert/1.0.19/array_includes.js +65 -0
  17. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts +17 -0
  18. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.d.ts.map +1 -0
  19. package/esm/deps/jsr.io/@std/assert/1.0.19/assert.js +23 -0
  20. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts +26 -0
  21. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.d.ts.map +1 -0
  22. package/esm/deps/jsr.io/@std/assert/1.0.19/assertion_error.js +30 -0
  23. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts +25 -0
  24. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.d.ts.map +1 -0
  25. package/esm/deps/jsr.io/@std/assert/1.0.19/equal.js +194 -0
  26. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts +37 -0
  27. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.d.ts.map +1 -0
  28. package/esm/deps/jsr.io/@std/assert/1.0.19/equals.js +61 -0
  29. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts +18 -0
  30. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.d.ts.map +1 -0
  31. package/esm/deps/jsr.io/@std/assert/1.0.19/exists.js +27 -0
  32. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts +15 -0
  33. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.d.ts.map +1 -0
  34. package/esm/deps/jsr.io/@std/assert/1.0.19/fail.js +20 -0
  35. package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts +19 -0
  36. package/esm/deps/jsr.io/@std/assert/1.0.19/false.d.ts.map +1 -0
  37. package/esm/deps/jsr.io/@std/assert/1.0.19/false.js +23 -0
  38. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts +20 -0
  39. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.d.ts.map +1 -0
  40. package/esm/deps/jsr.io/@std/assert/1.0.19/greater.js +29 -0
  41. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts +20 -0
  42. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.d.ts.map +1 -0
  43. package/esm/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.js +29 -0
  44. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts +23 -0
  45. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.d.ts.map +1 -0
  46. package/esm/deps/jsr.io/@std/assert/1.0.19/instance_of.js +52 -0
  47. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts +25 -0
  48. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.d.ts.map +1 -0
  49. package/esm/deps/jsr.io/@std/assert/1.0.19/is_error.js +53 -0
  50. package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts +19 -0
  51. package/esm/deps/jsr.io/@std/assert/1.0.19/less.d.ts.map +1 -0
  52. package/esm/deps/jsr.io/@std/assert/1.0.19/less.js +28 -0
  53. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts +20 -0
  54. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.d.ts.map +1 -0
  55. package/esm/deps/jsr.io/@std/assert/1.0.19/less_or_equal.js +29 -0
  56. package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts +18 -0
  57. package/esm/deps/jsr.io/@std/assert/1.0.19/match.d.ts.map +1 -0
  58. package/esm/deps/jsr.io/@std/assert/1.0.19/match.js +26 -0
  59. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts +44 -0
  60. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.d.ts.map +1 -0
  61. package/esm/deps/jsr.io/@std/assert/1.0.19/mod.js +45 -0
  62. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts +27 -0
  63. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.d.ts.map +1 -0
  64. package/esm/deps/jsr.io/@std/assert/1.0.19/not_equals.js +39 -0
  65. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts +20 -0
  66. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.d.ts.map +1 -0
  67. package/esm/deps/jsr.io/@std/assert/1.0.19/not_instance_of.js +29 -0
  68. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts +18 -0
  69. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.d.ts.map +1 -0
  70. package/esm/deps/jsr.io/@std/assert/1.0.19/not_match.js +26 -0
  71. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts +23 -0
  72. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.d.ts.map +1 -0
  73. package/esm/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.js +32 -0
  74. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts +29 -0
  75. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.d.ts.map +1 -0
  76. package/esm/deps/jsr.io/@std/assert/1.0.19/object_match.js +177 -0
  77. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts +42 -0
  78. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.d.ts.map +1 -0
  79. package/esm/deps/jsr.io/@std/assert/1.0.19/rejects.js +53 -0
  80. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts +24 -0
  81. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.d.ts.map +1 -0
  82. package/esm/deps/jsr.io/@std/assert/1.0.19/strict_equals.js +58 -0
  83. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts +18 -0
  84. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.d.ts.map +1 -0
  85. package/esm/deps/jsr.io/@std/assert/1.0.19/string_includes.js +26 -0
  86. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts +45 -0
  87. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.d.ts.map +1 -0
  88. package/esm/deps/jsr.io/@std/assert/1.0.19/throws.js +44 -0
  89. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts +15 -0
  90. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.d.ts.map +1 -0
  91. package/esm/deps/jsr.io/@std/assert/1.0.19/unimplemented.js +20 -0
  92. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts +15 -0
  93. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.d.ts.map +1 -0
  94. package/esm/deps/jsr.io/@std/assert/1.0.19/unreachable.js +20 -0
  95. package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.d.ts +150 -0
  96. package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.d.ts.map +1 -0
  97. package/esm/deps/jsr.io/@std/internal/1.0.13/assertion_state.js +224 -0
  98. package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.d.ts +80 -0
  99. package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.d.ts.map +1 -0
  100. package/esm/deps/jsr.io/@std/internal/1.0.13/build_message.js +116 -0
  101. package/esm/deps/jsr.io/@std/internal/1.0.13/diff.d.ts +140 -0
  102. package/esm/deps/jsr.io/@std/internal/1.0.13/diff.d.ts.map +1 -0
  103. package/esm/deps/jsr.io/@std/internal/1.0.13/diff.js +276 -0
  104. package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.d.ts +99 -0
  105. package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.d.ts.map +1 -0
  106. package/esm/deps/jsr.io/@std/internal/1.0.13/diff_str.js +182 -0
  107. package/esm/deps/jsr.io/@std/internal/1.0.13/format.d.ts +29 -0
  108. package/esm/deps/jsr.io/@std/internal/1.0.13/format.d.ts.map +1 -0
  109. package/esm/deps/jsr.io/@std/internal/1.0.13/format.js +70 -0
  110. package/esm/deps/jsr.io/@std/internal/1.0.13/styles.d.ts +159 -0
  111. package/esm/deps/jsr.io/@std/internal/1.0.13/styles.d.ts.map +1 -0
  112. package/esm/deps/jsr.io/@std/internal/1.0.13/styles.js +207 -0
  113. package/esm/deps/jsr.io/@std/internal/1.0.13/types.d.ts +25 -0
  114. package/esm/deps/jsr.io/@std/internal/1.0.13/types.d.ts.map +1 -0
  115. package/esm/deps/jsr.io/@std/internal/1.0.13/types.js +3 -0
  116. package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.d.ts +80 -0
  117. package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.d.ts.map +1 -0
  118. package/esm/deps/jsr.io/@std/testing/1.0.18/_test_suite.js +348 -0
  119. package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.d.ts +738 -0
  120. package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.d.ts.map +1 -0
  121. package/esm/deps/jsr.io/@std/testing/1.0.18/bdd.js +656 -0
  122. package/esm/src/agent/fork-runtime-stream.d.ts +143 -0
  123. package/esm/src/agent/fork-runtime-stream.d.ts.map +1 -0
  124. package/esm/src/agent/fork-runtime-stream.js +505 -0
  125. package/esm/src/agent/hosted-child-fork-stream-execution.d.ts +130 -0
  126. package/esm/src/agent/hosted-child-fork-stream-execution.d.ts.map +1 -0
  127. package/esm/src/agent/hosted-child-fork-stream-execution.js +391 -0
  128. package/esm/src/agent/index.d.ts +2 -0
  129. package/esm/src/agent/index.d.ts.map +1 -1
  130. package/esm/src/agent/index.js +2 -0
  131. package/esm/src/chat/conversation.d.ts +5 -5
  132. package/esm/src/chat/final-step-fallback.js +2 -2
  133. package/esm/src/modules/index.d.ts +12 -0
  134. package/esm/src/modules/index.d.ts.map +1 -0
  135. package/esm/src/modules/index.js +10 -0
  136. package/esm/src/modules/module-resolver.d.ts +28 -0
  137. package/esm/src/modules/module-resolver.d.ts.map +1 -0
  138. package/esm/src/modules/module-resolver.js +106 -0
  139. package/esm/src/rendering/cleanup.d.ts +7 -0
  140. package/esm/src/rendering/cleanup.d.ts.map +1 -0
  141. package/esm/src/rendering/cleanup.js +22 -0
  142. package/esm/src/rendering/ssr/index.d.ts +10 -0
  143. package/esm/src/rendering/ssr/index.d.ts.map +1 -0
  144. package/esm/src/rendering/ssr/index.js +8 -0
  145. package/esm/src/rendering/ssr/mdx-module-loader.d.ts +5 -0
  146. package/esm/src/rendering/ssr/mdx-module-loader.d.ts.map +1 -0
  147. package/esm/src/rendering/ssr/mdx-module-loader.js +150 -0
  148. package/esm/src/rendering/ssr/mdx-renderer.d.ts +4 -0
  149. package/esm/src/rendering/ssr/mdx-renderer.d.ts.map +1 -0
  150. package/esm/src/rendering/ssr/mdx-renderer.js +44 -0
  151. package/esm/src/rendering/ssr/types.d.ts +13 -0
  152. package/esm/src/rendering/ssr/types.d.ts.map +1 -0
  153. package/esm/src/rendering/ssr/types.js +1 -0
  154. package/esm/src/sandbox/index.d.ts +1 -0
  155. package/esm/src/sandbox/index.d.ts.map +1 -1
  156. package/esm/src/sandbox/index.js +1 -0
  157. package/esm/src/sandbox/shell-tools.d.ts +39 -0
  158. package/esm/src/sandbox/shell-tools.d.ts.map +1 -0
  159. package/esm/src/sandbox/shell-tools.js +177 -0
  160. package/esm/src/server/shared/index.d.ts +7 -0
  161. package/esm/src/server/shared/index.d.ts.map +1 -0
  162. package/esm/src/server/shared/index.js +6 -0
  163. package/esm/src/testing/assert.d.ts +22 -0
  164. package/esm/src/testing/assert.d.ts.map +1 -0
  165. package/esm/src/testing/assert.js +217 -0
  166. package/esm/src/testing/bdd.d.ts +67 -0
  167. package/esm/src/testing/bdd.d.ts.map +1 -0
  168. package/esm/src/testing/bdd.js +401 -0
  169. package/esm/src/testing/deno-compat.d.ts +26 -0
  170. package/esm/src/testing/deno-compat.d.ts.map +1 -0
  171. package/esm/src/testing/deno-compat.js +146 -0
  172. package/esm/src/testing/index.d.ts +28 -0
  173. package/esm/src/testing/index.d.ts.map +1 -0
  174. package/esm/src/testing/index.js +27 -0
  175. package/esm/src/testing/init.d.ts +2 -0
  176. package/esm/src/testing/init.d.ts.map +1 -0
  177. package/esm/src/testing/init.js +18 -0
  178. package/esm/src/testing/isolation.d.ts +30 -0
  179. package/esm/src/testing/isolation.d.ts.map +1 -0
  180. package/esm/src/testing/isolation.js +151 -0
  181. package/esm/src/testing/timing.d.ts +4 -0
  182. package/esm/src/testing/timing.d.ts.map +1 -0
  183. package/esm/src/testing/timing.js +22 -0
  184. package/esm/src/testing/utils.d.ts +6 -0
  185. package/esm/src/testing/utils.d.ts.map +1 -0
  186. package/esm/src/testing/utils.js +49 -0
  187. package/esm/src/types/global-guards.d.ts +11 -0
  188. package/esm/src/types/global-guards.d.ts.map +1 -0
  189. package/esm/src/types/global-guards.js +12 -0
  190. package/esm/src/utils/cache/keys/namespace.d.ts +3 -0
  191. package/esm/src/utils/cache/keys/namespace.d.ts.map +1 -0
  192. package/esm/src/utils/cache/keys/namespace.js +19 -0
  193. package/esm/src/utils/clsx.d.ts +3 -3
  194. package/esm/src/utils/clsx.d.ts.map +1 -1
  195. package/esm/src/utils/clsx.js +2 -3
  196. package/esm/src/utils/mime-types.d.ts +0 -6
  197. package/esm/src/utils/mime-types.d.ts.map +1 -1
  198. package/esm/src/utils/mime-types.js +0 -1
  199. package/esm/src/utils/version-constant.d.ts +1 -1
  200. package/esm/src/utils/version-constant.js +1 -1
  201. package/package.json +14 -1
  202. package/src/cli/commands/extension/init-command.ts +2 -2
  203. package/src/cli/commands/extension/validate-command.ts +1 -1
  204. package/src/deno.js +8 -1
  205. package/src/deps/esm.sh/@types/react-dom@19.2.3/client.d.ts +105 -0
  206. package/src/deps/esm.sh/@types/react@19.2.14/global.d.ts +166 -0
  207. package/src/deps/esm.sh/@types/react@19.2.14/index.d.ts +4370 -0
  208. package/src/deps/esm.sh/@types/scheduler@0.26.0/index.d.ts +30 -0
  209. package/src/deps/esm.sh/csstype@3.2.3/index.d.ts +22569 -0
  210. package/src/deps/esm.sh/react-dom@19.2.4/client.d.ts +105 -0
  211. package/src/deps/esm.sh/react-dom@19.2.4/client.js +5 -0
  212. package/src/deps/esm.sh/scheduler@^0.27.0.d.ts +30 -0
  213. package/src/deps/esm.sh/scheduler@^0.27.0.js +3 -0
  214. package/src/deps/jsr.io/@std/assert/1.0.19/almost_equals.ts +56 -0
  215. package/src/deps/jsr.io/@std/assert/1.0.19/array_includes.ts +76 -0
  216. package/src/deps/jsr.io/@std/assert/1.0.19/assert.ts +24 -0
  217. package/src/deps/jsr.io/@std/assert/1.0.19/assertion_error.ts +31 -0
  218. package/src/deps/jsr.io/@std/assert/1.0.19/equal.ts +226 -0
  219. package/src/deps/jsr.io/@std/assert/1.0.19/equals.ts +68 -0
  220. package/src/deps/jsr.io/@std/assert/1.0.19/exists.ts +31 -0
  221. package/src/deps/jsr.io/@std/assert/1.0.19/fail.ts +21 -0
  222. package/src/deps/jsr.io/@std/assert/1.0.19/false.ts +27 -0
  223. package/src/deps/jsr.io/@std/assert/1.0.19/greater.ts +30 -0
  224. package/src/deps/jsr.io/@std/assert/1.0.19/greater_or_equal.ts +36 -0
  225. package/src/deps/jsr.io/@std/assert/1.0.19/instance_of.ts +64 -0
  226. package/src/deps/jsr.io/@std/assert/1.0.19/is_error.ts +65 -0
  227. package/src/deps/jsr.io/@std/assert/1.0.19/less.ts +29 -0
  228. package/src/deps/jsr.io/@std/assert/1.0.19/less_or_equal.ts +36 -0
  229. package/src/deps/jsr.io/@std/assert/1.0.19/match.ts +30 -0
  230. package/src/deps/jsr.io/@std/assert/1.0.19/mod.ts +47 -0
  231. package/src/deps/jsr.io/@std/assert/1.0.19/not_equals.ts +43 -0
  232. package/src/deps/jsr.io/@std/assert/1.0.19/not_instance_of.ts +33 -0
  233. package/src/deps/jsr.io/@std/assert/1.0.19/not_match.ts +30 -0
  234. package/src/deps/jsr.io/@std/assert/1.0.19/not_strict_equals.ts +42 -0
  235. package/src/deps/jsr.io/@std/assert/1.0.19/object_match.ts +224 -0
  236. package/src/deps/jsr.io/@std/assert/1.0.19/rejects.ts +123 -0
  237. package/src/deps/jsr.io/@std/assert/1.0.19/strict_equals.ts +68 -0
  238. package/src/deps/jsr.io/@std/assert/1.0.19/string_includes.ts +30 -0
  239. package/src/deps/jsr.io/@std/assert/1.0.19/throws.ts +111 -0
  240. package/src/deps/jsr.io/@std/assert/1.0.19/unimplemented.ts +21 -0
  241. package/src/deps/jsr.io/@std/assert/1.0.19/unreachable.ts +21 -0
  242. package/src/deps/jsr.io/@std/internal/1.0.13/assertion_state.ts +248 -0
  243. package/src/deps/jsr.io/@std/internal/1.0.13/build_message.ts +147 -0
  244. package/src/deps/jsr.io/@std/internal/1.0.13/diff.ts +317 -0
  245. package/src/deps/jsr.io/@std/internal/1.0.13/diff_str.ts +208 -0
  246. package/src/deps/jsr.io/@std/internal/1.0.13/format.ts +89 -0
  247. package/src/deps/jsr.io/@std/internal/1.0.13/styles.ts +233 -0
  248. package/src/deps/jsr.io/@std/internal/1.0.13/types.ts +30 -0
  249. package/src/deps/jsr.io/@std/testing/1.0.18/_test_suite.ts +461 -0
  250. package/src/deps/jsr.io/@std/testing/1.0.18/bdd.ts +1294 -0
  251. package/src/src/agent/fork-runtime-stream.ts +780 -0
  252. package/src/src/agent/hosted-child-fork-stream-execution.ts +579 -0
  253. package/src/src/agent/index.ts +26 -0
  254. package/src/src/chat/final-step-fallback.ts +2 -2
  255. package/src/src/modules/index.ts +43 -0
  256. package/src/src/modules/module-resolver.ts +145 -0
  257. package/src/src/rendering/cleanup.ts +27 -0
  258. package/src/src/rendering/ssr/index.ts +10 -0
  259. package/src/src/rendering/ssr/mdx-module-loader.ts +185 -0
  260. package/src/src/rendering/ssr/mdx-renderer.ts +66 -0
  261. package/src/src/rendering/ssr/types.ts +14 -0
  262. package/src/src/sandbox/index.ts +9 -0
  263. package/src/src/sandbox/shell-tools.ts +242 -0
  264. package/src/src/server/shared/index.ts +12 -0
  265. package/src/src/testing/assert.ts +352 -0
  266. package/src/src/testing/bdd.ts +618 -0
  267. package/src/src/testing/deno-compat.ts +206 -0
  268. package/src/src/testing/index.ts +92 -0
  269. package/src/src/testing/init.ts +21 -0
  270. package/src/src/testing/isolation.ts +177 -0
  271. package/src/src/testing/timing.ts +27 -0
  272. package/src/src/testing/utils.ts +44 -0
  273. package/src/src/types/global-guards.ts +21 -0
  274. package/src/src/utils/cache/keys/namespace.ts +25 -0
  275. package/src/src/utils/clsx.ts +2 -4
  276. package/src/src/utils/mime-types.ts +0 -2
  277. package/src/src/utils/version-constant.ts +1 -1
@@ -0,0 +1,1294 @@
1
+ // Copyright 2018-2026 the Deno authors. MIT license.
2
+
3
+ /**
4
+ * A {@link https://en.wikipedia.org/wiki/Behavior-driven_development | BDD} interface
5
+ * to `Deno.test()` API.
6
+ *
7
+ * With `@std/testing/bdd` module you can write your tests in a familiar format for
8
+ * grouping tests and adding setup/teardown hooks used by other JavaScript testing
9
+ * frameworks like Jasmine, Jest, and Mocha.
10
+ *
11
+ * The `describe` function creates a block that groups together several related
12
+ * tests. The `it` function registers an individual test case.
13
+ *
14
+ * ## Hooks
15
+ *
16
+ * There are 4 types of hooks available for test suites. A test suite can have
17
+ * multiples of each type of hook, they will be called in the order that they are
18
+ * registered. The `afterEach` and `afterAll` hooks will be called whether or not
19
+ * the test case passes. The *All hooks will be called once for the whole group
20
+ * while the *Each hooks will be called for each individual test case.
21
+ *
22
+ * - `beforeAll`: Runs before all of the tests in the group.
23
+ * - `afterAll`: Runs after all of the tests in the group finish.
24
+ * - `beforeEach`: Runs before each of the individual test cases in the group.
25
+ * - `afterEach`: Runs after each of the individual test cases in the group.
26
+ *
27
+ * If a hook is registered at the top level, a global test suite will be registered
28
+ * and all tests will belong to it. Hooks registered at the top level must be
29
+ * registered before any individual test cases or test suites.
30
+ *
31
+ * ## Focusing tests
32
+ *
33
+ * If you would like to run only specific test cases, you can do so by calling
34
+ * `it.only` instead of `it`. If you would like to run only specific test suites,
35
+ * you can do so by calling `describe.only` instead of `describe`.
36
+ *
37
+ * There is one limitation to this when using the flat test grouping style. When
38
+ * `describe` is called without being nested, it registers the test with
39
+ * `Deno.test`. If a child test case or suite is registered with `it.only` or
40
+ * `describe.only`, it will be scoped to the top test suite instead of the file. To
41
+ * make them the only tests that run in the file, you would need to register the
42
+ * top test suite with `describe.only` too.
43
+ *
44
+ * ## Ignoring tests
45
+ *
46
+ * If you would like to not run specific individual test cases, you can do so by
47
+ * calling `it.ignore` instead of `it`. If you would like to not run specific test
48
+ * suites, you can do so by calling `describe.ignore` instead of `describe`.
49
+ *
50
+ * ## Sanitization options
51
+ *
52
+ * Like `Deno.TestDefinition`, the `DescribeDefinition` and `ItDefinition` have
53
+ * sanitization options. They work in the same way.
54
+ *
55
+ * - `sanitizeExit`: Ensure the test case does not prematurely cause the process to
56
+ * exit, for example via a call to Deno.exit. Defaults to true.
57
+ * - `sanitizeOps`: Check that the number of async completed ops after the test is
58
+ * the same as number of dispatched ops. Defaults to true.
59
+ * - `sanitizeResources`: Ensure the test case does not "leak" resources - ie. the
60
+ * resource table after the test has exactly the same contents as before the
61
+ * test. Defaults to true.
62
+ *
63
+ * ## Permissions option
64
+ *
65
+ * Like `Deno.TestDefinition`, the `DescribeDefinition` and `ItDefinition` have a
66
+ * `permissions` option. They specify the permissions that should be used to run an
67
+ * individual test case or test suite. Set this to `"inherit"` to keep the calling
68
+ * thread's permissions. Set this to `"none"` to revoke all permissions.
69
+ *
70
+ * This setting defaults to `"inherit"`.
71
+ *
72
+ * There is currently one limitation to this, you cannot use the permissions option
73
+ * on an individual test case or test suite that belongs to another test suite.
74
+ * That's because internally those tests are registered with `t.step` which does
75
+ * not support the permissions option.
76
+ *
77
+ * ## Comparing to Deno\.test
78
+ *
79
+ * The default way of writing tests is using `Deno.test` and `t.step`. The
80
+ * `describe` and `it` functions have similar call signatures to `Deno.test`,
81
+ * making it easy to switch between the default style and the behavior-driven
82
+ * development style of writing tests. Internally, `describe` and `it` are
83
+ * registering tests with `Deno.test` and `t.step`.
84
+ *
85
+ * Below is an example of a test file using `Deno.test` and `t.step`. In the
86
+ * following sections there are examples of how the same test could be written with
87
+ * `describe` and `it` using nested test grouping, flat test grouping, or a mix of
88
+ * both styles.
89
+ *
90
+ * ```ts
91
+ * import {
92
+ * assertEquals,
93
+ * assertStrictEquals,
94
+ * assertThrows,
95
+ * } from "@std/assert";
96
+ *
97
+ * class User {
98
+ * static users: Map<string, User> = new Map();
99
+ * name: string;
100
+ * age?: number;
101
+ *
102
+ * constructor(name: string) {
103
+ * if (User.users.has(name)) {
104
+ * throw new Deno.errors.AlreadyExists(`User ${name} already exists`);
105
+ * }
106
+ * this.name = name;
107
+ * User.users.set(name, this);
108
+ * }
109
+ *
110
+ * getAge(): number {
111
+ * if (!this.age) {
112
+ * throw new Error("Age unknown");
113
+ * }
114
+ * return this.age;
115
+ * }
116
+ *
117
+ * setAge(age: number) {
118
+ * this.age = age;
119
+ * }
120
+ * }
121
+ *
122
+ * Deno.test("User.users initially empty", () => {
123
+ * assertEquals(User.users.size, 0);
124
+ * });
125
+ *
126
+ * Deno.test("User constructor", () => {
127
+ * try {
128
+ * const user = new User("Kyle");
129
+ * assertEquals(user.name, "Kyle");
130
+ * assertStrictEquals(User.users.get("Kyle"), user);
131
+ * } finally {
132
+ * User.users.clear();
133
+ * }
134
+ * });
135
+ *
136
+ * Deno.test("User age", async (t) => {
137
+ * const user = new User("Kyle");
138
+ *
139
+ * await t.step("getAge", () => {
140
+ * assertThrows(() => user.getAge(), Error, "Age unknown");
141
+ * user.age = 18;
142
+ * assertEquals(user.getAge(), 18);
143
+ * });
144
+ *
145
+ * await t.step("setAge", () => {
146
+ * user.setAge(18);
147
+ * assertEquals(user.getAge(), 18);
148
+ * });
149
+ * });
150
+ * ```
151
+ *
152
+ * ### Nested test grouping
153
+ *
154
+ * Tests created within the callback of a `describe` function call will belong to
155
+ * the new test suite it creates. The hooks can be created within it or be added to
156
+ * the options argument for describe.
157
+ *
158
+ * ```ts ignore
159
+ * import {
160
+ * assertEquals,
161
+ * assertStrictEquals,
162
+ * assertThrows,
163
+ * } from "@std/assert";
164
+ * import {
165
+ * afterEach,
166
+ * beforeEach,
167
+ * describe,
168
+ * it,
169
+ * } from "@std/testing/bdd";
170
+ *
171
+ * class User {
172
+ * static users: Map<string, User> = new Map();
173
+ * name: string;
174
+ * age?: number;
175
+ *
176
+ * constructor(name: string) {
177
+ * if (User.users.has(name)) {
178
+ * throw new Deno.errors.AlreadyExists(`User ${name} already exists`);
179
+ * }
180
+ * this.name = name;
181
+ * User.users.set(name, this);
182
+ * }
183
+ *
184
+ * getAge(): number {
185
+ * if (!this.age) {
186
+ * throw new Error("Age unknown");
187
+ * }
188
+ * return this.age;
189
+ * }
190
+ *
191
+ * setAge(age: number) {
192
+ * this.age = age;
193
+ * }
194
+ * }
195
+ *
196
+ * describe("User", () => {
197
+ * it("users initially empty", () => {
198
+ * assertEquals(User.users.size, 0);
199
+ * });
200
+ *
201
+ * it("constructor", () => {
202
+ * try {
203
+ * const user = new User("Kyle");
204
+ * assertEquals(user.name, "Kyle");
205
+ * assertStrictEquals(User.users.get("Kyle"), user);
206
+ * } finally {
207
+ * User.users.clear();
208
+ * }
209
+ * });
210
+ *
211
+ * describe("age", () => {
212
+ * let user: User;
213
+ *
214
+ * beforeEach(() => {
215
+ * user = new User("Kyle");
216
+ * });
217
+ *
218
+ * afterEach(() => {
219
+ * User.users.clear();
220
+ * });
221
+ *
222
+ * it("getAge", function () {
223
+ * assertThrows(() => user.getAge(), Error, "Age unknown");
224
+ * user.age = 18;
225
+ * assertEquals(user.getAge(), 18);
226
+ * });
227
+ *
228
+ * it("setAge", function () {
229
+ * user.setAge(18);
230
+ * assertEquals(user.getAge(), 18);
231
+ * });
232
+ * });
233
+ * });
234
+ * ```
235
+ *
236
+ * ### Flat test grouping
237
+ *
238
+ * The `describe` function returns a unique symbol that can be used to reference
239
+ * the test suite for adding tests to it without having to create them within a
240
+ * callback. The gives you the ability to have test grouping without any extra
241
+ * indentation in front of the grouped tests.
242
+ *
243
+ * ```ts ignore
244
+ * import {
245
+ * assertEquals,
246
+ * assertStrictEquals,
247
+ * assertThrows,
248
+ * } from "@std/assert";
249
+ * import {
250
+ * describe,
251
+ * it,
252
+ * } from "@std/testing/bdd";
253
+ *
254
+ * class User {
255
+ * static users: Map<string, User> = new Map();
256
+ * name: string;
257
+ * age?: number;
258
+ *
259
+ * constructor(name: string) {
260
+ * if (User.users.has(name)) {
261
+ * throw new Deno.errors.AlreadyExists(`User ${name} already exists`);
262
+ * }
263
+ * this.name = name;
264
+ * User.users.set(name, this);
265
+ * }
266
+ *
267
+ * getAge(): number {
268
+ * if (!this.age) {
269
+ * throw new Error("Age unknown");
270
+ * }
271
+ * return this.age;
272
+ * }
273
+ *
274
+ * setAge(age: number) {
275
+ * this.age = age;
276
+ * }
277
+ * }
278
+ *
279
+ * const userTests = describe("User");
280
+ *
281
+ * it(userTests, "users initially empty", () => {
282
+ * assertEquals(User.users.size, 0);
283
+ * });
284
+ *
285
+ * it(userTests, "constructor", () => {
286
+ * try {
287
+ * const user = new User("Kyle");
288
+ * assertEquals(user.name, "Kyle");
289
+ * assertStrictEquals(User.users.get("Kyle"), user);
290
+ * } finally {
291
+ * User.users.clear();
292
+ * }
293
+ * });
294
+ *
295
+ * const ageTests = describe({
296
+ * name: "age",
297
+ * suite: userTests,
298
+ * beforeEach(this: { user: User }) {
299
+ * this.user = new User("Kyle");
300
+ * },
301
+ * afterEach() {
302
+ * User.users.clear();
303
+ * },
304
+ * });
305
+ *
306
+ * it(ageTests, "getAge", function () {
307
+ * const { user } = this;
308
+ * assertThrows(() => user.getAge(), Error, "Age unknown");
309
+ * user.age = 18;
310
+ * assertEquals(user.getAge(), 18);
311
+ * });
312
+ *
313
+ * it(ageTests, "setAge", function () {
314
+ * const { user } = this;
315
+ * user.setAge(18);
316
+ * assertEquals(user.getAge(), 18);
317
+ * });
318
+ * ```
319
+ *
320
+ * ### Mixed test grouping
321
+ *
322
+ * Both nested test grouping and flat test grouping can be used together. This can
323
+ * be useful if you'd like to create deep groupings without all the extra
324
+ * indentation in front of each line.
325
+ *
326
+ * ```ts ignore
327
+ * import {
328
+ * assertEquals,
329
+ * assertStrictEquals,
330
+ * assertThrows,
331
+ * } from "@std/assert";
332
+ * import {
333
+ * describe,
334
+ * it,
335
+ * } from "@std/testing/bdd";
336
+ *
337
+ * class User {
338
+ * static users: Map<string, User> = new Map();
339
+ * name: string;
340
+ * age?: number;
341
+ *
342
+ * constructor(name: string) {
343
+ * if (User.users.has(name)) {
344
+ * throw new Deno.errors.AlreadyExists(`User ${name} already exists`);
345
+ * }
346
+ * this.name = name;
347
+ * User.users.set(name, this);
348
+ * }
349
+ *
350
+ * getAge(): number {
351
+ * if (!this.age) {
352
+ * throw new Error("Age unknown");
353
+ * }
354
+ * return this.age;
355
+ * }
356
+ *
357
+ * setAge(age: number) {
358
+ * this.age = age;
359
+ * }
360
+ * }
361
+ *
362
+ * describe("User", () => {
363
+ * it("users initially empty", () => {
364
+ * assertEquals(User.users.size, 0);
365
+ * });
366
+ *
367
+ * it("constructor", () => {
368
+ * try {
369
+ * const user = new User("Kyle");
370
+ * assertEquals(user.name, "Kyle");
371
+ * assertStrictEquals(User.users.get("Kyle"), user);
372
+ * } finally {
373
+ * User.users.clear();
374
+ * }
375
+ * });
376
+ *
377
+ * const ageTests = describe({
378
+ * name: "age",
379
+ * beforeEach(this: { user: User }) {
380
+ * this.user = new User("Kyle");
381
+ * },
382
+ * afterEach() {
383
+ * User.users.clear();
384
+ * },
385
+ * });
386
+ *
387
+ * it(ageTests, "getAge", function () {
388
+ * const { user } = this;
389
+ * assertThrows(() => user.getAge(), Error, "Age unknown");
390
+ * user.age = 18;
391
+ * assertEquals(user.getAge(), 18);
392
+ * });
393
+ *
394
+ * it(ageTests, "setAge", function () {
395
+ * const { user } = this;
396
+ * user.setAge(18);
397
+ * assertEquals(user.getAge(), 18);
398
+ * });
399
+ * });
400
+ * ```
401
+ *
402
+ * @module
403
+ */
404
+ import * as dntShim from "../../../../../_dnt.shims.js";
405
+
406
+
407
+ import { getAssertionState } from "../../internal/1.0.13/assertion_state.js";
408
+ import { AssertionError } from "../../assert/1.0.19/assertion_error.js";
409
+ import {
410
+ type DescribeDefinition,
411
+ globalSanitizersState,
412
+ type HookNames,
413
+ type ItDefinition,
414
+ type TestSuite,
415
+ TestSuiteInternal,
416
+ } from "./_test_suite.js";
417
+ export type { DescribeDefinition, ItDefinition, TestSuite };
418
+
419
+ /** The arguments for an ItFunction. */
420
+ export type ItArgs<T> =
421
+ | [options: ItDefinition<T>]
422
+ | [
423
+ name: string,
424
+ options: Omit<ItDefinition<T>, "name">,
425
+ ]
426
+ | [
427
+ name: string,
428
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
429
+ ]
430
+ | [fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>]
431
+ | [
432
+ name: string,
433
+ options: Omit<ItDefinition<T>, "fn" | "name">,
434
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
435
+ ]
436
+ | [
437
+ options: Omit<ItDefinition<T>, "fn">,
438
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
439
+ ]
440
+ | [
441
+ options: Omit<ItDefinition<T>, "fn" | "name">,
442
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
443
+ ]
444
+ | [
445
+ suite: TestSuite<T>,
446
+ name: string,
447
+ options: Omit<ItDefinition<T>, "name" | "suite">,
448
+ ]
449
+ | [
450
+ suite: TestSuite<T>,
451
+ name: string,
452
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
453
+ ]
454
+ | [
455
+ suite: TestSuite<T>,
456
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
457
+ ]
458
+ | [
459
+ suite: TestSuite<T>,
460
+ name: string,
461
+ options: Omit<ItDefinition<T>, "fn" | "name" | "suite">,
462
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
463
+ ]
464
+ | [
465
+ suite: TestSuite<T>,
466
+ options: Omit<ItDefinition<T>, "fn" | "suite">,
467
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
468
+ ]
469
+ | [
470
+ suite: TestSuite<T>,
471
+ options: Omit<ItDefinition<T>, "fn" | "name" | "suite">,
472
+ fn: (this: T, t: dntShim.Deno.TestContext) => void | Promise<void>,
473
+ ];
474
+
475
+ /** Generates an ItDefinition from ItArgs. */
476
+ function itDefinition<T>(...args: ItArgs<T>): ItDefinition<T> {
477
+ let [
478
+ suiteOptionsOrNameOrFn,
479
+ optionsOrNameOrFn,
480
+ optionsOrFn,
481
+ fn,
482
+ ] = args;
483
+ let suite: TestSuite<T> | undefined = undefined;
484
+ let name: string;
485
+ let options:
486
+ | ItDefinition<T>
487
+ | Omit<ItDefinition<T>, "fn">
488
+ | Omit<ItDefinition<T>, "name">
489
+ | Omit<ItDefinition<T>, "fn" | "name">;
490
+ if (
491
+ typeof suiteOptionsOrNameOrFn === "object" &&
492
+ typeof (suiteOptionsOrNameOrFn as TestSuite<T>).symbol === "symbol"
493
+ ) {
494
+ suite = suiteOptionsOrNameOrFn as TestSuite<T>;
495
+ } else {
496
+ fn = optionsOrFn as typeof fn;
497
+ optionsOrFn = optionsOrNameOrFn as typeof optionsOrFn;
498
+ optionsOrNameOrFn = suiteOptionsOrNameOrFn as typeof optionsOrNameOrFn;
499
+ }
500
+ if (typeof optionsOrNameOrFn === "string") {
501
+ name = optionsOrNameOrFn;
502
+ if (typeof optionsOrFn === "function") {
503
+ fn = optionsOrFn;
504
+ options = {};
505
+ } else {
506
+ options = optionsOrFn!;
507
+ if (!fn) fn = (options as Omit<ItDefinition<T>, "name">).fn;
508
+ }
509
+ } else if (typeof optionsOrNameOrFn === "function") {
510
+ fn = optionsOrNameOrFn;
511
+ name = fn.name;
512
+ options = {};
513
+ } else {
514
+ options = optionsOrNameOrFn!;
515
+ if (typeof optionsOrFn === "function") {
516
+ fn = optionsOrFn;
517
+ } else {
518
+ fn = (options as ItDefinition<T>).fn;
519
+ }
520
+ name = (options as ItDefinition<T>).name ?? fn.name;
521
+ }
522
+
523
+ return {
524
+ ...(suite !== undefined ? { suite } : {}),
525
+ ...options,
526
+ name,
527
+ fn,
528
+ };
529
+ }
530
+
531
+ /** Registers an individual test case. */
532
+ // deno-lint-ignore deno-style-guide/naming-convention
533
+ export interface it {
534
+ <T>(...args: ItArgs<T>): void;
535
+
536
+ /** Registers an individual test case with only set to true. */
537
+ only<T>(...args: ItArgs<T>): void;
538
+
539
+ /** Registers an individual test case with ignore set to true. */
540
+ ignore<T>(...args: ItArgs<T>): void;
541
+
542
+ /**
543
+ * Registers an individual test case with ignore set to true. Alias of
544
+ * `.ignore()`.
545
+ */
546
+ skip<T>(...args: ItArgs<T>): void;
547
+ }
548
+
549
+ /**
550
+ * Registers an individual test case.
551
+ *
552
+ * @example Usage
553
+ * ```ts ignore
554
+ * import { describe, it } from "@std/testing/bdd";
555
+ * import { assertEquals } from "@std/assert";
556
+ *
557
+ * describe("example", () => {
558
+ * it("should pass", () => {
559
+ * // test case
560
+ * assertEquals(2 + 2, 4);
561
+ * });
562
+ * });
563
+ * ```
564
+ *
565
+ * @typeParam T The self type of the function to implement the test case
566
+ * @param args The test case
567
+ */
568
+ export function it<T>(...args: ItArgs<T>) {
569
+ if (TestSuiteInternal.runningCount > 0) {
570
+ throw new Error(
571
+ "Cannot register new test cases after already registered test cases start running",
572
+ );
573
+ }
574
+ const assertionState = getAssertionState();
575
+ const options = itDefinition(...args);
576
+ const { suite } = options;
577
+ const testSuite = suite
578
+ ? TestSuiteInternal.suites.get(suite.symbol)
579
+ : TestSuiteInternal.current;
580
+
581
+ if (!TestSuiteInternal.started) TestSuiteInternal.started = true;
582
+ if (testSuite) {
583
+ TestSuiteInternal.addStep(testSuite, options);
584
+ } else {
585
+ const {
586
+ name,
587
+ fn,
588
+ ignore,
589
+ only,
590
+ permissions,
591
+ sanitizeExit = globalSanitizersState.sanitizeExit,
592
+ sanitizeOps = globalSanitizersState.sanitizeOps,
593
+ sanitizeResources = globalSanitizersState.sanitizeResources,
594
+ } = options;
595
+ const opts: dntShim.Deno.TestDefinition = {
596
+ name,
597
+ async fn(t) {
598
+ TestSuiteInternal.runningCount++;
599
+ try {
600
+ await fn.call({} as T, t);
601
+ } finally {
602
+ TestSuiteInternal.runningCount--;
603
+ }
604
+
605
+ try {
606
+ if (assertionState.checkAssertionErrorState()) {
607
+ throw new AssertionError(
608
+ "Expected at least one assertion to be called but received none",
609
+ );
610
+ }
611
+
612
+ if (assertionState.checkAssertionCountSatisfied()) {
613
+ throw new AssertionError(
614
+ `Expected exactly ${assertionState.assertionCount} ${
615
+ assertionState.assertionCount === 1 ? "assertion" : "assertions"
616
+ } to be called, ` +
617
+ `but received ${assertionState.assertionTriggeredCount}`,
618
+ );
619
+ }
620
+ } finally {
621
+ assertionState.resetAssertionState();
622
+ }
623
+ },
624
+ };
625
+ if (ignore !== undefined) {
626
+ opts.ignore = ignore;
627
+ }
628
+ if (only !== undefined) {
629
+ opts.only = only;
630
+ }
631
+ if (permissions !== undefined) {
632
+ opts.permissions = permissions;
633
+ }
634
+ if (sanitizeExit !== undefined) {
635
+ opts.sanitizeExit = sanitizeExit;
636
+ }
637
+ if (sanitizeOps !== undefined) {
638
+ opts.sanitizeOps = sanitizeOps;
639
+ }
640
+ if (sanitizeResources !== undefined) {
641
+ opts.sanitizeResources = sanitizeResources;
642
+ }
643
+ TestSuiteInternal.registerTest(opts);
644
+ }
645
+ }
646
+
647
+ /**
648
+ * Only execute this test case.
649
+ *
650
+ * @example Usage
651
+ * ```ts ignore
652
+ * import { describe, it } from "@std/testing/bdd";
653
+ * import { assertEquals } from "@std/assert";
654
+ *
655
+ * describe("example", () => {
656
+ * it("should pass", () => {
657
+ * assertEquals(2 + 2, 4);
658
+ * });
659
+ *
660
+ * it.only("should pass too", () => {
661
+ * assertEquals(3 + 4, 7);
662
+ * });
663
+ * });
664
+ * ```
665
+ *
666
+ * @param args The test case
667
+ */
668
+ it.only = function itOnly<T>(...args: ItArgs<T>): void {
669
+ const options = itDefinition(...args);
670
+ return it({
671
+ ...options,
672
+ only: true,
673
+ });
674
+ };
675
+
676
+ /**
677
+ * Ignore this test case.
678
+ *
679
+ * @example Usage
680
+ * ```ts ignore
681
+ * import { describe, it } from "@std/testing/bdd";
682
+ * import { assertEquals } from "@std/assert";
683
+ *
684
+ * describe("example", () => {
685
+ * it("should pass", () => {
686
+ * assertEquals(2 + 2, 4);
687
+ * });
688
+ *
689
+ * it.ignore("should pass too", () => {
690
+ * assertEquals(3 + 4, 7);
691
+ * });
692
+ * });
693
+ * ```
694
+ *
695
+ * @param args The test case
696
+ */
697
+ it.ignore = function itIgnore<T>(...args: ItArgs<T>): void {
698
+ const options = itDefinition(...args);
699
+ return it({
700
+ ...options,
701
+ ignore: true,
702
+ });
703
+ };
704
+
705
+ /** Skip this test case.
706
+ *
707
+ * @example Usage
708
+ * ```ts ignore
709
+ * import { describe, it } from "@std/testing/bdd";
710
+ * import { assertEquals } from "@std/assert";
711
+ *
712
+ * describe("example", () => {
713
+ * it("should pass", () => {
714
+ * assertEquals(2 + 2, 4);
715
+ * });
716
+ *
717
+ * it.skip("should pass too", () => {
718
+ * assertEquals(3 + 4, 7);
719
+ * });
720
+ * });
721
+ * ```
722
+ *
723
+ * @param args The test case
724
+ */
725
+ it.skip = function itSkip<T>(...args: ItArgs<T>): void {
726
+ it.ignore(...args);
727
+ };
728
+
729
+ /**
730
+ * Alias of {@linkcode it}
731
+ *
732
+ * Registers an individual test case.
733
+ *
734
+ * @example Usage
735
+ * ```ts ignore
736
+ * import { test } from "@std/testing/bdd";
737
+ * import { assertEquals } from "@std/assert";
738
+ *
739
+ * test("a test case", () => {
740
+ * // test case
741
+ * assertEquals(2 + 2, 4);
742
+ * });
743
+ * ```
744
+ *
745
+ * @typeParam T The self type of the function to implement the test case
746
+ * @param args The test case
747
+ */
748
+ export function test<T>(...args: ItArgs<T>) {
749
+ it(...args);
750
+ }
751
+
752
+ /**
753
+ * Only execute this test case.
754
+ *
755
+ * @example Usage
756
+ * ```ts ignore
757
+ * import { describe, test } from "@std/testing/bdd";
758
+ * import { assertEquals } from "@std/assert";
759
+ *
760
+ * describe("example", () => {
761
+ * test("should pass", () => {
762
+ * assertEquals(2 + 2, 4);
763
+ * });
764
+ *
765
+ * test.only("should pass too", () => {
766
+ * assertEquals(3 + 4, 7);
767
+ * });
768
+ * });
769
+ * ```
770
+ *
771
+ * @param args The test case
772
+ */
773
+ test.only = function itOnly<T>(...args: ItArgs<T>): void {
774
+ it.only(...args);
775
+ };
776
+
777
+ /**
778
+ * Ignore this test case.
779
+ *
780
+ * @example Usage
781
+ * ```ts ignore
782
+ * import { describe, test } from "@std/testing/bdd";
783
+ * import { assertEquals } from "@std/assert";
784
+ *
785
+ * describe("example", () => {
786
+ * test("should pass", () => {
787
+ * assertEquals(2 + 2, 4);
788
+ * });
789
+ *
790
+ * test.ignore("should pass too", () => {
791
+ * assertEquals(3 + 4, 7);
792
+ * });
793
+ * });
794
+ * ```
795
+ *
796
+ * @param args The test case
797
+ */
798
+ test.ignore = function itIgnore<T>(...args: ItArgs<T>): void {
799
+ it.ignore(...args);
800
+ };
801
+
802
+ /** Skip this test case.
803
+ *
804
+ * @example Usage
805
+ * ```ts ignore
806
+ * import { describe, test } from "@std/testing/bdd";
807
+ * import { assertEquals } from "@std/assert";
808
+ *
809
+ * describe("example", () => {
810
+ * test("should pass", () => {
811
+ * assertEquals(2 + 2, 4);
812
+ * });
813
+ *
814
+ * test.skip("should pass too", () => {
815
+ * assertEquals(3 + 4, 7);
816
+ * });
817
+ * });
818
+ * ```
819
+ *
820
+ * @param args The test case
821
+ */
822
+ test.skip = function itSkip<T>(...args: ItArgs<T>): void {
823
+ it.ignore(...args);
824
+ };
825
+
826
+ function addHook<T>(
827
+ name: HookNames,
828
+ fn: (this: T) => void | Promise<void>,
829
+ ) {
830
+ if (!TestSuiteInternal.current) {
831
+ if (TestSuiteInternal.started) {
832
+ throw new Error(
833
+ "Cannot add global hooks after a global test is registered",
834
+ );
835
+ }
836
+ TestSuiteInternal.current = new TestSuiteInternal({
837
+ name: "global",
838
+ [name]: fn,
839
+ });
840
+ } else {
841
+ TestSuiteInternal.setHook(TestSuiteInternal.current!, name, fn);
842
+ }
843
+ }
844
+
845
+ /**
846
+ * Run some shared setup before all of the tests in the group.
847
+ * Useful for async setup in `describe` blocks. Outside them,
848
+ * top-level initialization code should be used instead.
849
+ *
850
+ * @example Usage
851
+ * ```ts ignore
852
+ * import { describe, it, beforeAll } from "@std/testing/bdd";
853
+ * import { assertEquals } from "@std/assert";
854
+ *
855
+ * beforeAll(() => {
856
+ * console.log("beforeAll");
857
+ * });
858
+ *
859
+ * describe("example", () => {
860
+ * it("should pass", () => {
861
+ * // test case
862
+ * assertEquals(2 + 2, 4);
863
+ * });
864
+ * });
865
+ * ```
866
+ *
867
+ * @typeParam T The self type of the function
868
+ * @param fn The function to implement the setup behavior.
869
+ */
870
+ export function beforeAll<T>(
871
+ fn: (this: T) => void | Promise<void>,
872
+ ) {
873
+ addHook("beforeAll", fn);
874
+ }
875
+
876
+ /**
877
+ * Alias of {@linkcode beforeAll}
878
+ *
879
+ * Run some shared setup before all of the tests in the suite.
880
+ *
881
+ * @example Usage
882
+ * ```ts ignore
883
+ * import { describe, it, before } from "@std/testing/bdd";
884
+ * import { assertEquals } from "@std/assert";
885
+ *
886
+ * before(() => {
887
+ * console.log("before");
888
+ * });
889
+ *
890
+ * describe("example", () => {
891
+ * it("should pass", () => {
892
+ * // test case
893
+ * assertEquals(2 + 2, 4);
894
+ * });
895
+ * });
896
+ * ```
897
+ *
898
+ * @typeParam T The self type of the function
899
+ * @param fn The function to implement the setup behavior.
900
+ */
901
+ export function before<T>(
902
+ fn: (this: T) => void | Promise<void>,
903
+ ) {
904
+ beforeAll(fn);
905
+ }
906
+
907
+ /**
908
+ * Run some shared teardown after all of the tests in the suite.
909
+ *
910
+ * @example Usage
911
+ * ```ts ignore
912
+ * import { describe, it, afterAll } from "@std/testing/bdd";
913
+ * import { assertEquals } from "@std/assert";
914
+ *
915
+ * afterAll(() => {
916
+ * console.log("afterAll");
917
+ * });
918
+ *
919
+ * describe("example", () => {
920
+ * it("should pass", () => {
921
+ * // test case
922
+ * assertEquals(2 + 2, 4);
923
+ * });
924
+ * });
925
+ * ```
926
+ *
927
+ * @typeParam T The self type of the function
928
+ * @param fn The function to implement the teardown behavior.
929
+ */
930
+ export function afterAll<T>(
931
+ fn: (this: T) => void | Promise<void>,
932
+ ) {
933
+ addHook("afterAll", fn);
934
+ }
935
+
936
+ /**
937
+ * Alias of {@linkcode afterAll}.
938
+ *
939
+ * Run some shared teardown after all of the tests in the suite.
940
+ *
941
+ * @example Usage
942
+ * ```ts ignore
943
+ * import { describe, it, after } from "@std/testing/bdd";
944
+ * import { assertEquals } from "@std/assert";
945
+ *
946
+ * after(() => {
947
+ * console.log("after");
948
+ * });
949
+ *
950
+ * describe("example", () => {
951
+ * it("should pass", () => {
952
+ * // test case
953
+ * assertEquals(2 + 2, 4);
954
+ * });
955
+ * });
956
+ * ```
957
+ *
958
+ * @typeParam T The self type of the function
959
+ * @param fn The function to implement the teardown behavior.
960
+ */
961
+ export function after<T>(
962
+ fn: (this: T) => void | Promise<void>,
963
+ ) {
964
+ afterAll(fn);
965
+ }
966
+
967
+ /**
968
+ * Run some shared setup before each test in the suite.
969
+ *
970
+ * @example Usage
971
+ * ```ts ignore
972
+ * import { describe, it, beforeEach } from "@std/testing/bdd";
973
+ * import { assertEquals } from "@std/assert";
974
+ *
975
+ * beforeEach(() => {
976
+ * console.log("beforeEach");
977
+ * });
978
+ *
979
+ * describe("example", () => {
980
+ * it("should pass", () => {
981
+ * // test case
982
+ * assertEquals(2 + 2, 4);
983
+ * });
984
+ * });
985
+ * ```
986
+ *
987
+ * @typeParam T The self type of the function
988
+ * @param fn The function to implement the shared setup behavior
989
+ */
990
+ export function beforeEach<T>(
991
+ fn: (this: T) => void | Promise<void>,
992
+ ) {
993
+ addHook("beforeEach", fn);
994
+ }
995
+
996
+ /**
997
+ * Run some shared teardown after each test in the suite.
998
+ *
999
+ * @example Usage
1000
+ * ```ts ignore
1001
+ * import { describe, it, afterEach } from "@std/testing/bdd";
1002
+ * import { assertEquals } from "@std/assert";
1003
+ *
1004
+ * afterEach(() => {
1005
+ * console.log("afterEach");
1006
+ * });
1007
+ *
1008
+ * describe("example", () => {
1009
+ * it("should pass", () => {
1010
+ * // test case
1011
+ * assertEquals(2 + 2, 4);
1012
+ * });
1013
+ * });
1014
+ * ```
1015
+ *
1016
+ * @typeParam T The self type of the function
1017
+ * @param fn The function to implement the shared teardown behavior
1018
+ */
1019
+ export function afterEach<T>(
1020
+ fn: (this: T) => void | Promise<void>,
1021
+ ) {
1022
+ addHook("afterEach", fn);
1023
+ }
1024
+
1025
+ /** The arguments for a DescribeFunction. */
1026
+ export type DescribeArgs<T> =
1027
+ | [options: DescribeDefinition<T>]
1028
+ | [name: string]
1029
+ | [
1030
+ name: string,
1031
+ options: Omit<DescribeDefinition<T>, "name">,
1032
+ ]
1033
+ | [name: string, fn: () => void | undefined]
1034
+ | [fn: () => void | undefined]
1035
+ | [
1036
+ name: string,
1037
+ options: Omit<DescribeDefinition<T>, "fn" | "name">,
1038
+ fn: () => void | undefined,
1039
+ ]
1040
+ | [
1041
+ options: Omit<DescribeDefinition<T>, "fn">,
1042
+ fn: () => void | undefined,
1043
+ ]
1044
+ | [
1045
+ options: Omit<DescribeDefinition<T>, "fn" | "name">,
1046
+ fn: () => void | undefined,
1047
+ ]
1048
+ | [
1049
+ suite: TestSuite<T>,
1050
+ name: string,
1051
+ ]
1052
+ | [
1053
+ suite: TestSuite<T>,
1054
+ name: string,
1055
+ options: Omit<DescribeDefinition<T>, "name" | "suite">,
1056
+ ]
1057
+ | [
1058
+ suite: TestSuite<T>,
1059
+ name: string,
1060
+ fn: () => void | undefined,
1061
+ ]
1062
+ | [
1063
+ suite: TestSuite<T>,
1064
+ fn: () => void | undefined,
1065
+ ]
1066
+ | [
1067
+ suite: TestSuite<T>,
1068
+ name: string,
1069
+ options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
1070
+ fn: () => void | undefined,
1071
+ ]
1072
+ | [
1073
+ suite: TestSuite<T>,
1074
+ options: Omit<DescribeDefinition<T>, "fn" | "suite">,
1075
+ fn: () => void | undefined,
1076
+ ]
1077
+ | [
1078
+ suite: TestSuite<T>,
1079
+ options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
1080
+ fn: () => void | undefined,
1081
+ ];
1082
+
1083
+ /** Generates a DescribeDefinition from DescribeArgs. */
1084
+ function describeDefinition<T>(
1085
+ ...args: DescribeArgs<T>
1086
+ ): DescribeDefinition<T> {
1087
+ let [
1088
+ suiteOptionsOrNameOrFn,
1089
+ optionsOrNameOrFn,
1090
+ optionsOrFn,
1091
+ fn,
1092
+ ] = args;
1093
+ let suite: TestSuite<T> | undefined = undefined;
1094
+ let name: string;
1095
+ let options:
1096
+ | DescribeDefinition<T>
1097
+ | Omit<DescribeDefinition<T>, "fn">
1098
+ | Omit<DescribeDefinition<T>, "name">
1099
+ | Omit<DescribeDefinition<T>, "fn" | "name">;
1100
+ if (
1101
+ typeof suiteOptionsOrNameOrFn === "object" &&
1102
+ typeof (suiteOptionsOrNameOrFn as TestSuite<T>).symbol === "symbol"
1103
+ ) {
1104
+ suite = suiteOptionsOrNameOrFn as TestSuite<T>;
1105
+ } else {
1106
+ fn = optionsOrFn as typeof fn;
1107
+ optionsOrFn = optionsOrNameOrFn as typeof optionsOrFn;
1108
+ optionsOrNameOrFn = suiteOptionsOrNameOrFn as typeof optionsOrNameOrFn;
1109
+ }
1110
+ if (typeof optionsOrNameOrFn === "string") {
1111
+ name = optionsOrNameOrFn;
1112
+ if (typeof optionsOrFn === "function") {
1113
+ fn = optionsOrFn;
1114
+ options = {};
1115
+ } else {
1116
+ options = optionsOrFn ?? {};
1117
+ if (fn === undefined) {
1118
+ fn = (options as Omit<DescribeDefinition<T>, "name">).fn;
1119
+ }
1120
+ }
1121
+ } else if (typeof optionsOrNameOrFn === "function") {
1122
+ fn = optionsOrNameOrFn;
1123
+ name = fn.name;
1124
+ options = {};
1125
+ } else {
1126
+ options = optionsOrNameOrFn ?? {};
1127
+ if (typeof optionsOrFn === "function") {
1128
+ fn = optionsOrFn;
1129
+ } else {
1130
+ fn = (options as DescribeDefinition<T>).fn;
1131
+ }
1132
+ name = (options as DescribeDefinition<T>).name ?? fn?.name ?? "";
1133
+ }
1134
+
1135
+ if (suite === undefined) {
1136
+ suite = options.suite;
1137
+ }
1138
+ if (suite === undefined && TestSuiteInternal.current) {
1139
+ const { symbol } = TestSuiteInternal.current;
1140
+ suite = { symbol };
1141
+ }
1142
+
1143
+ return {
1144
+ ...options,
1145
+ suite: suite!,
1146
+ name,
1147
+ fn: fn!,
1148
+ };
1149
+ }
1150
+
1151
+ /** Registers a test suite. */
1152
+ // deno-lint-ignore deno-style-guide/naming-convention
1153
+ export interface describe {
1154
+ <T>(...args: DescribeArgs<T>): TestSuite<T>;
1155
+
1156
+ /** Registers a test suite with only set to true. */
1157
+ only<T>(...args: DescribeArgs<T>): TestSuite<T>;
1158
+
1159
+ /** Registers a test suite with ignore set to true. */
1160
+ ignore<T>(...args: DescribeArgs<T>): TestSuite<T>;
1161
+
1162
+ /** Registers a test suite with ignore set to true. Alias of `.ignore()`. */
1163
+ skip<T>(...args: ItArgs<T>): void;
1164
+ }
1165
+
1166
+ /**
1167
+ * Registers a test suite.
1168
+ *
1169
+ * @example Usage
1170
+ * ```ts ignore
1171
+ * import { describe, it } from "@std/testing/bdd";
1172
+ * import { assertEquals } from "@std/assert";
1173
+ *
1174
+ * describe("example", () => {
1175
+ * it("should pass", () => {
1176
+ * // test case
1177
+ * assertEquals(2 + 2, 4);
1178
+ * });
1179
+ * });
1180
+ * ```
1181
+ *
1182
+ * @typeParam T The self type of the test suite body.
1183
+ * @param args The test suite body.
1184
+ * @returns The test suite
1185
+ */
1186
+ export function describe<T>(
1187
+ ...args: DescribeArgs<T>
1188
+ ): TestSuite<T> {
1189
+ if (TestSuiteInternal.runningCount > 0) {
1190
+ throw new Error(
1191
+ "Cannot register new test suites after already registered test cases start running",
1192
+ );
1193
+ }
1194
+ const options = describeDefinition(...args);
1195
+ if (!TestSuiteInternal.started) TestSuiteInternal.started = true;
1196
+ const { symbol } = new TestSuiteInternal(options);
1197
+ return { symbol };
1198
+ }
1199
+
1200
+ /**
1201
+ * Only execute this test suite.
1202
+ *
1203
+ * @example Usage
1204
+ * ```ts ignore
1205
+ * import { describe, it, beforeAll } from "@std/testing/bdd";
1206
+ * import { assertEquals } from "@std/assert";
1207
+ *
1208
+ * describe("example", () => {
1209
+ * it("should pass", () => {
1210
+ * assertEquals(2 + 2, 4);
1211
+ * });
1212
+ * });
1213
+ *
1214
+ * // Only this test suite will run
1215
+ * describe.only("example 2", () => {
1216
+ * it("should pass too", () => {
1217
+ * assertEquals(3 + 4, 7);
1218
+ * });
1219
+ * });
1220
+ * ```
1221
+ *
1222
+ * @param args The test suite body
1223
+ */
1224
+ describe.only = function describeOnly<T>(
1225
+ ...args: DescribeArgs<T>
1226
+ ): TestSuite<T> {
1227
+ const options = describeDefinition(...args);
1228
+ return describe({
1229
+ ...options,
1230
+ only: true,
1231
+ });
1232
+ };
1233
+
1234
+ /**
1235
+ * Ignore the test suite.
1236
+ *
1237
+ * @example Usage
1238
+ * ```ts ignore
1239
+ * import { describe, it, beforeAll } from "@std/testing/bdd";
1240
+ * import { assertEquals } from "@std/assert";
1241
+ *
1242
+ * describe("example", () => {
1243
+ * it("should pass", () => {
1244
+ * assertEquals(2 + 2, 4);
1245
+ * });
1246
+ * });
1247
+ *
1248
+ * describe.ignore("example 2", () => {
1249
+ * it("should pass too", () => {
1250
+ * assertEquals(3 + 4, 7);
1251
+ * });
1252
+ * });
1253
+ * ```
1254
+ *
1255
+ * @param args The test suite body
1256
+ */
1257
+ describe.ignore = function describeIgnore<T>(
1258
+ ...args: DescribeArgs<T>
1259
+ ): TestSuite<T> {
1260
+ const options = describeDefinition(...args);
1261
+ return describe({
1262
+ ...options,
1263
+ ignore: true,
1264
+ });
1265
+ };
1266
+
1267
+ /**
1268
+ * Skip the test suite.
1269
+ *
1270
+ * @example Usage
1271
+ * ```ts ignore
1272
+ * import { describe, it, beforeAll } from "@std/testing/bdd";
1273
+ * import { assertEquals } from "@std/assert";
1274
+ *
1275
+ * describe("example", () => {
1276
+ * it("should pass", () => {
1277
+ * assertEquals(2 + 2, 4);
1278
+ * });
1279
+ * });
1280
+ *
1281
+ * describe.skip("example 2", () => {
1282
+ * it("should pass too", () => {
1283
+ * assertEquals(3 + 4, 7);
1284
+ * });
1285
+ * });
1286
+ * ```
1287
+ *
1288
+ * @param args The test suite body
1289
+ */
1290
+ describe.skip = function describeSkip<T>(
1291
+ ...args: DescribeArgs<T>
1292
+ ): TestSuite<T> {
1293
+ return describe.ignore(...args);
1294
+ };