@metamask/snaps-jest 8.3.2 → 8.5.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 (305) hide show
  1. package/CHANGELOG.md +80 -1
  2. package/LICENSE +15 -0
  3. package/dist/environment.cjs +2 -1
  4. package/dist/environment.cjs.map +1 -1
  5. package/dist/environment.d.cts +2 -2
  6. package/dist/environment.d.cts.map +1 -1
  7. package/dist/environment.d.mts +2 -2
  8. package/dist/environment.d.mts.map +1 -1
  9. package/dist/environment.mjs +3 -2
  10. package/dist/environment.mjs.map +1 -1
  11. package/dist/helpers.cjs +9 -176
  12. package/dist/helpers.cjs.map +1 -1
  13. package/dist/helpers.d.cts +1 -44
  14. package/dist/helpers.d.cts.map +1 -1
  15. package/dist/helpers.d.mts +1 -44
  16. package/dist/helpers.d.mts.map +1 -1
  17. package/dist/helpers.mjs +11 -171
  18. package/dist/helpers.mjs.map +1 -1
  19. package/dist/index.cjs +8 -2
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +2 -1
  22. package/dist/index.d.cts.map +1 -1
  23. package/dist/index.d.mts +2 -1
  24. package/dist/index.d.mts.map +1 -1
  25. package/dist/index.mjs +1 -1
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/internals/index.cjs +0 -3
  28. package/dist/internals/index.cjs.map +1 -1
  29. package/dist/internals/index.d.cts +0 -3
  30. package/dist/internals/index.d.cts.map +1 -1
  31. package/dist/internals/index.d.mts +0 -3
  32. package/dist/internals/index.d.mts.map +1 -1
  33. package/dist/internals/index.mjs +0 -3
  34. package/dist/internals/index.mjs.map +1 -1
  35. package/dist/matchers.cjs +3 -3
  36. package/dist/matchers.cjs.map +1 -1
  37. package/dist/matchers.d.cts.map +1 -1
  38. package/dist/matchers.d.mts.map +1 -1
  39. package/dist/matchers.mjs +1 -1
  40. package/dist/matchers.mjs.map +1 -1
  41. package/package.json +38 -33
  42. package/dist/internals/request.cjs +0 -143
  43. package/dist/internals/request.cjs.map +0 -1
  44. package/dist/internals/request.d.cts +0 -56
  45. package/dist/internals/request.d.cts.map +0 -1
  46. package/dist/internals/request.d.mts +0 -56
  47. package/dist/internals/request.d.mts.map +0 -1
  48. package/dist/internals/request.mjs +0 -138
  49. package/dist/internals/request.mjs.map +0 -1
  50. package/dist/internals/simulation/constants.cjs +0 -21
  51. package/dist/internals/simulation/constants.cjs.map +0 -1
  52. package/dist/internals/simulation/constants.d.cts +0 -18
  53. package/dist/internals/simulation/constants.d.cts.map +0 -1
  54. package/dist/internals/simulation/constants.d.mts +0 -18
  55. package/dist/internals/simulation/constants.d.mts.map +0 -1
  56. package/dist/internals/simulation/constants.mjs +0 -18
  57. package/dist/internals/simulation/constants.mjs.map +0 -1
  58. package/dist/internals/simulation/controllers.cjs +0 -101
  59. package/dist/internals/simulation/controllers.cjs.map +0 -1
  60. package/dist/internals/simulation/controllers.d.cts +0 -41
  61. package/dist/internals/simulation/controllers.d.cts.map +0 -1
  62. package/dist/internals/simulation/controllers.d.mts +0 -41
  63. package/dist/internals/simulation/controllers.d.mts.map +0 -1
  64. package/dist/internals/simulation/controllers.mjs +0 -96
  65. package/dist/internals/simulation/controllers.mjs.map +0 -1
  66. package/dist/internals/simulation/files.cjs +0 -94
  67. package/dist/internals/simulation/files.cjs.map +0 -1
  68. package/dist/internals/simulation/files.d.cts +0 -49
  69. package/dist/internals/simulation/files.d.cts.map +0 -1
  70. package/dist/internals/simulation/files.d.mts +0 -49
  71. package/dist/internals/simulation/files.d.mts.map +0 -1
  72. package/dist/internals/simulation/files.mjs +0 -91
  73. package/dist/internals/simulation/files.mjs.map +0 -1
  74. package/dist/internals/simulation/index.cjs +0 -22
  75. package/dist/internals/simulation/index.cjs.map +0 -1
  76. package/dist/internals/simulation/index.d.cts +0 -6
  77. package/dist/internals/simulation/index.d.cts.map +0 -1
  78. package/dist/internals/simulation/index.d.mts +0 -6
  79. package/dist/internals/simulation/index.d.mts.map +0 -1
  80. package/dist/internals/simulation/index.mjs +0 -6
  81. package/dist/internals/simulation/index.mjs.map +0 -1
  82. package/dist/internals/simulation/interface.cjs +0 -527
  83. package/dist/internals/simulation/interface.cjs.map +0 -1
  84. package/dist/internals/simulation/interface.d.cts +0 -152
  85. package/dist/internals/simulation/interface.d.cts.map +0 -1
  86. package/dist/internals/simulation/interface.d.mts +0 -152
  87. package/dist/internals/simulation/interface.d.mts.map +0 -1
  88. package/dist/internals/simulation/interface.mjs +0 -513
  89. package/dist/internals/simulation/interface.mjs.map +0 -1
  90. package/dist/internals/simulation/methods/constants.cjs +0 -72
  91. package/dist/internals/simulation/methods/constants.cjs.map +0 -1
  92. package/dist/internals/simulation/methods/constants.d.cts +0 -11
  93. package/dist/internals/simulation/methods/constants.d.cts.map +0 -1
  94. package/dist/internals/simulation/methods/constants.d.mts +0 -11
  95. package/dist/internals/simulation/methods/constants.d.mts.map +0 -1
  96. package/dist/internals/simulation/methods/constants.mjs +0 -69
  97. package/dist/internals/simulation/methods/constants.mjs.map +0 -1
  98. package/dist/internals/simulation/methods/hooks/get-preferences.cjs +0 -18
  99. package/dist/internals/simulation/methods/hooks/get-preferences.cjs.map +0 -1
  100. package/dist/internals/simulation/methods/hooks/get-preferences.d.cts +0 -14
  101. package/dist/internals/simulation/methods/hooks/get-preferences.d.cts.map +0 -1
  102. package/dist/internals/simulation/methods/hooks/get-preferences.d.mts +0 -14
  103. package/dist/internals/simulation/methods/hooks/get-preferences.d.mts.map +0 -1
  104. package/dist/internals/simulation/methods/hooks/get-preferences.mjs +0 -14
  105. package/dist/internals/simulation/methods/hooks/get-preferences.mjs.map +0 -1
  106. package/dist/internals/simulation/methods/hooks/index.cjs +0 -22
  107. package/dist/internals/simulation/methods/hooks/index.cjs.map +0 -1
  108. package/dist/internals/simulation/methods/hooks/index.d.cts +0 -6
  109. package/dist/internals/simulation/methods/hooks/index.d.cts.map +0 -1
  110. package/dist/internals/simulation/methods/hooks/index.d.mts +0 -6
  111. package/dist/internals/simulation/methods/hooks/index.d.mts.map +0 -1
  112. package/dist/internals/simulation/methods/hooks/index.mjs +0 -6
  113. package/dist/internals/simulation/methods/hooks/index.mjs.map +0 -1
  114. package/dist/internals/simulation/methods/hooks/interface.cjs +0 -24
  115. package/dist/internals/simulation/methods/hooks/interface.cjs.map +0 -1
  116. package/dist/internals/simulation/methods/hooks/interface.d.cts +0 -17
  117. package/dist/internals/simulation/methods/hooks/interface.d.cts.map +0 -1
  118. package/dist/internals/simulation/methods/hooks/interface.d.mts +0 -17
  119. package/dist/internals/simulation/methods/hooks/interface.d.mts.map +0 -1
  120. package/dist/internals/simulation/methods/hooks/interface.mjs +0 -19
  121. package/dist/internals/simulation/methods/hooks/interface.mjs.map +0 -1
  122. package/dist/internals/simulation/methods/hooks/notifications.cjs +0 -58
  123. package/dist/internals/simulation/methods/hooks/notifications.cjs.map +0 -1
  124. package/dist/internals/simulation/methods/hooks/notifications.d.cts +0 -17
  125. package/dist/internals/simulation/methods/hooks/notifications.d.cts.map +0 -1
  126. package/dist/internals/simulation/methods/hooks/notifications.d.mts +0 -17
  127. package/dist/internals/simulation/methods/hooks/notifications.d.mts.map +0 -1
  128. package/dist/internals/simulation/methods/hooks/notifications.mjs +0 -55
  129. package/dist/internals/simulation/methods/hooks/notifications.mjs.map +0 -1
  130. package/dist/internals/simulation/methods/hooks/request-user-approval.cjs +0 -38
  131. package/dist/internals/simulation/methods/hooks/request-user-approval.cjs.map +0 -1
  132. package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts +0 -16
  133. package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts.map +0 -1
  134. package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts +0 -16
  135. package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts.map +0 -1
  136. package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +0 -35
  137. package/dist/internals/simulation/methods/hooks/request-user-approval.mjs.map +0 -1
  138. package/dist/internals/simulation/methods/hooks/state.cjs +0 -84
  139. package/dist/internals/simulation/methods/hooks/state.cjs.map +0 -1
  140. package/dist/internals/simulation/methods/hooks/state.d.cts +0 -24
  141. package/dist/internals/simulation/methods/hooks/state.d.cts.map +0 -1
  142. package/dist/internals/simulation/methods/hooks/state.d.mts +0 -24
  143. package/dist/internals/simulation/methods/hooks/state.d.mts.map +0 -1
  144. package/dist/internals/simulation/methods/hooks/state.mjs +0 -79
  145. package/dist/internals/simulation/methods/hooks/state.mjs.map +0 -1
  146. package/dist/internals/simulation/methods/index.cjs +0 -18
  147. package/dist/internals/simulation/methods/index.cjs.map +0 -1
  148. package/dist/internals/simulation/methods/index.d.cts +0 -2
  149. package/dist/internals/simulation/methods/index.d.cts.map +0 -1
  150. package/dist/internals/simulation/methods/index.d.mts +0 -2
  151. package/dist/internals/simulation/methods/index.d.mts.map +0 -1
  152. package/dist/internals/simulation/methods/index.mjs +0 -2
  153. package/dist/internals/simulation/methods/index.mjs.map +0 -1
  154. package/dist/internals/simulation/methods/specifications.cjs +0 -85
  155. package/dist/internals/simulation/methods/specifications.cjs.map +0 -1
  156. package/dist/internals/simulation/methods/specifications.d.cts +0 -57
  157. package/dist/internals/simulation/methods/specifications.d.cts.map +0 -1
  158. package/dist/internals/simulation/methods/specifications.d.mts +0 -57
  159. package/dist/internals/simulation/methods/specifications.d.mts.map +0 -1
  160. package/dist/internals/simulation/methods/specifications.mjs +0 -78
  161. package/dist/internals/simulation/methods/specifications.mjs.map +0 -1
  162. package/dist/internals/simulation/middleware/engine.cjs +0 -37
  163. package/dist/internals/simulation/middleware/engine.cjs.map +0 -1
  164. package/dist/internals/simulation/middleware/engine.d.cts +0 -27
  165. package/dist/internals/simulation/middleware/engine.d.cts.map +0 -1
  166. package/dist/internals/simulation/middleware/engine.d.mts +0 -27
  167. package/dist/internals/simulation/middleware/engine.d.mts.map +0 -1
  168. package/dist/internals/simulation/middleware/engine.mjs +0 -34
  169. package/dist/internals/simulation/middleware/engine.mjs.map +0 -1
  170. package/dist/internals/simulation/middleware/index.cjs +0 -18
  171. package/dist/internals/simulation/middleware/index.cjs.map +0 -1
  172. package/dist/internals/simulation/middleware/index.d.cts +0 -2
  173. package/dist/internals/simulation/middleware/index.d.cts.map +0 -1
  174. package/dist/internals/simulation/middleware/index.d.mts +0 -2
  175. package/dist/internals/simulation/middleware/index.d.mts.map +0 -1
  176. package/dist/internals/simulation/middleware/index.mjs +0 -2
  177. package/dist/internals/simulation/middleware/index.mjs.map +0 -1
  178. package/dist/internals/simulation/middleware/internal-methods/accounts.cjs +0 -34
  179. package/dist/internals/simulation/middleware/internal-methods/accounts.cjs.map +0 -1
  180. package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts +0 -20
  181. package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts.map +0 -1
  182. package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts +0 -20
  183. package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts.map +0 -1
  184. package/dist/internals/simulation/middleware/internal-methods/accounts.mjs +0 -30
  185. package/dist/internals/simulation/middleware/internal-methods/accounts.mjs.map +0 -1
  186. package/dist/internals/simulation/middleware/internal-methods/index.cjs +0 -18
  187. package/dist/internals/simulation/middleware/internal-methods/index.cjs.map +0 -1
  188. package/dist/internals/simulation/middleware/internal-methods/index.d.cts +0 -2
  189. package/dist/internals/simulation/middleware/internal-methods/index.d.cts.map +0 -1
  190. package/dist/internals/simulation/middleware/internal-methods/index.d.mts +0 -2
  191. package/dist/internals/simulation/middleware/internal-methods/index.d.mts.map +0 -1
  192. package/dist/internals/simulation/middleware/internal-methods/index.mjs +0 -2
  193. package/dist/internals/simulation/middleware/internal-methods/index.mjs.map +0 -1
  194. package/dist/internals/simulation/middleware/internal-methods/middleware.cjs +0 -44
  195. package/dist/internals/simulation/middleware/internal-methods/middleware.cjs.map +0 -1
  196. package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts +0 -23
  197. package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts.map +0 -1
  198. package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts +0 -23
  199. package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts.map +0 -1
  200. package/dist/internals/simulation/middleware/internal-methods/middleware.mjs +0 -40
  201. package/dist/internals/simulation/middleware/internal-methods/middleware.mjs.map +0 -1
  202. package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs +0 -28
  203. package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs.map +0 -1
  204. package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts +0 -16
  205. package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts.map +0 -1
  206. package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts +0 -16
  207. package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts.map +0 -1
  208. package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs +0 -24
  209. package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs.map +0 -1
  210. package/dist/internals/simulation/middleware/mock.cjs +0 -22
  211. package/dist/internals/simulation/middleware/mock.cjs.map +0 -1
  212. package/dist/internals/simulation/middleware/mock.d.cts +0 -11
  213. package/dist/internals/simulation/middleware/mock.d.cts.map +0 -1
  214. package/dist/internals/simulation/middleware/mock.d.mts +0 -11
  215. package/dist/internals/simulation/middleware/mock.d.mts.map +0 -1
  216. package/dist/internals/simulation/middleware/mock.mjs +0 -18
  217. package/dist/internals/simulation/middleware/mock.mjs.map +0 -1
  218. package/dist/internals/simulation/options.cjs +0 -25
  219. package/dist/internals/simulation/options.cjs.map +0 -1
  220. package/dist/internals/simulation/options.d.cts +0 -40
  221. package/dist/internals/simulation/options.d.cts.map +0 -1
  222. package/dist/internals/simulation/options.d.mts +0 -40
  223. package/dist/internals/simulation/options.d.mts.map +0 -1
  224. package/dist/internals/simulation/options.mjs +0 -21
  225. package/dist/internals/simulation/options.mjs.map +0 -1
  226. package/dist/internals/simulation/simulation.cjs +0 -155
  227. package/dist/internals/simulation/simulation.cjs.map +0 -1
  228. package/dist/internals/simulation/simulation.d.cts +0 -103
  229. package/dist/internals/simulation/simulation.d.cts.map +0 -1
  230. package/dist/internals/simulation/simulation.d.mts +0 -103
  231. package/dist/internals/simulation/simulation.d.mts.map +0 -1
  232. package/dist/internals/simulation/simulation.mjs +0 -150
  233. package/dist/internals/simulation/simulation.mjs.map +0 -1
  234. package/dist/internals/simulation/store/index.cjs +0 -21
  235. package/dist/internals/simulation/store/index.cjs.map +0 -1
  236. package/dist/internals/simulation/store/index.d.cts +0 -5
  237. package/dist/internals/simulation/store/index.d.cts.map +0 -1
  238. package/dist/internals/simulation/store/index.d.mts +0 -5
  239. package/dist/internals/simulation/store/index.d.mts.map +0 -1
  240. package/dist/internals/simulation/store/index.mjs +0 -5
  241. package/dist/internals/simulation/store/index.mjs.map +0 -1
  242. package/dist/internals/simulation/store/mocks.cjs +0 -39
  243. package/dist/internals/simulation/store/mocks.cjs.map +0 -1
  244. package/dist/internals/simulation/store/mocks.d.cts +0 -36
  245. package/dist/internals/simulation/store/mocks.d.cts.map +0 -1
  246. package/dist/internals/simulation/store/mocks.d.mts +0 -36
  247. package/dist/internals/simulation/store/mocks.d.mts.map +0 -1
  248. package/dist/internals/simulation/store/mocks.mjs +0 -35
  249. package/dist/internals/simulation/store/mocks.mjs.map +0 -1
  250. package/dist/internals/simulation/store/notifications.cjs +0 -35
  251. package/dist/internals/simulation/store/notifications.cjs.map +0 -1
  252. package/dist/internals/simulation/store/notifications.d.cts +0 -45
  253. package/dist/internals/simulation/store/notifications.d.cts.map +0 -1
  254. package/dist/internals/simulation/store/notifications.d.mts +0 -45
  255. package/dist/internals/simulation/store/notifications.d.mts.map +0 -1
  256. package/dist/internals/simulation/store/notifications.mjs +0 -32
  257. package/dist/internals/simulation/store/notifications.mjs.map +0 -1
  258. package/dist/internals/simulation/store/state.cjs +0 -54
  259. package/dist/internals/simulation/store/state.cjs.map +0 -1
  260. package/dist/internals/simulation/store/state.d.cts +0 -56
  261. package/dist/internals/simulation/store/state.d.cts.map +0 -1
  262. package/dist/internals/simulation/store/state.d.mts +0 -56
  263. package/dist/internals/simulation/store/state.d.mts.map +0 -1
  264. package/dist/internals/simulation/store/state.mjs +0 -50
  265. package/dist/internals/simulation/store/state.mjs.map +0 -1
  266. package/dist/internals/simulation/store/store.cjs +0 -51
  267. package/dist/internals/simulation/store/store.cjs.map +0 -1
  268. package/dist/internals/simulation/store/store.d.cts +0 -22
  269. package/dist/internals/simulation/store/store.d.cts.map +0 -1
  270. package/dist/internals/simulation/store/store.d.mts +0 -22
  271. package/dist/internals/simulation/store/store.d.mts.map +0 -1
  272. package/dist/internals/simulation/store/store.mjs +0 -45
  273. package/dist/internals/simulation/store/store.mjs.map +0 -1
  274. package/dist/internals/simulation/store/ui.cjs +0 -24
  275. package/dist/internals/simulation/store/ui.cjs.map +0 -1
  276. package/dist/internals/simulation/store/ui.d.cts +0 -27
  277. package/dist/internals/simulation/store/ui.d.cts.map +0 -1
  278. package/dist/internals/simulation/store/ui.d.mts +0 -27
  279. package/dist/internals/simulation/store/ui.d.mts.map +0 -1
  280. package/dist/internals/simulation/store/ui.mjs +0 -21
  281. package/dist/internals/simulation/store/ui.mjs.map +0 -1
  282. package/dist/internals/structs.cjs +0 -157
  283. package/dist/internals/structs.cjs.map +0 -1
  284. package/dist/internals/structs.d.cts +0 -205
  285. package/dist/internals/structs.d.cts.map +0 -1
  286. package/dist/internals/structs.d.mts +0 -205
  287. package/dist/internals/structs.d.mts.map +0 -1
  288. package/dist/internals/structs.mjs +0 -154
  289. package/dist/internals/structs.mjs.map +0 -1
  290. package/dist/types/index.cjs +0 -18
  291. package/dist/types/index.cjs.map +0 -1
  292. package/dist/types/index.d.cts +0 -2
  293. package/dist/types/index.d.cts.map +0 -1
  294. package/dist/types/index.d.mts +0 -2
  295. package/dist/types/index.d.mts.map +0 -1
  296. package/dist/types/index.mjs +0 -2
  297. package/dist/types/index.mjs.map +0 -1
  298. package/dist/types/types.cjs +0 -3
  299. package/dist/types/types.cjs.map +0 -1
  300. package/dist/types/types.d.cts +0 -386
  301. package/dist/types/types.d.cts.map +0 -1
  302. package/dist/types/types.d.mts +0 -386
  303. package/dist/types/types.d.mts.map +0 -1
  304. package/dist/types/types.mjs +0 -2
  305. package/dist/types/types.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -6,12 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
7
 
7
8
  ## [Unreleased]
8
9
 
10
+ ## [8.5.0]
11
+
12
+ ### Changed
13
+
14
+ - Move helper functions to simulation package ([#2769](https://github.com/MetaMask/snaps/pull/2769))
15
+
16
+ ## [8.4.0]
17
+
18
+ ### Added
19
+
20
+ - Add support for selector component ([#2724](https://github.com/MetaMask/snaps/pull/2724))
21
+ - Interfaces now have a `selectFromSelector` function that can be used to
22
+ select an option from a selector.
23
+
24
+ ### Changed
25
+
26
+ - Extract simulation part of `snaps-jest` to separate package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
27
+
9
28
  ## [8.3.2]
29
+
10
30
  ### Fixed
31
+
11
32
  - Fix invalid types in type declaration in some cases ([#2714](https://github.com/MetaMask/snaps/pull/2714))
12
33
 
13
34
  ## [8.3.1]
35
+
14
36
  ### Fixed
37
+
15
38
  - Fix ESM version of the package ([#2682](https://github.com/MetaMask/snaps/pull/2682))
16
39
  - This fixes the ESM version of the package to be fully compliant with the ESM
17
40
  standard.
@@ -19,44 +42,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
42
  - Bump other MetaMask dependencies ([#2703](https://github.com/MetaMask/snaps/pull/2703))
20
43
 
21
44
  ## [8.3.0]
45
+
22
46
  ### Added
47
+
23
48
  - Add support for `snap_getPreferences` ([#2607](https://github.com/MetaMask/snaps/pull/2607))
24
49
  - Add `RadioGroup` component ([#2592](https://github.com/MetaMask/snaps/pull/2592))
25
50
  - Add support for custom dialogs in `snaps-jest` ([#2526](https://github.com/MetaMask/snaps/pull/2526), [#2509](https://github.com/MetaMask/snaps/pull/2509))
26
51
 
27
52
  ### Changed
53
+
28
54
  - Replace `superstruct` with ESM-compatible fork `@metamask/superstruct` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
29
55
 
30
56
  ## [8.2.0]
57
+
31
58
  ### Added
59
+
32
60
  - Add support for `Checkbox` to `snaps-jest` ([#2515](https://github.com/MetaMask/snaps/pull/2515))
33
61
  - Checkboxes can be interacted with using `clickElement`.
34
62
  - Add support for `FileInput` to `snaps-jest` ([#2494](https://github.com/MetaMask/snaps/pull/2494))
35
63
  - Files can be uploaded to file inputs using `uploadFile`.
36
64
 
37
65
  ## [8.1.3]
66
+
38
67
  ### Changed
68
+
39
69
  - Bump MetaMask dependencies ([#2460](https://github.com/MetaMask/snaps/pull/2460), [#2477](https://github.com/MetaMask/snaps/pull/2477))
40
70
 
41
71
  ## [8.1.2]
72
+
42
73
  ### Fixed
74
+
43
75
  - Fix invalid `@metamask/snaps-sdk` imports ([#2452](https://github.com/MetaMask/snaps/pull/2452))
44
76
 
45
77
  ## [8.1.1]
78
+
46
79
  ### Changed
80
+
47
81
  - Bump `@metamask/key-tree` from `9.1.0` to `9.1.1` ([#2431](https://github.com/MetaMask/snaps/pull/2431))
48
82
 
49
83
  ## [8.1.0]
84
+
50
85
  ### Added
86
+
51
87
  - Add `selectInDropdown` to be used with the newly added `Dropdown` component ([#2420](https://github.com/MetaMask/snaps/pull/2420))
52
88
  - Add `context` field to `snap_createInterface` ([#2413](https://github.com/MetaMask/snaps/pull/2413))
53
89
 
54
90
  ### Fixed
91
+
55
92
  - Properly handle invalid interfaces during test ([#2433](https://github.com/MetaMask/snaps/pull/2433))
56
93
  - Properly diff when using legacy UI with `toRender` matcher ([#2432](https://github.com/MetaMask/snaps/pull/2432))
57
94
 
58
95
  ## [8.0.0]
96
+
59
97
  ### Added
98
+
60
99
  - **BREAKING:** Add JSX support for custom UI ([#2258](https://github.com/MetaMask/snaps/pull/2258))
61
100
  - It's now possible to use JSX components from `@metamask/snaps-sdk` to build
62
101
  user interfaces for Snaps.
@@ -66,38 +105,52 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66
105
  need to update your tests to check the JSX format.
67
106
 
68
107
  ### Changed
108
+
69
109
  - Bump `@metamask/base-controller` from `5.0.1` to `5.0.2` ([#2375](https://github.com/MetaMask/snaps/pull/2375))
70
110
 
71
111
  ## [7.0.2]
112
+
72
113
  ### Changed
114
+
73
115
  - Bump `@metamask/snaps-execution-environments` to latest ([#2339](https://github.com/MetaMask/snaps/pull/2339))
74
116
 
75
117
  ## [7.0.1]
118
+
76
119
  ### Fixed
120
+
77
121
  - Improve correctness of `clickElement` ([#2334](https://github.com/MetaMask/snaps/pull/2334))
78
122
  - The function should now behave closer to the client implementation.
79
123
 
80
124
  ## [7.0.0]
125
+
81
126
  ### Added
127
+
82
128
  - **BREAKING:** Support Interactive UI in `snaps-jest` ([#2286](https://github.com/MetaMask/snaps/pull/2286))
83
129
  - Remove `content` from the Snap response, instead `getInterface()` must be used
84
130
  - `clickElement` and `typeInField` can be used on the interface return value to simulate actions
85
131
 
86
132
  ### Changed
133
+
87
134
  - Improve Jest expect types ([#2308](https://github.com/MetaMask/snaps/pull/2308))
88
135
  - Refactor to support changes to encryption ([#2316](https://github.com/MetaMask/snaps/pull/2316))
89
136
 
90
137
  ## [6.0.2]
138
+
91
139
  ### Changed
140
+
92
141
  - Bump MetaMask dependencies ([#2270](https://github.com/MetaMask/snaps/pull/2270))
93
142
  - Bump @metamask/json-rpc-engine from 7.3.2 to 7.3.3 ([#2247](https://github.com/MetaMask/snaps/pull/2247))
94
143
 
95
144
  ## [6.0.1]
145
+
96
146
  ### Fixed
147
+
97
148
  - Fix minor build configuration problems ([#2220](https://github.com/MetaMask/snaps/pull/2220))
98
149
 
99
150
  ## [6.0.0]
151
+
100
152
  ### Changed
153
+
101
154
  - **BREAKING:** Update ESM build to be fully compliant with the ESM standard ([#2210](https://github.com/MetaMask/snaps/pull/2210))
102
155
  - **BREAKING:** Move Node.js exports to separate export ([#2210](https://github.com/MetaMask/snaps/pull/2210))
103
156
  - The default export is now browser-compatible.
@@ -105,7 +158,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
105
158
  - Bump `@metamask/rpc-errors` to `^6.2.1` ([#2209](https://github.com/MetaMask/snaps/pull/2209))
106
159
 
107
160
  ## [5.0.0]
161
+
108
162
  ### Added
163
+
109
164
  - **BREAKING:** Implement testing framework using Node.js executor ([#1982](https://github.com/MetaMask/snaps/pull/1982), [#2118](https://github.com/MetaMask/snaps/pull/2118))
110
165
  - The network mocking functionality was removed, but may be reintroduced in a future version.
111
166
  - `mockJsonRpc` no longer returns a `Promise`.
@@ -116,30 +171,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
116
171
  - Add `snap_getClientStatus` support ([#2159](https://github.com/MetaMask/snaps/pull/2159))
117
172
 
118
173
  ### Changed
174
+
119
175
  - Bump several MetaMask dependencies ([#2101](https://github.com/MetaMask/snaps/pull/2101), [#2100](https://github.com/MetaMask/snaps/pull/2100), [#2129](https://github.com/MetaMask/snaps/pull/2129), [#2140](https://github.com/MetaMask/snaps/pull/2140), [#2141](https://github.com/MetaMask/snaps/pull/2141), [#2142](https://github.com/MetaMask/snaps/pull/2142))
120
176
 
121
177
  ## [4.0.1]
178
+
122
179
  ### Fixed
180
+
123
181
  - Fix coercing of address values in `sendTransaction` function ([#1970](https://github.com/MetaMask/snaps/pull/1970))
124
182
 
125
183
  ## [4.0.0]
184
+
126
185
  ### Changed
186
+
127
187
  - Use `@metamask/snaps-sdk` package ([#1930](https://github.com/MetaMask/snaps/pull/1930),
128
188
  [#1950](https://github.com/MetaMask/snaps/pull/1950), [#1954](https://github.com/MetaMask/snaps/pull/1954))
129
189
  - This package replaces the `@metamask/snaps-types` and
130
190
  - `@metamask/snaps-ui` packages.
131
191
 
132
192
  ### Removed
193
+
133
194
  - **BREAKING**: `DialogType`, `ManageStateOperation`, `NotificationType` are no
134
195
  longer re-exported from `@metamask/snaps-jest` ([#1930](https://github.com/MetaMask/snaps/pull/1930))
135
196
  - These enums can now be imported from `@metamask/snaps-sdk` instead.
136
197
 
137
198
  ## [3.1.0]
199
+
138
200
  ### Added
201
+
139
202
  - Add support for links in custom UI and notifications ([#1814](https://github.com/MetaMask/snaps/pull/1814))
140
203
 
141
204
  ## [3.0.0]
205
+
142
206
  ### Changed
207
+
143
208
  - **BREAKING:** Improve error handling ([#1841](https://github.com/MetaMask/snaps/pull/1841))
144
209
  - This is a breaking change, because errors returned by the Snap now have a different format. For example, if the Snap throws a JSON-RPC method not found error, previously, the following error would be returned:
145
210
  ```ts
@@ -168,32 +233,46 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
168
233
  ```
169
234
 
170
235
  ## [2.0.0]
236
+
171
237
  ### Changed
238
+
172
239
  - **BREAKING:** Bump minimum Node.js version to `^18.16.0` ([#1741](https://github.com/MetaMask/snaps/pull/1741))
173
240
 
174
241
  ## [1.0.0]
242
+
175
243
  ### Changed
244
+
176
245
  - Initial stable release from main branch ([#1757](https://github.com/MetaMask/snaps/pull/1757))
177
246
 
178
247
  ## [0.37.5-flask.1]
248
+
179
249
  ### Changed
250
+
180
251
  - Bump `metamask/utils` and `metamask/snaps-registry` ([#1738](https://github.com/MetaMask/snaps/pull/1738), [#1694](https://github.com/MetaMask/snaps/pull/1694))
181
252
 
182
253
  ## [0.37.4-flask.1]
254
+
183
255
  ### Fixed
256
+
184
257
  - Remove unused dependencies ([#1680](https://github.com/MetaMask/snaps/pull/1680))
185
258
 
186
259
  ## [0.37.3-flask.1]
260
+
187
261
  ### Changed
262
+
188
263
  - Bump `semver` to `^7.5.4` ([#1631](https://github.com/MetaMask/snaps/pull/1631))
189
264
 
190
265
  ## [0.37.2-flask.1]
266
+
191
267
  ### Changed
268
+
192
269
  - Release package independently ([#1600](https://github.com/MetaMask/snaps/pull/1600))
193
270
  - The version of the package no longer needs to match the version of all other
194
271
  MetaMask Snaps packages.
195
272
 
196
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.2...HEAD
273
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.5.0...HEAD
274
+ [8.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.4.0...@metamask/snaps-jest@8.5.0
275
+ [8.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.2...@metamask/snaps-jest@8.4.0
197
276
  [8.3.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.1...@metamask/snaps-jest@8.3.2
198
277
  [8.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.0...@metamask/snaps-jest@8.3.1
199
278
  [8.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.2.0...@metamask/snaps-jest@8.3.0
package/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2023 MetaMask
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  var _SnapsEnvironment_options, _SnapsEnvironment_server, _SnapsEnvironment_instance;
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.SnapsEnvironment = void 0;
19
+ const snaps_simulation_1 = require("@metamask/snaps-simulation");
19
20
  const utils_1 = require("@metamask/utils");
20
21
  const jest_environment_node_1 = __importDefault(require("jest-environment-node"));
21
22
  const internals_1 = require("./internals/index.cjs");
@@ -73,7 +74,7 @@ class SnapsEnvironment extends jest_environment_node_1.default {
73
74
  */
74
75
  async installSnap(snapId = this.snapId, options = {}) {
75
76
  await __classPrivateFieldGet(this, _SnapsEnvironment_instance, "f")?.executionService.terminateAllSnaps();
76
- __classPrivateFieldSet(this, _SnapsEnvironment_instance, await (0, internals_1.handleInstallSnap)(snapId, options), "f");
77
+ __classPrivateFieldSet(this, _SnapsEnvironment_instance, await (0, snaps_simulation_1.installSnap)(snapId, options), "f");
77
78
  return __classPrivateFieldGet(this, _SnapsEnvironment_instance, "f");
78
79
  }
79
80
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,2CAA6D;AAE7D,kFAAoD;AAIpD,qDAAyE;AAEzE,2CAAuC;AAMvC,mBAAmB;AAEnB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAa,gBAAiB,SAAQ,+BAAe;IAOnD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAb1B,4CAAkC;QAElC,2CAA4B;QAE5B,6CAAqC;QAUnC,uBAAA,IAAI,6BAAY,IAAA,oBAAU,EAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAA,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,uBAAA,IAAI,4BAAW,MAAM,IAAA,uBAAW,EAAC,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,gCAAQ,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,WAAW,CAKf,SAAiB,IAAI,CAAC,MAAM,EAC5B,UAAgD,EAAE;QAElD,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,8BAAa,MAAM,IAAA,6BAAiB,EAAC,MAAgB,EAAE,OAAO,CAAC,MAAA,CAAC;QACpE,OAAO,uBAAA,IAAI,kCAAU,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,IAAA,cAAM,EACJ,uBAAA,IAAI,gCAAQ,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAA,IAAI,gCAAQ,CAAC,OAAO,EAAiB,CAAC;QACvD,OAAO,0BAA0B,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;AAvFD,4CAuFC;;AAED,kBAAe,gBAAgB,CAAC","sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\n\nimport type { InstalledSnap, InstallSnapOptions } from './internals';\nimport { handleInstallSnap, rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n #options: SnapsEnvironmentOptions;\n\n #server: Server | undefined;\n\n #instance: InstalledSnap | undefined;\n\n /**\n * Constructor.\n *\n * @param options - The environment options.\n * @param context - The environment context.\n */\n constructor(options: JestEnvironmentConfig, context: EnvironmentContext) {\n super(options, context);\n this.#options = getOptions(options.projectConfig.testEnvironmentOptions);\n }\n\n /**\n * Set up the environment. This starts the built-in HTTP server, and creates a\n * new browser instance.\n */\n async setup() {\n await super.setup();\n\n if (this.#options.server.enabled) {\n log('Starting server.');\n this.#server = await startServer(this.#options.server);\n }\n\n this.global.snapsEnvironment = this;\n }\n\n /**\n * Tear down the environment. This closes the browser, and stops the built-in\n * HTTP server.\n */\n async teardown() {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#server?.close();\n await super.teardown();\n }\n\n /**\n * Install a Snap in the environment. This will terminate any previously\n * installed Snaps, and run the Snap code in a new execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n * @returns The installed Snap.\n */\n async installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n >(\n snapId: string = this.snapId,\n options: Partial<InstallSnapOptions<Service>> = {},\n ) {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#instance = await handleInstallSnap(snapId as SnapId, options);\n return this.#instance;\n }\n\n /**\n * Get the snap ID for the current environment, which is used if no snap ID is\n * passed to {@link installSnap}. This assumes that the built-in server is\n * running.\n *\n * @returns The snap ID.\n * @throws If the server is not running.\n */\n get snapId() {\n assert(\n this.#server,\n 'You must specify a snap ID, because the built-in server is not running.',\n );\n\n const { port } = this.#server.address() as AddressInfo;\n return `local:http://localhost:${port}`;\n }\n}\n\nexport default SnapsEnvironment;\n"]}
1
+ {"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,iEAAyD;AAMzD,2CAA6D;AAE7D,kFAAoD;AAGpD,qDAAsD;AAEtD,2CAAuC;AAMvC,mBAAmB;AAEnB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAa,gBAAiB,SAAQ,+BAAe;IAOnD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAb1B,4CAAkC;QAElC,2CAA4B;QAE5B,6CAAqD;QAUnD,uBAAA,IAAI,6BAAY,IAAA,oBAAU,EAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAA,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,uBAAA,IAAI,4BAAW,MAAM,IAAA,uBAAW,EAAC,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,gCAAQ,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,WAAW,CAKf,SAAiB,IAAI,CAAC,MAAM,EAC5B,UAAgD,EAAE;QAElD,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,8BAAa,MAAM,IAAA,8BAAW,EAAC,MAAgB,EAAE,OAAO,CAAC,MAAA,CAAC;QAC9D,OAAO,uBAAA,IAAI,kCAAU,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,IAAA,cAAM,EACJ,uBAAA,IAAI,gCAAQ,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAA,IAAI,gCAAQ,CAAC,OAAO,EAAiB,CAAC;QACvD,OAAO,0BAA0B,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;AAvFD,4CAuFC;;AAED,kBAAe,gBAAgB,CAAC","sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { installSnap } from '@metamask/snaps-simulation';\nimport type {\n InstalledSnap,\n InstallSnapOptions,\n SnapHelpers,\n} from '@metamask/snaps-simulation';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\n\nimport { rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n #options: SnapsEnvironmentOptions;\n\n #server: Server | undefined;\n\n #instance: (InstalledSnap & SnapHelpers) | undefined;\n\n /**\n * Constructor.\n *\n * @param options - The environment options.\n * @param context - The environment context.\n */\n constructor(options: JestEnvironmentConfig, context: EnvironmentContext) {\n super(options, context);\n this.#options = getOptions(options.projectConfig.testEnvironmentOptions);\n }\n\n /**\n * Set up the environment. This starts the built-in HTTP server, and creates a\n * new browser instance.\n */\n async setup() {\n await super.setup();\n\n if (this.#options.server.enabled) {\n log('Starting server.');\n this.#server = await startServer(this.#options.server);\n }\n\n this.global.snapsEnvironment = this;\n }\n\n /**\n * Tear down the environment. This closes the browser, and stops the built-in\n * HTTP server.\n */\n async teardown() {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#server?.close();\n await super.teardown();\n }\n\n /**\n * Install a Snap in the environment. This will terminate any previously\n * installed Snaps, and run the Snap code in a new execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n * @returns The installed Snap.\n */\n async installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n >(\n snapId: string = this.snapId,\n options: Partial<InstallSnapOptions<Service>> = {},\n ) {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#instance = await installSnap(snapId as SnapId, options);\n return this.#instance;\n }\n\n /**\n * Get the snap ID for the current environment, which is used if no snap ID is\n * passed to {@link installSnap}. This assumes that the built-in server is\n * running.\n *\n * @returns The snap ID.\n * @throws If the server is not running.\n */\n get snapId() {\n assert(\n this.#server,\n 'You must specify a snap ID, because the built-in server is not running.',\n );\n\n const { port } = this.#server.address() as AddressInfo;\n return `local:http://localhost:${port}`;\n }\n}\n\nexport default SnapsEnvironment;\n"]}
@@ -1,7 +1,7 @@
1
1
  import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
2
2
  import type { AbstractExecutionService } from "@metamask/snaps-controllers";
3
+ import type { InstalledSnap, InstallSnapOptions, SnapHelpers } from "@metamask/snaps-simulation";
3
4
  import NodeEnvironment from "jest-environment-node";
4
- import type { InstalledSnap, InstallSnapOptions } from "./internals/index.cjs";
5
5
  declare global {
6
6
  const snapsEnvironment: SnapsEnvironment;
7
7
  }
@@ -38,7 +38,7 @@ export declare class SnapsEnvironment extends NodeEnvironment {
38
38
  * @template Service - The type of the execution service.
39
39
  * @returns The installed Snap.
40
40
  */
41
- installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap>;
41
+ installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap & SnapHelpers>;
42
42
  /**
43
43
  * Get the snap ID for the current environment, which is used if no snap ID is
44
44
  * passed to {@link installSnap}. This assumes that the built-in server is
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.cts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAI5E,OAAO,eAAe,8BAA8B;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,8BAAoB;AAMrE,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAKD,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,kBAAkB;IAKvE;;;OAGG;IACG,KAAK;IAWX;;;OAGG;IACG,QAAQ;IAMd;;;;;;;;;;;;;OAaG;IACG,WAAW,CACf,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"environment.d.cts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAG5E,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,eAAe,8BAA8B;AAQpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAKD,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,kBAAkB;IAKvE;;;OAGG;IACG,KAAK;IAWX;;;OAGG;IACG,QAAQ;IAMd;;;;;;;;;;;;;OAaG;IACG,WAAW,CACf,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
@@ -1,7 +1,7 @@
1
1
  import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
2
2
  import type { AbstractExecutionService } from "@metamask/snaps-controllers";
3
+ import type { InstalledSnap, InstallSnapOptions, SnapHelpers } from "@metamask/snaps-simulation";
3
4
  import NodeEnvironment from "jest-environment-node";
4
- import type { InstalledSnap, InstallSnapOptions } from "./internals/index.mjs";
5
5
  declare global {
6
6
  const snapsEnvironment: SnapsEnvironment;
7
7
  }
@@ -38,7 +38,7 @@ export declare class SnapsEnvironment extends NodeEnvironment {
38
38
  * @template Service - The type of the execution service.
39
39
  * @returns The installed Snap.
40
40
  */
41
- installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap>;
41
+ installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap & SnapHelpers>;
42
42
  /**
43
43
  * Get the snap ID for the current environment, which is used if no snap ID is
44
44
  * passed to {@link installSnap}. This assumes that the built-in server is
@@ -1 +1 @@
1
- {"version":3,"file":"environment.d.mts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAI5E,OAAO,eAAe,8BAA8B;AAGpD,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,8BAAoB;AAMrE,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAKD,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,kBAAkB;IAKvE;;;OAGG;IACG,KAAK;IAWX;;;OAGG;IACG,QAAQ;IAMd;;;;;;;;;;;;;OAaG;IACG,WAAW,CACf,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"environment.d.mts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAG5E,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,eAAe,8BAA8B;AAQpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAKD,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,kBAAkB;IAKvE;;;OAGG;IACG,KAAK;IAWX;;;OAGG;IACG,QAAQ;IAMd;;;;;;;;;;;;;OAaG;IACG,WAAW,CACf,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
@@ -16,10 +16,11 @@ function $importDefault(module) {
16
16
  }
17
17
  return module;
18
18
  }
19
+ import { installSnap } from "@metamask/snaps-simulation";
19
20
  import { assert, createModuleLogger } from "@metamask/utils";
20
21
  import $NodeEnvironment from "jest-environment-node";
21
22
  const NodeEnvironment = $importDefault($NodeEnvironment);
22
- import { handleInstallSnap, rootLogger, startServer } from "./internals/index.mjs";
23
+ import { rootLogger, startServer } from "./internals/index.mjs";
23
24
  import { getOptions } from "./options.mjs";
24
25
  /* eslint-enable */
25
26
  const log = createModuleLogger(rootLogger, 'environment');
@@ -74,7 +75,7 @@ export class SnapsEnvironment extends NodeEnvironment {
74
75
  */
75
76
  async installSnap(snapId = this.snapId, options = {}) {
76
77
  await __classPrivateFieldGet(this, _SnapsEnvironment_instance, "f")?.executionService.terminateAllSnaps();
77
- __classPrivateFieldSet(this, _SnapsEnvironment_instance, await handleInstallSnap(snapId, options), "f");
78
+ __classPrivateFieldSet(this, _SnapsEnvironment_instance, await installSnap(snapId, options), "f");
78
79
  return __classPrivateFieldGet(this, _SnapsEnvironment_instance, "f");
79
80
  }
80
81
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"environment.mjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,wBAAwB;AAE7D,OAAO,gBAAe,8BAA8B;;AAIpD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,8BAAoB;AAEzE,OAAO,EAAE,UAAU,EAAE,sBAAkB;AAMvC,mBAAmB;AAEnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IAOnD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAb1B,4CAAkC;QAElC,2CAA4B;QAE5B,6CAAqC;QAUnC,uBAAA,IAAI,6BAAY,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAA,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,uBAAA,IAAI,4BAAW,MAAM,WAAW,CAAC,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,gCAAQ,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,WAAW,CAKf,SAAiB,IAAI,CAAC,MAAM,EAC5B,UAAgD,EAAE;QAElD,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,8BAAa,MAAM,iBAAiB,CAAC,MAAgB,EAAE,OAAO,CAAC,MAAA,CAAC;QACpE,OAAO,uBAAA,IAAI,kCAAU,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,MAAM,CACJ,uBAAA,IAAI,gCAAQ,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAA,IAAI,gCAAQ,CAAC,OAAO,EAAiB,CAAC;QACvD,OAAO,0BAA0B,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;;AAED,eAAe,gBAAgB,CAAC","sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\n\nimport type { InstalledSnap, InstallSnapOptions } from './internals';\nimport { handleInstallSnap, rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n #options: SnapsEnvironmentOptions;\n\n #server: Server | undefined;\n\n #instance: InstalledSnap | undefined;\n\n /**\n * Constructor.\n *\n * @param options - The environment options.\n * @param context - The environment context.\n */\n constructor(options: JestEnvironmentConfig, context: EnvironmentContext) {\n super(options, context);\n this.#options = getOptions(options.projectConfig.testEnvironmentOptions);\n }\n\n /**\n * Set up the environment. This starts the built-in HTTP server, and creates a\n * new browser instance.\n */\n async setup() {\n await super.setup();\n\n if (this.#options.server.enabled) {\n log('Starting server.');\n this.#server = await startServer(this.#options.server);\n }\n\n this.global.snapsEnvironment = this;\n }\n\n /**\n * Tear down the environment. This closes the browser, and stops the built-in\n * HTTP server.\n */\n async teardown() {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#server?.close();\n await super.teardown();\n }\n\n /**\n * Install a Snap in the environment. This will terminate any previously\n * installed Snaps, and run the Snap code in a new execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n * @returns The installed Snap.\n */\n async installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n >(\n snapId: string = this.snapId,\n options: Partial<InstallSnapOptions<Service>> = {},\n ) {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#instance = await handleInstallSnap(snapId as SnapId, options);\n return this.#instance;\n }\n\n /**\n * Get the snap ID for the current environment, which is used if no snap ID is\n * passed to {@link installSnap}. This assumes that the built-in server is\n * running.\n *\n * @returns The snap ID.\n * @throws If the server is not running.\n */\n get snapId() {\n assert(\n this.#server,\n 'You must specify a snap ID, because the built-in server is not running.',\n );\n\n const { port } = this.#server.address() as AddressInfo;\n return `local:http://localhost:${port}`;\n }\n}\n\nexport default SnapsEnvironment;\n"]}
1
+ {"version":3,"file":"environment.mjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAMzD,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,wBAAwB;AAE7D,OAAO,gBAAe,8BAA8B;;AAGpD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,8BAAoB;AAEtD,OAAO,EAAE,UAAU,EAAE,sBAAkB;AAMvC,mBAAmB;AAEnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IAOnD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAb1B,4CAAkC;QAElC,2CAA4B;QAE5B,6CAAqD;QAUnD,uBAAA,IAAI,6BAAY,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAA,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,uBAAA,IAAI,4BAAW,MAAM,WAAW,CAAC,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,gCAAQ,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,WAAW,CAKf,SAAiB,IAAI,CAAC,MAAM,EAC5B,UAAgD,EAAE;QAElD,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,8BAAa,MAAM,WAAW,CAAC,MAAgB,EAAE,OAAO,CAAC,MAAA,CAAC;QAC9D,OAAO,uBAAA,IAAI,kCAAU,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,MAAM,CACJ,uBAAA,IAAI,gCAAQ,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAA,IAAI,gCAAQ,CAAC,OAAO,EAAiB,CAAC;QACvD,OAAO,0BAA0B,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;;AAED,eAAe,gBAAgB,CAAC","sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { installSnap } from '@metamask/snaps-simulation';\nimport type {\n InstalledSnap,\n InstallSnapOptions,\n SnapHelpers,\n} from '@metamask/snaps-simulation';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\n\nimport { rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n #options: SnapsEnvironmentOptions;\n\n #server: Server | undefined;\n\n #instance: (InstalledSnap & SnapHelpers) | undefined;\n\n /**\n * Constructor.\n *\n * @param options - The environment options.\n * @param context - The environment context.\n */\n constructor(options: JestEnvironmentConfig, context: EnvironmentContext) {\n super(options, context);\n this.#options = getOptions(options.projectConfig.testEnvironmentOptions);\n }\n\n /**\n * Set up the environment. This starts the built-in HTTP server, and creates a\n * new browser instance.\n */\n async setup() {\n await super.setup();\n\n if (this.#options.server.enabled) {\n log('Starting server.');\n this.#server = await startServer(this.#options.server);\n }\n\n this.global.snapsEnvironment = this;\n }\n\n /**\n * Tear down the environment. This closes the browser, and stops the built-in\n * HTTP server.\n */\n async teardown() {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#server?.close();\n await super.teardown();\n }\n\n /**\n * Install a Snap in the environment. This will terminate any previously\n * installed Snaps, and run the Snap code in a new execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n * @returns The installed Snap.\n */\n async installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n >(\n snapId: string = this.snapId,\n options: Partial<InstallSnapOptions<Service>> = {},\n ) {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#instance = await installSnap(snapId as SnapId, options);\n return this.#instance;\n }\n\n /**\n * Get the snap ID for the current environment, which is used if no snap ID is\n * passed to {@link installSnap}. This assumes that the built-in server is\n * running.\n *\n * @returns The snap ID.\n * @throws If the server is not running.\n */\n get snapId() {\n assert(\n this.#server,\n 'You must specify a snap ID, because the built-in server is not running.',\n );\n\n const { port } = this.#server.address() as AddressInfo;\n return `local:http://localhost:${port}`;\n }\n}\n\nexport default SnapsEnvironment;\n"]}
package/dist/helpers.cjs CHANGED
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.installSnap = exports.assertCustomDialogHasNoFooter = exports.assertCustomDialogHasPartialFooter = exports.assertCustomDialogHasFooter = exports.assertIsCustomDialog = exports.assertIsPromptDialog = exports.assertIsConfirmationDialog = exports.assertIsAlertDialog = void 0;
4
- const snaps_sdk_1 = require("@metamask/snaps-sdk");
3
+ exports.installSnap = void 0;
5
4
  const snaps_utils_1 = require("@metamask/snaps-utils");
6
- const superstruct_1 = require("@metamask/superstruct");
7
5
  const utils_1 = require("@metamask/utils");
8
6
  const internals_1 = require("./internals/index.cjs");
9
- const mocks_1 = require("./internals/simulation/store/mocks.cjs");
10
7
  const log = (0, utils_1.createModuleLogger)(internals_1.rootLogger, 'helpers');
11
8
  /**
12
9
  * Get the options for {@link installSnap}.
@@ -21,80 +18,6 @@ function getOptions(snapId, options) {
21
18
  }
22
19
  return [snapId, options];
23
20
  }
24
- /**
25
- * Ensure that the actual response contains `getInterface`.
26
- *
27
- * @param response - The response of the handler.
28
- */
29
- function assertIsResponseWithInterface(response) {
30
- (0, utils_1.assertStruct)(response, internals_1.SnapResponseWithInterfaceStruct);
31
- }
32
- /**
33
- * Ensure that the actual interface is an alert dialog.
34
- *
35
- * @param ui - The interface to verify.
36
- */
37
- function assertIsAlertDialog(ui) {
38
- (0, utils_1.assert)((0, utils_1.hasProperty)(ui, 'type') && ui.type === snaps_sdk_1.DialogType.Alert);
39
- }
40
- exports.assertIsAlertDialog = assertIsAlertDialog;
41
- /**
42
- * Ensure that the actual interface is a confirmation dialog.
43
- *
44
- * @param ui - The interface to verify.
45
- */
46
- function assertIsConfirmationDialog(ui) {
47
- (0, utils_1.assert)((0, utils_1.hasProperty)(ui, 'type') && ui.type === snaps_sdk_1.DialogType.Confirmation);
48
- }
49
- exports.assertIsConfirmationDialog = assertIsConfirmationDialog;
50
- /**
51
- * Ensure that the actual interface is a Prompt dialog.
52
- *
53
- * @param ui - The interface to verify.
54
- */
55
- function assertIsPromptDialog(ui) {
56
- (0, utils_1.assert)((0, utils_1.hasProperty)(ui, 'type') && ui.type === snaps_sdk_1.DialogType.Prompt);
57
- }
58
- exports.assertIsPromptDialog = assertIsPromptDialog;
59
- /**
60
- * Ensure that the actual interface is a custom dialog.
61
- *
62
- * @param ui - The interface to verify.
63
- */
64
- function assertIsCustomDialog(ui) {
65
- (0, utils_1.assert)(!(0, utils_1.hasProperty)(ui, 'type'));
66
- }
67
- exports.assertIsCustomDialog = assertIsCustomDialog;
68
- /**
69
- * Ensure that the actual interface is a custom dialog with a complete footer.
70
- *
71
- * @param ui - The interface to verify.
72
- */
73
- function assertCustomDialogHasFooter(ui) {
74
- const footer = (0, internals_1.getElementByType)(ui.content, 'Footer');
75
- (0, utils_1.assert)(footer && (0, snaps_utils_1.getJsxChildren)(footer).length === 2);
76
- }
77
- exports.assertCustomDialogHasFooter = assertCustomDialogHasFooter;
78
- /**
79
- * Ensure that the actual interface is a custom dialog with a partial footer.
80
- *
81
- * @param ui - The interface to verify.
82
- */
83
- function assertCustomDialogHasPartialFooter(ui) {
84
- const footer = (0, internals_1.getElementByType)(ui.content, 'Footer');
85
- (0, utils_1.assert)(footer && (0, snaps_utils_1.getJsxChildren)(footer).length === 1);
86
- }
87
- exports.assertCustomDialogHasPartialFooter = assertCustomDialogHasPartialFooter;
88
- /**
89
- * Ensure that the actual interface is a custom dialog without a footer.
90
- *
91
- * @param ui - The interface to verify.
92
- */
93
- function assertCustomDialogHasNoFooter(ui) {
94
- const footer = (0, internals_1.getElementByType)(ui.content, 'Footer');
95
- (0, utils_1.assert)(!footer);
96
- }
97
- exports.assertCustomDialogHasNoFooter = assertCustomDialogHasNoFooter;
98
21
  /**
99
22
  * Load a snap into the environment. This is the main entry point for testing
100
23
  * snaps: It returns a {@link Snap} object that can be used to interact with the
@@ -129,110 +52,20 @@ exports.assertCustomDialogHasNoFooter = assertCustomDialogHasNoFooter;
129
52
  */
130
53
  async function installSnap(snapId, options = {}) {
131
54
  const resolvedOptions = getOptions(snapId, options);
132
- const { snapId: installedSnapId, store, executionService, runSaga, controllerMessenger, } = await (0, internals_1.getEnvironment)().installSnap(...resolvedOptions);
133
- const onTransaction = async (request) => {
134
- log('Sending transaction %o.', request);
135
- const { origin: transactionOrigin, chainId, ...transaction } = (0, superstruct_1.create)(request, internals_1.TransactionOptionsStruct);
136
- const response = await (0, internals_1.handleRequest)({
137
- snapId: installedSnapId,
138
- store,
139
- executionService,
140
- runSaga,
141
- controllerMessenger,
142
- handler: snaps_utils_1.HandlerType.OnTransaction,
143
- request: {
144
- method: '',
145
- params: {
146
- chainId,
147
- transaction,
148
- transactionOrigin,
149
- },
150
- },
151
- });
152
- assertIsResponseWithInterface(response);
153
- return response;
154
- };
155
- const onCronjob = (request) => {
156
- log('Running cronjob %o.', options);
157
- return (0, internals_1.handleRequest)({
158
- snapId: installedSnapId,
159
- store,
160
- executionService,
161
- controllerMessenger,
162
- runSaga,
163
- handler: snaps_utils_1.HandlerType.OnCronjob,
164
- request,
165
- });
166
- };
55
+ const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onHomePage, mockJsonRpc, close, } = await (0, internals_1.getEnvironment)().installSnap(...resolvedOptions);
167
56
  return {
168
- request: (request) => {
169
- log('Sending request %o.', request);
170
- return (0, internals_1.handleRequest)({
171
- snapId: installedSnapId,
172
- store,
173
- executionService,
174
- controllerMessenger,
175
- runSaga,
176
- handler: snaps_utils_1.HandlerType.OnRpcRequest,
177
- request,
178
- });
179
- },
57
+ request,
180
58
  onTransaction,
181
- sendTransaction: onTransaction,
182
- onSignature: async (request) => {
183
- log('Requesting signature %o.', request);
184
- const { origin: signatureOrigin, ...signature } = (0, superstruct_1.create)(request, internals_1.SignatureOptionsStruct);
185
- const response = await (0, internals_1.handleRequest)({
186
- snapId: installedSnapId,
187
- store,
188
- executionService,
189
- controllerMessenger,
190
- runSaga,
191
- handler: snaps_utils_1.HandlerType.OnSignature,
192
- request: {
193
- method: '',
194
- params: {
195
- signature,
196
- signatureOrigin,
197
- },
198
- },
199
- });
200
- assertIsResponseWithInterface(response);
201
- return response;
202
- },
59
+ sendTransaction,
60
+ onSignature,
203
61
  onCronjob,
204
- runCronjob: onCronjob,
205
- onHomePage: async () => {
206
- log('Rendering home page.');
207
- const response = await (0, internals_1.handleRequest)({
208
- snapId: installedSnapId,
209
- store,
210
- executionService,
211
- controllerMessenger,
212
- runSaga,
213
- handler: snaps_utils_1.HandlerType.OnHomePage,
214
- request: {
215
- method: '',
216
- },
217
- });
218
- assertIsResponseWithInterface(response);
219
- return response;
220
- },
221
- mockJsonRpc(mock) {
222
- log('Mocking JSON-RPC request %o.', mock);
223
- const { method, result } = (0, superstruct_1.create)(mock, internals_1.JsonRpcMockOptionsStruct);
224
- store.dispatch((0, mocks_1.addJsonRpcMock)({ method, result }));
225
- return {
226
- unmock() {
227
- log('Unmocking JSON-RPC request %o.', mock);
228
- store.dispatch((0, mocks_1.removeJsonRpcMock)(method));
229
- },
230
- };
231
- },
62
+ runCronjob,
63
+ onHomePage,
64
+ mockJsonRpc,
232
65
  close: async () => {
233
66
  log('Closing execution service.');
234
67
  (0, snaps_utils_1.logInfo)('Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.');
235
- await executionService.terminateAllSnaps();
68
+ await close();
236
69
  },
237
70
  };
238
71
  }