@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/dist/matchers.cjs CHANGED
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.toRender = exports.toSendNotification = exports.toRespondWithError = exports.toRespondWith = void 0;
5
5
  const globals_1 = require("@jest/globals");
6
6
  const jsx_1 = require("@metamask/snaps-sdk/jsx");
7
+ const snaps_simulation_1 = require("@metamask/snaps-simulation");
7
8
  const snaps_utils_1 = require("@metamask/snaps-utils");
8
9
  const superstruct_1 = require("@metamask/superstruct");
9
10
  const utils_1 = require("@metamask/utils");
10
11
  const jest_matcher_utils_1 = require("jest-matcher-utils");
11
- const internals_1 = require("./internals/index.cjs");
12
12
  /**
13
13
  * Ensure that the actual value is a response from the `request` function.
14
14
  *
@@ -17,7 +17,7 @@ const internals_1 = require("./internals/index.cjs");
17
17
  * @param options - The matcher options.
18
18
  */
19
19
  function assertActualIsSnapResponse(actual, matcherName, options) {
20
- if (!(0, superstruct_1.is)(actual, internals_1.SnapResponseStruct)) {
20
+ if (!(0, superstruct_1.is)(actual, snaps_simulation_1.SnapResponseStruct)) {
21
21
  throw new Error((0, jest_matcher_utils_1.matcherErrorMessage)((0, jest_matcher_utils_1.matcherHint)(matcherName, undefined, undefined, options), `${(0, jest_matcher_utils_1.RECEIVED_COLOR)('received')} value must be a response from the \`request\` function`, (0, jest_matcher_utils_1.printWithType)('Received', actual, jest_matcher_utils_1.printReceived)));
22
22
  }
23
23
  }
@@ -30,7 +30,7 @@ function assertActualIsSnapResponse(actual, matcherName, options) {
30
30
  * @param options - The matcher options.
31
31
  */
32
32
  function assertHasInterface(actual, matcherName, options) {
33
- if (!(0, superstruct_1.is)(actual, internals_1.InterfaceStruct) || !actual.content) {
33
+ if (!(0, superstruct_1.is)(actual, snaps_simulation_1.InterfaceStruct) || !actual.content) {
34
34
  throw new Error((0, jest_matcher_utils_1.matcherErrorMessage)((0, jest_matcher_utils_1.matcherHint)(matcherName, undefined, undefined, options), `${(0, jest_matcher_utils_1.RECEIVED_COLOR)('received')} value must have a \`content\` property`, (0, jest_matcher_utils_1.printWithType)('Received', actual, jest_matcher_utils_1.printReceived)));
35
35
  }
36
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.cjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAMpC,2CAAuC;AAQvC,iDAA6D;AAC7D,uDAG+B;AAC/B,uDAA2C;AAE3C,2CAA8C;AAE9C,2DAQ4B;AAE5B,qDAAkE;AAGlE;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,IAAA,gBAAE,EAAC,MAAM,EAAE,8BAAkB,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,IAAA,wCAAmB,EACjB,IAAA,gCAAW,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,IAAA,mCAAc,EACf,UAAU,CACX,yDAAyD,EAC1D,IAAA,kCAAa,EAAC,UAAU,EAAE,MAAM,EAAE,kCAAa,CAAC,CACjD,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CACzB,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,IAAA,gBAAE,EAAC,MAAM,EAAE,2BAAe,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,IAAA,wCAAmB,EACjB,IAAA,gCAAW,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,IAAA,mCAAc,EAAC,UAAU,CAAC,yCAAyC,EACtE,IAAA,kCAAa,EAAC,UAAU,EAAE,MAAM,E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IAClB,QAAQ,EAAR,gBAAQ;CACT,CAAC,CAAC","sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
1
+ {"version":3,"file":"matchers.cjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAMpC,2CAAuC;AAQvC,iDAA6D;AAE7D,iEAGoC;AACpC,uDAG+B;AAC/B,uDAA2C;AAE3C,2CAA8C;AAE9C,2DAQ4B;AAE5B;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,IAAA,gBAAE,EAAC,MAAM,EAAE,qCAAkB,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,IAAA,wCAAmB,EACjB,IAAA,gCAAW,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OA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AAY,EAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE;QACtC,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM;YAC5C,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAhCS,QAAA,QAAQ,YAgCjB;AAEJ,gBAAM,CAAC,MAAM,CAAC;IACZ,aAAa,EAAb,qBAAa;IACb,kBAAkB,EAAlB,0BAAkB;IAClB,kBAAkB,EAAlB,0BAAkB;IAClB,QAAQ,EAAR,gBAAQ;CACT,CAAC,CAAC","sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.d.cts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAEnB,4BAA4B;AAQ7B,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAiE5C;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IAAC,QAAQ,EAAE,MAAM;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;CAAC,CAwBrE,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAgClE,CAAC"}
1
+ {"version":3,"file":"matchers.d.cts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAEnB,4BAA4B;AAa7B,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AA8D5C;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IAAC,QAAQ,EAAE,MAAM;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;CAAC,CAwBrE,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAgClE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.d.mts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAEnB,4BAA4B;AAQ7B,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAiE5C;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IAAC,QAAQ,EAAE,MAAM;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;CAAC,CAwBrE,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAgClE,CAAC"}
1
+ {"version":3,"file":"matchers.d.mts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAEnB,4BAA4B;AAa7B,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AA8D5C;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IAAC,QAAQ,EAAE,MAAM;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;CAAC,CAwBrE,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAgClE,CAAC"}
package/dist/matchers.mjs CHANGED
@@ -2,11 +2,11 @@
2
2
  import $jestglobals from "@jest/globals";
3
3
  const { expect } = $jestglobals;
4
4
  import { isJSXElementUnsafe } from "@metamask/snaps-sdk/jsx";
5
+ import { InterfaceStruct, SnapResponseStruct } from "@metamask/snaps-simulation";
5
6
  import { getJsxElementFromComponent, serialiseJsx } from "@metamask/snaps-utils";
6
7
  import { is } from "@metamask/superstruct";
7
8
  import { hasProperty } from "@metamask/utils";
8
9
  import { EXPECTED_COLOR, diff, matcherErrorMessage, matcherHint, printReceived, printWithType, RECEIVED_COLOR } from "jest-matcher-utils";
9
- import { InterfaceStruct, SnapResponseStruct } from "./internals/index.mjs";
10
10
  /**
11
11
  * Ensure that the actual value is a response from the `request` function.
12
12
  *
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.mjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA,oCAAoC;;;AAcpC,OAAO,EAAE,kBAAkB,EAAE,gCAAgC;AAC7D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,WAAW,EAAE,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C,CACZ,CAAC;IAEZ,MAAM,OAAO,GAAG,IAAI;QAClB,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,eAAe,CAAC,MAAM;YAChD,cAAc,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE;QACtC,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM;YAC5C,cAAc,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,CAAC;IACZ,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,QAAQ;CACT,CAAC,CAAC","sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
1
+ {"version":3,"file":"matchers.mjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA,oCAAoC;;;AAcpC,OAAO,EAAE,kBAAkB,EAAE,gCAAgC;AAE7D,OAAO,EACL,eAAe,EACf,kBAAkB,EACnB,mCAAmC;AACpC,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,OAAO,EACL,cAAc,EACd,IAAI,EACJ,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,aAAa,EACb,cAAc,EACf,2BAA2B;AAE5B;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,mBAAmB,CACjB,WAAW,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,cAAc,CACf,UAAU,CACX,yDAAyD,EAC1D,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,CAAC,CACjD,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CACzB,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,mBAAmB,CACjB,W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be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
package/package.json CHANGED
@@ -1,7 +1,21 @@
1
1
  {
2
2
  "name": "@metamask/snaps-jest",
3
- "version": "8.3.2",
4
- "description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers.",
3
+ "version": "8.5.0",
4
+ "description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers",
5
+ "keywords": [
6
+ "MetaMask",
7
+ "Snaps",
8
+ "Ethereum"
9
+ ],
10
+ "homepage": "https://github.com/MetaMask/snaps/tree/main/packages/snaps-jest#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/MetaMask/snaps/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/MetaMask/snaps.git"
17
+ },
18
+ "license": "ISC",
5
19
  "sideEffects": false,
6
20
  "exports": {
7
21
  ".": {
@@ -25,45 +39,36 @@
25
39
  "jest-preset.js"
26
40
  ],
27
41
  "scripts": {
28
- "test": "jest --passWithNoTests && yarn posttest",
29
- "posttest": "jest-it-up",
30
- "test:ci": "yarn test",
31
- "lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
32
- "lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
33
- "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog && yarn lint:dependencies",
42
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
43
+ "changelog:update": "../../scripts/update-changelog.sh @metamask/snaps-jest",
44
+ "changelog:validate": "../../scripts/validate-changelog.sh @metamask/snaps-jest",
45
+ "lint": "yarn lint:eslint && yarn lint:misc --check && yarn changelog:validate && yarn lint:dependencies",
34
46
  "lint:ci": "yarn lint",
47
+ "lint:dependencies": "depcheck",
48
+ "lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
35
49
  "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
36
- "lint:changelog": "../../scripts/validate-changelog.sh @metamask/snaps-jest",
37
- "build": "ts-bridge --project tsconfig.build.json --verbose --no-references",
50
+ "lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
38
51
  "publish:preview": "yarn npm publish --tag preview",
39
- "lint:dependencies": "depcheck"
52
+ "since-latest-release": "../../scripts/since-latest-release.sh",
53
+ "test": "jest --reporters=jest-silent-reporter",
54
+ "test:clean": "jest --clearCache",
55
+ "test:post": "jest-it-up",
56
+ "test:verbose": "jest --verbose",
57
+ "test:watch": "jest --watch"
40
58
  },
41
59
  "dependencies": {
42
60
  "@jest/environment": "^29.5.0",
43
61
  "@jest/expect": "^29.5.0",
44
62
  "@jest/globals": "^29.5.0",
45
- "@metamask/base-controller": "^6.0.2",
46
- "@metamask/eth-json-rpc-middleware": "^14.0.0",
47
- "@metamask/json-rpc-engine": "^9.0.2",
48
- "@metamask/json-rpc-middleware-stream": "^8.0.2",
49
- "@metamask/key-tree": "^9.1.2",
50
- "@metamask/permission-controller": "^11.0.0",
51
- "@metamask/phishing-controller": "^12.0.2",
52
- "@metamask/snaps-controllers": "^9.7.0",
53
- "@metamask/snaps-execution-environments": "^6.7.1",
54
- "@metamask/snaps-rpc-methods": "^11.1.1",
55
- "@metamask/snaps-sdk": "^6.5.0",
56
- "@metamask/snaps-utils": "^8.1.1",
63
+ "@metamask/snaps-controllers": "^9.10.0",
64
+ "@metamask/snaps-sdk": "^6.7.0",
65
+ "@metamask/snaps-simulation": "^1.1.0",
57
66
  "@metamask/superstruct": "^3.1.0",
58
67
  "@metamask/utils": "^9.2.1",
59
- "@reduxjs/toolkit": "^1.9.5",
60
68
  "express": "^4.18.2",
61
69
  "jest-environment-node": "^29.5.0",
62
70
  "jest-matcher-utils": "^29.5.0",
63
- "mime": "^3.0.0",
64
- "readable-stream": "^3.6.2",
65
- "redux": "^4.2.1",
66
- "redux-saga": "^1.2.3"
71
+ "redux": "^4.2.1"
67
72
  },
68
73
  "devDependencies": {
69
74
  "@jest/types": "^29.6.3",
@@ -73,11 +78,11 @@
73
78
  "@metamask/eslint-config-jest": "^12.1.0",
74
79
  "@metamask/eslint-config-nodejs": "^12.1.0",
75
80
  "@metamask/eslint-config-typescript": "^12.1.0",
81
+ "@metamask/snaps-utils": "^8.3.0",
76
82
  "@swc/core": "1.3.78",
77
83
  "@swc/jest": "^0.2.26",
78
84
  "@ts-bridge/cli": "^0.5.1",
79
85
  "@types/jest": "^27.5.1",
80
- "@types/mime": "^3.0.0",
81
86
  "@types/semver": "^7.5.0",
82
87
  "@typescript-eslint/eslint-plugin": "^5.42.1",
83
88
  "@typescript-eslint/parser": "^6.21.0",
@@ -93,8 +98,9 @@
93
98
  "eslint-plugin-promise": "^6.1.1",
94
99
  "jest": "^29.0.2",
95
100
  "jest-it-up": "^2.0.0",
96
- "prettier": "^2.7.1",
97
- "prettier-plugin-packagejson": "^2.2.11",
101
+ "jest-silent-reporter": "^0.6.0",
102
+ "prettier": "^2.8.8",
103
+ "prettier-plugin-packagejson": "^2.5.2",
98
104
  "typescript": "~5.3.3"
99
105
  },
100
106
  "engines": {
@@ -103,6 +109,5 @@
103
109
  "publishConfig": {
104
110
  "access": "public",
105
111
  "registry": "https://registry.npmjs.org/"
106
- },
107
- "packageManager": "yarn@3.4.1"
112
+ }
108
113
  }
@@ -1,143 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getInterfaceApi = exports.getInterfaceFromResult = exports.handleRequest = void 0;
4
- const snaps_sdk_1 = require("@metamask/snaps-sdk");
5
- const snaps_utils_1 = require("@metamask/snaps-utils");
6
- const superstruct_1 = require("@metamask/superstruct");
7
- const utils_1 = require("@metamask/utils");
8
- const toolkit_1 = require("@reduxjs/toolkit");
9
- const simulation_1 = require("./simulation/index.cjs");
10
- const structs_1 = require("./structs.cjs");
11
- /**
12
- * Send a JSON-RPC request to the Snap, and wrap the response in a
13
- * {@link SnapResponse} object.
14
- *
15
- * @param options - The request options.
16
- * @param options.snapId - The ID of the Snap to send the request to.
17
- * @param options.store - The Redux store.
18
- * @param options.executionService - The execution service to use to send the
19
- * request.
20
- * @param options.handler - The handler to use to send the request.
21
- * @param options.controllerMessenger - The controller messenger used to call actions.
22
- * @param options.runSaga - A function to run a saga outside the usual Redux
23
- * flow.
24
- * @param options.request - The request to send.
25
- * @param options.request.id - The ID of the request. If not provided, a random
26
- * ID will be generated.
27
- * @param options.request.origin - The origin of the request. Defaults to
28
- * `https://metamask.io`.
29
- * @returns The response, wrapped in a {@link SnapResponse} object.
30
- */
31
- function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id = (0, toolkit_1.nanoid)(), origin = 'https://metamask.io', ...options }, }) {
32
- const getInterfaceError = () => {
33
- throw new Error('Unable to get the interface from the Snap: The request to the Snap failed.');
34
- };
35
- const promise = executionService
36
- .handleRpcRequest(snapId, {
37
- origin,
38
- handler,
39
- request: {
40
- jsonrpc: '2.0',
41
- id: 1,
42
- ...options,
43
- },
44
- })
45
- .then(async (result) => {
46
- const notifications = (0, simulation_1.getNotifications)(store.getState());
47
- store.dispatch((0, simulation_1.clearNotifications)());
48
- try {
49
- const getInterfaceFn = await getInterfaceApi(result, snapId, controllerMessenger);
50
- return {
51
- id: String(id),
52
- response: {
53
- result: (0, utils_1.getSafeJson)(result),
54
- },
55
- notifications,
56
- ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),
57
- };
58
- }
59
- catch (error) {
60
- const [unwrappedError] = (0, snaps_utils_1.unwrapError)(error);
61
- return {
62
- id: String(id),
63
- response: {
64
- error: unwrappedError.serialize(),
65
- },
66
- notifications: [],
67
- getInterface: getInterfaceError,
68
- };
69
- }
70
- })
71
- .catch((error) => {
72
- const [unwrappedError] = (0, snaps_utils_1.unwrapError)(error);
73
- return {
74
- id: String(id),
75
- response: {
76
- error: unwrappedError.serialize(),
77
- },
78
- notifications: [],
79
- getInterface: getInterfaceError,
80
- };
81
- });
82
- promise.getInterface = async () => {
83
- const sagaPromise = runSaga(simulation_1.getInterface, runSaga, snapId, controllerMessenger).toPromise();
84
- const result = await Promise.race([promise, sagaPromise]);
85
- // If the request promise has resolved to an error, we should throw
86
- // instead of waiting for an interface that likely will never be displayed
87
- if ((0, superstruct_1.is)(result, structs_1.SnapResponseStruct) &&
88
- (0, utils_1.hasProperty)(result.response, 'error')) {
89
- throw new Error(`Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${result.response.error.message}`);
90
- }
91
- return await sagaPromise;
92
- };
93
- return promise;
94
- }
95
- exports.handleRequest = handleRequest;
96
- /**
97
- * Get the interface ID from the result if it's available or create a new interface if the result contains static components.
98
- *
99
- * @param result - The handler result object.
100
- * @param snapId - The Snap ID.
101
- * @param controllerMessenger - The controller messenger.
102
- * @returns The interface ID or undefined if the result doesn't include content.
103
- */
104
- async function getInterfaceFromResult(result, snapId, controllerMessenger) {
105
- if ((0, utils_1.isPlainObject)(result) && (0, utils_1.hasProperty)(result, 'id')) {
106
- return result.id;
107
- }
108
- if ((0, utils_1.isPlainObject)(result) && (0, utils_1.hasProperty)(result, 'content')) {
109
- (0, utils_1.assert)((0, superstruct_1.is)(result.content, snaps_sdk_1.ComponentOrElementStruct), 'The Snap returned an invalid interface.');
110
- const id = await controllerMessenger.call('SnapInterfaceController:createInterface', snapId, result.content);
111
- return id;
112
- }
113
- return undefined;
114
- }
115
- exports.getInterfaceFromResult = getInterfaceFromResult;
116
- /**
117
- * Get the response content from the `SnapInterfaceController` and include the
118
- * interaction methods.
119
- *
120
- * @param result - The handler result object.
121
- * @param snapId - The Snap ID.
122
- * @param controllerMessenger - The controller messenger.
123
- * @returns The content components if any.
124
- */
125
- async function getInterfaceApi(result, snapId, controllerMessenger) {
126
- const interfaceId = await getInterfaceFromResult(result, snapId, controllerMessenger);
127
- if (interfaceId) {
128
- return () => {
129
- const { content } = controllerMessenger.call('SnapInterfaceController:getInterface', snapId, interfaceId);
130
- const actions = (0, simulation_1.getInterfaceActions)(snapId, controllerMessenger, {
131
- id: interfaceId,
132
- content,
133
- });
134
- return {
135
- content,
136
- ...actions,
137
- };
138
- };
139
- }
140
- return undefined;
141
- }
142
- exports.getInterfaceApi = getInterfaceApi;
143
- //# sourceMappingURL=request.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request.cjs","sourceRoot":"","sources":["../../src/internals/request.ts"],"names":[],"mappings":";;;AACA,mDAK6B;AAE7B,uDAAoD;AACpD,uDAA2C;AAC3C,2CAKyB;AACzB,8CAA0C;AAQ1C,uDAKsB;AAEtB,2CAA+C;AAY/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,EACP,OAAO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IAAI,IAAA,qBAAa,EAAC,MAAM,CAAC,IAAI,IAAA,mBAAW,EAAC,MAAM,EAAE,SAAS,CAAC,EAAE,CAAC;QAC5D,IAAA,cAAM,EACJ,IAAA,gBAAE,EAAC,MAAM,CAAC,OAAO,EAAE,oCAAwB,CAAC,EAC5C,yCAAyC,CAC1C,CAAC;QACF,MAAM,EAAE,GAAG,MAAM,mBAAmB,CAAC,IAAI,CACvC,yCAAyC,EACzC,MAAM,EACN,MAAM,CAAC,OAA6B,CACrC,CAAC;QAEF,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAxBD,wDAwBC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,eAAe,CACnC,MAAe,EACf,MAAc,EACd,mBAA4C;IAE5C,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAC9C,MAAM,EACN,MAAM,EACN,mBAAmB,CACpB,CAAC;IAEF,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,GAAG,EAAE;YACV,MAAM,EAAE,OAAO,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAC1C,sCAAsC,EACtC,MAAM,EACN,WAAW,CACZ,CAAC;YAEF,MAAM,OAAO,GAAG,IAAA,gCAAmB,EAAC,MAAM,EAAE,mBAAmB,EAAE;gBAC/D,EAAE,EAAE,WAAW;gBACf,OAAO;aACR,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO;gBACP,GAAG,OAAO;aACX,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAhCD,0CAgCC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type ComponentOrElement,\n ComponentOrElementStruct,\n type JsonRpcError,\n type SnapId,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\n\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from '../types';\nimport type { RunSagaFunction, Store } from './simulation';\nimport {\n clearNotifications,\n getInterface,\n getInterfaceActions,\n getNotifications,\n} from './simulation';\nimport type { RootControllerMessenger } from './simulation/controllers';\nimport { SnapResponseStruct } from './structs';\n\nexport type HandleRequestOptions = {\n snapId: SnapId;\n store: Store;\n executionService: AbstractExecutionService<unknown>;\n handler: HandlerType;\n controllerMessenger: RootControllerMessenger;\n runSaga: RunSagaFunction;\n request: RequestOptions;\n};\n\n/**\n * Send a JSON-RPC request to the Snap, and wrap the response in a\n * {@link SnapResponse} object.\n *\n * @param options - The request options.\n * @param options.snapId - The ID of the Snap to send the request to.\n * @param options.store - The Redux store.\n * @param options.executionService - The execution service to use to send the\n * request.\n * @param options.handler - The handler to use to send the request.\n * @param options.controllerMessenger - The controller messenger used to call actions.\n * @param options.runSaga - A function to run a saga outside the usual Redux\n * flow.\n * @param options.request - The request to send.\n * @param options.request.id - The ID of the request. If not provided, a random\n * ID will be generated.\n * @param options.request.origin - The origin of the request. Defaults to\n * `https://metamask.io`.\n * @returns The response, wrapped in a {@link SnapResponse} object.\n */\nexport function handleRequest({\n snapId,\n store,\n executionService,\n handler,\n controllerMessenger,\n runSaga,\n request: { id = nanoid(), origin = 'https://metamask.io', ...options },\n}: HandleRequestOptions): SnapRequest {\n const getInterfaceError = () => {\n throw new Error(\n 'Unable to get the interface from the Snap: The request to the Snap failed.',\n );\n };\n\n const promise = executionService\n .handleRpcRequest(snapId, {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n })\n .then(async (result) => {\n const notifications = getNotifications(store.getState());\n store.dispatch(clearNotifications());\n\n try {\n const getInterfaceFn = await getInterfaceApi(\n result,\n snapId,\n controllerMessenger,\n );\n\n return {\n id: String(id),\n response: {\n result: getSafeJson(result),\n },\n notifications,\n ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),\n };\n } catch (error) {\n const [unwrappedError] = unwrapError(error);\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }\n })\n .catch((error) => {\n const [unwrappedError] = unwrapError(error);\n\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }) as unknown as SnapRequest;\n\n promise.getInterface = async () => {\n const sagaPromise = runSaga(\n getInterface,\n runSaga,\n snapId,\n controllerMessenger,\n ).toPromise();\n const result = await Promise.race([promise, sagaPromise]);\n\n // If the request promise has resolved to an error, we should throw\n // instead of waiting for an interface that likely will never be displayed\n if (\n is(result, SnapResponseStruct) &&\n hasProperty(result.response, 'error')\n ) {\n throw new Error(\n `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${\n (result.response.error as JsonRpcError).message\n }`,\n );\n }\n\n return await sagaPromise;\n };\n\n return promise;\n}\n\n/**\n * Get the interface ID from the result if it's available or create a new interface if the result contains static components.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The interface ID or undefined if the result doesn't include content.\n */\nexport async function getInterfaceFromResult(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n) {\n if (isPlainObject(result) && hasProperty(result, 'id')) {\n return result.id as string;\n }\n\n if (isPlainObject(result) && hasProperty(result, 'content')) {\n assert(\n is(result.content, ComponentOrElementStruct),\n 'The Snap returned an invalid interface.',\n );\n const id = await controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n result.content as ComponentOrElement,\n );\n\n return id;\n }\n\n return undefined;\n}\n\n/**\n * Get the response content from the `SnapInterfaceController` and include the\n * interaction methods.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The content components if any.\n */\nexport async function getInterfaceApi(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): Promise<(() => SnapHandlerInterface) | undefined> {\n const interfaceId = await getInterfaceFromResult(\n result,\n snapId,\n controllerMessenger,\n );\n\n if (interfaceId) {\n return () => {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n interfaceId,\n );\n\n const actions = getInterfaceActions(snapId, controllerMessenger, {\n id: interfaceId,\n content,\n });\n\n return {\n content,\n ...actions,\n };\n };\n }\n\n return undefined;\n}\n"]}
@@ -1,56 +0,0 @@
1
- import type { AbstractExecutionService } from "@metamask/snaps-controllers";
2
- import { type SnapId } from "@metamask/snaps-sdk";
3
- import type { HandlerType } from "@metamask/snaps-utils";
4
- import type { RequestOptions, SnapHandlerInterface, SnapRequest } from "../types/index.cjs";
5
- import type { RunSagaFunction, Store } from "./simulation/index.cjs";
6
- import type { RootControllerMessenger } from "./simulation/controllers.cjs";
7
- export type HandleRequestOptions = {
8
- snapId: SnapId;
9
- store: Store;
10
- executionService: AbstractExecutionService<unknown>;
11
- handler: HandlerType;
12
- controllerMessenger: RootControllerMessenger;
13
- runSaga: RunSagaFunction;
14
- request: RequestOptions;
15
- };
16
- /**
17
- * Send a JSON-RPC request to the Snap, and wrap the response in a
18
- * {@link SnapResponse} object.
19
- *
20
- * @param options - The request options.
21
- * @param options.snapId - The ID of the Snap to send the request to.
22
- * @param options.store - The Redux store.
23
- * @param options.executionService - The execution service to use to send the
24
- * request.
25
- * @param options.handler - The handler to use to send the request.
26
- * @param options.controllerMessenger - The controller messenger used to call actions.
27
- * @param options.runSaga - A function to run a saga outside the usual Redux
28
- * flow.
29
- * @param options.request - The request to send.
30
- * @param options.request.id - The ID of the request. If not provided, a random
31
- * ID will be generated.
32
- * @param options.request.origin - The origin of the request. Defaults to
33
- * `https://metamask.io`.
34
- * @returns The response, wrapped in a {@link SnapResponse} object.
35
- */
36
- export declare function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id, origin, ...options }, }: HandleRequestOptions): SnapRequest;
37
- /**
38
- * Get the interface ID from the result if it's available or create a new interface if the result contains static components.
39
- *
40
- * @param result - The handler result object.
41
- * @param snapId - The Snap ID.
42
- * @param controllerMessenger - The controller messenger.
43
- * @returns The interface ID or undefined if the result doesn't include content.
44
- */
45
- export declare function getInterfaceFromResult(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<string | undefined>;
46
- /**
47
- * Get the response content from the `SnapInterfaceController` and include the
48
- * interaction methods.
49
- *
50
- * @param result - The handler result object.
51
- * @param snapId - The Snap ID.
52
- * @param controllerMessenger - The controller messenger.
53
- * @returns The content components if any.
54
- */
55
- export declare function getInterfaceApi(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<(() => SnapHandlerInterface) | undefined>;
56
- //# sourceMappingURL=request.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request.d.cts","sourceRoot":"","sources":["../../src/internals/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,EAIL,KAAK,MAAM,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAWzD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACZ,2BAAiB;AAClB,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,+BAAqB;AAO3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,qCAAiC;AAGxE,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,EAAE,WAAW,CAAC;IACrB,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,EACP,OAAO,EAAE,EAAE,EAAa,EAAE,MAA8B,EAAE,GAAG,OAAO,EAAE,GACvE,EAAE,oBAAoB,GAAG,WAAW,CAuFpC;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,+BAqB7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,GAC3C,OAAO,CAAC,CAAC,MAAM,oBAAoB,CAAC,GAAG,SAAS,CAAC,CA4BnD"}
@@ -1,56 +0,0 @@
1
- import type { AbstractExecutionService } from "@metamask/snaps-controllers";
2
- import { type SnapId } from "@metamask/snaps-sdk";
3
- import type { HandlerType } from "@metamask/snaps-utils";
4
- import type { RequestOptions, SnapHandlerInterface, SnapRequest } from "../types/index.mjs";
5
- import type { RunSagaFunction, Store } from "./simulation/index.mjs";
6
- import type { RootControllerMessenger } from "./simulation/controllers.mjs";
7
- export type HandleRequestOptions = {
8
- snapId: SnapId;
9
- store: Store;
10
- executionService: AbstractExecutionService<unknown>;
11
- handler: HandlerType;
12
- controllerMessenger: RootControllerMessenger;
13
- runSaga: RunSagaFunction;
14
- request: RequestOptions;
15
- };
16
- /**
17
- * Send a JSON-RPC request to the Snap, and wrap the response in a
18
- * {@link SnapResponse} object.
19
- *
20
- * @param options - The request options.
21
- * @param options.snapId - The ID of the Snap to send the request to.
22
- * @param options.store - The Redux store.
23
- * @param options.executionService - The execution service to use to send the
24
- * request.
25
- * @param options.handler - The handler to use to send the request.
26
- * @param options.controllerMessenger - The controller messenger used to call actions.
27
- * @param options.runSaga - A function to run a saga outside the usual Redux
28
- * flow.
29
- * @param options.request - The request to send.
30
- * @param options.request.id - The ID of the request. If not provided, a random
31
- * ID will be generated.
32
- * @param options.request.origin - The origin of the request. Defaults to
33
- * `https://metamask.io`.
34
- * @returns The response, wrapped in a {@link SnapResponse} object.
35
- */
36
- export declare function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id, origin, ...options }, }: HandleRequestOptions): SnapRequest;
37
- /**
38
- * Get the interface ID from the result if it's available or create a new interface if the result contains static components.
39
- *
40
- * @param result - The handler result object.
41
- * @param snapId - The Snap ID.
42
- * @param controllerMessenger - The controller messenger.
43
- * @returns The interface ID or undefined if the result doesn't include content.
44
- */
45
- export declare function getInterfaceFromResult(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<string | undefined>;
46
- /**
47
- * Get the response content from the `SnapInterfaceController` and include the
48
- * interaction methods.
49
- *
50
- * @param result - The handler result object.
51
- * @param snapId - The Snap ID.
52
- * @param controllerMessenger - The controller messenger.
53
- * @returns The content components if any.
54
- */
55
- export declare function getInterfaceApi(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<(() => SnapHandlerInterface) | undefined>;
56
- //# sourceMappingURL=request.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request.d.mts","sourceRoot":"","sources":["../../src/internals/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,EAIL,KAAK,MAAM,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAWzD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACZ,2BAAiB;AAClB,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,+BAAqB;AAO3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,qCAAiC;AAGxE,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,gBAA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