@metamask/snaps-jest 7.0.2 → 8.1.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 (92) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/dist/{chunk-7L5S3PID.js → chunk-2OHD2VKS.js} +72 -20
  3. package/dist/chunk-2OHD2VKS.js.map +1 -0
  4. package/dist/{chunk-LMCG5RIX.js → chunk-3FDEYMQU.js} +12 -12
  5. package/dist/{chunk-DTDYOBCI.js → chunk-44ARQBXS.js} +3 -3
  6. package/dist/{chunk-BVGI3E45.mjs → chunk-6V5GEUDO.mjs} +84 -7
  7. package/dist/chunk-6V5GEUDO.mjs.map +1 -0
  8. package/dist/{chunk-QPC6UJH7.mjs → chunk-AFA4KKWW.mjs} +134 -41
  9. package/dist/chunk-AFA4KKWW.mjs.map +1 -0
  10. package/dist/{chunk-VSUNWJMQ.mjs → chunk-E2BYTLOT.mjs} +3 -3
  11. package/dist/{chunk-MCYTJUDG.js → chunk-EDFQDZNY.js} +6 -6
  12. package/dist/{chunk-WH5C5WIZ.mjs → chunk-FQWOVTBB.mjs} +4 -3
  13. package/dist/chunk-FQWOVTBB.mjs.map +1 -0
  14. package/dist/{chunk-LG3VKXGH.mjs → chunk-GG2BCPQH.mjs} +2 -2
  15. package/dist/{chunk-YEVKBYKO.mjs → chunk-HOI6FPLR.mjs} +4 -7
  16. package/dist/chunk-HOI6FPLR.mjs.map +1 -0
  17. package/dist/{chunk-MJHR5RTY.js → chunk-J3I5KZIF.js} +4 -3
  18. package/dist/chunk-J3I5KZIF.js.map +1 -0
  19. package/dist/{chunk-2JAGD4N6.js → chunk-JXAJWUVZ.js} +3 -3
  20. package/dist/{chunk-X5IPMTHO.mjs → chunk-K55LIE3W.mjs} +2 -2
  21. package/dist/{chunk-FIZAYEHV.js → chunk-KQBJQLZG.js} +87 -10
  22. package/dist/chunk-KQBJQLZG.js.map +1 -0
  23. package/dist/{chunk-ZWN4SO2V.js → chunk-MBQHVBLA.js} +4 -4
  24. package/dist/{chunk-KR7CYXCR.js → chunk-R55KAAM4.js} +130 -37
  25. package/dist/chunk-R55KAAM4.js.map +1 -0
  26. package/dist/{chunk-TAIJXTLU.mjs → chunk-TMAWGVZP.mjs} +2 -2
  27. package/dist/{chunk-3OEADJAL.mjs → chunk-U3DVRTS2.mjs} +3 -3
  28. package/dist/{chunk-ZJVA3AOC.mjs → chunk-UPR3PTSA.mjs} +70 -18
  29. package/dist/chunk-UPR3PTSA.mjs.map +1 -0
  30. package/dist/{chunk-IDGD7TZ7.js → chunk-YNUVT3HC.js} +3 -6
  31. package/dist/chunk-YNUVT3HC.js.map +1 -0
  32. package/dist/environment.js +9 -9
  33. package/dist/environment.mjs +8 -8
  34. package/dist/helpers.js +9 -9
  35. package/dist/helpers.mjs +8 -8
  36. package/dist/index.js +10 -10
  37. package/dist/index.mjs +9 -9
  38. package/dist/internals/index.js +10 -8
  39. package/dist/internals/index.mjs +9 -7
  40. package/dist/internals/request.js +8 -7
  41. package/dist/internals/request.mjs +7 -6
  42. package/dist/internals/simulation/controllers.js +4 -4
  43. package/dist/internals/simulation/controllers.mjs +3 -3
  44. package/dist/internals/simulation/index.js +8 -6
  45. package/dist/internals/simulation/index.mjs +7 -5
  46. package/dist/internals/simulation/interface.js +4 -2
  47. package/dist/internals/simulation/interface.mjs +3 -1
  48. package/dist/internals/simulation/methods/hooks/index.js +2 -2
  49. package/dist/internals/simulation/methods/hooks/index.mjs +1 -1
  50. package/dist/internals/simulation/methods/hooks/interface.js +2 -2
  51. package/dist/internals/simulation/methods/hooks/interface.mjs +1 -1
  52. package/dist/internals/simulation/methods/index.js +3 -3
  53. package/dist/internals/simulation/methods/index.mjs +2 -2
  54. package/dist/internals/simulation/methods/specifications.js +3 -3
  55. package/dist/internals/simulation/methods/specifications.mjs +2 -2
  56. package/dist/internals/simulation/simulation.js +5 -5
  57. package/dist/internals/simulation/simulation.mjs +4 -4
  58. package/dist/internals/structs.js +2 -2
  59. package/dist/internals/structs.mjs +1 -1
  60. package/dist/matchers.js +11 -9
  61. package/dist/matchers.mjs +10 -8
  62. package/dist/setup.js +8 -8
  63. package/dist/setup.mjs +8 -8
  64. package/dist/tsconfig.build.tsbuildinfo +1 -1
  65. package/dist/types/global.d.ts +2 -2
  66. package/dist/types/internals/request.d.ts +1 -1
  67. package/dist/types/internals/simulation/interface.d.ts +29 -8
  68. package/dist/types/internals/simulation/methods/hooks/interface.d.ts +2 -2
  69. package/dist/types/internals/structs.d.ts +16 -152
  70. package/dist/types/matchers.d.ts +12 -2
  71. package/dist/types/types.d.ts +13 -5
  72. package/package.json +10 -10
  73. package/dist/chunk-7L5S3PID.js.map +0 -1
  74. package/dist/chunk-BVGI3E45.mjs.map +0 -1
  75. package/dist/chunk-FIZAYEHV.js.map +0 -1
  76. package/dist/chunk-IDGD7TZ7.js.map +0 -1
  77. package/dist/chunk-KR7CYXCR.js.map +0 -1
  78. package/dist/chunk-MJHR5RTY.js.map +0 -1
  79. package/dist/chunk-QPC6UJH7.mjs.map +0 -1
  80. package/dist/chunk-WH5C5WIZ.mjs.map +0 -1
  81. package/dist/chunk-YEVKBYKO.mjs.map +0 -1
  82. package/dist/chunk-ZJVA3AOC.mjs.map +0 -1
  83. /package/dist/{chunk-LMCG5RIX.js.map → chunk-3FDEYMQU.js.map} +0 -0
  84. /package/dist/{chunk-DTDYOBCI.js.map → chunk-44ARQBXS.js.map} +0 -0
  85. /package/dist/{chunk-VSUNWJMQ.mjs.map → chunk-E2BYTLOT.mjs.map} +0 -0
  86. /package/dist/{chunk-MCYTJUDG.js.map → chunk-EDFQDZNY.js.map} +0 -0
  87. /package/dist/{chunk-LG3VKXGH.mjs.map → chunk-GG2BCPQH.mjs.map} +0 -0
  88. /package/dist/{chunk-2JAGD4N6.js.map → chunk-JXAJWUVZ.js.map} +0 -0
  89. /package/dist/{chunk-X5IPMTHO.mjs.map → chunk-K55LIE3W.mjs.map} +0 -0
  90. /package/dist/{chunk-ZWN4SO2V.js.map → chunk-MBQHVBLA.js.map} +0 -0
  91. /package/dist/{chunk-TAIJXTLU.mjs.map → chunk-TMAWGVZP.mjs.map} +0 -0
  92. /package/dist/{chunk-3OEADJAL.mjs.map → chunk-U3DVRTS2.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [8.1.0]
10
+ ### Added
11
+ - Add `selectInDropdown` to be used with the newly added `Dropdown` component ([#2420](https://github.com/MetaMask/snaps/pull/2420))
12
+ - Add `context` field to `snap_createInterface` ([#2413](https://github.com/MetaMask/snaps/pull/2413))
13
+
14
+ ### Fixed
15
+ - Properly handle invalid interfaces during test ([#2433](https://github.com/MetaMask/snaps/pull/2433))
16
+ - Properly diff when using legacy UI with `toRender` matcher ([#2432](https://github.com/MetaMask/snaps/pull/2432))
17
+
18
+ ## [8.0.0]
19
+ ### Added
20
+ - **BREAKING:** Add JSX support for custom UI ([#2258](https://github.com/MetaMask/snaps/pull/2258))
21
+ - It's now possible to use JSX components from `@metamask/snaps-sdk` to build
22
+ user interfaces for Snaps.
23
+ - This is a breaking change, because the legacy user interfaces are converted
24
+ to the new JSX format.
25
+ - If you are checking the format of a interface without `toRender`, you will
26
+ need to update your tests to check the JSX format.
27
+
28
+ ### Changed
29
+ - Bump `@metamask/base-controller` from `5.0.1` to `5.0.2` ([#2375](https://github.com/MetaMask/snaps/pull/2375))
30
+
9
31
  ## [7.0.2]
10
32
  ### Changed
11
33
  - Bump `@metamask/snaps-execution-environments` to latest ([#2339](https://github.com/MetaMask/snaps/pull/2339))
@@ -131,7 +153,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
131
153
  - The version of the package no longer needs to match the version of all other
132
154
  MetaMask Snaps packages.
133
155
 
134
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@7.0.2...HEAD
156
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.1.0...HEAD
157
+ [8.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.0.0...@metamask/snaps-jest@8.1.0
158
+ [8.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@7.0.2...@metamask/snaps-jest@8.0.0
135
159
  [7.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@7.0.1...@metamask/snaps-jest@7.0.2
136
160
  [7.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@7.0.0...@metamask/snaps-jest@7.0.1
137
161
  [7.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@6.0.2...@metamask/snaps-jest@7.0.0
@@ -2,16 +2,29 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkKR7CYXCRjs = require('./chunk-KR7CYXCR.js');
5
+
6
+ var _chunkR55KAAM4js = require('./chunk-R55KAAM4.js');
7
+
8
+
9
+ var _chunkYNUVT3HCjs = require('./chunk-YNUVT3HC.js');
6
10
 
7
11
 
8
12
 
9
13
  var _chunk2YE2P5BZjs = require('./chunk-2YE2P5BZ.js');
10
14
 
11
15
  // src/internals/request.ts
16
+
17
+
18
+ var _snapssdk = require('@metamask/snaps-sdk');
12
19
  var _snapsutils = require('@metamask/snaps-utils');
20
+
21
+
22
+
23
+
24
+
13
25
  var _utils = require('@metamask/utils');
14
26
  var _toolkit = require('@reduxjs/toolkit');
27
+ var _superstruct = require('superstruct');
15
28
  function handleRequest({
16
29
  snapId,
17
30
  store,
@@ -21,6 +34,11 @@ function handleRequest({
21
34
  runSaga,
22
35
  request: { id = _toolkit.nanoid.call(void 0, ), origin = "https://metamask.io", ...options }
23
36
  }) {
37
+ const getInterfaceError = () => {
38
+ throw new Error(
39
+ "Unable to get the interface from the Snap: The request to the Snap failed."
40
+ );
41
+ };
24
42
  const promise = executionService.handleRpcRequest(snapId, {
25
43
  origin,
26
44
  handler,
@@ -32,19 +50,31 @@ function handleRequest({
32
50
  }).then(async (result) => {
33
51
  const notifications = _chunk2YE2P5BZjs.getNotifications.call(void 0, store.getState());
34
52
  store.dispatch(_chunk2YE2P5BZjs.clearNotifications.call(void 0, ));
35
- const getInterfaceFn = await getInterfaceApi(
36
- result,
37
- snapId,
38
- controllerMessenger
39
- );
40
- return {
41
- id: String(id),
42
- response: {
43
- result: _utils.getSafeJson.call(void 0, result)
44
- },
45
- notifications,
46
- ...getInterfaceFn ? { getInterface: getInterfaceFn } : {}
47
- };
53
+ try {
54
+ const getInterfaceFn = await getInterfaceApi(
55
+ result,
56
+ snapId,
57
+ controllerMessenger
58
+ );
59
+ return {
60
+ id: String(id),
61
+ response: {
62
+ result: _utils.getSafeJson.call(void 0, result)
63
+ },
64
+ notifications,
65
+ ...getInterfaceFn ? { getInterface: getInterfaceFn } : {}
66
+ };
67
+ } catch (error) {
68
+ const [unwrappedError] = _snapsutils.unwrapError.call(void 0, error);
69
+ return {
70
+ id: String(id),
71
+ response: {
72
+ error: unwrappedError.serialize()
73
+ },
74
+ notifications: [],
75
+ getInterface: getInterfaceError
76
+ };
77
+ }
48
78
  }).catch((error) => {
49
79
  const [unwrappedError] = _snapsutils.unwrapError.call(void 0, error);
50
80
  return {
@@ -52,16 +82,24 @@ function handleRequest({
52
82
  response: {
53
83
  error: unwrappedError.serialize()
54
84
  },
55
- notifications: []
85
+ notifications: [],
86
+ getInterface: getInterfaceError
56
87
  };
57
88
  });
58
89
  promise.getInterface = async () => {
59
- return await runSaga(
60
- _chunkKR7CYXCRjs.getInterface,
90
+ const sagaPromise = runSaga(
91
+ _chunkR55KAAM4js.getInterface,
61
92
  runSaga,
62
93
  snapId,
63
94
  controllerMessenger
64
95
  ).toPromise();
96
+ const result = await Promise.race([promise, sagaPromise]);
97
+ if (_superstruct.is.call(void 0, result, _chunkYNUVT3HCjs.SnapResponseStruct) && _utils.hasProperty.call(void 0, result.response, "error")) {
98
+ throw new Error(
99
+ `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${result.response.error.message}`
100
+ );
101
+ }
102
+ return await sagaPromise;
65
103
  };
66
104
  return promise;
67
105
  }
@@ -70,6 +108,10 @@ async function getInterfaceFromResult(result, snapId, controllerMessenger) {
70
108
  return result.id;
71
109
  }
72
110
  if (_utils.isPlainObject.call(void 0, result) && _utils.hasProperty.call(void 0, result, "content")) {
111
+ _utils.assert.call(void 0,
112
+ _superstruct.is.call(void 0, result.content, _snapssdk.ComponentOrElementStruct),
113
+ "The Snap returned an invalid interface."
114
+ );
73
115
  const id = await controllerMessenger.call(
74
116
  "SnapInterfaceController:createInterface",
75
117
  snapId,
@@ -95,7 +137,7 @@ async function getInterfaceApi(result, snapId, controllerMessenger) {
95
137
  return {
96
138
  content,
97
139
  clickElement: async (name) => {
98
- await _chunkKR7CYXCRjs.clickElement.call(void 0,
140
+ await _chunkR55KAAM4js.clickElement.call(void 0,
99
141
  controllerMessenger,
100
142
  interfaceId,
101
143
  content,
@@ -104,7 +146,17 @@ async function getInterfaceApi(result, snapId, controllerMessenger) {
104
146
  );
105
147
  },
106
148
  typeInField: async (name, value) => {
107
- await _chunkKR7CYXCRjs.typeInField.call(void 0,
149
+ await _chunkR55KAAM4js.typeInField.call(void 0,
150
+ controllerMessenger,
151
+ interfaceId,
152
+ content,
153
+ snapId,
154
+ name,
155
+ value
156
+ );
157
+ },
158
+ selectInDropdown: async (name, value) => {
159
+ await _chunkR55KAAM4js.selectInDropdown.call(void 0,
108
160
  controllerMessenger,
109
161
  interfaceId,
110
162
  content,
@@ -124,4 +176,4 @@ async function getInterfaceApi(result, snapId, controllerMessenger) {
124
176
 
125
177
 
126
178
  exports.handleRequest = handleRequest; exports.getInterfaceFromResult = getInterfaceFromResult; exports.getInterfaceApi = getInterfaceApi;
127
- //# sourceMappingURL=chunk-7L5S3PID.js.map
179
+ //# sourceMappingURL=chunk-2OHD2VKS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internals/request.ts"],"names":[],"mappings":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AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,aAAa,OAAO,MAAM,UAAU;AAClC,gBAAM;AAAA,YACJ;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,kBAAkB,OAAO,MAAM,UAAU;AACvC,gBAAM;AAAA,YACJ;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type SnapId,\n type JsonRpcError,\n type ComponentOrElement,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\nimport { is } from 'superstruct';\n\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from '../types';\nimport {\n clearNotifications,\n clickElement,\n getInterface,\n getNotifications,\n typeInField,\n selectInDropdown,\n} from './simulation';\nimport type { RunSagaFunction, Store } 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 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 return {\n content,\n clickElement: async (name) => {\n await clickElement(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n );\n },\n typeInField: async (name, value) => {\n await typeInField(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n value,\n );\n },\n selectInDropdown: async (name, value) => {\n await selectInDropdown(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n value,\n );\n },\n };\n };\n }\n\n return undefined;\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  var _chunk2JTGBHPRjs = require('./chunk-2JTGBHPR.js');
4
4
 
5
5
 
6
- var _chunk7L5S3PIDjs = require('./chunk-7L5S3PID.js');
6
+ var _chunk2OHD2VKSjs = require('./chunk-2OHD2VKS.js');
7
7
 
8
8
 
9
9
  var _chunkTZB4LBT7js = require('./chunk-TZB4LBT7.js');
@@ -12,7 +12,7 @@ var _chunkTZB4LBT7js = require('./chunk-TZB4LBT7.js');
12
12
 
13
13
 
14
14
 
15
- var _chunkIDGD7TZ7js = require('./chunk-IDGD7TZ7.js');
15
+ var _chunkYNUVT3HCjs = require('./chunk-YNUVT3HC.js');
16
16
 
17
17
 
18
18
 
@@ -30,7 +30,7 @@ function getOptions(snapId, options) {
30
30
  return [snapId, options];
31
31
  }
32
32
  function assertIsResponseWithInterface(response) {
33
- _utils.assertStruct.call(void 0, response, _chunkIDGD7TZ7js.SnapResponseWithInterfaceStruct);
33
+ _utils.assertStruct.call(void 0, response, _chunkYNUVT3HCjs.SnapResponseWithInterfaceStruct);
34
34
  }
35
35
  async function installSnap(snapId, options = {}) {
36
36
  const resolvedOptions = getOptions(snapId, options);
@@ -47,8 +47,8 @@ async function installSnap(snapId, options = {}) {
47
47
  origin: transactionOrigin,
48
48
  chainId,
49
49
  ...transaction
50
- } = _superstruct.create.call(void 0, request, _chunkIDGD7TZ7js.TransactionOptionsStruct);
51
- const response = await _chunk7L5S3PIDjs.handleRequest.call(void 0, {
50
+ } = _superstruct.create.call(void 0, request, _chunkYNUVT3HCjs.TransactionOptionsStruct);
51
+ const response = await _chunk2OHD2VKSjs.handleRequest.call(void 0, {
52
52
  snapId: installedSnapId,
53
53
  store,
54
54
  executionService,
@@ -69,7 +69,7 @@ async function installSnap(snapId, options = {}) {
69
69
  };
70
70
  const onCronjob = (request) => {
71
71
  log("Running cronjob %o.", options);
72
- return _chunk7L5S3PIDjs.handleRequest.call(void 0, {
72
+ return _chunk2OHD2VKSjs.handleRequest.call(void 0, {
73
73
  snapId: installedSnapId,
74
74
  store,
75
75
  executionService,
@@ -82,7 +82,7 @@ async function installSnap(snapId, options = {}) {
82
82
  return {
83
83
  request: (request) => {
84
84
  log("Sending request %o.", request);
85
- return _chunk7L5S3PIDjs.handleRequest.call(void 0, {
85
+ return _chunk2OHD2VKSjs.handleRequest.call(void 0, {
86
86
  snapId: installedSnapId,
87
87
  store,
88
88
  executionService,
@@ -98,9 +98,9 @@ async function installSnap(snapId, options = {}) {
98
98
  log("Requesting signature %o.", request);
99
99
  const { origin: signatureOrigin, ...signature } = _superstruct.create.call(void 0,
100
100
  request,
101
- _chunkIDGD7TZ7js.SignatureOptionsStruct
101
+ _chunkYNUVT3HCjs.SignatureOptionsStruct
102
102
  );
103
- const response = await _chunk7L5S3PIDjs.handleRequest.call(void 0, {
103
+ const response = await _chunk2OHD2VKSjs.handleRequest.call(void 0, {
104
104
  snapId: installedSnapId,
105
105
  store,
106
106
  executionService,
@@ -122,7 +122,7 @@ async function installSnap(snapId, options = {}) {
122
122
  runCronjob: onCronjob,
123
123
  onHomePage: async () => {
124
124
  log("Rendering home page.");
125
- const response = await _chunk7L5S3PIDjs.handleRequest.call(void 0, {
125
+ const response = await _chunk2OHD2VKSjs.handleRequest.call(void 0, {
126
126
  snapId: installedSnapId,
127
127
  store,
128
128
  executionService,
@@ -138,7 +138,7 @@ async function installSnap(snapId, options = {}) {
138
138
  },
139
139
  mockJsonRpc(mock) {
140
140
  log("Mocking JSON-RPC request %o.", mock);
141
- const { method, result } = _superstruct.create.call(void 0, mock, _chunkIDGD7TZ7js.JsonRpcMockOptionsStruct);
141
+ const { method, result } = _superstruct.create.call(void 0, mock, _chunkYNUVT3HCjs.JsonRpcMockOptionsStruct);
142
142
  store.dispatch(_chunkLACTK6EOjs.addJsonRpcMock.call(void 0, { method, result }));
143
143
  return {
144
144
  unmock() {
@@ -160,4 +160,4 @@ async function installSnap(snapId, options = {}) {
160
160
 
161
161
 
162
162
  exports.installSnap = installSnap;
163
- //# sourceMappingURL=chunk-LMCG5RIX.js.map
163
+ //# sourceMappingURL=chunk-3FDEYMQU.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkZWN4SO2Vjs = require('./chunk-ZWN4SO2V.js');
3
+ var _chunkMBQHVBLAjs = require('./chunk-MBQHVBLA.js');
4
4
 
5
5
 
6
6
  var _chunkXAOCS6ZDjs = require('./chunk-XAOCS6ZD.js');
@@ -47,7 +47,7 @@ function getControllers(options) {
47
47
  }
48
48
  function getPermissionController(options) {
49
49
  const { controllerMessenger } = options;
50
- const permissionSpecifications = _chunkZWN4SO2Vjs.getPermissionSpecifications.call(void 0, options);
50
+ const permissionSpecifications = _chunkMBQHVBLAjs.getPermissionSpecifications.call(void 0, options);
51
51
  return new (0, _permissioncontroller.PermissionController)({
52
52
  messenger: controllerMessenger.getRestricted({
53
53
  name: "PermissionController",
@@ -92,4 +92,4 @@ async function registerSnap(snapId, manifest, {
92
92
 
93
93
 
94
94
  exports.getControllers = getControllers; exports.registerSnap = registerSnap;
95
- //# sourceMappingURL=chunk-DTDYOBCI.js.map
95
+ //# sourceMappingURL=chunk-44ARQBXS.js.map
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  InterfaceStruct,
3
3
  SnapResponseStruct
4
- } from "./chunk-YEVKBYKO.mjs";
4
+ } from "./chunk-HOI6FPLR.mjs";
5
5
 
6
6
  // src/matchers.ts
7
7
  import { expect } from "@jest/globals";
8
+ import { isJSXElementUnsafe } from "@metamask/snaps-sdk/jsx";
9
+ import { getJsxElementFromComponent } from "@metamask/snaps-utils";
8
10
  import { hasProperty } from "@metamask/utils";
9
11
  import {
12
+ EXPECTED_COLOR,
10
13
  diff,
11
14
  matcherErrorMessage,
12
15
  matcherHint,
@@ -96,22 +99,95 @@ Expected type: ${this.utils.printExpected(type)}
96
99
  Received: ${this.utils.printReceived(notifications)}`;
97
100
  return { message, pass };
98
101
  };
102
+ function serialiseProp(prop) {
103
+ if (typeof prop === "string") {
104
+ return `"${prop}"`;
105
+ }
106
+ return `{${JSON.stringify(prop)}}`;
107
+ }
108
+ function serialiseProps(props) {
109
+ return Object.entries(props).filter(([key]) => key !== "children").sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => ` ${key}=${serialiseProp(value)}`).join("");
110
+ }
111
+ function serialiseJsx(node, indentation = 0) {
112
+ if (Array.isArray(node)) {
113
+ return node.map((child) => serialiseJsx(child, indentation)).join("");
114
+ }
115
+ const indent = " ".repeat(indentation);
116
+ if (typeof node === "string") {
117
+ return `${indent}${node}
118
+ `;
119
+ }
120
+ if (!node) {
121
+ return "";
122
+ }
123
+ const { type, props } = node;
124
+ const trailingNewline = indentation > 0 ? "\n" : "";
125
+ if (hasProperty(props, "children")) {
126
+ const children = serialiseJsx(props.children, indentation + 1);
127
+ return `${indent}<${type}${serialiseProps(
128
+ props
129
+ )}>
130
+ ${children}${indent}</${type}>${trailingNewline}`;
131
+ }
132
+ return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;
133
+ }
134
+ var toRenderLegacy = function(actual, expected) {
135
+ assertHasInterface(actual, "toRender");
136
+ const { content } = actual;
137
+ const expectedElement = getJsxElementFromComponent(expected);
138
+ const pass = this.equals(content, expectedElement);
139
+ const difference = diff(expectedElement, content);
140
+ const message = pass ? () => `${this.utils.matcherHint(".not.toRender")}
141
+
142
+ Expected:
143
+ ${this.utils.printExpected(expectedElement)}
144
+
145
+ Received:
146
+ ${this.utils.printReceived(content)}
147
+
148
+ Difference:
149
+
150
+ ${difference}` : () => `${this.utils.matcherHint(".toRender")}
151
+
152
+ Expected:
153
+ ${this.utils.printExpected(expectedElement)}
154
+
155
+ Received:
156
+ ${this.utils.printReceived(content)}
157
+
158
+ Difference:
159
+
160
+ ${difference}`;
161
+ return { message, pass };
162
+ };
99
163
  var toRender = function(actual, expected) {
100
164
  assertHasInterface(actual, "toRender");
165
+ if (!isJSXElementUnsafe(expected)) {
166
+ return toRenderLegacy.call(this, actual, expected);
167
+ }
101
168
  const { content } = actual;
102
169
  const pass = this.equals(content, expected);
103
- const difference = diff(expected, content);
170
+ const difference = diff(
171
+ serialiseJsx(expected),
172
+ serialiseJsx(content)
173
+ );
104
174
  const message = pass ? () => `${this.utils.matcherHint(".not.toRender")}
105
175
 
106
- Expected: ${this.utils.printExpected(expected)}
107
- Received: ${this.utils.printReceived(content)}
176
+ Expected:
177
+ ${EXPECTED_COLOR(serialiseJsx(expected))}
178
+
179
+ Received:
180
+ ${RECEIVED_COLOR(serialiseJsx(content))}
108
181
 
109
182
  Difference:
110
183
 
111
184
  ${difference}` : () => `${this.utils.matcherHint(".toRender")}
112
185
 
113
- Expected: ${this.utils.printExpected(expected)}
114
- Received: ${this.utils.printReceived(content)}
186
+ Expected:
187
+ ${EXPECTED_COLOR(serialiseJsx(expected))}
188
+
189
+ Received:
190
+ ${RECEIVED_COLOR(serialiseJsx(content))}
115
191
 
116
192
  Difference:
117
193
 
@@ -129,6 +205,7 @@ export {
129
205
  toRespondWith,
130
206
  toRespondWithError,
131
207
  toSendNotification,
208
+ serialiseJsx,
132
209
  toRender
133
210
  };
134
- //# sourceMappingURL=chunk-BVGI3E45.mjs.map
211
+ //# sourceMappingURL=chunk-6V5GEUDO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/matchers.ts"],"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, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport { getJsxElementFromComponent } from '@metamask/snaps-utils';\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';\nimport { is } from 'superstruct';\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\n/**\n * Serialise a JSX prop to a string.\n *\n * @param prop - The JSX prop.\n * @returns The serialised JSX prop.\n */\nfunction serialiseProp(prop: unknown): string {\n if (typeof prop === 'string') {\n return `\"${prop}\"`;\n }\n\n return `{${JSON.stringify(prop)}}`;\n}\n\n/**\n * Serialise JSX props to a string.\n *\n * @param props - The JSX props.\n * @returns The serialised JSX props.\n */\nfunction serialiseProps(props: Record<string, unknown>): string {\n return Object.entries(props)\n .filter(([key]) => key !== 'children')\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, value]) => ` ${key}=${serialiseProp(value)}`)\n .join('');\n}\n\n/**\n * Serialise a JSX node to a string.\n *\n * @param node - The JSX node.\n * @param indentation - The indentation level. Defaults to `0`. This should not\n * be set by the caller, as it is used for recursion.\n * @returns The serialised JSX node.\n */\nexport function serialiseJsx(node: SnapNode, indentation = 0): string {\n if (Array.isArray(node)) {\n return node.map((child) => serialiseJsx(child, indentation)).join('');\n }\n\n const indent = ' '.repeat(indentation);\n if (typeof node === 'string') {\n return `${indent}${node}\\n`;\n }\n\n if (!node) {\n return '';\n }\n\n const { type, props } = node;\n const trailingNewline = indentation > 0 ? '\\n' : '';\n\n if (hasProperty(props, 'children')) {\n const children = serialiseJsx(props.children as SnapNode, indentation + 1);\n return `${indent}<${type}${serialiseProps(\n props,\n )}>\\n${children}${indent}</${type}>${trailingNewline}`;\n }\n\n return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;\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"],"mappings":";;;;;;AAMA,SAAS,cAAc;AAQvB,SAAS,0BAA0B;AACnC,SAAS,kCAAkC;AAE3C,SAAS,mBAAmB;AAE5B;AAAA,EACE;AAAA,EACA;AAAA,EAC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