@metamask/snaps-jest 4.0.0 → 5.0.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 (217) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/README.md +66 -179
  3. package/dist/cjs/environment.js +21 -82
  4. package/dist/cjs/environment.js.map +1 -1
  5. package/dist/cjs/helpers.js +118 -43
  6. package/dist/cjs/helpers.js.map +1 -1
  7. package/dist/cjs/internals/environment.js +1 -1
  8. package/dist/cjs/internals/environment.js.map +1 -1
  9. package/dist/cjs/internals/index.js +1 -4
  10. package/dist/cjs/internals/index.js.map +1 -1
  11. package/dist/cjs/internals/request.js +42 -94
  12. package/dist/cjs/internals/request.js.map +1 -1
  13. package/dist/cjs/internals/server.js +0 -4
  14. package/dist/cjs/internals/server.js.map +1 -1
  15. package/dist/cjs/internals/simulation/constants.js +29 -0
  16. package/dist/cjs/internals/simulation/constants.js.map +1 -0
  17. package/dist/cjs/internals/simulation/controllers.js +95 -0
  18. package/dist/cjs/internals/simulation/controllers.js.map +1 -0
  19. package/dist/cjs/internals/simulation/files.js +22 -0
  20. package/dist/cjs/internals/simulation/files.js.map +1 -0
  21. package/dist/cjs/internals/simulation/index.js +24 -0
  22. package/dist/cjs/internals/simulation/index.js.map +1 -0
  23. package/dist/cjs/internals/simulation/interface.js +98 -0
  24. package/dist/cjs/internals/simulation/interface.js.map +1 -0
  25. package/dist/cjs/internals/simulation/methods/constants.js +84 -0
  26. package/dist/cjs/internals/simulation/methods/constants.js.map +1 -0
  27. package/dist/cjs/internals/simulation/methods/hooks/encryption.js +33 -0
  28. package/dist/cjs/internals/simulation/methods/hooks/encryption.js.map +1 -0
  29. package/dist/cjs/internals/simulation/methods/hooks/get-locale.js +17 -0
  30. package/dist/cjs/internals/simulation/methods/hooks/get-locale.js.map +1 -0
  31. package/dist/cjs/internals/simulation/methods/hooks/index.js +25 -0
  32. package/dist/cjs/internals/simulation/methods/hooks/index.js.map +1 -0
  33. package/dist/cjs/internals/simulation/methods/hooks/interface.js +26 -0
  34. package/dist/cjs/internals/simulation/methods/hooks/interface.js.map +1 -0
  35. package/dist/cjs/internals/simulation/methods/hooks/notifications.js +66 -0
  36. package/dist/cjs/internals/simulation/methods/hooks/notifications.js.map +1 -0
  37. package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js +43 -0
  38. package/dist/cjs/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
  39. package/dist/cjs/internals/simulation/methods/hooks/state.js +80 -0
  40. package/dist/cjs/internals/simulation/methods/hooks/state.js.map +1 -0
  41. package/dist/cjs/internals/simulation/methods/index.js +20 -0
  42. package/dist/cjs/internals/simulation/methods/index.js.map +1 -0
  43. package/dist/cjs/internals/simulation/methods/specifications.js +81 -0
  44. package/dist/cjs/internals/simulation/methods/specifications.js.map +1 -0
  45. package/dist/cjs/internals/simulation/middleware/engine.js +31 -0
  46. package/dist/cjs/internals/simulation/middleware/engine.js.map +1 -0
  47. package/dist/cjs/internals/simulation/middleware/index.js +20 -0
  48. package/dist/cjs/internals/simulation/middleware/index.js.map +1 -0
  49. package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js +30 -0
  50. package/dist/cjs/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
  51. package/dist/cjs/internals/simulation/middleware/internal-methods/index.js +20 -0
  52. package/dist/cjs/internals/simulation/middleware/internal-methods/index.js.map +1 -0
  53. package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js +37 -0
  54. package/dist/cjs/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
  55. package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
  56. package/dist/cjs/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
  57. package/dist/cjs/internals/simulation/middleware/mock.js +23 -0
  58. package/dist/cjs/internals/simulation/middleware/mock.js.map +1 -0
  59. package/dist/cjs/internals/simulation/options.js +24 -0
  60. package/dist/cjs/internals/simulation/options.js.map +1 -0
  61. package/dist/cjs/internals/simulation/simulation.js +124 -0
  62. package/dist/cjs/internals/simulation/simulation.js.map +1 -0
  63. package/dist/cjs/internals/simulation/store/index.js +23 -0
  64. package/dist/cjs/internals/simulation/store/index.js.map +1 -0
  65. package/dist/cjs/internals/simulation/store/mocks.js +52 -0
  66. package/dist/cjs/internals/simulation/store/mocks.js.map +1 -0
  67. package/dist/cjs/internals/simulation/store/notifications.js +52 -0
  68. package/dist/cjs/internals/simulation/store/notifications.js.map +1 -0
  69. package/dist/cjs/internals/simulation/store/state.js +64 -0
  70. package/dist/cjs/internals/simulation/store/state.js.map +1 -0
  71. package/dist/cjs/internals/simulation/store/store.js +57 -0
  72. package/dist/cjs/internals/simulation/store/store.js.map +1 -0
  73. package/dist/cjs/internals/simulation/store/ui.js +48 -0
  74. package/dist/cjs/internals/simulation/store/ui.js.map +1 -0
  75. package/dist/cjs/internals/structs.js +47 -5
  76. package/dist/cjs/internals/structs.js.map +1 -1
  77. package/dist/cjs/matchers.js +5 -2
  78. package/dist/cjs/matchers.js.map +1 -1
  79. package/dist/cjs/options.js +0 -6
  80. package/dist/cjs/options.js.map +1 -1
  81. package/dist/esm/environment.js +22 -83
  82. package/dist/esm/environment.js.map +1 -1
  83. package/dist/esm/helpers.js +127 -46
  84. package/dist/esm/helpers.js.map +1 -1
  85. package/dist/esm/internals/environment.js +1 -1
  86. package/dist/esm/internals/environment.js.map +1 -1
  87. package/dist/esm/internals/index.js +1 -5
  88. package/dist/esm/internals/index.js.map +1 -1
  89. package/dist/esm/internals/request.js +61 -104
  90. package/dist/esm/internals/request.js.map +1 -1
  91. package/dist/esm/internals/server.js +1 -5
  92. package/dist/esm/internals/server.js.map +1 -1
  93. package/dist/esm/internals/simulation/constants.js +12 -0
  94. package/dist/esm/internals/simulation/constants.js.map +1 -0
  95. package/dist/esm/internals/simulation/controllers.js +90 -0
  96. package/dist/esm/internals/simulation/controllers.js.map +1 -0
  97. package/dist/esm/internals/simulation/files.js +19 -0
  98. package/dist/esm/internals/simulation/files.js.map +1 -0
  99. package/dist/esm/internals/simulation/index.js +7 -0
  100. package/dist/esm/internals/simulation/index.js.map +1 -0
  101. package/dist/esm/internals/simulation/interface.js +95 -0
  102. package/dist/esm/internals/simulation/interface.js.map +1 -0
  103. package/dist/esm/internals/simulation/methods/constants.js +69 -0
  104. package/dist/esm/internals/simulation/methods/constants.js.map +1 -0
  105. package/dist/esm/internals/simulation/methods/hooks/encryption.js +39 -0
  106. package/dist/esm/internals/simulation/methods/hooks/encryption.js.map +1 -0
  107. package/dist/esm/internals/simulation/methods/hooks/get-locale.js +13 -0
  108. package/dist/esm/internals/simulation/methods/hooks/get-locale.js.map +1 -0
  109. package/dist/esm/internals/simulation/methods/hooks/index.js +8 -0
  110. package/dist/esm/internals/simulation/methods/hooks/index.js.map +1 -0
  111. package/dist/esm/internals/simulation/methods/hooks/interface.js +18 -0
  112. package/dist/esm/internals/simulation/methods/hooks/interface.js.map +1 -0
  113. package/dist/esm/internals/simulation/methods/hooks/notifications.js +58 -0
  114. package/dist/esm/internals/simulation/methods/hooks/notifications.js.map +1 -0
  115. package/dist/esm/internals/simulation/methods/hooks/show-dialog.js +38 -0
  116. package/dist/esm/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
  117. package/dist/esm/internals/simulation/methods/hooks/state.js +74 -0
  118. package/dist/esm/internals/simulation/methods/hooks/state.js.map +1 -0
  119. package/dist/esm/internals/simulation/methods/index.js +3 -0
  120. package/dist/esm/internals/simulation/methods/index.js.map +1 -0
  121. package/dist/esm/internals/simulation/methods/specifications.js +84 -0
  122. package/dist/esm/internals/simulation/methods/specifications.js.map +1 -0
  123. package/dist/esm/internals/simulation/middleware/engine.js +33 -0
  124. package/dist/esm/internals/simulation/middleware/engine.js.map +1 -0
  125. package/dist/esm/internals/simulation/middleware/index.js +3 -0
  126. package/dist/esm/internals/simulation/middleware/index.js.map +1 -0
  127. package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js +31 -0
  128. package/dist/esm/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
  129. package/dist/esm/internals/simulation/middleware/internal-methods/index.js +3 -0
  130. package/dist/esm/internals/simulation/middleware/internal-methods/index.js.map +1 -0
  131. package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js +37 -0
  132. package/dist/esm/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
  133. package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js +23 -0
  134. package/dist/esm/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
  135. package/dist/esm/internals/simulation/middleware/mock.js +18 -0
  136. package/dist/esm/internals/simulation/middleware/mock.js.map +1 -0
  137. package/dist/esm/internals/simulation/options.js +20 -0
  138. package/dist/esm/internals/simulation/options.js.map +1 -0
  139. package/dist/esm/internals/simulation/simulation.js +128 -0
  140. package/dist/esm/internals/simulation/simulation.js.map +1 -0
  141. package/dist/esm/internals/simulation/store/index.js +6 -0
  142. package/dist/esm/internals/simulation/store/index.js.map +1 -0
  143. package/dist/esm/internals/simulation/store/mocks.js +32 -0
  144. package/dist/esm/internals/simulation/store/mocks.js.map +1 -0
  145. package/dist/esm/internals/simulation/store/notifications.js +30 -0
  146. package/dist/esm/internals/simulation/store/notifications.js.map +1 -0
  147. package/dist/esm/internals/simulation/store/state.js +47 -0
  148. package/dist/esm/internals/simulation/store/state.js.map +1 -0
  149. package/dist/esm/internals/simulation/store/store.js +50 -0
  150. package/dist/esm/internals/simulation/store/store.js.map +1 -0
  151. package/dist/esm/internals/simulation/store/ui.js +21 -0
  152. package/dist/esm/internals/simulation/store/ui.js.map +1 -0
  153. package/dist/esm/internals/structs.js +41 -5
  154. package/dist/esm/internals/structs.js.map +1 -1
  155. package/dist/esm/matchers.js +5 -2
  156. package/dist/esm/matchers.js.map +1 -1
  157. package/dist/esm/options.js +1 -7
  158. package/dist/esm/options.js.map +1 -1
  159. package/dist/esm/types.js.map +1 -1
  160. package/dist/types/environment.d.ts +14 -15
  161. package/dist/types/helpers.d.ts +64 -3
  162. package/dist/types/internals/index.d.ts +1 -4
  163. package/dist/types/internals/request.d.ts +38 -56
  164. package/dist/types/internals/simulation/constants.d.ts +13 -0
  165. package/dist/types/internals/simulation/controllers.d.ts +40 -0
  166. package/dist/types/internals/simulation/files.d.ts +11 -0
  167. package/dist/types/internals/simulation/index.d.ts +5 -0
  168. package/dist/types/internals/simulation/interface.d.ts +25 -0
  169. package/dist/types/internals/simulation/methods/constants.d.ts +10 -0
  170. package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +29 -0
  171. package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +9 -0
  172. package/dist/types/internals/simulation/methods/hooks/index.d.ts +6 -0
  173. package/dist/types/internals/simulation/methods/hooks/interface.d.ts +16 -0
  174. package/dist/types/internals/simulation/methods/hooks/notifications.d.ts +16 -0
  175. package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +9 -0
  176. package/dist/types/internals/simulation/methods/hooks/state.d.ts +22 -0
  177. package/dist/types/internals/simulation/methods/index.d.ts +1 -0
  178. package/dist/types/internals/simulation/methods/specifications.d.ts +56 -0
  179. package/dist/types/internals/simulation/middleware/engine.d.ts +26 -0
  180. package/dist/types/internals/simulation/middleware/index.d.ts +1 -0
  181. package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +18 -0
  182. package/dist/types/internals/simulation/middleware/internal-methods/index.d.ts +1 -0
  183. package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +22 -0
  184. package/dist/types/internals/simulation/middleware/internal-methods/provider-state.d.ts +14 -0
  185. package/dist/types/internals/simulation/middleware/mock.d.ts +10 -0
  186. package/dist/types/internals/simulation/options.d.ts +37 -0
  187. package/dist/types/internals/simulation/simulation.d.ts +98 -0
  188. package/dist/types/internals/simulation/store/index.d.ts +4 -0
  189. package/dist/types/internals/simulation/store/mocks.d.ts +35 -0
  190. package/dist/types/internals/simulation/store/notifications.d.ts +44 -0
  191. package/dist/types/internals/simulation/store/state.d.ts +55 -0
  192. package/dist/types/internals/simulation/store/store.d.ts +22 -0
  193. package/dist/types/internals/simulation/store/ui.d.ts +25 -0
  194. package/dist/types/internals/structs.d.ts +229 -16
  195. package/dist/types/options.d.ts +3 -35
  196. package/dist/types/types.d.ts +88 -41
  197. package/package.json +21 -12
  198. package/dist/cjs/internals/interface.js +0 -103
  199. package/dist/cjs/internals/interface.js.map +0 -1
  200. package/dist/cjs/internals/network.js +0 -148
  201. package/dist/cjs/internals/network.js.map +0 -1
  202. package/dist/cjs/internals/types.js +0 -6
  203. package/dist/cjs/internals/types.js.map +0 -1
  204. package/dist/cjs/internals/wait-for.js +0 -63
  205. package/dist/cjs/internals/wait-for.js.map +0 -1
  206. package/dist/esm/internals/interface.js +0 -100
  207. package/dist/esm/internals/interface.js.map +0 -1
  208. package/dist/esm/internals/network.js +0 -143
  209. package/dist/esm/internals/network.js.map +0 -1
  210. package/dist/esm/internals/types.js +0 -3
  211. package/dist/esm/internals/types.js.map +0 -1
  212. package/dist/esm/internals/wait-for.js +0 -63
  213. package/dist/esm/internals/wait-for.js.map +0 -1
  214. package/dist/types/internals/interface.d.ts +0 -25
  215. package/dist/types/internals/network.d.ts +0 -87
  216. package/dist/types/internals/types.d.ts +0 -18
  217. package/dist/types/internals/wait-for.d.ts +0 -38
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/options.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n optional,\n string,\n type,\n} from 'superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n executionEnvironmentUrl: optional(string()),\n simulatorUrl: optional(string()),\n keepAlive: defaulted(boolean(), false),\n\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n\n browser: defaulted(\n object({\n headless: defaulted(boolean(), true),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * ```json\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * ```\n * @property executionEnvironmentUrl - The URL of the execution environment. If\n * this is not provided, the execution environment will be served from the\n * built-in HTTP server.\n * @property simulatorUrl - The URL of the simulator. If this is not provided,\n * the simulator will be served from the built-in HTTP server.\n * @property keepAlive - Whether to keep the browser open after the tests have\n * finished. This is useful for debugging. Defaults to `false`.\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n * @property browser - The options for the browser.\n * @property browser.headless - Whether to run the browser in headless mode.\n * Defaults to `true`.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n"],"names":["getOptions","SnapsEnvironmentOptionsStruct","type","executionEnvironmentUrl","optional","string","simulatorUrl","keepAlive","defaulted","boolean","server","object","enabled","port","number","root","process","cwd","browser","headless","testEnvironmentOptions","create"],"mappings":";;;;+BAmFgBA;;;eAAAA;;;6BAzET;AAEP,MAAMC,gCAAgCC,IAAAA,iBAAI,EAAC;IACzCC,yBAAyBC,IAAAA,qBAAQ,EAACC,IAAAA,mBAAM;IACxCC,cAAcF,IAAAA,qBAAQ,EAACC,IAAAA,mBAAM;IAC7BE,WAAWC,IAAAA,sBAAS,EAACC,IAAAA,oBAAO,KAAI;IAEhCC,QAAQF,IAAAA,sBAAS,EACfG,IAAAA,mBAAM,EAAC;QACLC,SAASJ,IAAAA,sBAAS,EAACC,IAAAA,oBAAO,KAAI;QAC9BI,MAAML,IAAAA,sBAAS,EAACM,IAAAA,mBAAM,KAAI;QAC1BC,MAAMP,IAAAA,sBAAS,EAACH,IAAAA,mBAAM,KAAIW,QAAQC,GAAG;IACvC,IACA,CAAC;IAGHC,SAASV,IAAAA,sBAAS,EAChBG,IAAAA,mBAAM,EAAC;QACLQ,UAAUX,IAAAA,sBAAS,EAACC,IAAAA,oBAAO,KAAI;IACjC,IACA,CAAC;AAEL;AAmDO,SAAST,WAAWoB,sBAA+C;IACxE,OAAOC,IAAAA,mBAAM,EAACD,wBAAwBnB;AACxC"}
1
+ {"version":3,"sources":["../../src/options.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from 'superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n"],"names":["getOptions","SnapsEnvironmentOptionsStruct","type","server","defaulted","object","enabled","boolean","port","number","root","string","process","cwd","testEnvironmentOptions","create"],"mappings":";;;;+BA2DgBA;;;eAAAA;;;6BAlDT;AAEP,MAAMC,gCAAgCC,IAAAA,iBAAI,EAAC;IACzCC,QAAQC,IAAAA,sBAAS,EACfC,IAAAA,mBAAM,EAAC;QACLC,SAASF,IAAAA,sBAAS,EAACG,IAAAA,oBAAO,KAAI;QAC9BC,MAAMJ,IAAAA,sBAAS,EAACK,IAAAA,mBAAM,KAAI;QAC1BC,MAAMN,IAAAA,sBAAS,EAACO,IAAAA,mBAAM,KAAIC,QAAQC,GAAG;IACvC,IACA,CAAC;AAEL;AAuCO,SAASb,WAAWc,sBAA+C;IACxE,OAAOC,IAAAA,mBAAM,EAACD,wBAAwBb;AACxC"}
@@ -38,26 +38,12 @@ function _class_private_field_set(receiver, privateMap, value) {
38
38
  _class_apply_descriptor_set(receiver, descriptor, value);
39
39
  return value;
40
40
  }
41
- function _define_property(obj, key, value) {
42
- if (key in obj) {
43
- Object.defineProperty(obj, key, {
44
- value: value,
45
- enumerable: true,
46
- configurable: true,
47
- writable: true
48
- });
49
- } else {
50
- obj[key] = value;
51
- }
52
- return obj;
53
- }
54
41
  import { assert, createModuleLogger } from '@metamask/utils';
55
42
  import NodeEnvironment from 'jest-environment-node';
56
- import { remote } from 'webdriverio';
57
- import { rootLogger, startServer } from './internals';
43
+ import { handleInstallSnap, rootLogger, startServer } from './internals';
58
44
  import { getOptions } from './options';
59
45
  /* eslint-enable */ const log = createModuleLogger(rootLogger, 'environment');
60
- var _options = /*#__PURE__*/ new WeakMap(), _server = /*#__PURE__*/ new WeakMap();
46
+ var _options = /*#__PURE__*/ new WeakMap(), _server = /*#__PURE__*/ new WeakMap(), _instance = /*#__PURE__*/ new WeakMap();
61
47
  export class SnapsEnvironment extends NodeEnvironment {
62
48
  /**
63
49
  * Set up the environment. This starts the built-in HTTP server, and creates a
@@ -68,48 +54,33 @@ export class SnapsEnvironment extends NodeEnvironment {
68
54
  log('Starting server.');
69
55
  _class_private_field_set(this, _server, await startServer(_class_private_field_get(this, _options).server));
70
56
  }
71
- const args = [];
72
- if (_class_private_field_get(this, _options).browser.headless) {
73
- args.push('--headless', '--disable-gpu');
74
- }
75
- log('Starting browser.');
76
- this.browser = await remote({
77
- logLevel: 'error',
78
- capabilities: {
79
- browserName: 'chrome',
80
- // eslint-disable-next-line @typescript-eslint/naming-convention
81
- 'goog:chromeOptions': {
82
- args
83
- }
84
- }
85
- });
86
- this.global.browser = this.browser;
87
57
  this.global.snapsEnvironment = this;
88
58
  }
89
59
  /**
90
60
  * Tear down the environment. This closes the browser, and stops the built-in
91
61
  * HTTP server.
92
62
  */ async teardown() {
93
- if (_class_private_field_get(this, _options).keepAlive) {
94
- log('Not tearing down environment because keepAlive is enabled.');
95
- return;
96
- }
97
- log('Closing browser, and stopping server.');
98
- await this.browser?.deleteSession();
63
+ await _class_private_field_get(this, _instance)?.executionService.terminateAllSnaps();
99
64
  _class_private_field_get(this, _server)?.close();
100
65
  await super.teardown();
101
66
  }
102
67
  /**
103
- * Get the URL to the simulator, including the environment URL.
68
+ * Install a Snap in the environment. This will terminate any previously
69
+ * installed Snaps, and run the Snap code in a new execution service.
104
70
  *
105
- * @returns The simulator URL.
106
- * @throws If the server is not running.
107
- */ get url() {
108
- assert(_class_private_field_get(this, _server), 'Server is not running.');
109
- const { port } = _class_private_field_get(this, _server).address();
110
- const simulatorUrl = _class_private_field_get(this, _options).simulatorUrl ?? `http://localhost:${port}/simulator/`;
111
- const executionEnvironmentUrl = _class_private_field_get(this, _options).executionEnvironmentUrl ?? `http://localhost:${port}/environment/`;
112
- return `${simulatorUrl}?environment=${encodeURIComponent(executionEnvironmentUrl)}`;
71
+ * @param snapId - The ID of the Snap to install.
72
+ * @param options - The options to use when installing the Snap.
73
+ * @param options.executionService - The execution service to use.
74
+ * @param options.executionServiceOptions - The options to use when creating the
75
+ * execution service, if any. This should only include options specific to the
76
+ * provided execution service.
77
+ * @param options.options - The simulation options.
78
+ * @template Service - The type of the execution service.
79
+ * @returns The installed Snap.
80
+ */ async installSnap(snapId = this.snapId, options = {}) {
81
+ await _class_private_field_get(this, _instance)?.executionService.terminateAllSnaps();
82
+ _class_private_field_set(this, _instance, await handleInstallSnap(snapId, options));
83
+ return _class_private_field_get(this, _instance);
113
84
  }
114
85
  /**
115
86
  * Get the snap ID for the current environment, which is used if no snap ID is
@@ -124,48 +95,12 @@ export class SnapsEnvironment extends NodeEnvironment {
124
95
  return `local:http://localhost:${port}`;
125
96
  }
126
97
  /**
127
- * Create a new page, and attach logging handlers.
128
- *
129
- * @param url - The page URL. Defaults to the specified Snaps Simulator URL,
130
- * or the default simulator URL if none is specified.
131
- * @param timeout - The page timeout, in milliseconds.
132
- * @returns The new page.
133
- */ async createPage(url = this.url, timeout = 10000) {
134
- const puppeteer = await this.browser.getPuppeteer();
135
- const page = await puppeteer.newPage();
136
- page.setDefaultTimeout(timeout);
137
- page.setDefaultNavigationTimeout(timeout);
138
- // Give the page permission to show notifications. This is required for
139
- // testing `snap_notify`.
140
- await page.browserContext().overridePermissions(url, [
141
- 'notifications'
142
- ]);
143
- // `networkidle0` is used to ensure that the page is fully loaded. This
144
- // makes it wait for no requests to be made, which guarantees that the page
145
- // is ready.
146
- await page.goto(url, {
147
- waitUntil: 'networkidle0'
148
- });
149
- const browserLog = createModuleLogger(rootLogger, 'browser');
150
- page// This is fired when the page calls `console.log` or similar.
151
- .on('console', (message)=>{
152
- browserLog(`[${message.type()}] ${message.text()}`);
153
- })// This is fired when the page throws an error.
154
- .on('pageerror', ({ message })=>{
155
- browserLog(`[page error] ${message}`);
156
- });
157
- return page;
158
- }
159
- /**
160
98
  * Constructor.
161
99
  *
162
100
  * @param options - The environment options.
163
101
  * @param context - The environment context.
164
102
  */ constructor(options, context){
165
103
  super(options, context);
166
- // `browser` is always set in the environment setup function. To avoid needing
167
- // to check for `undefined` everywhere, we use a type assertion here.
168
- _define_property(this, "browser", void 0);
169
104
  _class_private_field_init(this, _options, {
170
105
  writable: true,
171
106
  value: void 0
@@ -174,6 +109,10 @@ export class SnapsEnvironment extends NodeEnvironment {
174
109
  writable: true,
175
110
  value: void 0
176
111
  });
112
+ _class_private_field_init(this, _instance, {
113
+ writable: true,
114
+ value: void 0
115
+ });
177
116
  _class_private_field_set(this, _options, getOptions(options.projectConfig.testEnvironmentOptions));
178
117
  }
179
118
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/environment.ts"],"sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\nimport type { Browser } from 'puppeteer';\nimport { remote } from 'webdriverio';\n\nimport { rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const browser: WebdriverIO.Browser;\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n // `browser` is always set in the environment setup function. To avoid needing\n // to check for `undefined` everywhere, we use a type assertion here.\n browser!: WebdriverIO.Browser;\n\n #options: SnapsEnvironmentOptions;\n\n #server: Server | 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 const args = [];\n if (this.#options.browser.headless) {\n args.push('--headless', '--disable-gpu');\n }\n\n log('Starting browser.');\n this.browser = await remote({\n logLevel: 'error',\n capabilities: {\n browserName: 'chrome',\n // eslint-disable-next-line @typescript-eslint/naming-convention\n 'goog:chromeOptions': {\n args,\n },\n },\n });\n\n this.global.browser = this.browser;\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 if (this.#options.keepAlive) {\n log('Not tearing down environment because keepAlive is enabled.');\n return;\n }\n\n log('Closing browser, and stopping server.');\n await this.browser?.deleteSession();\n this.#server?.close();\n\n await super.teardown();\n }\n\n /**\n * Get the URL to the simulator, including the environment URL.\n *\n * @returns The simulator URL.\n * @throws If the server is not running.\n */\n get url() {\n assert(this.#server, 'Server is not running.');\n\n const { port } = this.#server.address() as AddressInfo;\n const simulatorUrl =\n this.#options.simulatorUrl ?? `http://localhost:${port}/simulator/`;\n\n const executionEnvironmentUrl =\n this.#options.executionEnvironmentUrl ??\n `http://localhost:${port}/environment/`;\n\n return `${simulatorUrl}?environment=${encodeURIComponent(\n executionEnvironmentUrl,\n )}`;\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 /**\n * Create a new page, and attach logging handlers.\n *\n * @param url - The page URL. Defaults to the specified Snaps Simulator URL,\n * or the default simulator URL if none is specified.\n * @param timeout - The page timeout, in milliseconds.\n * @returns The new page.\n */\n async createPage(url: string = this.url, timeout = 10000) {\n const puppeteer = (await this.browser.getPuppeteer()) as unknown as Browser;\n const page = await puppeteer.newPage();\n\n page.setDefaultTimeout(timeout);\n page.setDefaultNavigationTimeout(timeout);\n\n // Give the page permission to show notifications. This is required for\n // testing `snap_notify`.\n await page.browserContext().overridePermissions(url, ['notifications']);\n\n // `networkidle0` is used to ensure that the page is fully loaded. This\n // makes it wait for no requests to be made, which guarantees that the page\n // is ready.\n await page.goto(url, { waitUntil: 'networkidle0' });\n\n const browserLog = createModuleLogger(rootLogger, 'browser');\n\n page\n // This is fired when the page calls `console.log` or similar.\n .on('console', (message) => {\n browserLog(`[${message.type()}] ${message.text()}`);\n })\n\n // This is fired when the page throws an error.\n .on('pageerror', ({ message }) => {\n browserLog(`[page error] ${message}`);\n });\n\n return page;\n }\n}\n\nexport default SnapsEnvironment;\n"],"names":["assert","createModuleLogger","NodeEnvironment","remote","rootLogger","startServer","getOptions","log","SnapsEnvironment","setup","options","server","enabled","args","browser","headless","push","logLevel","capabilities","browserName","global","snapsEnvironment","teardown","keepAlive","deleteSession","close","url","port","address","simulatorUrl","executionEnvironmentUrl","encodeURIComponent","snapId","createPage","timeout","puppeteer","getPuppeteer","page","newPage","setDefaultTimeout","setDefaultNavigationTimeout","browserContext","overridePermissions","goto","waitUntil","browserLog","on","message","type","text","constructor","context","projectConfig","testEnvironmentOptions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAASA,MAAM,EAAEC,kBAAkB,QAAQ,kBAAkB;AAE7D,OAAOC,qBAAqB,wBAAwB;AAGpD,SAASC,MAAM,QAAQ,cAAc;AAErC,SAASC,UAAU,EAAEC,WAAW,QAAQ,cAAc;AAEtD,SAASC,UAAU,QAAQ,YAAY;AAOvC,iBAAiB,GAEjB,MAAMC,MAAMN,mBAAmBG,YAAY;IAOzC,wCAEA;AAPF,OAAO,MAAMI,yBAAyBN;IAoBpC;;;GAGC,GACD,MAAMO,QAAQ;QACZ,MAAM,KAAK,CAACA;QAEZ,IAAI,yBAAA,IAAI,EAAEC,UAAQC,MAAM,CAACC,OAAO,EAAE;YAChCL,IAAI;2CACEI,SAAS,MAAMN,YAAY,yBAAA,IAAI,EAAEK,UAAQC,MAAM;QACvD;QAEA,MAAME,OAAO,EAAE;QACf,IAAI,yBAAA,IAAI,EAAEH,UAAQI,OAAO,CAACC,QAAQ,EAAE;YAClCF,KAAKG,IAAI,CAAC,cAAc;QAC1B;QAEAT,IAAI;QACJ,IAAI,CAACO,OAAO,GAAG,MAAMX,OAAO;YAC1Bc,UAAU;YACVC,cAAc;gBACZC,aAAa;gBACb,gEAAgE;gBAChE,sBAAsB;oBACpBN;gBACF;YACF;QACF;QAEA,IAAI,CAACO,MAAM,CAACN,OAAO,GAAG,IAAI,CAACA,OAAO;QAClC,IAAI,CAACM,MAAM,CAACC,gBAAgB,GAAG,IAAI;IACrC;IAEA;;;GAGC,GACD,MAAMC,WAAW;QACf,IAAI,yBAAA,IAAI,EAAEZ,UAAQa,SAAS,EAAE;YAC3BhB,IAAI;YACJ;QACF;QAEAA,IAAI;QACJ,MAAM,IAAI,CAACO,OAAO,EAAEU;iCACpB,IAAI,EAAEb,UAAQc;QAEd,MAAM,KAAK,CAACH;IACd;IAEA;;;;;GAKC,GACD,IAAII,MAAM;QACR1B,gCAAO,IAAI,EAAEW,UAAQ;QAErB,MAAM,EAAEgB,IAAI,EAAE,GAAG,yBAAA,IAAI,EAAEhB,SAAOiB,OAAO;QACrC,MAAMC,eACJ,yBAAA,IAAI,EAAEnB,UAAQmB,YAAY,IAAI,CAAC,iBAAiB,EAAEF,KAAK,WAAW,CAAC;QAErE,MAAMG,0BACJ,yBAAA,IAAI,EAAEpB,UAAQoB,uBAAuB,IACrC,CAAC,iBAAiB,EAAEH,KAAK,aAAa,CAAC;QAEzC,OAAO,CAAC,EAAEE,aAAa,aAAa,EAAEE,mBACpCD,yBACA,CAAC;IACL;IAEA;;;;;;;GAOC,GACD,IAAIE,SAAS;QACXhC,gCACE,IAAI,EAAEW,UACN;QAGF,MAAM,EAAEgB,IAAI,EAAE,GAAG,yBAAA,IAAI,EAAEhB,SAAOiB,OAAO;QACrC,OAAO,CAAC,uBAAuB,EAAED,KAAK,CAAC;IACzC;IAEA;;;;;;;GAOC,GACD,MAAMM,WAAWP,MAAc,IAAI,CAACA,GAAG,EAAEQ,UAAU,KAAK,EAAE;QACxD,MAAMC,YAAa,MAAM,IAAI,CAACrB,OAAO,CAACsB,YAAY;QAClD,MAAMC,OAAO,MAAMF,UAAUG,OAAO;QAEpCD,KAAKE,iBAAiB,CAACL;QACvBG,KAAKG,2BAA2B,CAACN;QAEjC,uEAAuE;QACvE,yBAAyB;QACzB,MAAMG,KAAKI,cAAc,GAAGC,mBAAmB,CAAChB,KAAK;YAAC;SAAgB;QAEtE,uEAAuE;QACvE,2EAA2E;QAC3E,YAAY;QACZ,MAAMW,KAAKM,IAAI,CAACjB,KAAK;YAAEkB,WAAW;QAAe;QAEjD,MAAMC,aAAa5C,mBAAmBG,YAAY;QAElDiC,IACE,8DAA8D;SAC7DS,EAAE,CAAC,WAAW,CAACC;YACdF,WAAW,CAAC,CAAC,EAAEE,QAAQC,IAAI,GAAG,EAAE,EAAED,QAAQE,IAAI,GAAG,CAAC;QACpD,EAEA,+CAA+C;SAC9CH,EAAE,CAAC,aAAa,CAAC,EAAEC,OAAO,EAAE;YAC3BF,WAAW,CAAC,aAAa,EAAEE,QAAQ,CAAC;QACtC;QAEF,OAAOV;IACT;IA3IA;;;;;GAKC,GACDa,YAAYxC,OAA8B,EAAEyC,OAA2B,CAAE;QACvE,KAAK,CAACzC,SAASyC;QAfjB,8EAA8E;QAC9E,qEAAqE;QACrErC,uBAAAA,WAAAA,KAAAA;QAEA,gCAAA;;mBAAA,KAAA;;QAEA,gCAAA;;mBAAA,KAAA;;uCAUQJ,UAAUJ,WAAWI,QAAQ0C,aAAa,CAACC,sBAAsB;IACzE;AAmIF;AAEA,eAAe7C,iBAAiB"}
1
+ {"version":3,"sources":["../../src/environment.ts"],"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"],"names":["assert","createModuleLogger","NodeEnvironment","handleInstallSnap","rootLogger","startServer","getOptions","log","SnapsEnvironment","setup","options","server","enabled","global","snapsEnvironment","teardown","instance","executionService","terminateAllSnaps","close","installSnap","snapId","port","address","constructor","context","projectConfig","testEnvironmentOptions"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMA,SAASA,MAAM,EAAEC,kBAAkB,QAAQ,kBAAkB;AAE7D,OAAOC,qBAAqB,wBAAwB;AAIpD,SAASC,iBAAiB,EAAEC,UAAU,EAAEC,WAAW,QAAQ,cAAc;AAEzE,SAASC,UAAU,QAAQ,YAAY;AAMvC,iBAAiB,GAEjB,MAAMC,MAAMN,mBAAmBG,YAAY;IAGzC,wCAEA,uCAEA;AALF,OAAO,MAAMI,yBAAyBN;IAkBpC;;;GAGC,GACD,MAAMO,QAAQ;QACZ,MAAM,KAAK,CAACA;QAEZ,IAAI,yBAAA,IAAI,EAAEC,UAAQC,MAAM,CAACC,OAAO,EAAE;YAChCL,IAAI;2CACEI,SAAS,MAAMN,YAAY,yBAAA,IAAI,EAAEK,UAAQC,MAAM;QACvD;QAEA,IAAI,CAACE,MAAM,CAACC,gBAAgB,GAAG,IAAI;IACrC;IAEA;;;GAGC,GACD,MAAMC,WAAW;QACf,+BAAM,IAAI,EAAEC,YAAUC,iBAAiBC;iCACvC,IAAI,EAAEP,UAAQQ;QACd,MAAM,KAAK,CAACJ;IACd;IAEA;;;;;;;;;;;;;GAaC,GACD,MAAMK,YAKJC,SAAiB,IAAI,CAACA,MAAM,EAC5BX,UAAgD,CAAC,CAAC,EAClD;QACA,+BAAM,IAAI,EAAEM,YAAUC,iBAAiBC;uCACjCF,WAAW,MAAMb,kBAAkBkB,QAAkBX;QAC3D,gCAAO,IAAI,EAAEM;IACf;IAEA;;;;;;;GAOC,GACD,IAAIK,SAAS;QACXrB,gCACE,IAAI,EAAEW,UACN;QAGF,MAAM,EAAEW,IAAI,EAAE,GAAG,yBAAA,IAAI,EAAEX,SAAOY,OAAO;QACrC,OAAO,CAAC,uBAAuB,EAAED,KAAK,CAAC;IACzC;IA/EA;;;;;GAKC,GACDE,YAAYd,OAA8B,EAAEe,OAA2B,CAAE;QACvE,KAAK,CAACf,SAASe;QAbjB,gCAAA;;mBAAA,KAAA;;QAEA,gCAAA;;mBAAA,KAAA;;QAEA,gCAAA;;mBAAA,KAAA;;uCAUQf,UAAUJ,WAAWI,QAAQgB,aAAa,CAACC,sBAAsB;IACzE;AAuEF;AAEA,eAAenB,iBAAiB"}
@@ -1,16 +1,33 @@
1
+ import { HandlerType, logInfo } from '@metamask/snaps-utils';
1
2
  import { createModuleLogger } from '@metamask/utils';
2
- import { getDocument, queries } from 'pptr-testing-library';
3
- import { getEnvironment, mock, waitFor, request, sendTransaction, runCronjob, mockJsonRpc, rootLogger } from './internals';
4
- // eslint-disable-next-line @typescript-eslint/unbound-method
5
- const { getByTestId } = queries;
3
+ import { create } from 'superstruct';
4
+ import { rootLogger, handleRequest, TransactionOptionsStruct, getEnvironment, JsonRpcMockOptionsStruct, SignatureOptionsStruct } from './internals';
5
+ import { addJsonRpcMock, removeJsonRpcMock } from './internals/simulation/store/mocks';
6
6
  const log = createModuleLogger(rootLogger, 'helpers');
7
+ /**
8
+ * Get the options for {@link installSnap}.
9
+ *
10
+ * @param snapId - The ID of the Snap, or the options.
11
+ * @param options - The options, if any.
12
+ * @returns The options.
13
+ */ function getOptions(snapId, options) {
14
+ if (typeof snapId === 'object') {
15
+ return [
16
+ undefined,
17
+ snapId
18
+ ];
19
+ }
20
+ return [
21
+ snapId,
22
+ options
23
+ ];
24
+ }
7
25
  /**
8
26
  * Load a snap into the environment. This is the main entry point for testing
9
27
  * snaps: It returns a {@link Snap} object that can be used to interact with the
10
28
  * snap.
11
29
  *
12
30
  * @example
13
- * ```ts
14
31
  * import { installSnap } from '@metamask/snaps-jest';
15
32
  *
16
33
  * describe('My Snap', () => {
@@ -23,58 +40,122 @@ const log = createModuleLogger(rootLogger, 'helpers');
23
40
  * expect(response).toRespondWith('bar');
24
41
  * });
25
42
  * });
26
- * ```
27
43
  * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults
28
44
  * to the URL of the built-in server, if it is running. This supports both
29
45
  * local snap IDs and NPM snap IDs.
46
+ * @param options - The options to use.
47
+ * @param options.executionService - The execution service to use. Defaults to
48
+ * {@link NodeThreadExecutionService}. You do not need to provide this unless
49
+ * you are testing a custom execution service.
50
+ * @param options.executionServiceOptions - The options to use when creating the
51
+ * execution service, if any. This should only include options specific to the
52
+ * provided execution service.
53
+ * @param options.options - The simulation options.
30
54
  * @returns The snap.
31
55
  * @throws If the built-in server is not running, and no snap ID is provided.
32
- */ export async function installSnap(snapId = getEnvironment().snapId) {
33
- const environment = getEnvironment();
34
- log('Installing snap %s.', snapId);
35
- const page = await environment.createPage();
36
- const document = await getDocument(page);
37
- log('Setting snap ID to %s.', snapId);
38
- await page.evaluate((payload)=>{
39
- window.__SIMULATOR_API__.dispatch({
40
- type: 'configuration/setSnapId',
41
- payload
56
+ */ export async function installSnap(snapId, options = {}) {
57
+ const resolvedOptions = getOptions(snapId, options);
58
+ const { snapId: installedSnapId, store, executionService, runSaga, controllerMessenger } = await getEnvironment().installSnap(...resolvedOptions);
59
+ const onTransaction = async (request)=>{
60
+ log('Sending transaction %o.', request);
61
+ const { origin: transactionOrigin, chainId, ...transaction } = create(request, TransactionOptionsStruct);
62
+ return handleRequest({
63
+ snapId: installedSnapId,
64
+ store,
65
+ executionService,
66
+ runSaga,
67
+ controllerMessenger,
68
+ handler: HandlerType.OnTransaction,
69
+ request: {
70
+ method: '',
71
+ params: {
72
+ chainId,
73
+ transaction,
74
+ transactionOrigin
75
+ }
76
+ }
77
+ });
78
+ };
79
+ const onCronjob = (request)=>{
80
+ log('Running cronjob %o.', options);
81
+ return handleRequest({
82
+ snapId: installedSnapId,
83
+ store,
84
+ executionService,
85
+ controllerMessenger,
86
+ runSaga,
87
+ handler: HandlerType.OnCronjob,
88
+ request
42
89
  });
43
- }, snapId);
44
- log('Waiting for snap to install.');
45
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
46
- await waitFor(async ()=>await getByTestId(document, 'status-ok'), {
47
- timeout: 10000,
48
- message: `Timed out waiting for snap to install. Make sure the snap ID ("${snapId}") is correct, and the server is running.`
49
- });
90
+ };
50
91
  return {
51
- request: (options)=>{
52
- log('Sending request %o.', options);
53
- // Note: This function is intentionally not async, so that we can access
54
- // the `getInterface` method on the response.
55
- return request(page, options);
56
- },
57
- sendTransaction: async (options = {})=>{
58
- log('Sending transaction %o.', options);
59
- return await sendTransaction(page, options);
92
+ request: (request)=>{
93
+ log('Sending request %o.', request);
94
+ return handleRequest({
95
+ snapId: installedSnapId,
96
+ store,
97
+ executionService,
98
+ controllerMessenger,
99
+ runSaga,
100
+ handler: HandlerType.OnRpcRequest,
101
+ request
102
+ });
60
103
  },
61
- runCronjob: (options)=>{
62
- log('Running cronjob %o.', options);
63
- // Note: This function is intentionally not async, so that we can access
64
- // the `getInterface` method on the response.
65
- return runCronjob(page, options);
104
+ onTransaction,
105
+ sendTransaction: onTransaction,
106
+ onSignature: async (request)=>{
107
+ log('Requesting signature %o.', request);
108
+ const { origin: signatureOrigin, ...signature } = create(request, SignatureOptionsStruct);
109
+ return handleRequest({
110
+ snapId: installedSnapId,
111
+ store,
112
+ executionService,
113
+ controllerMessenger,
114
+ runSaga,
115
+ handler: HandlerType.OnSignature,
116
+ request: {
117
+ method: '',
118
+ params: {
119
+ signature,
120
+ signatureOrigin
121
+ }
122
+ }
123
+ });
66
124
  },
67
- close: async ()=>{
68
- log('Closing page.');
69
- await page.close();
125
+ onCronjob,
126
+ runCronjob: onCronjob,
127
+ onHomePage: async ()=>{
128
+ log('Rendering home page.');
129
+ return handleRequest({
130
+ snapId: installedSnapId,
131
+ store,
132
+ executionService,
133
+ controllerMessenger,
134
+ runSaga,
135
+ handler: HandlerType.OnHomePage,
136
+ request: {
137
+ method: ''
138
+ }
139
+ });
70
140
  },
71
- mock: async (options)=>{
72
- log('Mocking %o.', options);
73
- return await mock(page, options);
141
+ mockJsonRpc (mock) {
142
+ log('Mocking JSON-RPC request %o.', mock);
143
+ const { method, result } = create(mock, JsonRpcMockOptionsStruct);
144
+ store.dispatch(addJsonRpcMock({
145
+ method,
146
+ result
147
+ }));
148
+ return {
149
+ unmock () {
150
+ log('Unmocking JSON-RPC request %o.', mock);
151
+ store.dispatch(removeJsonRpcMock(method));
152
+ }
153
+ };
74
154
  },
75
- mockJsonRpc: async (options)=>{
76
- log('Mocking JSON-RPC %o.', options);
77
- return await mockJsonRpc(page, options);
155
+ close: async ()=>{
156
+ log('Closing execution service.');
157
+ logInfo('Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.');
158
+ await executionService.terminateAllSnaps();
78
159
  }
79
160
  };
80
161
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/helpers.ts"],"sourcesContent":["import { createModuleLogger } from '@metamask/utils';\nimport { getDocument, queries } from 'pptr-testing-library';\n\nimport {\n getEnvironment,\n mock,\n waitFor,\n request,\n sendTransaction,\n runCronjob,\n mockJsonRpc,\n rootLogger,\n} from './internals';\nimport type { Snap, SnapResponse } from './types';\n\n// eslint-disable-next-line @typescript-eslint/unbound-method\nconst { getByTestId } = queries;\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * ```ts\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * ```\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(\n snapId: string = getEnvironment().snapId,\n): Promise<Snap> {\n const environment = getEnvironment();\n\n log('Installing snap %s.', snapId);\n\n const page = await environment.createPage();\n const document = await getDocument(page);\n\n log('Setting snap ID to %s.', snapId);\n await page.evaluate((payload) => {\n window.__SIMULATOR_API__.dispatch({\n type: 'configuration/setSnapId',\n payload,\n });\n }, snapId);\n\n log('Waiting for snap to install.');\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n await waitFor(async () => await getByTestId(document, 'status-ok'), {\n timeout: 10000,\n message: `Timed out waiting for snap to install. Make sure the snap ID (\"${snapId}\") is correct, and the server is running.`,\n });\n\n return {\n request: (options) => {\n log('Sending request %o.', options);\n\n // Note: This function is intentionally not async, so that we can access\n // the `getInterface` method on the response.\n return request(page, options);\n },\n\n sendTransaction: async (options = {}): Promise<SnapResponse> => {\n log('Sending transaction %o.', options);\n\n return await sendTransaction(page, options);\n },\n\n runCronjob: (options) => {\n log('Running cronjob %o.', options);\n\n // Note: This function is intentionally not async, so that we can access\n // the `getInterface` method on the response.\n return runCronjob(page, options);\n },\n\n close: async () => {\n log('Closing page.');\n\n await page.close();\n },\n\n mock: async (options) => {\n log('Mocking %o.', options);\n\n return await mock(page, options);\n },\n\n mockJsonRpc: async (options) => {\n log('Mocking JSON-RPC %o.', options);\n\n return await mockJsonRpc(page, options);\n },\n };\n}\n"],"names":["createModuleLogger","getDocument","queries","getEnvironment","mock","waitFor","request","sendTransaction","runCronjob","mockJsonRpc","rootLogger","getByTestId","log","installSnap","snapId","environment","page","createPage","document","evaluate","payload","window","__SIMULATOR_API__","dispatch","type","timeout","message","options","close"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,kBAAkB;AACrD,SAASC,WAAW,EAAEC,OAAO,QAAQ,uBAAuB;AAE5D,SACEC,cAAc,EACdC,IAAI,EACJC,OAAO,EACPC,OAAO,EACPC,eAAe,EACfC,UAAU,EACVC,WAAW,EACXC,UAAU,QACL,cAAc;AAGrB,6DAA6D;AAC7D,MAAM,EAAEC,WAAW,EAAE,GAAGT;AAExB,MAAMU,MAAMZ,mBAAmBU,YAAY;AAE3C;;;;;;;;;;;;;;;;;;;;;;;;;CAyBC,GACD,OAAO,eAAeG,YACpBC,SAAiBX,iBAAiBW,MAAM;IAExC,MAAMC,cAAcZ;IAEpBS,IAAI,uBAAuBE;IAE3B,MAAME,OAAO,MAAMD,YAAYE,UAAU;IACzC,MAAMC,WAAW,MAAMjB,YAAYe;IAEnCJ,IAAI,0BAA0BE;IAC9B,MAAME,KAAKG,QAAQ,CAAC,CAACC;QACnBC,OAAOC,iBAAiB,CAACC,QAAQ,CAAC;YAChCC,MAAM;YACNJ;QACF;IACF,GAAGN;IAEHF,IAAI;IACJ,kEAAkE;IAClE,MAAMP,QAAQ,UAAY,MAAMM,YAAYO,UAAU,cAAc;QAClEO,SAAS;QACTC,SAAS,CAAC,+DAA+D,EAAEZ,OAAO,yCAAyC,CAAC;IAC9H;IAEA,OAAO;QACLR,SAAS,CAACqB;YACRf,IAAI,uBAAuBe;YAE3B,wEAAwE;YACxE,6CAA6C;YAC7C,OAAOrB,QAAQU,MAAMW;QACvB;QAEApB,iBAAiB,OAAOoB,UAAU,CAAC,CAAC;YAClCf,IAAI,2BAA2Be;YAE/B,OAAO,MAAMpB,gBAAgBS,MAAMW;QACrC;QAEAnB,YAAY,CAACmB;YACXf,IAAI,uBAAuBe;YAE3B,wEAAwE;YACxE,6CAA6C;YAC7C,OAAOnB,WAAWQ,MAAMW;QAC1B;QAEAC,OAAO;YACLhB,IAAI;YAEJ,MAAMI,KAAKY,KAAK;QAClB;QAEAxB,MAAM,OAAOuB;YACXf,IAAI,eAAee;YAEnB,OAAO,MAAMvB,KAAKY,MAAMW;QAC1B;QAEAlB,aAAa,OAAOkB;YAClBf,IAAI,wBAAwBe;YAE5B,OAAO,MAAMlB,YAAYO,MAAMW;QACjC;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/helpers.ts"],"sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType, logInfo } from '@metamask/snaps-utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { create } from 'superstruct';\n\nimport {\n rootLogger,\n handleRequest,\n TransactionOptionsStruct,\n getEnvironment,\n JsonRpcMockOptionsStruct,\n SignatureOptionsStruct,\n} from './internals';\nimport type { InstallSnapOptions } from './internals';\nimport {\n addJsonRpcMock,\n removeJsonRpcMock,\n} from './internals/simulation/store/mocks';\nimport type {\n CronjobOptions,\n JsonRpcMockOptions,\n Snap,\n SnapResponse,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n const {\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n } = await getEnvironment().installSnap(...resolvedOptions);\n\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponse> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n };\n\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n return {\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onSignature: async (request: unknown): Promise<SnapResponse> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n },\n\n onCronjob,\n runCronjob: onCronjob,\n\n onHomePage: async (): Promise<SnapResponse> => {\n log('Rendering home page.');\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await executionService.terminateAllSnaps();\n },\n };\n}\n"],"names":["HandlerType","logInfo","createModuleLogger","create","rootLogger","handleRequest","TransactionOptionsStruct","getEnvironment","JsonRpcMockOptionsStruct","SignatureOptionsStruct","addJsonRpcMock","removeJsonRpcMock","log","getOptions","snapId","options","undefined","installSnap","resolvedOptions","installedSnapId","store","executionService","runSaga","controllerMessenger","onTransaction","request","origin","transactionOrigin","chainId","transaction","handler","OnTransaction","method","params","onCronjob","OnCronjob","OnRpcRequest","sendTransaction","onSignature","signatureOrigin","signature","OnSignature","runCronjob","onHomePage","OnHomePage","mockJsonRpc","mock","result","dispatch","unmock","close","terminateAllSnaps"],"mappings":"AAEA,SAASA,WAAW,EAAEC,OAAO,QAAQ,wBAAwB;AAC7D,SAASC,kBAAkB,QAAQ,kBAAkB;AACrD,SAASC,MAAM,QAAQ,cAAc;AAErC,SACEC,UAAU,EACVC,aAAa,EACbC,wBAAwB,EACxBC,cAAc,EACdC,wBAAwB,EACxBC,sBAAsB,QACjB,cAAc;AAErB,SACEC,cAAc,EACdC,iBAAiB,QACZ,qCAAqC;AAS5C,MAAMC,MAAMV,mBAAmBE,YAAY;AAE3C;;;;;;CAMC,GACD,SAASS,WAKPC,MAAiE,EACjEC,OAA6C;IAE7C,IAAI,OAAOD,WAAW,UAAU;QAC9B,OAAO;YAACE;YAAWF;SAAO;IAC5B;IAEA,OAAO;QAACA;QAAQC;KAAQ;AAC1B;AAqGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+BC,GACD,OAAO,eAAeE,YAKpBH,MAAsD,EACtDC,UAAgD,CAAC,CAAC;IAElD,MAAMG,kBAAkBL,WAAWC,QAAQC;IAC3C,MAAM,EACJD,QAAQK,eAAe,EACvBC,KAAK,EACLC,gBAAgB,EAChBC,OAAO,EACPC,mBAAmB,EACpB,GAAG,MAAMhB,iBAAiBU,WAAW,IAAIC;IAE1C,MAAMM,gBAAgB,OACpBC;QAEAb,IAAI,2BAA2Ba;QAE/B,MAAM,EACJC,QAAQC,iBAAiB,EACzBC,OAAO,EACP,GAAGC,aACJ,GAAG1B,OAAOsB,SAASnB;QAEpB,OAAOD,cAAc;YACnBS,QAAQK;YACRC;YACAC;YACAC;YACAC;YACAO,SAAS9B,YAAY+B,aAAa;YAClCN,SAAS;gBACPO,QAAQ;gBACRC,QAAQ;oBACNL;oBACAC;oBACAF;gBACF;YACF;QACF;IACF;IAEA,MAAMO,YAAY,CAACT;QACjBb,IAAI,uBAAuBG;QAE3B,OAAOV,cAAc;YACnBS,QAAQK;YACRC;YACAC;YACAE;YACAD;YACAQ,SAAS9B,YAAYmC,SAAS;YAC9BV;QACF;IACF;IAEA,OAAO;QACLA,SAAS,CAACA;YACRb,IAAI,uBAAuBa;YAE3B,OAAOpB,cAAc;gBACnBS,QAAQK;gBACRC;gBACAC;gBACAE;gBACAD;gBACAQ,SAAS9B,YAAYoC,YAAY;gBACjCX;YACF;QACF;QAEAD;QACAa,iBAAiBb;QAEjBc,aAAa,OAAOb;YAClBb,IAAI,4BAA4Ba;YAEhC,MAAM,EAAEC,QAAQa,eAAe,EAAE,GAAGC,WAAW,GAAGrC,OAChDsB,SACAhB;YAGF,OAAOJ,cAAc;gBACnBS,QAAQK;gBACRC;gBACAC;gBACAE;gBACAD;gBACAQ,SAAS9B,YAAYyC,WAAW;gBAChChB,SAAS;oBACPO,QAAQ;oBACRC,QAAQ;wBACNO;wBACAD;oBACF;gBACF;YACF;QACF;QAEAL;QACAQ,YAAYR;QAEZS,YAAY;YACV/B,IAAI;YAEJ,OAAOP,cAAc;gBACnBS,QAAQK;gBACRC;gBACAC;gBACAE;gBACAD;gBACAQ,SAAS9B,YAAY4C,UAAU;gBAC/BnB,SAAS;oBACPO,QAAQ;gBACV;YACF;QACF;QAEAa,aAAYC,IAAwB;YAClClC,IAAI,gCAAgCkC;YAEpC,MAAM,EAAEd,MAAM,EAAEe,MAAM,EAAE,GAAG5C,OAAO2C,MAAMtC;YACxCY,MAAM4B,QAAQ,CAACtC,eAAe;gBAAEsB;gBAAQe;YAAO;YAE/C,OAAO;gBACLE;oBACErC,IAAI,kCAAkCkC;oBAEtC1B,MAAM4B,QAAQ,CAACrC,kBAAkBqB;gBACnC;YACF;QACF;QAEAkB,OAAO;YACLtC,IAAI;YACJX,QACE;YAGF,MAAMoB,iBAAiB8B,iBAAiB;QAC1C;IACF;AACF"}
@@ -7,7 +7,7 @@ import { assert } from '@metamask/utils';
7
7
  */ export function getEnvironment() {
8
8
  // `snapsEnvironment` is a global variable that is set by the Jest
9
9
  // environment.
10
- assert(snapsEnvironment, 'Snaps environment not found. Make sure you have configured the environment correctly.');
10
+ assert(typeof snapsEnvironment !== 'undefined', 'Snaps environment not found. Make sure you have configured the environment correctly.');
11
11
  return snapsEnvironment;
12
12
  }
13
13
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/environment.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\n\n/**\n * Get the Snaps environment. This asserts that the environment has been\n * configured.\n *\n * @returns The Snaps environment.\n */\nexport function getEnvironment() {\n // `snapsEnvironment` is a global variable that is set by the Jest\n // environment.\n assert(\n snapsEnvironment,\n 'Snaps environment not found. Make sure you have configured the environment correctly.',\n );\n\n return snapsEnvironment;\n}\n"],"names":["assert","getEnvironment","snapsEnvironment"],"mappings":"AAAA,SAASA,MAAM,QAAQ,kBAAkB;AAEzC;;;;;CAKC,GACD,OAAO,SAASC;IACd,kEAAkE;IAClE,eAAe;IACfD,OACEE,kBACA;IAGF,OAAOA;AACT"}
1
+ {"version":3,"sources":["../../../src/internals/environment.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\n\n/**\n * Get the Snaps environment. This asserts that the environment has been\n * configured.\n *\n * @returns The Snaps environment.\n */\nexport function getEnvironment() {\n // `snapsEnvironment` is a global variable that is set by the Jest\n // environment.\n assert(\n typeof snapsEnvironment !== 'undefined',\n 'Snaps environment not found. Make sure you have configured the environment correctly.',\n );\n\n return snapsEnvironment;\n}\n"],"names":["assert","getEnvironment","snapsEnvironment"],"mappings":"AAAA,SAASA,MAAM,QAAQ,kBAAkB;AAEzC;;;;;CAKC,GACD,OAAO,SAASC;IACd,kEAAkE;IAClE,eAAe;IACfD,OACE,OAAOE,qBAAqB,aAC5B;IAGF,OAAOA;AACT"}
@@ -1,12 +1,8 @@
1
1
  export * from './environment';
2
- export * from './interface';
3
2
  export * from './logger';
4
- export * from './network';
5
3
  export * from './request';
6
4
  export * from './server';
5
+ export * from './simulation';
7
6
  export * from './structs';
8
- // eslint-disable-next-line import/export
9
- export * from './types';
10
- export * from './wait-for';
11
7
 
12
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './environment';\nexport * from './interface';\nexport * from './logger';\nexport * from './network';\nexport * from './request';\nexport * from './server';\nexport * from './structs';\n// eslint-disable-next-line import/export\nexport * from './types';\nexport * from './wait-for';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,cAAc;AAC5B,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,YAAY;AAC1B,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,yCAAyC;AACzC,cAAc,UAAU;AACxB,cAAc,aAAa"}
1
+ {"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './environment';\nexport * from './logger';\nexport * from './request';\nexport * from './server';\nexport * from './simulation';\nexport * from './structs';\n"],"names":[],"mappings":"AAAA,cAAc,gBAAgB;AAC9B,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,WAAW;AACzB,cAAc,eAAe;AAC7B,cAAc,YAAY"}