@matter/tools 0.11.0-alpha.0-20241005-e3e4e4a7a

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 (414) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +100 -0
  3. package/bin/build.js +10 -0
  4. package/bin/prepare-chip.js +5 -0
  5. package/bin/run.js +7 -0
  6. package/bin/test.js +7 -0
  7. package/bin/version.js +7 -0
  8. package/chip/Dockerfile +23 -0
  9. package/dist/cjs/building/builder.d.ts +35 -0
  10. package/dist/cjs/building/builder.d.ts.map +1 -0
  11. package/dist/cjs/building/builder.js +210 -0
  12. package/dist/cjs/building/builder.js.map +6 -0
  13. package/dist/cjs/building/cli.d.ts +7 -0
  14. package/dist/cjs/building/cli.d.ts.map +1 -0
  15. package/dist/cjs/building/cli.js +100 -0
  16. package/dist/cjs/building/cli.js.map +6 -0
  17. package/dist/cjs/building/error.d.ts +16 -0
  18. package/dist/cjs/building/error.d.ts.map +1 -0
  19. package/dist/cjs/building/error.js +50 -0
  20. package/dist/cjs/building/error.js.map +6 -0
  21. package/dist/cjs/building/graph.d.ts +37 -0
  22. package/dist/cjs/building/graph.d.ts.map +1 -0
  23. package/dist/cjs/building/graph.js +222 -0
  24. package/dist/cjs/building/graph.js.map +6 -0
  25. package/dist/cjs/building/project.d.ts +56 -0
  26. package/dist/cjs/building/project.d.ts.map +1 -0
  27. package/dist/cjs/building/project.js +239 -0
  28. package/dist/cjs/building/project.js.map +6 -0
  29. package/dist/cjs/building/tsconfig.d.ts +16 -0
  30. package/dist/cjs/building/tsconfig.d.ts.map +1 -0
  31. package/dist/cjs/building/tsconfig.js +70 -0
  32. package/dist/cjs/building/tsconfig.js.map +6 -0
  33. package/dist/cjs/building/typescript/context.d.ts +16 -0
  34. package/dist/cjs/building/typescript/context.d.ts.map +1 -0
  35. package/dist/cjs/building/typescript/context.js +82 -0
  36. package/dist/cjs/building/typescript/context.js.map +6 -0
  37. package/dist/cjs/building/typescript/incremental-compiler.d.ts +10 -0
  38. package/dist/cjs/building/typescript/incremental-compiler.d.ts.map +1 -0
  39. package/dist/cjs/building/typescript/incremental-compiler.js +119 -0
  40. package/dist/cjs/building/typescript/incremental-compiler.js.map +6 -0
  41. package/dist/cjs/building/typescript/language-service.d.ts +13 -0
  42. package/dist/cjs/building/typescript/language-service.d.ts.map +1 -0
  43. package/dist/cjs/building/typescript/language-service.js +109 -0
  44. package/dist/cjs/building/typescript/language-service.js.map +6 -0
  45. package/dist/cjs/building/typescript/solution-builder.d.ts +10 -0
  46. package/dist/cjs/building/typescript/solution-builder.d.ts.map +1 -0
  47. package/dist/cjs/building/typescript/solution-builder.js +72 -0
  48. package/dist/cjs/building/typescript/solution-builder.js.map +6 -0
  49. package/dist/cjs/building/typescript.d.ts +13 -0
  50. package/dist/cjs/building/typescript.d.ts.map +1 -0
  51. package/dist/cjs/building/typescript.js +31 -0
  52. package/dist/cjs/building/typescript.js.map +6 -0
  53. package/dist/cjs/index.d.ts +15 -0
  54. package/dist/cjs/index.d.ts.map +1 -0
  55. package/dist/cjs/index.js +32 -0
  56. package/dist/cjs/index.js.map +6 -0
  57. package/dist/cjs/package.json +3 -0
  58. package/dist/cjs/running/cli.d.ts +19 -0
  59. package/dist/cjs/running/cli.d.ts.map +1 -0
  60. package/dist/cjs/running/cli.js +82 -0
  61. package/dist/cjs/running/cli.js.map +6 -0
  62. package/dist/cjs/running/execute.d.ts +8 -0
  63. package/dist/cjs/running/execute.d.ts.map +1 -0
  64. package/dist/cjs/running/execute.js +82 -0
  65. package/dist/cjs/running/execute.js.map +6 -0
  66. package/dist/cjs/testing/chip/pics-file.d.ts +20 -0
  67. package/dist/cjs/testing/chip/pics-file.d.ts.map +1 -0
  68. package/dist/cjs/testing/chip/pics-file.js +79 -0
  69. package/dist/cjs/testing/chip/pics-file.js.map +6 -0
  70. package/dist/cjs/testing/chip.d.ts +60 -0
  71. package/dist/cjs/testing/chip.d.ts.map +1 -0
  72. package/dist/cjs/testing/chip.js +306 -0
  73. package/dist/cjs/testing/chip.js.map +6 -0
  74. package/dist/cjs/testing/cli.d.ts +9 -0
  75. package/dist/cjs/testing/cli.d.ts.map +1 -0
  76. package/dist/cjs/testing/cli.js +117 -0
  77. package/dist/cjs/testing/cli.js.map +6 -0
  78. package/dist/cjs/testing/failure-detail.d.ts +19 -0
  79. package/dist/cjs/testing/failure-detail.d.ts.map +1 -0
  80. package/dist/cjs/testing/failure-detail.js +143 -0
  81. package/dist/cjs/testing/failure-detail.js.map +6 -0
  82. package/dist/cjs/testing/files.d.ts +8 -0
  83. package/dist/cjs/testing/files.d.ts.map +1 -0
  84. package/dist/cjs/testing/files.js +52 -0
  85. package/dist/cjs/testing/files.js.map +6 -0
  86. package/dist/cjs/testing/global-declarations.d.ts +38 -0
  87. package/dist/cjs/testing/global-declarations.d.ts.map +1 -0
  88. package/dist/cjs/testing/global-declarations.js +8 -0
  89. package/dist/cjs/testing/global-declarations.js.map +6 -0
  90. package/dist/cjs/testing/global-definitions.d.ts +7 -0
  91. package/dist/cjs/testing/global-definitions.d.ts.map +1 -0
  92. package/dist/cjs/testing/global-definitions.js +50 -0
  93. package/dist/cjs/testing/global-definitions.js.map +6 -0
  94. package/dist/cjs/testing/mocha.d.ts +36 -0
  95. package/dist/cjs/testing/mocha.d.ts.map +1 -0
  96. package/dist/cjs/testing/mocha.js +155 -0
  97. package/dist/cjs/testing/mocha.js.map +6 -0
  98. package/dist/cjs/testing/mocharc.cjs +68 -0
  99. package/dist/cjs/testing/mocharc.d.cts +7 -0
  100. package/dist/cjs/testing/mocks/crypto.d.ts +7 -0
  101. package/dist/cjs/testing/mocks/crypto.d.ts.map +1 -0
  102. package/dist/cjs/testing/mocks/crypto.js +79 -0
  103. package/dist/cjs/testing/mocks/crypto.js.map +6 -0
  104. package/dist/cjs/testing/mocks/environment.d.ts +7 -0
  105. package/dist/cjs/testing/mocks/environment.d.ts.map +1 -0
  106. package/dist/cjs/testing/mocks/environment.js +7 -0
  107. package/dist/cjs/testing/mocks/environment.js.map +6 -0
  108. package/dist/cjs/testing/mocks/index.d.ts +10 -0
  109. package/dist/cjs/testing/mocks/index.d.ts.map +1 -0
  110. package/dist/cjs/testing/mocks/index.js +27 -0
  111. package/dist/cjs/testing/mocks/index.js.map +6 -0
  112. package/dist/cjs/testing/mocks/logging.d.ts +28 -0
  113. package/dist/cjs/testing/mocks/logging.d.ts.map +1 -0
  114. package/dist/cjs/testing/mocks/logging.js +93 -0
  115. package/dist/cjs/testing/mocks/logging.js.map +6 -0
  116. package/dist/cjs/testing/mocks/time.d.ts +88 -0
  117. package/dist/cjs/testing/mocks/time.d.ts.map +1 -0
  118. package/dist/cjs/testing/mocks/time.js +250 -0
  119. package/dist/cjs/testing/mocks/time.js.map +6 -0
  120. package/dist/cjs/testing/node.d.ts +16 -0
  121. package/dist/cjs/testing/node.d.ts.map +1 -0
  122. package/dist/cjs/testing/node.js +108 -0
  123. package/dist/cjs/testing/node.js.map +6 -0
  124. package/dist/cjs/testing/options.d.ts +19 -0
  125. package/dist/cjs/testing/options.d.ts.map +1 -0
  126. package/dist/cjs/testing/options.js +62 -0
  127. package/dist/cjs/testing/options.js.map +6 -0
  128. package/dist/cjs/testing/reporter.d.ts +50 -0
  129. package/dist/cjs/testing/reporter.d.ts.map +1 -0
  130. package/dist/cjs/testing/reporter.js +137 -0
  131. package/dist/cjs/testing/reporter.js.map +6 -0
  132. package/dist/cjs/testing/runner.d.ts +22 -0
  133. package/dist/cjs/testing/runner.d.ts.map +1 -0
  134. package/dist/cjs/testing/runner.js +116 -0
  135. package/dist/cjs/testing/runner.js.map +6 -0
  136. package/dist/cjs/testing/web.d.ts +8 -0
  137. package/dist/cjs/testing/web.d.ts.map +1 -0
  138. package/dist/cjs/testing/web.js +165 -0
  139. package/dist/cjs/testing/web.js.map +6 -0
  140. package/dist/cjs/util/bootstrap.mjs +105 -0
  141. package/dist/cjs/util/docker.d.ts +27 -0
  142. package/dist/cjs/util/docker.d.ts.map +1 -0
  143. package/dist/cjs/util/docker.js +163 -0
  144. package/dist/cjs/util/docker.js.map +6 -0
  145. package/dist/cjs/util/errors.d.ts +8 -0
  146. package/dist/cjs/util/errors.d.ts.map +1 -0
  147. package/dist/cjs/util/errors.js +55 -0
  148. package/dist/cjs/util/errors.js.map +6 -0
  149. package/dist/cjs/util/index.d.ts +8 -0
  150. package/dist/cjs/util/index.d.ts.map +1 -0
  151. package/dist/cjs/util/index.js +25 -0
  152. package/dist/cjs/util/index.js.map +6 -0
  153. package/dist/cjs/util/node-shims.d.ts +7 -0
  154. package/dist/cjs/util/node-shims.d.ts.map +1 -0
  155. package/dist/cjs/util/node-shims.js +12 -0
  156. package/dist/cjs/util/node-shims.js.map +6 -0
  157. package/dist/cjs/util/package.d.ts +61 -0
  158. package/dist/cjs/util/package.d.ts.map +1 -0
  159. package/dist/cjs/util/package.js +324 -0
  160. package/dist/cjs/util/package.js.map +6 -0
  161. package/dist/cjs/util/progress.d.ts +31 -0
  162. package/dist/cjs/util/progress.d.ts.map +1 -0
  163. package/dist/cjs/util/progress.js +232 -0
  164. package/dist/cjs/util/progress.js.map +6 -0
  165. package/dist/cjs/util/tools-path.cjs +13 -0
  166. package/dist/cjs/util/tools-path.d.cts +7 -0
  167. package/dist/cjs/util/trace-unhandled.d.ts +9 -0
  168. package/dist/cjs/util/trace-unhandled.d.ts.map +1 -0
  169. package/dist/cjs/util/trace-unhandled.js +48 -0
  170. package/dist/cjs/util/trace-unhandled.js.map +6 -0
  171. package/dist/cjs/util/wtf.d.ts +10 -0
  172. package/dist/cjs/util/wtf.d.ts.map +1 -0
  173. package/dist/cjs/util/wtf.js +53 -0
  174. package/dist/cjs/util/wtf.js.map +6 -0
  175. package/dist/cjs/versioning/cli.d.ts +7 -0
  176. package/dist/cjs/versioning/cli.d.ts.map +1 -0
  177. package/dist/cjs/versioning/cli.js +62 -0
  178. package/dist/cjs/versioning/cli.js.map +6 -0
  179. package/dist/cjs/versioning/versioner.d.ts +18 -0
  180. package/dist/cjs/versioning/versioner.d.ts.map +1 -0
  181. package/dist/cjs/versioning/versioner.js +145 -0
  182. package/dist/cjs/versioning/versioner.js.map +6 -0
  183. package/dist/esm/building/builder.d.ts +35 -0
  184. package/dist/esm/building/builder.d.ts.map +1 -0
  185. package/dist/esm/building/builder.js +180 -0
  186. package/dist/esm/building/builder.js.map +6 -0
  187. package/dist/esm/building/cli.d.ts +7 -0
  188. package/dist/esm/building/cli.d.ts.map +1 -0
  189. package/dist/esm/building/cli.js +70 -0
  190. package/dist/esm/building/cli.js.map +6 -0
  191. package/dist/esm/building/error.d.ts +16 -0
  192. package/dist/esm/building/error.d.ts.map +1 -0
  193. package/dist/esm/building/error.js +30 -0
  194. package/dist/esm/building/error.js.map +6 -0
  195. package/dist/esm/building/graph.d.ts +37 -0
  196. package/dist/esm/building/graph.d.ts.map +1 -0
  197. package/dist/esm/building/graph.js +192 -0
  198. package/dist/esm/building/graph.js.map +6 -0
  199. package/dist/esm/building/project.d.ts +56 -0
  200. package/dist/esm/building/project.d.ts.map +1 -0
  201. package/dist/esm/building/project.js +219 -0
  202. package/dist/esm/building/project.js.map +6 -0
  203. package/dist/esm/building/tsconfig.d.ts +16 -0
  204. package/dist/esm/building/tsconfig.d.ts.map +1 -0
  205. package/dist/esm/building/tsconfig.js +50 -0
  206. package/dist/esm/building/tsconfig.js.map +6 -0
  207. package/dist/esm/building/typescript/context.d.ts +16 -0
  208. package/dist/esm/building/typescript/context.d.ts.map +1 -0
  209. package/dist/esm/building/typescript/context.js +68 -0
  210. package/dist/esm/building/typescript/context.js.map +6 -0
  211. package/dist/esm/building/typescript/incremental-compiler.d.ts +10 -0
  212. package/dist/esm/building/typescript/incremental-compiler.d.ts.map +1 -0
  213. package/dist/esm/building/typescript/incremental-compiler.js +99 -0
  214. package/dist/esm/building/typescript/incremental-compiler.js.map +6 -0
  215. package/dist/esm/building/typescript/language-service.d.ts +13 -0
  216. package/dist/esm/building/typescript/language-service.d.ts.map +1 -0
  217. package/dist/esm/building/typescript/language-service.js +99 -0
  218. package/dist/esm/building/typescript/language-service.js.map +6 -0
  219. package/dist/esm/building/typescript/solution-builder.d.ts +10 -0
  220. package/dist/esm/building/typescript/solution-builder.d.ts.map +1 -0
  221. package/dist/esm/building/typescript/solution-builder.js +52 -0
  222. package/dist/esm/building/typescript/solution-builder.js.map +6 -0
  223. package/dist/esm/building/typescript.d.ts +13 -0
  224. package/dist/esm/building/typescript.d.ts.map +1 -0
  225. package/dist/esm/building/typescript.js +11 -0
  226. package/dist/esm/building/typescript.js.map +6 -0
  227. package/dist/esm/index.d.ts +15 -0
  228. package/dist/esm/index.d.ts.map +1 -0
  229. package/dist/esm/index.js +15 -0
  230. package/dist/esm/index.js.map +6 -0
  231. package/dist/esm/package.json +3 -0
  232. package/dist/esm/running/cli.d.ts +19 -0
  233. package/dist/esm/running/cli.d.ts.map +1 -0
  234. package/dist/esm/running/cli.js +62 -0
  235. package/dist/esm/running/cli.js.map +6 -0
  236. package/dist/esm/running/execute.d.ts +8 -0
  237. package/dist/esm/running/execute.d.ts.map +1 -0
  238. package/dist/esm/running/execute.js +52 -0
  239. package/dist/esm/running/execute.js.map +6 -0
  240. package/dist/esm/testing/chip/pics-file.d.ts +20 -0
  241. package/dist/esm/testing/chip/pics-file.d.ts.map +1 -0
  242. package/dist/esm/testing/chip/pics-file.js +59 -0
  243. package/dist/esm/testing/chip/pics-file.js.map +6 -0
  244. package/dist/esm/testing/chip.d.ts +60 -0
  245. package/dist/esm/testing/chip.d.ts.map +1 -0
  246. package/dist/esm/testing/chip.js +286 -0
  247. package/dist/esm/testing/chip.js.map +6 -0
  248. package/dist/esm/testing/cli.d.ts +9 -0
  249. package/dist/esm/testing/cli.d.ts.map +1 -0
  250. package/dist/esm/testing/cli.js +87 -0
  251. package/dist/esm/testing/cli.js.map +6 -0
  252. package/dist/esm/testing/failure-detail.d.ts +19 -0
  253. package/dist/esm/testing/failure-detail.d.ts.map +1 -0
  254. package/dist/esm/testing/failure-detail.js +113 -0
  255. package/dist/esm/testing/failure-detail.js.map +6 -0
  256. package/dist/esm/testing/files.d.ts +8 -0
  257. package/dist/esm/testing/files.d.ts.map +1 -0
  258. package/dist/esm/testing/files.js +32 -0
  259. package/dist/esm/testing/files.js.map +6 -0
  260. package/dist/esm/testing/global-declarations.d.ts +38 -0
  261. package/dist/esm/testing/global-declarations.d.ts.map +1 -0
  262. package/dist/esm/testing/global-declarations.js +7 -0
  263. package/dist/esm/testing/global-declarations.js.map +6 -0
  264. package/dist/esm/testing/global-definitions.d.ts +7 -0
  265. package/dist/esm/testing/global-definitions.d.ts.map +1 -0
  266. package/dist/esm/testing/global-definitions.js +27 -0
  267. package/dist/esm/testing/global-definitions.js.map +6 -0
  268. package/dist/esm/testing/mocha.d.ts +36 -0
  269. package/dist/esm/testing/mocha.d.ts.map +1 -0
  270. package/dist/esm/testing/mocha.js +135 -0
  271. package/dist/esm/testing/mocha.js.map +6 -0
  272. package/dist/esm/testing/mocharc.cjs +68 -0
  273. package/dist/esm/testing/mocharc.d.cts +7 -0
  274. package/dist/esm/testing/mocks/crypto.d.ts +7 -0
  275. package/dist/esm/testing/mocks/crypto.d.ts.map +1 -0
  276. package/dist/esm/testing/mocks/crypto.js +59 -0
  277. package/dist/esm/testing/mocks/crypto.js.map +6 -0
  278. package/dist/esm/testing/mocks/environment.d.ts +7 -0
  279. package/dist/esm/testing/mocks/environment.d.ts.map +1 -0
  280. package/dist/esm/testing/mocks/environment.js +6 -0
  281. package/dist/esm/testing/mocks/environment.js.map +6 -0
  282. package/dist/esm/testing/mocks/index.d.ts +10 -0
  283. package/dist/esm/testing/mocks/index.d.ts.map +1 -0
  284. package/dist/esm/testing/mocks/index.js +10 -0
  285. package/dist/esm/testing/mocks/index.js.map +6 -0
  286. package/dist/esm/testing/mocks/logging.d.ts +28 -0
  287. package/dist/esm/testing/mocks/logging.d.ts.map +1 -0
  288. package/dist/esm/testing/mocks/logging.js +63 -0
  289. package/dist/esm/testing/mocks/logging.js.map +6 -0
  290. package/dist/esm/testing/mocks/time.d.ts +88 -0
  291. package/dist/esm/testing/mocks/time.d.ts.map +1 -0
  292. package/dist/esm/testing/mocks/time.js +230 -0
  293. package/dist/esm/testing/mocks/time.js.map +6 -0
  294. package/dist/esm/testing/node.d.ts +16 -0
  295. package/dist/esm/testing/node.d.ts.map +1 -0
  296. package/dist/esm/testing/node.js +78 -0
  297. package/dist/esm/testing/node.js.map +6 -0
  298. package/dist/esm/testing/options.d.ts +19 -0
  299. package/dist/esm/testing/options.d.ts.map +1 -0
  300. package/dist/esm/testing/options.js +42 -0
  301. package/dist/esm/testing/options.js.map +6 -0
  302. package/dist/esm/testing/reporter.d.ts +50 -0
  303. package/dist/esm/testing/reporter.d.ts.map +1 -0
  304. package/dist/esm/testing/reporter.js +107 -0
  305. package/dist/esm/testing/reporter.js.map +6 -0
  306. package/dist/esm/testing/runner.d.ts +22 -0
  307. package/dist/esm/testing/runner.d.ts.map +1 -0
  308. package/dist/esm/testing/runner.js +86 -0
  309. package/dist/esm/testing/runner.js.map +6 -0
  310. package/dist/esm/testing/web.d.ts +8 -0
  311. package/dist/esm/testing/web.d.ts.map +1 -0
  312. package/dist/esm/testing/web.js +135 -0
  313. package/dist/esm/testing/web.js.map +6 -0
  314. package/dist/esm/util/bootstrap.mjs +105 -0
  315. package/dist/esm/util/docker.d.ts +27 -0
  316. package/dist/esm/util/docker.d.ts.map +1 -0
  317. package/dist/esm/util/docker.js +133 -0
  318. package/dist/esm/util/docker.js.map +6 -0
  319. package/dist/esm/util/errors.d.ts +8 -0
  320. package/dist/esm/util/errors.d.ts.map +1 -0
  321. package/dist/esm/util/errors.js +35 -0
  322. package/dist/esm/util/errors.js.map +6 -0
  323. package/dist/esm/util/index.d.ts +8 -0
  324. package/dist/esm/util/index.d.ts.map +1 -0
  325. package/dist/esm/util/index.js +8 -0
  326. package/dist/esm/util/index.js.map +6 -0
  327. package/dist/esm/util/node-shims.d.ts +7 -0
  328. package/dist/esm/util/node-shims.d.ts.map +1 -0
  329. package/dist/esm/util/node-shims.js +11 -0
  330. package/dist/esm/util/node-shims.js.map +6 -0
  331. package/dist/esm/util/package.d.ts +61 -0
  332. package/dist/esm/util/package.d.ts.map +1 -0
  333. package/dist/esm/util/package.js +304 -0
  334. package/dist/esm/util/package.js.map +6 -0
  335. package/dist/esm/util/progress.d.ts +31 -0
  336. package/dist/esm/util/progress.d.ts.map +1 -0
  337. package/dist/esm/util/progress.js +202 -0
  338. package/dist/esm/util/progress.js.map +6 -0
  339. package/dist/esm/util/tools-path.cjs +13 -0
  340. package/dist/esm/util/tools-path.d.cts +7 -0
  341. package/dist/esm/util/trace-unhandled.d.ts +9 -0
  342. package/dist/esm/util/trace-unhandled.d.ts.map +1 -0
  343. package/dist/esm/util/trace-unhandled.js +18 -0
  344. package/dist/esm/util/trace-unhandled.js.map +6 -0
  345. package/dist/esm/util/wtf.d.ts +10 -0
  346. package/dist/esm/util/wtf.d.ts.map +1 -0
  347. package/dist/esm/util/wtf.js +23 -0
  348. package/dist/esm/util/wtf.js.map +6 -0
  349. package/dist/esm/versioning/cli.d.ts +7 -0
  350. package/dist/esm/versioning/cli.d.ts.map +1 -0
  351. package/dist/esm/versioning/cli.js +32 -0
  352. package/dist/esm/versioning/cli.js.map +6 -0
  353. package/dist/esm/versioning/versioner.d.ts +18 -0
  354. package/dist/esm/versioning/versioner.d.ts.map +1 -0
  355. package/dist/esm/versioning/versioner.js +115 -0
  356. package/dist/esm/versioning/versioner.js.map +6 -0
  357. package/package.json +82 -0
  358. package/src/building/builder.ts +216 -0
  359. package/src/building/cli.ts +89 -0
  360. package/src/building/error.ts +29 -0
  361. package/src/building/graph.ts +251 -0
  362. package/src/building/project.ts +313 -0
  363. package/src/building/tsconfig.ts +69 -0
  364. package/src/building/typescript/context.ts +85 -0
  365. package/src/building/typescript/incremental-compiler.ts +126 -0
  366. package/src/building/typescript/language-service.ts +132 -0
  367. package/src/building/typescript/solution-builder.ts +67 -0
  368. package/src/building/typescript.ts +15 -0
  369. package/src/index.ts +15 -0
  370. package/src/running/cli.ts +95 -0
  371. package/src/running/execute.ts +63 -0
  372. package/src/testing/chip/pics-file.ts +71 -0
  373. package/src/testing/chip/pics.properties +53 -0
  374. package/src/testing/chip.ts +420 -0
  375. package/src/testing/cli.ts +122 -0
  376. package/src/testing/failure-detail.ts +126 -0
  377. package/src/testing/files.ts +35 -0
  378. package/src/testing/global-declarations.ts +50 -0
  379. package/src/testing/global-definitions.ts +35 -0
  380. package/src/testing/index.html +16 -0
  381. package/src/testing/mocha.ts +162 -0
  382. package/src/testing/mocharc.cjs +68 -0
  383. package/src/testing/mocharc.d.cts +7 -0
  384. package/src/testing/mocks/crypto.ts +70 -0
  385. package/src/testing/mocks/environment.ts +7 -0
  386. package/src/testing/mocks/index.ts +10 -0
  387. package/src/testing/mocks/logging.ts +99 -0
  388. package/src/testing/mocks/time.ts +294 -0
  389. package/src/testing/node.ts +114 -0
  390. package/src/testing/options.ts +58 -0
  391. package/src/testing/reporter.ts +144 -0
  392. package/src/testing/runner.ts +98 -0
  393. package/src/testing/web.ts +174 -0
  394. package/src/tsconfig.json +14 -0
  395. package/src/util/bootstrap.mjs +105 -0
  396. package/src/util/docker.ts +176 -0
  397. package/src/util/errors.ts +33 -0
  398. package/src/util/index.ts +8 -0
  399. package/src/util/node-shims.ts +13 -0
  400. package/src/util/package.ts +369 -0
  401. package/src/util/progress.ts +252 -0
  402. package/src/util/tools-path.cjs +13 -0
  403. package/src/util/tools-path.d.cts +7 -0
  404. package/src/util/trace-unhandled.ts +17 -0
  405. package/src/util/wtf.ts +25 -0
  406. package/src/versioning/cli.ts +43 -0
  407. package/src/versioning/versioner.ts +139 -0
  408. package/test/testing/mocks/MockTimeTest.ts +113 -0
  409. package/test/tsconfig.json +15 -0
  410. package/tsc/tsconfig.app.json +7 -0
  411. package/tsc/tsconfig.base.json +41 -0
  412. package/tsc/tsconfig.lib.json +12 -0
  413. package/tsc/tsconfig.test.json +7 -0
  414. package/tsconfig.json +5 -0
@@ -0,0 +1,126 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import colors from "ansi-colors";
8
+
9
+ export interface FailureDetail {
10
+ message: string;
11
+ stack?: string;
12
+ diff?: string;
13
+ logs?: string;
14
+ cause?: FailureDetail;
15
+ errors?: FailureDetail[];
16
+ }
17
+
18
+ export function FailureDetail(error: any, logs?: string[]) {
19
+ let diff: string | undefined;
20
+
21
+ const { message, stack, cause, errors } = parseError(error);
22
+
23
+ if (error.expected && error.actual) {
24
+ if (FailureDetail.diff === undefined) {
25
+ diff = "(no diff implementation installed)";
26
+ } else {
27
+ diff = FailureDetail.diff(error.actual.toString(), error.expected.toString());
28
+ diff = diff.trim().replace(/^ {6}/gms, "");
29
+ }
30
+ }
31
+
32
+ const result = { message } as FailureDetail;
33
+ if (diff) {
34
+ result.diff = diff;
35
+ }
36
+ if (stack) {
37
+ result.stack = stack;
38
+ }
39
+ if (logs?.length) {
40
+ result.logs = logs.join("\n");
41
+ }
42
+ if (cause) {
43
+ result.cause = cause;
44
+ }
45
+ if (errors) {
46
+ result.errors = errors;
47
+ }
48
+
49
+ return result;
50
+ }
51
+
52
+ export namespace FailureDetail {
53
+ export function dump(failure: FailureDetail, prefix: string = "") {
54
+ process.stdout.write(colors.redBright(`${prefix}${failure.message}\n\n`));
55
+
56
+ if (failure.diff) {
57
+ process.stdout.write(`${prefix} ${failure.diff.replace(/\n/gm, "\n ")}\n\n`);
58
+ }
59
+
60
+ if (failure.stack) {
61
+ process.stdout.write(`${prefix}${colors.dim(failure.stack.replace(/\n/gm, `\n${prefix}`))}\n\n`);
62
+ }
63
+
64
+ if (failure.cause) {
65
+ process.stdout.write(`${prefix}Caused by:\n\n`);
66
+ dump(failure.cause, prefix);
67
+ }
68
+
69
+ if (failure.errors?.length) {
70
+ let num = 0;
71
+ for (const cause of failure.errors) {
72
+ process.stdout.write(`${prefix}Cause #${++num}:\n\n`);
73
+ dump(cause, `${prefix} `);
74
+ }
75
+ }
76
+
77
+ if (failure.logs) {
78
+ process.stdout.write(` ${failure.logs.replace(/\n/gm, "\n ")}\n\n`);
79
+ }
80
+ }
81
+
82
+ export let diff: undefined | ((actual: string, expected: string) => string);
83
+ }
84
+
85
+ function parseError(error: Error) {
86
+ let message, stack, cause: FailureDetail | undefined, errors: FailureDetail[] | undefined;
87
+
88
+ if (error === undefined || error === null) {
89
+ message = `(error is ${error})`;
90
+ } else {
91
+ message = error.message;
92
+ }
93
+
94
+ if (error.stack) {
95
+ let lines = error.stack.trim().split("\n");
96
+ if (!message) {
97
+ message = lines[0];
98
+ }
99
+ lines = lines.filter(line => line.match(/:\d+:\d+\)?/));
100
+ if (lines.length) {
101
+ stack = lines.map(line => line.trim()).join("\n");
102
+ }
103
+ } else if (error.message) {
104
+ message = error.message;
105
+ } else {
106
+ message = error.toString();
107
+ }
108
+
109
+ message = message.trim().replace(/Error: /, "");
110
+
111
+ if (message.endsWith(":")) {
112
+ message = message.slice(0, message.length - 1);
113
+ }
114
+
115
+ const errorCause = error.cause;
116
+ if (errorCause) {
117
+ cause = FailureDetail(errorCause);
118
+ }
119
+
120
+ const errorErrors = (error as AggregateError).errors;
121
+ if (Array.isArray(errorErrors)) {
122
+ errors = errorErrors.map(e => FailureDetail(e));
123
+ }
124
+
125
+ return { message, stack, cause, errors };
126
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { existsSync, statSync } from "fs";
8
+ import { Package } from "../util/package.js";
9
+
10
+ export function listSupportFiles(format = "cjs") {
11
+ const files = Array<string>();
12
+
13
+ // Always load tooling code in ESM format as tooling globals load as ESM
14
+ files.push(Package.tools.resolve("dist/esm/testing/global-definitions.js"));
15
+ files.push(Package.tools.resolve("dist/esm/testing/mocks/index.js"));
16
+
17
+ // Package code should load in the format being tested
18
+ const config = new Package().resolve(`build/${format}/test/test.config.js`);
19
+ if (existsSync(config)) {
20
+ files.push(config);
21
+ }
22
+
23
+ return files;
24
+ }
25
+
26
+ export function maybeStatSync(path: string) {
27
+ try {
28
+ return statSync(path);
29
+ } catch (e) {
30
+ if (typeof e === "object" && e !== null && "code" in e && (e.code === "ENOENT" || e.code === "ENOTDIR")) {
31
+ return;
32
+ }
33
+ throw e;
34
+ }
35
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import type Chai from "chai";
8
+ import "chai-as-promised";
9
+ import type { MockLogger } from "./mocks/logging.js";
10
+ import type { MockTime } from "./mocks/time.js";
11
+
12
+ declare global {
13
+ // Expose Chai globally
14
+ const expect: typeof Chai.expect;
15
+
16
+ // Expose API for controlling time
17
+ let MockTime: MockTime;
18
+
19
+ // Expose API for controlling logging
20
+ let MockLogger: MockLogger;
21
+
22
+ /**
23
+ * If present, the following hooks are engaged by matter.js packages to
24
+ * enable mocking. We use globals rather than imports so we can hook the
25
+ * modules regardless of whether they're loaded as CommonJS or ESM.
26
+ */
27
+ let MatterHooks:
28
+ | undefined
29
+ | {
30
+ /**
31
+ * Configure time.
32
+ */
33
+ timeSetup?: (Time: any) => void;
34
+
35
+ /**
36
+ * Configure logging.
37
+ */
38
+ loggerSetup?: (Logger: any) => void;
39
+
40
+ /**
41
+ * Configure crypto.
42
+ */
43
+ cryptoSetup?: (Crypto: any) => void;
44
+
45
+ /**
46
+ * Receive intercepted log messages. The logging mocks
47
+ */
48
+ loggerSink?: (level: number, message: string) => void;
49
+ };
50
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ // Note - we don't import mocha here because in the browser we load their standard browser bundle which is different
8
+ // from the Node version
9
+
10
+ import Chai from "chai";
11
+ import ChaiAsPromised from "chai-as-promised";
12
+ import { browserSetup, generalSetup } from "./mocha.js";
13
+ import { cryptoSetup } from "./mocks/crypto.js";
14
+ import { TheMockLogger, loggerSetup } from "./mocks/logging.js";
15
+ import { timeSetup } from "./mocks/time.js";
16
+
17
+ Chai.config.truncateThreshold = 200;
18
+ Chai.use(ChaiAsPromised);
19
+
20
+ Object.assign(globalThis, {
21
+ expect: Chai.expect,
22
+
23
+ MatterHooks: {
24
+ loggerSetup,
25
+ timeSetup,
26
+ cryptoSetup,
27
+ },
28
+
29
+ MockLogger: TheMockLogger,
30
+ });
31
+
32
+ if (typeof window === "object" && globalThis === window) {
33
+ generalSetup(mocha);
34
+ browserSetup(mocha);
35
+ }
@@ -0,0 +1,16 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Matter.js Web Testing</title>
5
+ <link rel="stylesheet" href="mocha/mocha.css">
6
+ </head>
7
+ <body>
8
+ <div id="mocha"></div>
9
+ <script src="mocha/mocha.js"></script>
10
+ <script src="tests.js"></script>
11
+ <script>
12
+ mocha.setup("bdd");
13
+ mocha.run();
14
+ </script>
15
+ </body>
16
+ </html>
@@ -0,0 +1,162 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ // Can't import Mocha in the browser so just import type here
8
+ import type MochaType from "mocha";
9
+ import { wtf } from "../util/wtf.js";
10
+ import { FailureDetail } from "./failure-detail.js";
11
+ import { LoggerHooks } from "./mocks/logging.js";
12
+ import { TestOptions } from "./options.js";
13
+ import { ConsoleProxyReporter, Reporter } from "./reporter.js";
14
+
15
+ export function generalSetup(mocha: MochaType) {
16
+ const Base = (mocha.constructor as typeof MochaType).reporters.Base;
17
+
18
+ // White text, 16-bit and 256-bit green background
19
+ Base.colors["diff added inline"] = "97;42;48;5;22" as any;
20
+
21
+ // White text, 16-bit and 256-bit red background
22
+ Base.colors["diff removed inline"] = "97;41;48;5;52" as any;
23
+
24
+ // Some of our test suites have setup/teardown logic that logs profusely. Hide these logs unless something goes
25
+ // wrong
26
+ async function onlyLogFailure(fn: () => any) {
27
+ if (!MatterHooks) {
28
+ throw new Error("Matter hooks not loaded");
29
+ }
30
+
31
+ const logs = Array<string>();
32
+ const existingSink = MatterHooks.loggerSink;
33
+ try {
34
+ MatterHooks.loggerSink = (_, message) => {
35
+ logs.push(message);
36
+ };
37
+ return await fn();
38
+ } catch (e) {
39
+ process.stdout.write(logs.join("\n"));
40
+ throw e;
41
+ } finally {
42
+ MatterHooks.loggerSink = existingSink;
43
+ }
44
+ }
45
+
46
+ function filterLogs(hook: "beforeAll" | "afterAll" | "beforeEach" | "afterEach") {
47
+ const actual = mocha.suite[hook] as (this: any, fn: Mocha.Func) => any;
48
+ mocha.suite[hook] = function (this: any, fn: Mocha.Func) {
49
+ return actual.call(this, async function (this: any, ...args: any) {
50
+ return await onlyLogFailure(() => fn.apply(this, args));
51
+ });
52
+ } as any;
53
+ }
54
+
55
+ filterLogs("beforeAll");
56
+ filterLogs("afterAll");
57
+ filterLogs("beforeEach");
58
+ filterLogs("afterEach");
59
+
60
+ // Reset mocks before each suite. Suites could conceivably have callbacks that occur across tests. If individual
61
+ // tests need a reset the suite needs to handle itself.
62
+ const actualBeforeAll = mocha.suite.beforeAll;
63
+ mocha.suite.beforeAll = function (this: Mocha.Context, ...args: any) {
64
+ MockTime.reset();
65
+ return actualBeforeAll.apply(this, args);
66
+ };
67
+
68
+ mocha.suite.beforeEach(() => {
69
+ for (const hook of LoggerHooks.beforeEach) {
70
+ hook(mocha);
71
+ }
72
+ });
73
+
74
+ mocha.suite.afterEach(() => {
75
+ for (const hook of LoggerHooks.afterEach) {
76
+ hook(mocha);
77
+ }
78
+ });
79
+
80
+ FailureDetail.diff = Base.generateDiff.bind(Base);
81
+ }
82
+
83
+ export function adaptReporter(Mocha: typeof MochaType, title: string, reporter: Reporter) {
84
+ const RUNNER = Mocha.Runner.constants;
85
+
86
+ let logs = Array<string>();
87
+
88
+ class MochaReporter extends Mocha.reporters.Base {
89
+ constructor(runner: Mocha.Runner) {
90
+ super(runner);
91
+
92
+ runner.once(RUNNER.EVENT_RUN_BEGIN, () => {
93
+ if (!MatterHooks) {
94
+ throw new Error("Matter hooks not loaded");
95
+ }
96
+ MatterHooks.loggerSink = (_, message) => {
97
+ logs.push(message);
98
+ };
99
+ reporter.beginRun(title, this.translatedStats);
100
+ });
101
+
102
+ runner.on(RUNNER.EVENT_SUITE_BEGIN, suite => {
103
+ reporter.beginSuite(suite.titlePath(), this.translatedStats);
104
+ });
105
+
106
+ runner.on(RUNNER.EVENT_TEST_BEGIN, test => {
107
+ logs = (test as any).logs = [];
108
+ reporter.beginTest(test.title, this.translatedStats);
109
+ });
110
+
111
+ runner.on(RUNNER.EVENT_TEST_FAIL, (test, error) => {
112
+ const logs = (test as any).logs as string[];
113
+ reporter.failTest(test.title, FailureDetail(error, logs));
114
+ wtf.dump();
115
+ });
116
+
117
+ runner.once(RUNNER.EVENT_RUN_END, () => {
118
+ if (!MatterHooks) {
119
+ throw new Error("Matter hooks not loaded");
120
+ }
121
+ MatterHooks.loggerSink = undefined;
122
+ reporter.endRun(this.translatedStats);
123
+ wtf.dump();
124
+ });
125
+ }
126
+
127
+ get translatedStats() {
128
+ return {
129
+ total: this.runner.total,
130
+ complete: this.stats.tests,
131
+ failures: this.stats.failures,
132
+ };
133
+ }
134
+ }
135
+
136
+ return MochaReporter;
137
+ }
138
+
139
+ export function browserSetup(mocha: BrowserMocha) {
140
+ mocha.setup("bdd");
141
+
142
+ (globalThis as any).MatterTest = {
143
+ // Starts Mocha (called by clicking link)
144
+ start: () => {
145
+ const root = document.querySelector("#mocha");
146
+ if (root) {
147
+ root.innerHTML = "";
148
+ }
149
+ return mocha.run();
150
+ },
151
+
152
+ // Start Mocha, proxying reporting through console to Playwright and completing once Mocha has finished
153
+ auto: async function (options: TestOptions) {
154
+ TestOptions.apply(mocha, options);
155
+ mocha.reporter(adaptReporter(Mocha, "Web", new ConsoleProxyReporter()));
156
+ return new Promise<void>(accept => {
157
+ const runner = this.start();
158
+ runner.on("end", accept);
159
+ });
160
+ },
161
+ };
162
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ // This file configures mocha for "buildless" dev execution. May be useful for running tests in IDE with Mocha support.
8
+ // Utilize by importing into .mocharc.cjs as a sibling of package.json in the package to test
9
+
10
+ // Required for Node < 19 (see node-shims.ts)
11
+ const webcrypto = require("node:crypto").webcrypto;
12
+ if (globalThis.crypto === undefined) {
13
+ Object.assign(globalThis, { crypto: webcrypto });
14
+ }
15
+
16
+ function mocharc(format = "cjs") {
17
+ const { resolve } = require("path");
18
+ const cli = require("mocha/lib/cli/cli");
19
+ const listSupportFiles = require("./files.js").listSupportFiles;
20
+
21
+ const TOOLS = resolve(__dirname, "../../..");
22
+
23
+ const testJs = `build/${format}/test`;
24
+ const defaultSpec = `${testJs}/**/*Test.js`;
25
+
26
+ // Build. Ideally we'd import build code but it's asynchronous so instead
27
+ // build in a separate process
28
+ const spawnSync = require("child_process").spawnSync;
29
+ const result = spawnSync(`${TOOLS}/bin/build.js`, [format], { stdio: "inherit" });
30
+ if (result.error) {
31
+ console.error(result.error);
32
+ process.exit(-1);
33
+ }
34
+
35
+ // Hook Mocha so we can futz with args
36
+ const main = cli.main;
37
+ cli.main = function (argv, args) {
38
+ const spec = args._;
39
+
40
+ // Remove wildcard test selection if there's an input file
41
+ if (spec.length > 1 && spec[spec.length - 1] === defaultSpec) {
42
+ spec.length = spec.length - 1;
43
+ }
44
+
45
+ // Map input files to the compiled test
46
+ for (let i = 0; i < spec.length; i++) {
47
+ let path = spec[i];
48
+
49
+ // Convenience - map src/ file to test equivalent
50
+ path = path.replace(/src\/(.*)(\.[jt]s)/, "test/$1Test$2");
51
+
52
+ // Map ts files to compiled equivalent
53
+ path = path.replace(/test\/(.*)\.ts/, `${testJs}/$1.js`);
54
+
55
+ spec[i] = path;
56
+ }
57
+
58
+ main.call(this, argv, args);
59
+ };
60
+
61
+ return {
62
+ inlineDiffs: true,
63
+ file: listSupportFiles(format),
64
+ spec: [defaultSpec],
65
+ };
66
+ }
67
+
68
+ module.exports.mocharc = mocharc;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ export function mocharc(): any;
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ const subtle = globalThis.crypto.subtle;
8
+
9
+ /**
10
+ * An extremely minimal Crypto mock.
11
+ *
12
+ * Only supports those subsets of crypto required to complete matter.js tests.
13
+ */
14
+ const TheCrypto = {
15
+ getRandomData: (length: number) => {
16
+ // Make random data deterministic
17
+ const bytes = new Uint8Array(length);
18
+
19
+ return bytes;
20
+ },
21
+
22
+ async pbkdf2(secret: Uint8Array, salt: Uint8Array, iteration: number, keyLength: number) {
23
+ const key = await subtle.importKey("raw", secret, "PBKDF2", false, ["deriveBits"]);
24
+ const bits = await subtle.deriveBits(
25
+ {
26
+ name: "PBKDF2",
27
+ hash: "SHA-256",
28
+ salt: salt,
29
+ iterations: iteration,
30
+ },
31
+ key,
32
+ keyLength * 8,
33
+ );
34
+ return new Uint8Array(bits);
35
+ },
36
+
37
+ async hkdf(secret: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number = 16) {
38
+ const key = await subtle.importKey("raw", secret, "HKDF", false, ["deriveBits"]);
39
+ return new Uint8Array(
40
+ await subtle.deriveBits(
41
+ {
42
+ name: "HKDF",
43
+ hash: "SHA-256",
44
+ salt: salt,
45
+ info: info,
46
+ },
47
+ key,
48
+ length,
49
+ ),
50
+ );
51
+ },
52
+
53
+ verify() {
54
+ // We do not really verify anything
55
+ return;
56
+ },
57
+
58
+ mock: true,
59
+ };
60
+
61
+ export function cryptoSetup(Crypto: any) {
62
+ try {
63
+ Crypto.get();
64
+ } catch (e) {
65
+ if ((e as Error).constructor.name !== "NoProviderError") {
66
+ throw e;
67
+ }
68
+ Crypto.get = () => TheCrypto;
69
+ }
70
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ // TODO
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import "./environment.js";
8
+ import "./logging.js";
9
+ export * from "./crypto.js";
10
+ export * from "./time.js";
@@ -0,0 +1,99 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2022-2024 Matter.js Authors
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import colors from "ansi-colors";
8
+
9
+ interface LoggerLike {
10
+ format: string;
11
+ log(level: number, message: string): void;
12
+ }
13
+
14
+ export interface MockLogger {
15
+ emitAll: boolean;
16
+ injectExternalMessage: (source: string, text: string) => void;
17
+ }
18
+
19
+ export const TheMockLogger: MockLogger = {
20
+ emitAll: false,
21
+ injectExternalMessage: (source: string, text: string) => console.log(formatExternalMessage(source, text)),
22
+ };
23
+
24
+ function formatExternalMessage(source: string, text: string) {
25
+ return ` ${colors.bgCyan.black.bold(` ${source} `)} ${colors.dim(text)}`;
26
+ }
27
+
28
+ /**
29
+ * These functions are invoked by beforeEach/afterEach handlers in generalSetup for Mocha.
30
+ *
31
+ * We place them in an array here rather than calling the global hook functions so that load order doesn't matter. We
32
+ * use an array so that if multiple Logger classes are created (e.g. one for CJS and one for ESM) we don't have to worry
33
+ * about which logger is doing the logging.
34
+ */
35
+ export const LoggerHooks = {
36
+ beforeEach: Array<(mocha: Mocha) => void>(),
37
+ afterEach: Array<(mocha: Mocha) => void>(),
38
+ };
39
+
40
+ export function loggerSetup(Logger: LoggerLike) {
41
+ // Currently everywhere we run tests supports ANSI escape codes for
42
+ // colorization. This includes:
43
+ //
44
+ // - Node console
45
+ // - Github actions
46
+ // - Headless browser -> node console
47
+ // - VS code/webstorm terminal
48
+ //
49
+ // Should this become a PITA we can add an option to disable
50
+ Logger.format = "ansi";
51
+
52
+ let messageBuffer: [number, string][] | undefined;
53
+
54
+ const defaultLog = Logger.log;
55
+
56
+ function passMessage(args: [number, string]) {
57
+ defaultLog.apply(Logger, args);
58
+ }
59
+
60
+ function interceptingLogger(...args: [number, string]) {
61
+ let emitAll = TheMockLogger.emitAll;
62
+ if (MatterHooks?.loggerSink) {
63
+ MatterHooks.loggerSink(...args);
64
+ } else if (!emitAll) {
65
+ if (messageBuffer) {
66
+ messageBuffer.push(args);
67
+ } else {
68
+ emitAll = true;
69
+ }
70
+ }
71
+
72
+ if (emitAll) {
73
+ passMessage(args);
74
+ }
75
+ }
76
+
77
+ TheMockLogger.injectExternalMessage = (source, text) => interceptingLogger(0, formatExternalMessage(source, text));
78
+
79
+ Logger.log = interceptingLogger;
80
+
81
+ // Divert log messages for test duration
82
+ LoggerHooks.beforeEach.push(function () {
83
+ if (!TheMockLogger.emitAll) {
84
+ messageBuffer = [];
85
+ }
86
+ });
87
+
88
+ // Emit log messages only if the test fails
89
+ LoggerHooks.afterEach.push(mocha => {
90
+ if (messageBuffer?.length) {
91
+ if (mocha.suite.ctx.currentTest?.isFailed()) {
92
+ for (const args of messageBuffer) {
93
+ passMessage(args);
94
+ }
95
+ }
96
+ messageBuffer = undefined;
97
+ }
98
+ });
99
+ }