typenative 0.1.2 → 0.2.0

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 (504) hide show
  1. package/.gitattributes +1 -0
  2. package/.github/workflows/ci.yml +1 -1
  3. package/.github/workflows/npm-publish-github-packages.yml +1 -1
  4. package/CHANGELOG.md +247 -0
  5. package/CONTRIBUTION.md +1 -1
  6. package/README.md +30 -21
  7. package/bin/cli.js +3 -1
  8. package/bin/go/bridge.js +919 -0
  9. package/bin/go/convert.js +238 -0
  10. package/bin/go/metadata.js +211 -0
  11. package/bin/go/overrides.js +68 -0
  12. package/bin/go/stdlib.generated.js +175 -0
  13. package/bin/index.js +98 -6
  14. package/bin/main.js +4 -1
  15. package/bin/node/assert.js +344 -0
  16. package/bin/node/async_hooks.js +273 -0
  17. package/bin/node/buffer.js +765 -0
  18. package/bin/node/child_process.js +600 -0
  19. package/bin/node/cluster.js +1002 -0
  20. package/bin/node/console.js +121 -0
  21. package/bin/node/core.js +111 -0
  22. package/bin/node/crypto.js +414 -0
  23. package/bin/node/crypto_keys.js +2685 -0
  24. package/bin/node/dgram.js +388 -0
  25. package/bin/node/diagnostics_channel.js +534 -0
  26. package/bin/node/dns.js +635 -0
  27. package/bin/node/events.js +743 -0
  28. package/bin/node/fetch.js +737 -0
  29. package/bin/node/fs.js +998 -0
  30. package/bin/node/http.js +1500 -0
  31. package/bin/node/http2.js +688 -0
  32. package/bin/node/net.js +1143 -0
  33. package/bin/node/os.js +257 -0
  34. package/bin/node/path.js +758 -0
  35. package/bin/node/process.js +316 -0
  36. package/bin/node/punycode.js +195 -0
  37. package/bin/node/querystring.js +143 -0
  38. package/bin/node/readline.js +299 -0
  39. package/bin/node/registry.js +161 -0
  40. package/bin/node/sqlite.js +1142 -0
  41. package/bin/node/stream.js +1221 -0
  42. package/bin/node/stream_web.js +2259 -0
  43. package/bin/node/string_decoder.js +101 -0
  44. package/bin/node/system_extra.js +661 -0
  45. package/bin/node/test.js +1068 -0
  46. package/bin/node/timers.js +250 -0
  47. package/bin/node/tls.js +719 -0
  48. package/bin/node/url.js +861 -0
  49. package/bin/node/util.js +1311 -0
  50. package/bin/node/util_extra.js +599 -0
  51. package/bin/node/worker_threads.js +745 -0
  52. package/bin/node/zlib.js +263 -0
  53. package/bin/parse-native.js +3 -2
  54. package/bin/parse-node.js +18 -2
  55. package/bin/transpiler.js +3529 -597
  56. package/bin/version.js +2 -0
  57. package/conformance.md +724 -258
  58. package/govendor/github.com/ncruces/go-sqlite3/LICENSE +21 -0
  59. package/govendor/github.com/ncruces/go-sqlite3/README.md +121 -0
  60. package/govendor/github.com/ncruces/go-sqlite3/backup.go +132 -0
  61. package/govendor/github.com/ncruces/go-sqlite3/blob.go +266 -0
  62. package/govendor/github.com/ncruces/go-sqlite3/config.go +397 -0
  63. package/govendor/github.com/ncruces/go-sqlite3/conn.go +540 -0
  64. package/govendor/github.com/ncruces/go-sqlite3/conn_127.go +93 -0
  65. package/govendor/github.com/ncruces/go-sqlite3/const.go +436 -0
  66. package/govendor/github.com/ncruces/go-sqlite3/context.go +222 -0
  67. package/govendor/github.com/ncruces/go-sqlite3/error.go +182 -0
  68. package/govendor/github.com/ncruces/go-sqlite3/ext.go +153 -0
  69. package/govendor/github.com/ncruces/go-sqlite3/func.go +309 -0
  70. package/govendor/github.com/ncruces/go-sqlite3/go.mod +3 -0
  71. package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk.go +29 -0
  72. package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk_other.go +13 -0
  73. package/govendor/github.com/ncruces/go-sqlite3/internal/dotlk/dotlk_unix.go +57 -0
  74. package/govendor/github.com/ncruces/go-sqlite3/internal/errutil/error.go +41 -0
  75. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/alloc.go +128 -0
  76. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/const.go +122 -0
  77. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/error.go +77 -0
  78. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem.go +116 -0
  79. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_other.go +34 -0
  80. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_unix.go +87 -0
  81. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mem_windows.go +149 -0
  82. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mmap_unix.go +80 -0
  83. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/mmap_windows.go +129 -0
  84. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/sys_windows.go +60 -0
  85. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap.go +82 -0
  86. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap_sys.go +113 -0
  87. package/govendor/github.com/ncruces/go-sqlite3/internal/sqlite3_wrap/wrap_vfs.go +181 -0
  88. package/govendor/github.com/ncruces/go-sqlite3/internal/testenv/env.go +55 -0
  89. package/govendor/github.com/ncruces/go-sqlite3/internal/util/json.go +54 -0
  90. package/govendor/github.com/ncruces/go-sqlite3/internal/util/json_v2.go +54 -0
  91. package/govendor/github.com/ncruces/go-sqlite3/internal/util/math.go +29 -0
  92. package/govendor/github.com/ncruces/go-sqlite3/internal/util/page.go +5 -0
  93. package/govendor/github.com/ncruces/go-sqlite3/internal/util/parse.go +142 -0
  94. package/govendor/github.com/ncruces/go-sqlite3/internal/util/pointer.go +3 -0
  95. package/govendor/github.com/ncruces/go-sqlite3/internal/util/reflect.go +10 -0
  96. package/govendor/github.com/ncruces/go-sqlite3/json.go +100 -0
  97. package/govendor/github.com/ncruces/go-sqlite3/json_v2.go +116 -0
  98. package/govendor/github.com/ncruces/go-sqlite3/pointer.go +13 -0
  99. package/govendor/github.com/ncruces/go-sqlite3/quote.go +140 -0
  100. package/govendor/github.com/ncruces/go-sqlite3/stmt.go +692 -0
  101. package/govendor/github.com/ncruces/go-sqlite3/time.go +360 -0
  102. package/govendor/github.com/ncruces/go-sqlite3/txn.go +374 -0
  103. package/govendor/github.com/ncruces/go-sqlite3/value.go +212 -0
  104. package/govendor/github.com/ncruces/go-sqlite3/vfs/README.md +133 -0
  105. package/govendor/github.com/ncruces/go-sqlite3/vfs/api.go +239 -0
  106. package/govendor/github.com/ncruces/go-sqlite3/vfs/cksm.go +143 -0
  107. package/govendor/github.com/ncruces/go-sqlite3/vfs/const.go +256 -0
  108. package/govendor/github.com/ncruces/go-sqlite3/vfs/file.go +260 -0
  109. package/govendor/github.com/ncruces/go-sqlite3/vfs/filename.go +187 -0
  110. package/govendor/github.com/ncruces/go-sqlite3/vfs/lock.go +128 -0
  111. package/govendor/github.com/ncruces/go-sqlite3/vfs/lock_other.go +23 -0
  112. package/govendor/github.com/ncruces/go-sqlite3/vfs/map.go +63 -0
  113. package/govendor/github.com/ncruces/go-sqlite3/vfs/map_other.go +13 -0
  114. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go +110 -0
  115. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_darwin.go +131 -0
  116. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_dotlk.go +140 -0
  117. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_f2fs_linux.go +56 -0
  118. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_linux.go +117 -0
  119. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_ofd.go +59 -0
  120. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std.go +50 -0
  121. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_alloc.go +19 -0
  122. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_atomic.go +9 -0
  123. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_rw.go +13 -0
  124. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_sync.go +9 -0
  125. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_std_temp.go +16 -0
  126. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_unix.go +108 -0
  127. package/govendor/github.com/ncruces/go-sqlite3/vfs/os_windows.go +180 -0
  128. package/govendor/github.com/ncruces/go-sqlite3/vfs/registry.go +48 -0
  129. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm.go +26 -0
  130. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_bsd.go +258 -0
  131. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_copy.go +90 -0
  132. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_dotlk.go +168 -0
  133. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_memlk.go +52 -0
  134. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_ofd.go +185 -0
  135. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_other.go +21 -0
  136. package/govendor/github.com/ncruces/go-sqlite3/vfs/shm_windows.go +124 -0
  137. package/govendor/github.com/ncruces/go-sqlite3/vfs/vfs.go +455 -0
  138. package/govendor/github.com/ncruces/go-sqlite3/vtab.go +677 -0
  139. package/govendor/github.com/ncruces/go-sqlite3/wrap.go +48 -0
  140. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/LICENSE +18 -0
  141. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/README.md +11 -0
  142. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/go.mod +3 -0
  143. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/libc.go +215 -0
  144. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/sqlite3.dat +0 -0
  145. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/sqlite3.go +157903 -0
  146. package/govendor/github.com/ncruces/go-sqlite3-wasm/v6/tools.sh +38 -0
  147. package/govendor/github.com/ncruces/julianday/LICENSE +21 -0
  148. package/govendor/github.com/ncruces/julianday/README.md +9 -0
  149. package/govendor/github.com/ncruces/julianday/go.mod +3 -0
  150. package/govendor/github.com/ncruces/julianday/julianday.go +124 -0
  151. package/govendor/golang.org/x/sys/LICENSE +27 -0
  152. package/govendor/golang.org/x/sys/PATENTS +22 -0
  153. package/govendor/golang.org/x/sys/go.mod +3 -0
  154. package/govendor/golang.org/x/sys/unix/README.md +184 -0
  155. package/govendor/golang.org/x/sys/unix/affinity_linux.go +189 -0
  156. package/govendor/golang.org/x/sys/unix/aliases.go +13 -0
  157. package/govendor/golang.org/x/sys/unix/asm_aix_ppc64.s +17 -0
  158. package/govendor/golang.org/x/sys/unix/asm_bsd_386.s +27 -0
  159. package/govendor/golang.org/x/sys/unix/asm_bsd_amd64.s +27 -0
  160. package/govendor/golang.org/x/sys/unix/asm_bsd_arm.s +27 -0
  161. package/govendor/golang.org/x/sys/unix/asm_bsd_arm64.s +27 -0
  162. package/govendor/golang.org/x/sys/unix/asm_bsd_ppc64.s +29 -0
  163. package/govendor/golang.org/x/sys/unix/asm_bsd_riscv64.s +27 -0
  164. package/govendor/golang.org/x/sys/unix/asm_linux_386.s +65 -0
  165. package/govendor/golang.org/x/sys/unix/asm_linux_amd64.s +57 -0
  166. package/govendor/golang.org/x/sys/unix/asm_linux_arm.s +56 -0
  167. package/govendor/golang.org/x/sys/unix/asm_linux_arm64.s +50 -0
  168. package/govendor/golang.org/x/sys/unix/asm_linux_loong64.s +51 -0
  169. package/govendor/golang.org/x/sys/unix/asm_linux_mips64x.s +54 -0
  170. package/govendor/golang.org/x/sys/unix/asm_linux_mipsx.s +52 -0
  171. package/govendor/golang.org/x/sys/unix/asm_linux_ppc64x.s +42 -0
  172. package/govendor/golang.org/x/sys/unix/asm_linux_riscv64.s +47 -0
  173. package/govendor/golang.org/x/sys/unix/asm_linux_s390x.s +54 -0
  174. package/govendor/golang.org/x/sys/unix/asm_openbsd_mips64.s +29 -0
  175. package/govendor/golang.org/x/sys/unix/asm_solaris_amd64.s +17 -0
  176. package/govendor/golang.org/x/sys/unix/asm_zos_s390x.s +382 -0
  177. package/govendor/golang.org/x/sys/unix/auxv.go +36 -0
  178. package/govendor/golang.org/x/sys/unix/auxv_unsupported.go +13 -0
  179. package/govendor/golang.org/x/sys/unix/bluetooth_linux.go +36 -0
  180. package/govendor/golang.org/x/sys/unix/bpxsvc_zos.go +657 -0
  181. package/govendor/golang.org/x/sys/unix/bpxsvc_zos.s +192 -0
  182. package/govendor/golang.org/x/sys/unix/cap_freebsd.go +195 -0
  183. package/govendor/golang.org/x/sys/unix/constants.go +13 -0
  184. package/govendor/golang.org/x/sys/unix/dev_aix_ppc.go +26 -0
  185. package/govendor/golang.org/x/sys/unix/dev_aix_ppc64.go +28 -0
  186. package/govendor/golang.org/x/sys/unix/dev_darwin.go +24 -0
  187. package/govendor/golang.org/x/sys/unix/dev_dragonfly.go +30 -0
  188. package/govendor/golang.org/x/sys/unix/dev_freebsd.go +30 -0
  189. package/govendor/golang.org/x/sys/unix/dev_linux.go +42 -0
  190. package/govendor/golang.org/x/sys/unix/dev_netbsd.go +29 -0
  191. package/govendor/golang.org/x/sys/unix/dev_openbsd.go +29 -0
  192. package/govendor/golang.org/x/sys/unix/dev_zos.go +28 -0
  193. package/govendor/golang.org/x/sys/unix/dirent.go +102 -0
  194. package/govendor/golang.org/x/sys/unix/endian_big.go +9 -0
  195. package/govendor/golang.org/x/sys/unix/endian_little.go +9 -0
  196. package/govendor/golang.org/x/sys/unix/env_unix.go +31 -0
  197. package/govendor/golang.org/x/sys/unix/fcntl.go +36 -0
  198. package/govendor/golang.org/x/sys/unix/fcntl_darwin.go +24 -0
  199. package/govendor/golang.org/x/sys/unix/fcntl_linux_32bit.go +13 -0
  200. package/govendor/golang.org/x/sys/unix/fdset.go +27 -0
  201. package/govendor/golang.org/x/sys/unix/gccgo.go +59 -0
  202. package/govendor/golang.org/x/sys/unix/gccgo_c.c +44 -0
  203. package/govendor/golang.org/x/sys/unix/gccgo_linux_amd64.go +20 -0
  204. package/govendor/golang.org/x/sys/unix/ifreq_linux.go +145 -0
  205. package/govendor/golang.org/x/sys/unix/ioctl_linux.go +341 -0
  206. package/govendor/golang.org/x/sys/unix/ioctl_signed.go +74 -0
  207. package/govendor/golang.org/x/sys/unix/ioctl_unsigned.go +74 -0
  208. package/govendor/golang.org/x/sys/unix/ioctl_zos.go +71 -0
  209. package/govendor/golang.org/x/sys/unix/mkall.sh +250 -0
  210. package/govendor/golang.org/x/sys/unix/mkerrors.sh +807 -0
  211. package/govendor/golang.org/x/sys/unix/mmap_nomremap.go +13 -0
  212. package/govendor/golang.org/x/sys/unix/mremap.go +57 -0
  213. package/govendor/golang.org/x/sys/unix/pagesize_unix.go +15 -0
  214. package/govendor/golang.org/x/sys/unix/pledge_openbsd.go +111 -0
  215. package/govendor/golang.org/x/sys/unix/ptrace_darwin.go +11 -0
  216. package/govendor/golang.org/x/sys/unix/ptrace_ios.go +11 -0
  217. package/govendor/golang.org/x/sys/unix/race.go +30 -0
  218. package/govendor/golang.org/x/sys/unix/race0.go +25 -0
  219. package/govendor/golang.org/x/sys/unix/readdirent_getdents.go +12 -0
  220. package/govendor/golang.org/x/sys/unix/readdirent_getdirentries.go +19 -0
  221. package/govendor/golang.org/x/sys/unix/readv_unix.go +103 -0
  222. package/govendor/golang.org/x/sys/unix/sockcmsg_dragonfly.go +16 -0
  223. package/govendor/golang.org/x/sys/unix/sockcmsg_linux.go +85 -0
  224. package/govendor/golang.org/x/sys/unix/sockcmsg_unix.go +106 -0
  225. package/govendor/golang.org/x/sys/unix/sockcmsg_unix_other.go +46 -0
  226. package/govendor/golang.org/x/sys/unix/sockcmsg_zos.go +58 -0
  227. package/govendor/golang.org/x/sys/unix/symaddr_zos_s390x.s +75 -0
  228. package/govendor/golang.org/x/sys/unix/syscall.go +86 -0
  229. package/govendor/golang.org/x/sys/unix/syscall_aix.go +582 -0
  230. package/govendor/golang.org/x/sys/unix/syscall_aix_ppc.go +52 -0
  231. package/govendor/golang.org/x/sys/unix/syscall_aix_ppc64.go +83 -0
  232. package/govendor/golang.org/x/sys/unix/syscall_bsd.go +609 -0
  233. package/govendor/golang.org/x/sys/unix/syscall_darwin.go +711 -0
  234. package/govendor/golang.org/x/sys/unix/syscall_darwin_amd64.go +50 -0
  235. package/govendor/golang.org/x/sys/unix/syscall_darwin_arm64.go +50 -0
  236. package/govendor/golang.org/x/sys/unix/syscall_darwin_libSystem.go +26 -0
  237. package/govendor/golang.org/x/sys/unix/syscall_dragonfly.go +359 -0
  238. package/govendor/golang.org/x/sys/unix/syscall_dragonfly_amd64.go +56 -0
  239. package/govendor/golang.org/x/sys/unix/syscall_freebsd.go +455 -0
  240. package/govendor/golang.org/x/sys/unix/syscall_freebsd_386.go +64 -0
  241. package/govendor/golang.org/x/sys/unix/syscall_freebsd_amd64.go +64 -0
  242. package/govendor/golang.org/x/sys/unix/syscall_freebsd_arm.go +60 -0
  243. package/govendor/golang.org/x/sys/unix/syscall_freebsd_arm64.go +60 -0
  244. package/govendor/golang.org/x/sys/unix/syscall_freebsd_riscv64.go +60 -0
  245. package/govendor/golang.org/x/sys/unix/syscall_hurd.go +30 -0
  246. package/govendor/golang.org/x/sys/unix/syscall_hurd_386.go +28 -0
  247. package/govendor/golang.org/x/sys/unix/syscall_illumos.go +78 -0
  248. package/govendor/golang.org/x/sys/unix/syscall_linux.go +2574 -0
  249. package/govendor/golang.org/x/sys/unix/syscall_linux_386.go +313 -0
  250. package/govendor/golang.org/x/sys/unix/syscall_linux_alarm.go +12 -0
  251. package/govendor/golang.org/x/sys/unix/syscall_linux_amd64.go +144 -0
  252. package/govendor/golang.org/x/sys/unix/syscall_linux_amd64_gc.go +12 -0
  253. package/govendor/golang.org/x/sys/unix/syscall_linux_arm.go +218 -0
  254. package/govendor/golang.org/x/sys/unix/syscall_linux_arm64.go +188 -0
  255. package/govendor/golang.org/x/sys/unix/syscall_linux_gc.go +14 -0
  256. package/govendor/golang.org/x/sys/unix/syscall_linux_gc_386.go +16 -0
  257. package/govendor/golang.org/x/sys/unix/syscall_linux_gc_arm.go +13 -0
  258. package/govendor/golang.org/x/sys/unix/syscall_linux_gccgo_386.go +30 -0
  259. package/govendor/golang.org/x/sys/unix/syscall_linux_gccgo_arm.go +20 -0
  260. package/govendor/golang.org/x/sys/unix/syscall_linux_loong64.go +220 -0
  261. package/govendor/golang.org/x/sys/unix/syscall_linux_mips64x.go +187 -0
  262. package/govendor/golang.org/x/sys/unix/syscall_linux_mipsx.go +173 -0
  263. package/govendor/golang.org/x/sys/unix/syscall_linux_ppc.go +203 -0
  264. package/govendor/golang.org/x/sys/unix/syscall_linux_ppc64x.go +114 -0
  265. package/govendor/golang.org/x/sys/unix/syscall_linux_riscv64.go +193 -0
  266. package/govendor/golang.org/x/sys/unix/syscall_linux_s390x.go +295 -0
  267. package/govendor/golang.org/x/sys/unix/syscall_linux_sparc64.go +111 -0
  268. package/govendor/golang.org/x/sys/unix/syscall_netbsd.go +388 -0
  269. package/govendor/golang.org/x/sys/unix/syscall_netbsd_386.go +37 -0
  270. package/govendor/golang.org/x/sys/unix/syscall_netbsd_amd64.go +37 -0
  271. package/govendor/golang.org/x/sys/unix/syscall_netbsd_arm.go +37 -0
  272. package/govendor/golang.org/x/sys/unix/syscall_netbsd_arm64.go +37 -0
  273. package/govendor/golang.org/x/sys/unix/syscall_openbsd.go +346 -0
  274. package/govendor/golang.org/x/sys/unix/syscall_openbsd_386.go +41 -0
  275. package/govendor/golang.org/x/sys/unix/syscall_openbsd_amd64.go +41 -0
  276. package/govendor/golang.org/x/sys/unix/syscall_openbsd_arm.go +41 -0
  277. package/govendor/golang.org/x/sys/unix/syscall_openbsd_arm64.go +41 -0
  278. package/govendor/golang.org/x/sys/unix/syscall_openbsd_libc.go +26 -0
  279. package/govendor/golang.org/x/sys/unix/syscall_openbsd_mips64.go +39 -0
  280. package/govendor/golang.org/x/sys/unix/syscall_openbsd_ppc64.go +41 -0
  281. package/govendor/golang.org/x/sys/unix/syscall_openbsd_riscv64.go +41 -0
  282. package/govendor/golang.org/x/sys/unix/syscall_solaris.go +1183 -0
  283. package/govendor/golang.org/x/sys/unix/syscall_solaris_amd64.go +27 -0
  284. package/govendor/golang.org/x/sys/unix/syscall_unix.go +619 -0
  285. package/govendor/golang.org/x/sys/unix/syscall_unix_gc.go +14 -0
  286. package/govendor/golang.org/x/sys/unix/syscall_unix_gc_ppc64x.go +22 -0
  287. package/govendor/golang.org/x/sys/unix/syscall_zos_s390x.go +3213 -0
  288. package/govendor/golang.org/x/sys/unix/sysvshm_linux.go +20 -0
  289. package/govendor/golang.org/x/sys/unix/sysvshm_unix.go +51 -0
  290. package/govendor/golang.org/x/sys/unix/sysvshm_unix_other.go +13 -0
  291. package/govendor/golang.org/x/sys/unix/timestruct.go +76 -0
  292. package/govendor/golang.org/x/sys/unix/unveil_openbsd.go +51 -0
  293. package/govendor/golang.org/x/sys/unix/vgetrandom_linux.go +13 -0
  294. package/govendor/golang.org/x/sys/unix/vgetrandom_unsupported.go +11 -0
  295. package/govendor/golang.org/x/sys/unix/xattr_bsd.go +280 -0
  296. package/govendor/golang.org/x/sys/unix/zerrors_aix_ppc.go +1384 -0
  297. package/govendor/golang.org/x/sys/unix/zerrors_aix_ppc64.go +1385 -0
  298. package/govendor/golang.org/x/sys/unix/zerrors_darwin_amd64.go +1922 -0
  299. package/govendor/golang.org/x/sys/unix/zerrors_darwin_arm64.go +1922 -0
  300. package/govendor/golang.org/x/sys/unix/zerrors_dragonfly_amd64.go +1737 -0
  301. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_386.go +2042 -0
  302. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_amd64.go +2039 -0
  303. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_arm.go +2033 -0
  304. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_arm64.go +2033 -0
  305. package/govendor/golang.org/x/sys/unix/zerrors_freebsd_riscv64.go +2147 -0
  306. package/govendor/golang.org/x/sys/unix/zerrors_linux.go +4209 -0
  307. package/govendor/golang.org/x/sys/unix/zerrors_linux_386.go +882 -0
  308. package/govendor/golang.org/x/sys/unix/zerrors_linux_amd64.go +882 -0
  309. package/govendor/golang.org/x/sys/unix/zerrors_linux_arm.go +887 -0
  310. package/govendor/golang.org/x/sys/unix/zerrors_linux_arm64.go +884 -0
  311. package/govendor/golang.org/x/sys/unix/zerrors_linux_loong64.go +874 -0
  312. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips.go +888 -0
  313. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64.go +888 -0
  314. package/govendor/golang.org/x/sys/unix/zerrors_linux_mips64le.go +888 -0
  315. package/govendor/golang.org/x/sys/unix/zerrors_linux_mipsle.go +888 -0
  316. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc.go +940 -0
  317. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64.go +944 -0
  318. package/govendor/golang.org/x/sys/unix/zerrors_linux_ppc64le.go +944 -0
  319. package/govendor/golang.org/x/sys/unix/zerrors_linux_riscv64.go +884 -0
  320. package/govendor/golang.org/x/sys/unix/zerrors_linux_s390x.go +943 -0
  321. package/govendor/golang.org/x/sys/unix/zerrors_linux_sparc64.go +992 -0
  322. package/govendor/golang.org/x/sys/unix/zerrors_netbsd_386.go +1779 -0
  323. package/govendor/golang.org/x/sys/unix/zerrors_netbsd_amd64.go +1769 -0
  324. package/govendor/golang.org/x/sys/unix/zerrors_netbsd_arm.go +1758 -0
  325. package/govendor/golang.org/x/sys/unix/zerrors_netbsd_arm64.go +1769 -0
  326. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_386.go +1905 -0
  327. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_amd64.go +1905 -0
  328. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_arm.go +1905 -0
  329. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_arm64.go +1905 -0
  330. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_mips64.go +1905 -0
  331. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_ppc64.go +1904 -0
  332. package/govendor/golang.org/x/sys/unix/zerrors_openbsd_riscv64.go +1903 -0
  333. package/govendor/golang.org/x/sys/unix/zerrors_solaris_amd64.go +1556 -0
  334. package/govendor/golang.org/x/sys/unix/zerrors_zos_s390x.go +990 -0
  335. package/govendor/golang.org/x/sys/unix/zptrace_armnn_linux.go +40 -0
  336. package/govendor/golang.org/x/sys/unix/zptrace_linux_arm64.go +17 -0
  337. package/govendor/golang.org/x/sys/unix/zptrace_mipsnn_linux.go +49 -0
  338. package/govendor/golang.org/x/sys/unix/zptrace_mipsnnle_linux.go +49 -0
  339. package/govendor/golang.org/x/sys/unix/zptrace_x86_linux.go +79 -0
  340. package/govendor/golang.org/x/sys/unix/zsymaddr_zos_s390x.s +364 -0
  341. package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc.go +1461 -0
  342. package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64.go +1420 -0
  343. package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gc.go +1188 -0
  344. package/govendor/golang.org/x/sys/unix/zsyscall_aix_ppc64_gccgo.go +1069 -0
  345. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.go +2728 -0
  346. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_amd64.s +799 -0
  347. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.go +2728 -0
  348. package/govendor/golang.org/x/sys/unix/zsyscall_darwin_arm64.s +799 -0
  349. package/govendor/golang.org/x/sys/unix/zsyscall_dragonfly_amd64.go +1666 -0
  350. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_386.go +1886 -0
  351. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_amd64.go +1886 -0
  352. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm.go +1886 -0
  353. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_arm64.go +1886 -0
  354. package/govendor/golang.org/x/sys/unix/zsyscall_freebsd_riscv64.go +1886 -0
  355. package/govendor/golang.org/x/sys/unix/zsyscall_illumos_amd64.go +101 -0
  356. package/govendor/golang.org/x/sys/unix/zsyscall_linux.go +2267 -0
  357. package/govendor/golang.org/x/sys/unix/zsyscall_linux_386.go +469 -0
  358. package/govendor/golang.org/x/sys/unix/zsyscall_linux_amd64.go +636 -0
  359. package/govendor/golang.org/x/sys/unix/zsyscall_linux_arm.go +584 -0
  360. package/govendor/golang.org/x/sys/unix/zsyscall_linux_arm64.go +535 -0
  361. package/govendor/golang.org/x/sys/unix/zsyscall_linux_loong64.go +469 -0
  362. package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips.go +636 -0
  363. package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips64.go +630 -0
  364. package/govendor/golang.org/x/sys/unix/zsyscall_linux_mips64le.go +619 -0
  365. package/govendor/golang.org/x/sys/unix/zsyscall_linux_mipsle.go +636 -0
  366. package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc.go +641 -0
  367. package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc64.go +687 -0
  368. package/govendor/golang.org/x/sys/unix/zsyscall_linux_ppc64le.go +687 -0
  369. package/govendor/golang.org/x/sys/unix/zsyscall_linux_riscv64.go +531 -0
  370. package/govendor/golang.org/x/sys/unix/zsyscall_linux_s390x.go +478 -0
  371. package/govendor/golang.org/x/sys/unix/zsyscall_linux_sparc64.go +631 -0
  372. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_386.go +1848 -0
  373. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_amd64.go +1848 -0
  374. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm.go +1848 -0
  375. package/govendor/golang.org/x/sys/unix/zsyscall_netbsd_arm64.go +1848 -0
  376. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_386.go +2407 -0
  377. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_386.s +719 -0
  378. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.go +2407 -0
  379. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_amd64.s +719 -0
  380. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.go +2407 -0
  381. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm.s +719 -0
  382. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.go +2407 -0
  383. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_arm64.s +719 -0
  384. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.go +2407 -0
  385. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_mips64.s +719 -0
  386. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_ppc64.go +2407 -0
  387. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_ppc64.s +862 -0
  388. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_riscv64.go +2407 -0
  389. package/govendor/golang.org/x/sys/unix/zsyscall_openbsd_riscv64.s +719 -0
  390. package/govendor/golang.org/x/sys/unix/zsyscall_solaris_amd64.go +2217 -0
  391. package/govendor/golang.org/x/sys/unix/zsyscall_zos_s390x.go +3458 -0
  392. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_386.go +280 -0
  393. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_amd64.go +280 -0
  394. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_arm.go +280 -0
  395. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_arm64.go +280 -0
  396. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_mips64.go +280 -0
  397. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_ppc64.go +280 -0
  398. package/govendor/golang.org/x/sys/unix/zsysctl_openbsd_riscv64.go +281 -0
  399. package/govendor/golang.org/x/sys/unix/zsysnum_darwin_amd64.go +439 -0
  400. package/govendor/golang.org/x/sys/unix/zsysnum_darwin_arm64.go +437 -0
  401. package/govendor/golang.org/x/sys/unix/zsysnum_dragonfly_amd64.go +316 -0
  402. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go +393 -0
  403. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go +393 -0
  404. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go +393 -0
  405. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_arm64.go +393 -0
  406. package/govendor/golang.org/x/sys/unix/zsysnum_freebsd_riscv64.go +393 -0
  407. package/govendor/golang.org/x/sys/unix/zsysnum_linux_386.go +470 -0
  408. package/govendor/golang.org/x/sys/unix/zsysnum_linux_amd64.go +394 -0
  409. package/govendor/golang.org/x/sys/unix/zsysnum_linux_arm.go +434 -0
  410. package/govendor/golang.org/x/sys/unix/zsysnum_linux_arm64.go +337 -0
  411. package/govendor/golang.org/x/sys/unix/zsysnum_linux_loong64.go +334 -0
  412. package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips.go +454 -0
  413. package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips64.go +384 -0
  414. package/govendor/golang.org/x/sys/unix/zsysnum_linux_mips64le.go +384 -0
  415. package/govendor/golang.org/x/sys/unix/zsysnum_linux_mipsle.go +454 -0
  416. package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc.go +461 -0
  417. package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc64.go +433 -0
  418. package/govendor/golang.org/x/sys/unix/zsysnum_linux_ppc64le.go +433 -0
  419. package/govendor/golang.org/x/sys/unix/zsysnum_linux_riscv64.go +338 -0
  420. package/govendor/golang.org/x/sys/unix/zsysnum_linux_s390x.go +399 -0
  421. package/govendor/golang.org/x/sys/unix/zsysnum_linux_sparc64.go +413 -0
  422. package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go +274 -0
  423. package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go +274 -0
  424. package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go +274 -0
  425. package/govendor/golang.org/x/sys/unix/zsysnum_netbsd_arm64.go +274 -0
  426. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_386.go +219 -0
  427. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_amd64.go +219 -0
  428. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_arm.go +219 -0
  429. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_arm64.go +218 -0
  430. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_mips64.go +221 -0
  431. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_ppc64.go +217 -0
  432. package/govendor/golang.org/x/sys/unix/zsysnum_openbsd_riscv64.go +218 -0
  433. package/govendor/golang.org/x/sys/unix/zsysnum_zos_s390x.go +2852 -0
  434. package/govendor/golang.org/x/sys/unix/ztypes_aix_ppc.go +353 -0
  435. package/govendor/golang.org/x/sys/unix/ztypes_aix_ppc64.go +357 -0
  436. package/govendor/golang.org/x/sys/unix/ztypes_darwin_amd64.go +878 -0
  437. package/govendor/golang.org/x/sys/unix/ztypes_darwin_arm64.go +878 -0
  438. package/govendor/golang.org/x/sys/unix/ztypes_dragonfly_amd64.go +473 -0
  439. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_386.go +651 -0
  440. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_amd64.go +656 -0
  441. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_arm.go +642 -0
  442. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_arm64.go +636 -0
  443. package/govendor/golang.org/x/sys/unix/ztypes_freebsd_riscv64.go +638 -0
  444. package/govendor/golang.org/x/sys/unix/ztypes_linux.go +6547 -0
  445. package/govendor/golang.org/x/sys/unix/ztypes_linux_386.go +747 -0
  446. package/govendor/golang.org/x/sys/unix/ztypes_linux_amd64.go +761 -0
  447. package/govendor/golang.org/x/sys/unix/ztypes_linux_arm.go +741 -0
  448. package/govendor/golang.org/x/sys/unix/ztypes_linux_arm64.go +740 -0
  449. package/govendor/golang.org/x/sys/unix/ztypes_linux_loong64.go +741 -0
  450. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips.go +746 -0
  451. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64.go +743 -0
  452. package/govendor/golang.org/x/sys/unix/ztypes_linux_mips64le.go +743 -0
  453. package/govendor/golang.org/x/sys/unix/ztypes_linux_mipsle.go +746 -0
  454. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc.go +754 -0
  455. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64.go +749 -0
  456. package/govendor/golang.org/x/sys/unix/ztypes_linux_ppc64le.go +749 -0
  457. package/govendor/golang.org/x/sys/unix/ztypes_linux_riscv64.go +828 -0
  458. package/govendor/golang.org/x/sys/unix/ztypes_linux_s390x.go +763 -0
  459. package/govendor/golang.org/x/sys/unix/ztypes_linux_sparc64.go +744 -0
  460. package/govendor/golang.org/x/sys/unix/ztypes_netbsd_386.go +585 -0
  461. package/govendor/golang.org/x/sys/unix/ztypes_netbsd_amd64.go +593 -0
  462. package/govendor/golang.org/x/sys/unix/ztypes_netbsd_arm.go +590 -0
  463. package/govendor/golang.org/x/sys/unix/ztypes_netbsd_arm64.go +593 -0
  464. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_386.go +568 -0
  465. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_amd64.go +568 -0
  466. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_arm.go +575 -0
  467. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_arm64.go +568 -0
  468. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_mips64.go +568 -0
  469. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_ppc64.go +570 -0
  470. package/govendor/golang.org/x/sys/unix/ztypes_openbsd_riscv64.go +570 -0
  471. package/govendor/golang.org/x/sys/unix/ztypes_solaris_amd64.go +516 -0
  472. package/govendor/golang.org/x/sys/unix/ztypes_zos_s390x.go +552 -0
  473. package/govendor/golang.org/x/sys/windows/aliases.go +13 -0
  474. package/govendor/golang.org/x/sys/windows/dll_windows.go +380 -0
  475. package/govendor/golang.org/x/sys/windows/env_windows.go +57 -0
  476. package/govendor/golang.org/x/sys/windows/eventlog.go +20 -0
  477. package/govendor/golang.org/x/sys/windows/exec_windows.go +248 -0
  478. package/govendor/golang.org/x/sys/windows/memory_windows.go +48 -0
  479. package/govendor/golang.org/x/sys/windows/mkerrors.bash +70 -0
  480. package/govendor/golang.org/x/sys/windows/mkknownfolderids.bash +27 -0
  481. package/govendor/golang.org/x/sys/windows/mksyscall.go +9 -0
  482. package/govendor/golang.org/x/sys/windows/race.go +30 -0
  483. package/govendor/golang.org/x/sys/windows/race0.go +25 -0
  484. package/govendor/golang.org/x/sys/windows/security_windows.go +1537 -0
  485. package/govendor/golang.org/x/sys/windows/service.go +257 -0
  486. package/govendor/golang.org/x/sys/windows/setupapi_windows.go +1425 -0
  487. package/govendor/golang.org/x/sys/windows/str.go +22 -0
  488. package/govendor/golang.org/x/sys/windows/syscall.go +104 -0
  489. package/govendor/golang.org/x/sys/windows/syscall_windows.go +1952 -0
  490. package/govendor/golang.org/x/sys/windows/types_windows.go +4058 -0
  491. package/govendor/golang.org/x/sys/windows/types_windows_386.go +35 -0
  492. package/govendor/golang.org/x/sys/windows/types_windows_amd64.go +34 -0
  493. package/govendor/golang.org/x/sys/windows/types_windows_arm.go +35 -0
  494. package/govendor/golang.org/x/sys/windows/types_windows_arm64.go +34 -0
  495. package/govendor/golang.org/x/sys/windows/zerrors_windows.go +9468 -0
  496. package/govendor/golang.org/x/sys/windows/zknownfolderids_windows.go +149 -0
  497. package/govendor/golang.org/x/sys/windows/zsyscall_windows.go +4828 -0
  498. package/govendor/manifest.txt +7 -0
  499. package/package.json +6 -1
  500. package/tsparser/main.go +37 -3
  501. package/tsparser/tsparser.exe +2 -2
  502. package/types/typenative-go.d.ts +15159 -5
  503. package/types/typenative-npm.d.ts +2637 -30
  504. package/types/typenative.d.ts +1092 -56
@@ -0,0 +1,1068 @@
1
+ // node:test — test / it / describe / suite with hooks, subtests (t.test),
2
+ // skip / todo, timeouts, async and callback-style tests, and mock.fn. Tests
3
+ // are collected while the program runs and executed one after another once
4
+ // the main module has finished (as in Node); the report uses Node's TAP
5
+ // reporter, or the spec reporter when stdout is a terminal. A failure sets
6
+ // the exit code to 1.
7
+ import { defineClass, defineHelper, defineModule, setResults } from './registry.js';
8
+ const testHelper = `// node:test
9
+ type TnTestNode struct {
10
+ name string
11
+ fn interface{}
12
+ suite bool
13
+ skip bool
14
+ skipMsg string
15
+ todo bool
16
+ todoMsg string
17
+ timeoutMs float64
18
+ parent *TnTestNode
19
+ children []*TnTestNode
20
+ before []interface{}
21
+ after []interface{}
22
+ beforeEach []interface{}
23
+ afterEach []interface{}
24
+ status string
25
+ err interface{}
26
+ failureType string
27
+ duration float64
28
+ diagnostics []string
29
+ started bool
30
+ headerShown bool
31
+ ctx *TnTestContext
32
+ done chan struct{}
33
+ }
34
+
35
+ var tnTestRoot = &TnTestNode{suite: true}
36
+ var tnTestCurrent = tnTestRoot
37
+ var tnTestRunning *TnTestNode
38
+ var tnTestScheduled bool
39
+ var tnTestSpec bool
40
+ var tnTestColor bool
41
+ var tnTestStart time.Time
42
+ var tnTestCounts = map[string]int{}
43
+ var tnTestFailures []*TnTestNode
44
+
45
+ // TestContext (t)
46
+ type TnTestContext struct {
47
+ node *TnTestNode
48
+ mock *TnMockTracker
49
+ signal *TnAbortSignal
50
+ planned float64
51
+ planSet bool
52
+ asserts float64
53
+ }
54
+
55
+ func (t *TnTestContext) Get_name() string { return t.node.name }
56
+ func (t *TnTestContext) Get_fullName() string {
57
+ names := []string{}
58
+ for n := t.node; n != nil && n.parent != nil; n = n.parent {
59
+ names = append([]string{n.name}, names...)
60
+ }
61
+ return strings.Join(names, " > ")
62
+ }
63
+ func (t *TnTestContext) Get_mock() *TnMockTracker { return t.mock }
64
+ func (t *TnTestContext) Get_signal() *TnAbortSignal { return t.signal }
65
+ func (t *TnTestContext) Get_filePath() string {
66
+ if len(os.Args) > 0 {
67
+ return os.Args[0]
68
+ }
69
+ return ""
70
+ }
71
+
72
+ func (t *TnTestContext) skip(msg ...interface{}) {
73
+ t.node.skip = true
74
+ if len(msg) > 0 && msg[0] != nil {
75
+ t.node.skipMsg = TnJSString(msg[0])
76
+ }
77
+ }
78
+
79
+ func (t *TnTestContext) todo(msg ...interface{}) {
80
+ t.node.todo = true
81
+ if len(msg) > 0 && msg[0] != nil {
82
+ t.node.todoMsg = TnJSString(msg[0])
83
+ }
84
+ }
85
+
86
+ func (t *TnTestContext) diagnostic(msg string) {
87
+ t.node.diagnostics = append(t.node.diagnostics, msg)
88
+ }
89
+
90
+ func (t *TnTestContext) plan(n float64, options ...interface{}) {
91
+ t.planned = n
92
+ t.planSet = true
93
+ }
94
+
95
+ func (t *TnTestContext) runOnly(flag bool) {}
96
+
97
+ // t.test(name, [options], fn): runs the subtest now; resolves when it is done
98
+ func (t *TnTestContext) test(args ...interface{}) chan struct{} {
99
+ child := tnTestNew(false, args)
100
+ child.parent = t.node
101
+ t.node.children = append(t.node.children, child)
102
+ t.asserts++
103
+ tnRunTestNode(child, tnTestDepth(child))
104
+ return child.done
105
+ }
106
+
107
+ func (t *TnTestContext) before(fn interface{}, options ...interface{}) {
108
+ t.node.before = append(t.node.before, fn)
109
+ }
110
+ func (t *TnTestContext) after(fn interface{}, options ...interface{}) {
111
+ t.node.after = append(t.node.after, fn)
112
+ }
113
+ func (t *TnTestContext) beforeEach(fn interface{}, options ...interface{}) {
114
+ t.node.beforeEach = append(t.node.beforeEach, fn)
115
+ }
116
+ func (t *TnTestContext) afterEach(fn interface{}, options ...interface{}) {
117
+ t.node.afterEach = append(t.node.afterEach, fn)
118
+ }
119
+
120
+ // test(name?, options?, fn?) arguments
121
+ func tnTestNew(suite bool, args []interface{}) *TnTestNode {
122
+ n := &TnTestNode{suite: suite, name: "<anonymous>", done: make(chan struct{}, 1)}
123
+ for _, a := range args {
124
+ switch x := a.(type) {
125
+ case string:
126
+ n.name = x
127
+ case nil:
128
+ default:
129
+ if tnTestIsFunc(a) {
130
+ n.fn = a
131
+ continue
132
+ }
133
+ switch s := TnGet(a, "skip").(type) {
134
+ case bool:
135
+ n.skip = s
136
+ case string:
137
+ n.skip, n.skipMsg = true, s
138
+ }
139
+ switch td := TnGet(a, "todo").(type) {
140
+ case bool:
141
+ n.todo = td
142
+ case string:
143
+ n.todo, n.todoMsg = true, td
144
+ }
145
+ if ms, ok := TnGet(a, "timeout").(float64); ok {
146
+ n.timeoutMs = ms
147
+ }
148
+ }
149
+ }
150
+ return n
151
+ }
152
+
153
+ func tnTestIsFunc(v interface{}) bool {
154
+ rv := reflect.ValueOf(v)
155
+ return rv.IsValid() && rv.Kind() == reflect.Func && !rv.IsNil()
156
+ }
157
+
158
+ func tnTestDepth(n *TnTestNode) int {
159
+ d := -1
160
+ for p := n; p.parent != nil; p = p.parent {
161
+ d++
162
+ }
163
+ return d
164
+ }
165
+
166
+ // test() / it(): registered with the enclosing describe (or the running test)
167
+ func TnTestRegister(variant string, args ...interface{}) chan struct{} {
168
+ n := tnTestNew(false, args)
169
+ switch variant {
170
+ case "skip":
171
+ n.skip = true
172
+ case "todo":
173
+ n.todo = true
174
+ }
175
+ if tnTestRunning != nil && tnTestCurrent == tnTestRoot && tnTestRunning.ctx != nil {
176
+ n.parent = tnTestRunning
177
+ tnTestRunning.children = append(tnTestRunning.children, n)
178
+ tnRunTestNode(n, tnTestDepth(n))
179
+ return n.done
180
+ }
181
+ n.parent = tnTestCurrent
182
+ tnTestCurrent.children = append(tnTestCurrent.children, n)
183
+ tnTestSchedule()
184
+ return n.done
185
+ }
186
+
187
+ // describe() / suite(): the body runs now and registers the suite's tests
188
+ func TnSuiteRegister(variant string, args ...interface{}) chan struct{} {
189
+ n := tnTestNew(true, args)
190
+ switch variant {
191
+ case "skip":
192
+ n.skip = true
193
+ case "todo":
194
+ n.todo = true
195
+ }
196
+ n.parent = tnTestCurrent
197
+ tnTestCurrent.children = append(tnTestCurrent.children, n)
198
+ if n.fn != nil {
199
+ saved := tnTestCurrent
200
+ tnTestCurrent = n
201
+ func() {
202
+ defer func() {
203
+ if r := recover(); r != nil {
204
+ n.err = r
205
+ n.failureType = "testCodeFailure"
206
+ }
207
+ }()
208
+ TnInvoke(n.fn, &TnTestContext{node: n})
209
+ }()
210
+ tnTestCurrent = saved
211
+ }
212
+ tnTestSchedule()
213
+ return n.done
214
+ }
215
+
216
+ // before / after / beforeEach / afterEach (in a describe body or at the top level)
217
+ func TnTestHook(kind string, fn interface{}, options ...interface{}) {
218
+ target := tnTestCurrent
219
+ if tnTestRunning != nil && target == tnTestRoot {
220
+ target = tnTestRunning
221
+ }
222
+ switch kind {
223
+ case "before":
224
+ target.before = append(target.before, fn)
225
+ case "after":
226
+ target.after = append(target.after, fn)
227
+ case "beforeEach":
228
+ target.beforeEach = append(target.beforeEach, fn)
229
+ case "afterEach":
230
+ target.afterEach = append(target.afterEach, fn)
231
+ }
232
+ tnTestSchedule()
233
+ }
234
+
235
+ // The run starts once the main module has finished (a loop task)
236
+ func tnTestSchedule() {
237
+ if tnTestScheduled {
238
+ return
239
+ }
240
+ tnTestScheduled = true
241
+ TnLoopRef()
242
+ TnLoopPost(func() {
243
+ TnStartAsync(func() {
244
+ defer TnLoopUnref()
245
+ tnRunRoot()
246
+ })
247
+ })
248
+ }
249
+
250
+ type tnTestOutcome struct {
251
+ err interface{}
252
+ failed bool
253
+ timedOut bool
254
+ }
255
+
256
+ // Calls a test / hook function: sync, async (a promise), or with a done callback
257
+ func tnTestInvoke(fn interface{}, ctx *TnTestContext, timeoutMs float64) tnTestOutcome {
258
+ outcome := make(chan tnTestOutcome, 1)
259
+ settle := func(o tnTestOutcome) {
260
+ select {
261
+ case outcome <- o:
262
+ default:
263
+ }
264
+ }
265
+ if timeoutMs > 0 && !math.IsInf(timeoutMs, 1) {
266
+ ms := timeoutMs
267
+ timer := time.AfterFunc(time.Duration(ms*float64(time.Millisecond)), func() {
268
+ settle(tnTestOutcome{err: TnNodeError("Error", "ERR_TEST_FAILURE", "test timed out after "+strconv.FormatFloat(ms, 'f', -1, 64)+"ms"), failed: true, timedOut: true})
269
+ })
270
+ defer timer.Stop()
271
+ }
272
+ fv := reflect.ValueOf(fn)
273
+ usesDone := fv.Kind() == reflect.Func && fv.Type().NumIn() >= 2
274
+ var result interface{}
275
+ panicked := func() (out *tnTestOutcome) {
276
+ defer func() {
277
+ if r := recover(); r != nil {
278
+ out = &tnTestOutcome{err: r, failed: true}
279
+ }
280
+ }()
281
+ if usesDone {
282
+ result = TnInvoke(fn, ctx, func(args ...interface{}) {
283
+ if len(args) > 0 && args[0] != nil && !TnIsNil(args[0]) {
284
+ settle(tnTestOutcome{err: args[0], failed: true})
285
+ return
286
+ }
287
+ settle(tnTestOutcome{})
288
+ })
289
+ } else {
290
+ result = TnInvoke(fn, ctx)
291
+ }
292
+ return nil
293
+ }()
294
+ if panicked != nil {
295
+ return *panicked
296
+ }
297
+ rv := reflect.ValueOf(result)
298
+ isPromise := rv.IsValid() && rv.Kind() == reflect.Chan
299
+ if !isPromise && !usesDone {
300
+ // A test that ran past its timeout (async callbacks run to completion)
301
+ select {
302
+ case o := <-outcome:
303
+ return o
304
+ default:
305
+ return tnTestOutcome{}
306
+ }
307
+ }
308
+ if isPromise {
309
+ go func() {
310
+ _, ok := rv.Recv()
311
+ if !ok {
312
+ if reason, rejected := tnRejections.Load(result); rejected {
313
+ settle(tnTestOutcome{err: reason, failed: true})
314
+ return
315
+ }
316
+ }
317
+ if !usesDone {
318
+ settle(tnTestOutcome{})
319
+ }
320
+ }()
321
+ }
322
+ o, _ := TnLoopReceive(outcome)
323
+ return o
324
+ }
325
+
326
+ func tnRunHooks(hooks []interface{}, ctx *TnTestContext) *tnTestOutcome {
327
+ for _, h := range hooks {
328
+ if o := tnTestInvoke(h, ctx, 0); o.failed {
329
+ return &o
330
+ }
331
+ }
332
+ return nil
333
+ }
334
+
335
+ func tnTestAncestors(n *TnTestNode) []*TnTestNode {
336
+ chain := []*TnTestNode{}
337
+ for p := n.parent; p != nil; p = p.parent {
338
+ chain = append([]*TnTestNode{p}, chain...)
339
+ }
340
+ return chain
341
+ }
342
+
343
+ func tnRunRoot() {
344
+ tnTestStart = time.Now()
345
+ tnTestSpec = TnIsTTY(os.Stdout)
346
+ tnTestColor = tnTestSpec && os.Getenv("NO_COLOR") == ""
347
+ if !tnTestSpec {
348
+ fmt.Println("TAP version 13")
349
+ }
350
+ root := tnTestRoot
351
+ ctx := &TnTestContext{node: root}
352
+ failedHook := tnRunHooks(root.before, ctx)
353
+ for i := 0; i < len(root.children); i++ {
354
+ child := root.children[i]
355
+ if failedHook != nil {
356
+ child.err, child.failureType = failedHook.err, "hookFailure"
357
+ }
358
+ tnRunTestNode(child, 0)
359
+ }
360
+ tnRunHooks(root.after, ctx)
361
+ tnTestFinish()
362
+ }
363
+
364
+ func tnRunTestNode(n *TnTestNode, depth int) {
365
+ n.started = true
366
+ tnTestShowParents(n)
367
+ indent := strings.Repeat(" ", depth)
368
+ if !tnTestSpec {
369
+ fmt.Println(indent + "# Subtest: " + n.name)
370
+ }
371
+ start := time.Now()
372
+ ctx := &TnTestContext{node: n, mock: TnNewMockTracker(), signal: TnNewAbortSignal()}
373
+ n.ctx = ctx
374
+ defer func() {
375
+ ctx.mock.reset()
376
+ n.done <- struct{}{}
377
+ }()
378
+ if n.suite {
379
+ if !n.skip && n.err == nil {
380
+ if o := tnRunHooks(n.before, ctx); o != nil {
381
+ n.err, n.failureType = o.err, "hookFailure"
382
+ }
383
+ }
384
+ for _, child := range n.children {
385
+ if n.skip {
386
+ child.skip = true
387
+ }
388
+ if n.err != nil && n.failureType == "hookFailure" && !child.skip {
389
+ child.err, child.failureType = n.err, "hookFailure"
390
+ }
391
+ tnRunTestNode(child, depth+1)
392
+ }
393
+ if !n.skip {
394
+ tnRunHooks(n.after, ctx)
395
+ }
396
+ } else if !n.skip && n.err == nil {
397
+ prev := tnTestRunning
398
+ tnTestRunning = n
399
+ chain := tnTestAncestors(n)
400
+ var failure *tnTestOutcome
401
+ for _, p := range chain {
402
+ if failure == nil {
403
+ failure = tnRunHooks(p.beforeEach, ctx)
404
+ }
405
+ }
406
+ if failure == nil && n.fn != nil {
407
+ o := tnTestInvoke(n.fn, ctx, n.timeoutMs)
408
+ if o.failed {
409
+ failure = &o
410
+ if o.timedOut {
411
+ n.failureType = "testTimeoutFailure"
412
+ }
413
+ }
414
+ }
415
+ // Subtests registered without awaiting them run before the parent finishes
416
+ for _, child := range n.children {
417
+ if !child.started {
418
+ tnRunTestNode(child, depth+1)
419
+ }
420
+ }
421
+ tnRunHooks(n.after, ctx)
422
+ for i := len(chain) - 1; i >= 0; i-- {
423
+ if o := tnRunHooks(chain[i].afterEach, ctx); o != nil && failure == nil {
424
+ failure = o
425
+ }
426
+ }
427
+ if failure != nil {
428
+ n.err = failure.err
429
+ if n.failureType == "" {
430
+ n.failureType = "testCodeFailure"
431
+ }
432
+ } else if ctx.planSet && ctx.planned != ctx.asserts {
433
+ n.err = TnNodeError("Error", "ERR_TEST_FAILURE", "plan expected "+strconv.FormatFloat(ctx.planned, 'f', -1, 64)+" assertions but received "+strconv.FormatFloat(ctx.asserts, 'f', -1, 64))
434
+ n.failureType = "testCodeFailure"
435
+ }
436
+ tnTestRunning = prev
437
+ }
438
+ n.duration = float64(time.Since(start).Nanoseconds()) / 1e6
439
+ switch {
440
+ case n.skip:
441
+ n.status = "skip"
442
+ case n.todo:
443
+ n.status = "todo"
444
+ case n.err != nil:
445
+ n.status = "fail"
446
+ default:
447
+ n.status = "pass"
448
+ for _, child := range n.children {
449
+ if child.status == "fail" {
450
+ n.status = "fail"
451
+ failed := 0
452
+ for _, c := range n.children {
453
+ if c.status == "fail" {
454
+ failed++
455
+ }
456
+ }
457
+ noun := "subtest"
458
+ if failed > 1 {
459
+ noun = "subtests"
460
+ }
461
+ n.err = TnNodeError("Error", "ERR_TEST_FAILURE", strconv.Itoa(failed)+" "+noun+" failed")
462
+ n.failureType = "subtestsFailed"
463
+ break
464
+ }
465
+ }
466
+ }
467
+ if n.suite {
468
+ tnTestCounts["suites"]++
469
+ } else {
470
+ tnTestCounts["tests"]++
471
+ switch n.status {
472
+ case "pass":
473
+ tnTestCounts["pass"]++
474
+ case "fail":
475
+ if n.failureType == "testTimeoutFailure" {
476
+ tnTestCounts["cancelled"]++
477
+ } else {
478
+ tnTestCounts["fail"]++
479
+ }
480
+ if n.failureType != "subtestsFailed" {
481
+ tnTestFailures = append(tnTestFailures, n)
482
+ }
483
+ case "skip":
484
+ tnTestCounts["skipped"]++
485
+ case "todo":
486
+ tnTestCounts["todo"]++
487
+ }
488
+ }
489
+ tnTestReport(n, depth)
490
+ }
491
+
492
+ // Spec reporter: a parent's ▶ line comes before its first child's output
493
+ func tnTestShowParents(n *TnTestNode) {
494
+ if !tnTestSpec {
495
+ return
496
+ }
497
+ chain := tnTestAncestors(n)
498
+ for i, p := range chain {
499
+ if p.parent == nil || p.headerShown {
500
+ continue
501
+ }
502
+ p.headerShown = true
503
+ fmt.Println(strings.Repeat(" ", i-1) + "\\u25b6 " + p.name)
504
+ }
505
+ }
506
+
507
+ func tnTestColorize(code string, s string) string {
508
+ if !tnTestColor {
509
+ return s
510
+ }
511
+ return "\\x1b[" + code + "m" + s + "\\x1b[39m"
512
+ }
513
+
514
+ func tnTestDuration(ms float64) string {
515
+ return strconv.FormatFloat(math.Round(ms*1e6)/1e6, 'f', -1, 64)
516
+ }
517
+
518
+ func tnTestErrorField(err interface{}, key string) interface{} {
519
+ if e, ok := err.(*TnError); ok {
520
+ if key == "message" {
521
+ return e.message
522
+ }
523
+ if key == "code" {
524
+ if e.code != "" {
525
+ return e.code
526
+ }
527
+ }
528
+ if key == "name" {
529
+ return e.Get_name()
530
+ }
531
+ return e.prop(key)
532
+ }
533
+ if key == "message" {
534
+ return TnJSString(err)
535
+ }
536
+ return nil
537
+ }
538
+
539
+ func tnTestYamlString(s string, indent string) string {
540
+ if strings.Contains(s, "\\n") {
541
+ lines := strings.Split(s, "\\n")
542
+ for i, l := range lines {
543
+ lines[i] = indent + " " + l
544
+ }
545
+ return "|-\\n" + strings.Join(lines, "\\n")
546
+ }
547
+ return "'" + strings.ReplaceAll(s, "'", "''") + "'"
548
+ }
549
+
550
+ func tnTestReport(n *TnTestNode, depth int) {
551
+ if tnTestSpec {
552
+ tnTestReportSpec(n, depth)
553
+ return
554
+ }
555
+ indent := strings.Repeat(" ", depth)
556
+ if len(n.children) > 0 {
557
+ fmt.Println(indent + " 1.." + strconv.Itoa(len(n.children)))
558
+ }
559
+ number := 1
560
+ if n.parent != nil {
561
+ for i, c := range n.parent.children {
562
+ if c == n {
563
+ number = i + 1
564
+ }
565
+ }
566
+ }
567
+ line := "ok"
568
+ if n.status == "fail" {
569
+ line = "not ok"
570
+ }
571
+ line = indent + line + " " + strconv.Itoa(number) + " - " + n.name
572
+ switch n.status {
573
+ case "skip":
574
+ line += " # SKIP"
575
+ if n.skipMsg != "" {
576
+ line += " " + n.skipMsg
577
+ }
578
+ case "todo":
579
+ line += " # TODO"
580
+ if n.todoMsg != "" {
581
+ line += " " + n.todoMsg
582
+ }
583
+ }
584
+ fmt.Println(line)
585
+ fmt.Println(indent + " ---")
586
+ fmt.Println(indent + " duration_ms: " + tnTestDuration(n.duration))
587
+ kind := "test"
588
+ if n.suite {
589
+ kind = "suite"
590
+ }
591
+ fmt.Println(indent + " type: '" + kind + "'")
592
+ if n.status == "fail" || (n.status == "todo" && n.err != nil) {
593
+ fmt.Println(indent + " failureType: '" + n.failureType + "'")
594
+ msg := TnJSString(tnTestErrorField(n.err, "message"))
595
+ if e, ok := n.err.(*TnError); ok && e.Get_name() == "AssertionError" && !strings.HasSuffix(msg, "\\n") && strings.Contains(msg, "\\n") {
596
+ msg += "\\n"
597
+ }
598
+ fmt.Println(indent + " error: " + tnTestYamlString(msg, indent))
599
+ code, _ := tnTestErrorField(n.err, "code").(string)
600
+ if code == "" {
601
+ code = "ERR_TEST_FAILURE"
602
+ }
603
+ fmt.Println(indent + " code: '" + code + "'")
604
+ if e, isTnErr := n.err.(*TnError); isTnErr && n.failureType == "testCodeFailure" && e.Get_name() == "AssertionError" {
605
+ fmt.Println(indent + " name: '" + TnJSString(tnTestErrorField(n.err, "name")) + "'")
606
+ for _, key := range []string{"expected", "actual", "operator"} {
607
+ if e, ok := n.err.(*TnError); ok {
608
+ if v, has := e.props[key]; has {
609
+ fmt.Println(indent + " " + key + ": " + TnInspect(v))
610
+ }
611
+ }
612
+ }
613
+ }
614
+ }
615
+ fmt.Println(indent + " ...")
616
+ for _, d := range n.diagnostics {
617
+ fmt.Println(indent + "# " + d)
618
+ }
619
+ }
620
+
621
+ func tnTestReportSpec(n *TnTestNode, depth int) {
622
+ indent := strings.Repeat(" ", depth)
623
+ dur := " (" + tnTestDuration(n.duration) + "ms)"
624
+ var line string
625
+ switch n.status {
626
+ case "pass":
627
+ line = tnTestColorize("32", "\\u2714 "+n.name+dur)
628
+ case "fail":
629
+ line = tnTestColorize("31", "\\u2716 "+n.name+dur)
630
+ case "skip":
631
+ msg := "SKIP"
632
+ if n.skipMsg != "" {
633
+ msg = n.skipMsg
634
+ }
635
+ line = tnTestColorize("90", "\\ufe63 "+n.name+dur+" # "+msg)
636
+ case "todo":
637
+ msg := "TODO"
638
+ if n.todoMsg != "" {
639
+ msg = n.todoMsg
640
+ }
641
+ mark := "\\u2714 "
642
+ if n.err != nil {
643
+ mark = "\\u2716 "
644
+ }
645
+ line = tnTestColorize("33", mark+n.name+dur+" # "+msg)
646
+ }
647
+ fmt.Println(indent + line)
648
+ for _, d := range n.diagnostics {
649
+ fmt.Println(indent + tnTestColorize("34", "\\u2139 "+d))
650
+ }
651
+ }
652
+
653
+ func tnTestFinish() {
654
+ stats := []string{"tests", "suites", "pass", "fail", "cancelled", "skipped", "todo"}
655
+ if !tnTestSpec {
656
+ fmt.Println("1.." + strconv.Itoa(len(tnTestRoot.children)))
657
+ }
658
+ for _, key := range stats {
659
+ line := key + " " + strconv.Itoa(tnTestCounts[key])
660
+ if tnTestSpec {
661
+ fmt.Println(tnTestColorize("34", "\\u2139 "+line))
662
+ } else {
663
+ fmt.Println("# " + line)
664
+ }
665
+ }
666
+ duration := "duration_ms " + tnTestDuration(float64(time.Since(tnTestStart).Nanoseconds())/1e6)
667
+ if tnTestSpec {
668
+ fmt.Println(tnTestColorize("34", "\\u2139 "+duration))
669
+ if len(tnTestFailures) > 0 {
670
+ fmt.Println("\\n" + tnTestColorize("31", "\\u2716 failing tests:"))
671
+ for _, n := range tnTestFailures {
672
+ fmt.Println("\\n" + tnTestColorize("31", "\\u2716 "+n.name+" ("+tnTestDuration(n.duration)+"ms)"))
673
+ name := TnJSString(tnTestErrorField(n.err, "name"))
674
+ head := name
675
+ if code, ok := tnTestErrorField(n.err, "code").(string); ok && code != "" {
676
+ head += " [" + code + "]"
677
+ }
678
+ for _, l := range strings.Split(head+": "+TnJSString(tnTestErrorField(n.err, "message")), "\\n") {
679
+ fmt.Println(" " + l)
680
+ }
681
+ }
682
+ }
683
+ } else {
684
+ fmt.Println("# " + duration)
685
+ }
686
+ if tnTestCounts["fail"] > 0 || tnTestCounts["cancelled"] > 0 {
687
+ TnSetExitCode(1)
688
+ }
689
+ }
690
+
691
+ // --- mocks ---
692
+
693
+ type TnMockCall struct {
694
+ arguments []interface{}
695
+ result interface{}
696
+ error_ interface{}
697
+ this interface{}
698
+ }
699
+
700
+ func (c *TnMockCall) Get_error() interface{} { return c.error_ }
701
+
702
+ type TnMockFunctionContext struct {
703
+ calls []*TnMockCall
704
+ impl interface{}
705
+ original interface{}
706
+ once map[int]interface{}
707
+ }
708
+
709
+ func (m *TnMockFunctionContext) Get_calls() []*TnMockCall { return m.calls }
710
+ func (m *TnMockFunctionContext) callCount() float64 { return float64(len(m.calls)) }
711
+ func (m *TnMockFunctionContext) resetCalls() { m.calls = nil }
712
+ func (m *TnMockFunctionContext) mockImplementation(fn interface{}) { m.impl = fn }
713
+ func (m *TnMockFunctionContext) mockImplementationOnce(fn interface{}, onCall ...float64) {
714
+ index := len(m.calls)
715
+ if len(onCall) > 0 {
716
+ index = int(onCall[0])
717
+ }
718
+ m.once[index] = fn
719
+ }
720
+ func (m *TnMockFunctionContext) restore() { m.impl = m.original }
721
+
722
+ var tnMocks = map[uintptr]*TnMockFunctionContext{}
723
+
724
+ type TnMockTracker struct {
725
+ mocks []*TnMockFunctionContext
726
+ timers *TnMockTimers
727
+ }
728
+
729
+ // mock.timers: fake setTimeout / setInterval / setImmediate / Date driven by tick()
730
+ type TnMockTimers struct {
731
+ enabled bool
732
+ now float64
733
+ seq int
734
+ queue []*tnFakeTimer
735
+ }
736
+
737
+ type tnFakeTimer struct {
738
+ runAt float64
739
+ interval float64
740
+ seq int
741
+ run func() bool
742
+ }
743
+
744
+ func (t *TnMockTracker) Get_timers() *TnMockTimers {
745
+ if t.timers == nil {
746
+ t.timers = &TnMockTimers{}
747
+ }
748
+ return t.timers
749
+ }
750
+
751
+ func tnMockTimersState(msg string) *TnError {
752
+ return TnNodeError("Error", "ERR_INVALID_STATE", "Invalid state: "+msg)
753
+ }
754
+
755
+ func (m *TnMockTimers) enable(options ...interface{}) {
756
+ if m.enabled {
757
+ panic(tnMockTimersState("MockTimers is already enabled!"))
758
+ }
759
+ apis := map[string]bool{"setTimeout": true, "setInterval": true, "setImmediate": true, "Date": true}
760
+ m.now = 0
761
+ if len(options) > 0 && options[0] != nil {
762
+ switch list := TnGet(options[0], "apis").(type) {
763
+ case []string:
764
+ apis = map[string]bool{}
765
+ for _, a := range list {
766
+ apis[a] = true
767
+ }
768
+ case []interface{}:
769
+ apis = map[string]bool{}
770
+ for _, a := range list {
771
+ apis[fmt.Sprint(a)] = true
772
+ }
773
+ }
774
+ switch now := TnGet(options[0], "now").(type) {
775
+ case float64:
776
+ m.now = now
777
+ case time.Time:
778
+ m.now = float64(now.UnixMilli())
779
+ }
780
+ }
781
+ m.enabled = true
782
+ m.queue = nil
783
+ tnMockTimerHook = func(kind string, ms float64, run func() bool) bool {
784
+ if !m.enabled || !apis[kind] {
785
+ return false
786
+ }
787
+ if ms < 0 || kind == "setImmediate" {
788
+ ms = 0
789
+ }
790
+ interval := 0.0
791
+ if kind == "setInterval" {
792
+ interval = math.Max(ms, 1)
793
+ }
794
+ m.seq++
795
+ m.queue = append(m.queue, &tnFakeTimer{runAt: m.now + ms, interval: interval, seq: m.seq, run: run})
796
+ return true
797
+ }
798
+ if apis["Date"] {
799
+ tnClockHook = func() time.Time { return time.UnixMilli(int64(m.now)) }
800
+ }
801
+ }
802
+
803
+ func (m *TnMockTimers) check() {
804
+ if !m.enabled {
805
+ panic(tnMockTimersState("You should enable MockTimers first by calling the .enable function"))
806
+ }
807
+ }
808
+
809
+ // The next timer to fire: earliest first, then in scheduling order
810
+ func (m *TnMockTimers) next() (*tnFakeTimer, int) {
811
+ best := -1
812
+ for i, t := range m.queue {
813
+ if best < 0 || t.runAt < m.queue[best].runAt || (t.runAt == m.queue[best].runAt && t.seq < m.queue[best].seq) {
814
+ best = i
815
+ }
816
+ }
817
+ if best < 0 {
818
+ return nil, -1
819
+ }
820
+ return m.queue[best], best
821
+ }
822
+
823
+ // tick(ms): advances the clock, then runs the timers that are due
824
+ func (m *TnMockTimers) tick(ms ...float64) {
825
+ m.check()
826
+ d := 1.0
827
+ if len(ms) > 0 {
828
+ d = ms[0]
829
+ }
830
+ if d < 0 {
831
+ panic(TnNodeError("TypeError", "ERR_INVALID_ARG_VALUE", "The argument 'time' must be a positive number. Received "+TnNumStr(d)))
832
+ }
833
+ m.now += d
834
+ for {
835
+ t, i := m.next()
836
+ if t == nil || t.runAt > m.now {
837
+ return
838
+ }
839
+ m.queue = append(m.queue[:i:i], m.queue[i+1:]...)
840
+ if t.run() && t.interval > 0 {
841
+ t.runAt += t.interval
842
+ m.queue = append(m.queue, t)
843
+ }
844
+ }
845
+ }
846
+
847
+ // runAll(): ticks up to the last pending timer
848
+ func (m *TnMockTimers) runAll() {
849
+ m.check()
850
+ last := m.now
851
+ for _, t := range m.queue {
852
+ last = math.Max(last, t.runAt)
853
+ }
854
+ m.tick(last - m.now)
855
+ }
856
+
857
+ func (m *TnMockTimers) setTime(ms float64) {
858
+ m.check()
859
+ m.now = ms
860
+ }
861
+
862
+ func (m *TnMockTimers) reset() {
863
+ if m.enabled {
864
+ tnMockTimerHook = nil
865
+ tnClockHook = nil
866
+ }
867
+ m.enabled = false
868
+ m.queue = nil
869
+ }
870
+
871
+ // t.assert: node:assert's functions, counted towards t.plan()
872
+ type TnTestAssert struct {
873
+ ctx *TnTestContext
874
+ }
875
+
876
+ func (t *TnTestContext) Get_assert() *TnTestAssert { return &TnTestAssert{ctx: t} }
877
+
878
+ func (a *TnTestAssert) count(run func()) {
879
+ a.ctx.asserts++
880
+ run()
881
+ }
882
+
883
+ func tnTestCounted[T any](a *TnTestAssert, v T) T {
884
+ a.ctx.asserts++
885
+ return v
886
+ }
887
+
888
+ func TnNewMockTracker() *TnMockTracker { return &TnMockTracker{} }
889
+
890
+ var TnMock = TnNewMockTracker()
891
+
892
+ // mock.fn(original?, implementation?): a function of the same type that records its calls
893
+ func TnMockFn[F any](tracker *TnMockTracker, original F, implementation ...F) F {
894
+ ctx := &TnMockFunctionContext{once: map[int]interface{}{}}
895
+ ctx.original = original
896
+ ctx.impl = original
897
+ if len(implementation) > 0 {
898
+ ctx.impl = implementation[0]
899
+ }
900
+ tracker.mocks = append(tracker.mocks, ctx)
901
+ ft := reflect.TypeOf(original)
902
+ wrapped := reflect.MakeFunc(ft, func(in []reflect.Value) []reflect.Value {
903
+ args := make([]interface{}, 0, len(in))
904
+ for i, v := range in {
905
+ if ft.IsVariadic() && i == len(in)-1 {
906
+ for j := 0; j < v.Len(); j++ {
907
+ args = append(args, v.Index(j).Interface())
908
+ }
909
+ continue
910
+ }
911
+ args = append(args, v.Interface())
912
+ }
913
+ call := &TnMockCall{arguments: args}
914
+ impl := ctx.impl
915
+ if once, ok := ctx.once[len(ctx.calls)]; ok {
916
+ impl = once
917
+ delete(ctx.once, len(ctx.calls))
918
+ }
919
+ ctx.calls = append(ctx.calls, call)
920
+ var out []reflect.Value
921
+ func() {
922
+ defer func() {
923
+ if r := recover(); r != nil {
924
+ call.error_ = r
925
+ panic(r)
926
+ }
927
+ }()
928
+ result := TnInvoke(impl, args...)
929
+ call.result = result
930
+ for i := 0; i < ft.NumOut(); i++ {
931
+ out = append(out, tnInvokeArg(result, ft.Out(i)))
932
+ }
933
+ }()
934
+ return out
935
+ })
936
+ fn := wrapped.Interface().(F)
937
+ tnMocks[tnFuncID(fn)] = ctx
938
+ return fn
939
+ }
940
+
941
+ // mock.fn() without a function: accepts anything, returns undefined
942
+ func TnMockFnEmpty(tracker *TnMockTracker) func(...interface{}) interface{} {
943
+ return TnMockFn(tracker, func(args ...interface{}) interface{} { return nil })
944
+ }
945
+
946
+ // fn.mock: the call record of a mock function
947
+ func TnMockOf(fn interface{}) *TnMockFunctionContext {
948
+ if ctx, ok := tnMocks[tnFuncID(fn)]; ok {
949
+ return ctx
950
+ }
951
+ panic(TnNodeError("TypeError", "", "not a mock function"))
952
+ }
953
+
954
+ func (t *TnMockTracker) reset() {
955
+ for _, m := range t.mocks {
956
+ m.resetCalls()
957
+ }
958
+ if t.timers != nil {
959
+ t.timers.reset()
960
+ }
961
+ t.restoreAll()
962
+ }
963
+
964
+ func (t *TnMockTracker) restoreAll() {
965
+ for _, m := range t.mocks {
966
+ m.restore()
967
+ }
968
+ }`;
969
+ function eventFn(nodes) {
970
+ void nodes;
971
+ return ['*TnTestContext', 'func(...interface{})'];
972
+ }
973
+ export function registerTest(r) {
974
+ defineModule(r, 'test');
975
+ defineHelper(r, 'nodeTest', ['fmt', 'math', 'os', 'reflect', 'strconv', 'strings', 'time'], ['eventLoop', 'promise', 'nodeInvoke', 'dynamic', 'nodeEvents', 'nodeProcess', 'nodeUtil', 'error', 'timerWait', 'clock'], testHelper);
976
+ const use = () => r.helper('nodeTest');
977
+ defineClass(r, 'test.TestContext', '*TnTestContext', 'class', 'skip=; todo=; diagnostic=; plan=; runOnly=; test=chan struct{}; before=; after=; beforeEach=; afterEach=', '', 'name=string; fullName=string; mock=*TnMockTracker; signal=*TnAbortSignal; filePath=string; assert=*TnTestAssert', '');
978
+ r.classes['test.SuiteContext'] = r.classes['test.TestContext'];
979
+ defineClass(r, 'test.MockTracker', '*TnMockTracker', 'class', 'reset=; restoreAll=', '', 'timers=*TnMockTimers', '');
980
+ defineClass(r, 'test.MockTimers', '*TnMockTimers', 'class', 'enable=; tick=; runAll=; setTime=; reset=', '', '', '');
981
+ // t.assert.x(...): node:assert's x, counted for t.plan()
982
+ defineClass(r, 'test.TestContextAssert', '*TnTestAssert', 'class', '', '', '', '');
983
+ const assertNames = ['ok', 'equal', 'notEqual', 'strictEqual', 'notStrictEqual', 'deepEqual', 'notDeepEqual', 'deepStrictEqual', 'notDeepStrictEqual', 'throws', 'doesNotThrow', 'rejects', 'doesNotReject', 'match', 'doesNotMatch', 'fail', 'ifError'];
984
+ for (const name of assertNames) {
985
+ const key = `test.TestContextAssert#${name}`;
986
+ r.methods[key] = (c) => {
987
+ use();
988
+ // node:assert's emitters ignore the receiver
989
+ const expr = r.functions[`assert.${name}`](c);
990
+ if (name === 'rejects' || name === 'doesNotReject')
991
+ return `tnTestCounted(${c.recv}, ${expr})`;
992
+ return `${c.recv}.count(func() { ${expr} })`;
993
+ };
994
+ r.typers[key] = (_c) => (name === 'rejects' || name === 'doesNotReject' ? 'chan struct{}' : '');
995
+ r.paramTypers[key] = (nodes) => (r.paramTypers[`assert.${name}`] ? r.paramTypers[`assert.${name}`](nodes) : []);
996
+ }
997
+ defineClass(r, 'test.MockFunctionContext', '*TnMockFunctionContext', 'class', 'callCount=float64; resetCalls=; mockImplementation=; mockImplementationOnce=; restore=', '', 'calls=[]*TnMockCall', '');
998
+ defineClass(r, 'test.MockCall', '*TnMockCall', 'class', '', 'arguments=[]interface{}; result=interface{}; this=interface{}', 'error=interface{}', '');
999
+ r.paramTypers['test.TestContext#test'] = eventFn;
1000
+ for (const hook of ['before', 'after', 'beforeEach', 'afterEach'])
1001
+ r.paramTypers[`test.TestContext#${hook}`] = eventFn;
1002
+ const register = (name, goFn, variant) => {
1003
+ r.functions[`test.${name}`] = (c) => {
1004
+ use();
1005
+ return `${goFn}(${JSON.stringify(variant)}${c.args.length > 0 ? ', ' : ''}${c.args.join(', ')})`;
1006
+ };
1007
+ r.results[`test.${name}`] = 'chan struct{}';
1008
+ r.paramTypers[`test.${name}`] = eventFn;
1009
+ };
1010
+ for (const name of ['test', 'it']) {
1011
+ register(name, 'TnTestRegister', '');
1012
+ register(`${name}.skip`, 'TnTestRegister', 'skip');
1013
+ register(`${name}.todo`, 'TnTestRegister', 'todo');
1014
+ register(`${name}.only`, 'TnTestRegister', '');
1015
+ }
1016
+ for (const name of ['describe', 'suite']) {
1017
+ register(name, 'TnSuiteRegister', '');
1018
+ register(`${name}.skip`, 'TnSuiteRegister', 'skip');
1019
+ register(`${name}.todo`, 'TnSuiteRegister', 'todo');
1020
+ register(`${name}.only`, 'TnSuiteRegister', '');
1021
+ }
1022
+ for (const variant of ['', '.skip', '.todo', '.only']) {
1023
+ r.functions[`test.default${variant}`] = r.functions[`test.test${variant}`];
1024
+ r.results[`test.default${variant}`] = 'chan struct{}';
1025
+ r.paramTypers[`test.default${variant}`] = eventFn;
1026
+ }
1027
+ for (const hook of ['before', 'after', 'beforeEach', 'afterEach']) {
1028
+ r.functions[`test.${hook}`] = (c) => {
1029
+ use();
1030
+ return `TnTestHook(${JSON.stringify(hook)}, ${c.args.join(', ')})`;
1031
+ };
1032
+ r.paramTypers[`test.${hook}`] = eventFn;
1033
+ }
1034
+ // mock.fn(original?, implementation?) / t.mock.fn(...)
1035
+ r.values['test.mock'] = (_c) => {
1036
+ use();
1037
+ return 'TnMock';
1038
+ };
1039
+ r.valueTypes['test.mock'] = '*TnMockTracker';
1040
+ r.methods['test.MockTracker#fn'] = (c) => {
1041
+ use();
1042
+ if (c.args.length === 0)
1043
+ return `TnMockFnEmpty(${c.recv})`;
1044
+ return `TnMockFn(${c.recv}, ${c.args.join(', ')})`;
1045
+ };
1046
+ r.functions['test.mock.fn'] = (c) => {
1047
+ use();
1048
+ if (c.args.length === 0)
1049
+ return 'TnMockFnEmpty(TnMock)';
1050
+ return `TnMockFn(TnMock, ${c.args.join(', ')})`;
1051
+ };
1052
+ r.typers['test.mock.fn'] = (c) => (c.nodes.length === 0 || !c.types[0] ? 'func(...interface{}) interface{}' : c.types[0]);
1053
+ for (const method of ['reset', 'restoreAll']) {
1054
+ r.functions[`test.mock.${method}`] = (_c) => {
1055
+ use();
1056
+ return `TnMock.${method}()`;
1057
+ };
1058
+ }
1059
+ for (const method of ['enable', 'tick', 'runAll', 'setTime', 'reset']) {
1060
+ r.functions[`test.mock.timers.${method}`] = (c) => {
1061
+ use();
1062
+ return `TnMock.Get_timers().${method}(${c.args.join(', ')})`;
1063
+ };
1064
+ r.results[`test.mock.timers.${method}`] = '';
1065
+ }
1066
+ r.typers['test.MockTracker#fn'] = (c) => (c.nodes.length === 0 || !c.types[0] ? 'func(...interface{}) interface{}' : c.types[0]);
1067
+ setResults(r, 'test', 'before=; after=; beforeEach=; afterEach=');
1068
+ }