@metamask/snaps-jest 8.4.0 → 8.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +70 -1
- package/LICENSE +15 -0
- package/dist/environment.cjs.map +1 -1
- package/dist/environment.d.cts +2 -2
- package/dist/environment.d.cts.map +1 -1
- package/dist/environment.d.mts +2 -2
- package/dist/environment.d.mts.map +1 -1
- package/dist/environment.mjs.map +1 -1
- package/dist/helpers.cjs +8 -108
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -2
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +1 -2
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +10 -110
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/matchers.cjs.map +1 -1
- package/dist/matchers.d.cts.map +1 -1
- package/dist/matchers.d.mts.map +1 -1
- package/dist/matchers.mjs.map +1 -1
- package/package.json +37 -19
- package/dist/types/index.cjs +0 -18
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -2
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -2
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/types.cjs +0 -3
- package/dist/types/types.cjs.map +0 -1
- package/dist/types/types.d.cts +0 -393
- package/dist/types/types.d.cts.map +0 -1
- package/dist/types/types.d.mts +0 -393
- package/dist/types/types.d.mts.map +0 -1
- package/dist/types/types.mjs +0 -2
- package/dist/types/types.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
|
|
2
3
|
All notable changes to this project will be documented in this file.
|
|
3
4
|
|
|
4
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
@@ -6,21 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
7
|
|
|
7
8
|
## [Unreleased]
|
|
8
9
|
|
|
10
|
+
## [8.5.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Move helper functions to simulation package ([#2769](https://github.com/MetaMask/snaps/pull/2769))
|
|
15
|
+
|
|
9
16
|
## [8.4.0]
|
|
17
|
+
|
|
10
18
|
### Added
|
|
19
|
+
|
|
11
20
|
- Add support for selector component ([#2724](https://github.com/MetaMask/snaps/pull/2724))
|
|
12
21
|
- Interfaces now have a `selectFromSelector` function that can be used to
|
|
13
22
|
select an option from a selector.
|
|
14
23
|
|
|
15
24
|
### Changed
|
|
25
|
+
|
|
16
26
|
- Extract simulation part of `snaps-jest` to separate package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
|
|
17
27
|
|
|
18
28
|
## [8.3.2]
|
|
29
|
+
|
|
19
30
|
### Fixed
|
|
31
|
+
|
|
20
32
|
- Fix invalid types in type declaration in some cases ([#2714](https://github.com/MetaMask/snaps/pull/2714))
|
|
21
33
|
|
|
22
34
|
## [8.3.1]
|
|
35
|
+
|
|
23
36
|
### Fixed
|
|
37
|
+
|
|
24
38
|
- Fix ESM version of the package ([#2682](https://github.com/MetaMask/snaps/pull/2682))
|
|
25
39
|
- This fixes the ESM version of the package to be fully compliant with the ESM
|
|
26
40
|
standard.
|
|
@@ -28,44 +42,60 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
28
42
|
- Bump other MetaMask dependencies ([#2703](https://github.com/MetaMask/snaps/pull/2703))
|
|
29
43
|
|
|
30
44
|
## [8.3.0]
|
|
45
|
+
|
|
31
46
|
### Added
|
|
47
|
+
|
|
32
48
|
- Add support for `snap_getPreferences` ([#2607](https://github.com/MetaMask/snaps/pull/2607))
|
|
33
49
|
- Add `RadioGroup` component ([#2592](https://github.com/MetaMask/snaps/pull/2592))
|
|
34
50
|
- Add support for custom dialogs in `snaps-jest` ([#2526](https://github.com/MetaMask/snaps/pull/2526), [#2509](https://github.com/MetaMask/snaps/pull/2509))
|
|
35
51
|
|
|
36
52
|
### Changed
|
|
53
|
+
|
|
37
54
|
- Replace `superstruct` with ESM-compatible fork `@metamask/superstruct` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
38
55
|
|
|
39
56
|
## [8.2.0]
|
|
57
|
+
|
|
40
58
|
### Added
|
|
59
|
+
|
|
41
60
|
- Add support for `Checkbox` to `snaps-jest` ([#2515](https://github.com/MetaMask/snaps/pull/2515))
|
|
42
61
|
- Checkboxes can be interacted with using `clickElement`.
|
|
43
62
|
- Add support for `FileInput` to `snaps-jest` ([#2494](https://github.com/MetaMask/snaps/pull/2494))
|
|
44
63
|
- Files can be uploaded to file inputs using `uploadFile`.
|
|
45
64
|
|
|
46
65
|
## [8.1.3]
|
|
66
|
+
|
|
47
67
|
### Changed
|
|
68
|
+
|
|
48
69
|
- Bump MetaMask dependencies ([#2460](https://github.com/MetaMask/snaps/pull/2460), [#2477](https://github.com/MetaMask/snaps/pull/2477))
|
|
49
70
|
|
|
50
71
|
## [8.1.2]
|
|
72
|
+
|
|
51
73
|
### Fixed
|
|
74
|
+
|
|
52
75
|
- Fix invalid `@metamask/snaps-sdk` imports ([#2452](https://github.com/MetaMask/snaps/pull/2452))
|
|
53
76
|
|
|
54
77
|
## [8.1.1]
|
|
78
|
+
|
|
55
79
|
### Changed
|
|
80
|
+
|
|
56
81
|
- Bump `@metamask/key-tree` from `9.1.0` to `9.1.1` ([#2431](https://github.com/MetaMask/snaps/pull/2431))
|
|
57
82
|
|
|
58
83
|
## [8.1.0]
|
|
84
|
+
|
|
59
85
|
### Added
|
|
86
|
+
|
|
60
87
|
- Add `selectInDropdown` to be used with the newly added `Dropdown` component ([#2420](https://github.com/MetaMask/snaps/pull/2420))
|
|
61
88
|
- Add `context` field to `snap_createInterface` ([#2413](https://github.com/MetaMask/snaps/pull/2413))
|
|
62
89
|
|
|
63
90
|
### Fixed
|
|
91
|
+
|
|
64
92
|
- Properly handle invalid interfaces during test ([#2433](https://github.com/MetaMask/snaps/pull/2433))
|
|
65
93
|
- Properly diff when using legacy UI with `toRender` matcher ([#2432](https://github.com/MetaMask/snaps/pull/2432))
|
|
66
94
|
|
|
67
95
|
## [8.0.0]
|
|
96
|
+
|
|
68
97
|
### Added
|
|
98
|
+
|
|
69
99
|
- **BREAKING:** Add JSX support for custom UI ([#2258](https://github.com/MetaMask/snaps/pull/2258))
|
|
70
100
|
- It's now possible to use JSX components from `@metamask/snaps-sdk` to build
|
|
71
101
|
user interfaces for Snaps.
|
|
@@ -75,38 +105,52 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
75
105
|
need to update your tests to check the JSX format.
|
|
76
106
|
|
|
77
107
|
### Changed
|
|
108
|
+
|
|
78
109
|
- Bump `@metamask/base-controller` from `5.0.1` to `5.0.2` ([#2375](https://github.com/MetaMask/snaps/pull/2375))
|
|
79
110
|
|
|
80
111
|
## [7.0.2]
|
|
112
|
+
|
|
81
113
|
### Changed
|
|
114
|
+
|
|
82
115
|
- Bump `@metamask/snaps-execution-environments` to latest ([#2339](https://github.com/MetaMask/snaps/pull/2339))
|
|
83
116
|
|
|
84
117
|
## [7.0.1]
|
|
118
|
+
|
|
85
119
|
### Fixed
|
|
120
|
+
|
|
86
121
|
- Improve correctness of `clickElement` ([#2334](https://github.com/MetaMask/snaps/pull/2334))
|
|
87
122
|
- The function should now behave closer to the client implementation.
|
|
88
123
|
|
|
89
124
|
## [7.0.0]
|
|
125
|
+
|
|
90
126
|
### Added
|
|
127
|
+
|
|
91
128
|
- **BREAKING:** Support Interactive UI in `snaps-jest` ([#2286](https://github.com/MetaMask/snaps/pull/2286))
|
|
92
129
|
- Remove `content` from the Snap response, instead `getInterface()` must be used
|
|
93
130
|
- `clickElement` and `typeInField` can be used on the interface return value to simulate actions
|
|
94
131
|
|
|
95
132
|
### Changed
|
|
133
|
+
|
|
96
134
|
- Improve Jest expect types ([#2308](https://github.com/MetaMask/snaps/pull/2308))
|
|
97
135
|
- Refactor to support changes to encryption ([#2316](https://github.com/MetaMask/snaps/pull/2316))
|
|
98
136
|
|
|
99
137
|
## [6.0.2]
|
|
138
|
+
|
|
100
139
|
### Changed
|
|
140
|
+
|
|
101
141
|
- Bump MetaMask dependencies ([#2270](https://github.com/MetaMask/snaps/pull/2270))
|
|
102
142
|
- Bump @metamask/json-rpc-engine from 7.3.2 to 7.3.3 ([#2247](https://github.com/MetaMask/snaps/pull/2247))
|
|
103
143
|
|
|
104
144
|
## [6.0.1]
|
|
145
|
+
|
|
105
146
|
### Fixed
|
|
147
|
+
|
|
106
148
|
- Fix minor build configuration problems ([#2220](https://github.com/MetaMask/snaps/pull/2220))
|
|
107
149
|
|
|
108
150
|
## [6.0.0]
|
|
151
|
+
|
|
109
152
|
### Changed
|
|
153
|
+
|
|
110
154
|
- **BREAKING:** Update ESM build to be fully compliant with the ESM standard ([#2210](https://github.com/MetaMask/snaps/pull/2210))
|
|
111
155
|
- **BREAKING:** Move Node.js exports to separate export ([#2210](https://github.com/MetaMask/snaps/pull/2210))
|
|
112
156
|
- The default export is now browser-compatible.
|
|
@@ -114,7 +158,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
114
158
|
- Bump `@metamask/rpc-errors` to `^6.2.1` ([#2209](https://github.com/MetaMask/snaps/pull/2209))
|
|
115
159
|
|
|
116
160
|
## [5.0.0]
|
|
161
|
+
|
|
117
162
|
### Added
|
|
163
|
+
|
|
118
164
|
- **BREAKING:** Implement testing framework using Node.js executor ([#1982](https://github.com/MetaMask/snaps/pull/1982), [#2118](https://github.com/MetaMask/snaps/pull/2118))
|
|
119
165
|
- The network mocking functionality was removed, but may be reintroduced in a future version.
|
|
120
166
|
- `mockJsonRpc` no longer returns a `Promise`.
|
|
@@ -125,30 +171,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
125
171
|
- Add `snap_getClientStatus` support ([#2159](https://github.com/MetaMask/snaps/pull/2159))
|
|
126
172
|
|
|
127
173
|
### Changed
|
|
174
|
+
|
|
128
175
|
- Bump several MetaMask dependencies ([#2101](https://github.com/MetaMask/snaps/pull/2101), [#2100](https://github.com/MetaMask/snaps/pull/2100), [#2129](https://github.com/MetaMask/snaps/pull/2129), [#2140](https://github.com/MetaMask/snaps/pull/2140), [#2141](https://github.com/MetaMask/snaps/pull/2141), [#2142](https://github.com/MetaMask/snaps/pull/2142))
|
|
129
176
|
|
|
130
177
|
## [4.0.1]
|
|
178
|
+
|
|
131
179
|
### Fixed
|
|
180
|
+
|
|
132
181
|
- Fix coercing of address values in `sendTransaction` function ([#1970](https://github.com/MetaMask/snaps/pull/1970))
|
|
133
182
|
|
|
134
183
|
## [4.0.0]
|
|
184
|
+
|
|
135
185
|
### Changed
|
|
186
|
+
|
|
136
187
|
- Use `@metamask/snaps-sdk` package ([#1930](https://github.com/MetaMask/snaps/pull/1930),
|
|
137
188
|
[#1950](https://github.com/MetaMask/snaps/pull/1950), [#1954](https://github.com/MetaMask/snaps/pull/1954))
|
|
138
189
|
- This package replaces the `@metamask/snaps-types` and
|
|
139
190
|
- `@metamask/snaps-ui` packages.
|
|
140
191
|
|
|
141
192
|
### Removed
|
|
193
|
+
|
|
142
194
|
- **BREAKING**: `DialogType`, `ManageStateOperation`, `NotificationType` are no
|
|
143
195
|
longer re-exported from `@metamask/snaps-jest` ([#1930](https://github.com/MetaMask/snaps/pull/1930))
|
|
144
196
|
- These enums can now be imported from `@metamask/snaps-sdk` instead.
|
|
145
197
|
|
|
146
198
|
## [3.1.0]
|
|
199
|
+
|
|
147
200
|
### Added
|
|
201
|
+
|
|
148
202
|
- Add support for links in custom UI and notifications ([#1814](https://github.com/MetaMask/snaps/pull/1814))
|
|
149
203
|
|
|
150
204
|
## [3.0.0]
|
|
205
|
+
|
|
151
206
|
### Changed
|
|
207
|
+
|
|
152
208
|
- **BREAKING:** Improve error handling ([#1841](https://github.com/MetaMask/snaps/pull/1841))
|
|
153
209
|
- This is a breaking change, because errors returned by the Snap now have a different format. For example, if the Snap throws a JSON-RPC method not found error, previously, the following error would be returned:
|
|
154
210
|
```ts
|
|
@@ -177,32 +233,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
177
233
|
```
|
|
178
234
|
|
|
179
235
|
## [2.0.0]
|
|
236
|
+
|
|
180
237
|
### Changed
|
|
238
|
+
|
|
181
239
|
- **BREAKING:** Bump minimum Node.js version to `^18.16.0` ([#1741](https://github.com/MetaMask/snaps/pull/1741))
|
|
182
240
|
|
|
183
241
|
## [1.0.0]
|
|
242
|
+
|
|
184
243
|
### Changed
|
|
244
|
+
|
|
185
245
|
- Initial stable release from main branch ([#1757](https://github.com/MetaMask/snaps/pull/1757))
|
|
186
246
|
|
|
187
247
|
## [0.37.5-flask.1]
|
|
248
|
+
|
|
188
249
|
### Changed
|
|
250
|
+
|
|
189
251
|
- Bump `metamask/utils` and `metamask/snaps-registry` ([#1738](https://github.com/MetaMask/snaps/pull/1738), [#1694](https://github.com/MetaMask/snaps/pull/1694))
|
|
190
252
|
|
|
191
253
|
## [0.37.4-flask.1]
|
|
254
|
+
|
|
192
255
|
### Fixed
|
|
256
|
+
|
|
193
257
|
- Remove unused dependencies ([#1680](https://github.com/MetaMask/snaps/pull/1680))
|
|
194
258
|
|
|
195
259
|
## [0.37.3-flask.1]
|
|
260
|
+
|
|
196
261
|
### Changed
|
|
262
|
+
|
|
197
263
|
- Bump `semver` to `^7.5.4` ([#1631](https://github.com/MetaMask/snaps/pull/1631))
|
|
198
264
|
|
|
199
265
|
## [0.37.2-flask.1]
|
|
266
|
+
|
|
200
267
|
### Changed
|
|
268
|
+
|
|
201
269
|
- Release package independently ([#1600](https://github.com/MetaMask/snaps/pull/1600))
|
|
202
270
|
- The version of the package no longer needs to match the version of all other
|
|
203
271
|
MetaMask Snaps packages.
|
|
204
272
|
|
|
205
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.
|
|
273
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.5.0...HEAD
|
|
274
|
+
[8.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.4.0...@metamask/snaps-jest@8.5.0
|
|
206
275
|
[8.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.2...@metamask/snaps-jest@8.4.0
|
|
207
276
|
[8.3.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.1...@metamask/snaps-jest@8.3.2
|
|
208
277
|
[8.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.0...@metamask/snaps-jest@8.3.1
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 MetaMask
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/dist/environment.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,iEAAyD;AAMzD,2CAA6D;AAE7D,kFAAoD;AAGpD,qDAAsD;AAEtD,2CAAuC;AAMvC,mBAAmB;AAEnB,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAa,gBAAiB,SAAQ,+BAAe;IAOnD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAb1B,4CAAkC;QAElC,2CAA4B;QAE5B,6CAAqD;QAUnD,uBAAA,IAAI,6BAAY,IAAA,oBAAU,EAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAA,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,uBAAA,IAAI,4BAAW,MAAM,IAAA,uBAAW,EAAC,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,gCAAQ,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,WAAW,CAKf,SAAiB,IAAI,CAAC,MAAM,EAC5B,UAAgD,EAAE;QAElD,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,8BAAa,MAAM,IAAA,8BAAW,EAAC,MAAgB,EAAE,OAAO,CAAC,MAAA,CAAC;QAC9D,OAAO,uBAAA,IAAI,kCAAU,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,IAAA,cAAM,EACJ,uBAAA,IAAI,gCAAQ,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAA,IAAI,gCAAQ,CAAC,OAAO,EAAiB,CAAC;QACvD,OAAO,0BAA0B,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;AAvFD,4CAuFC;;AAED,kBAAe,gBAAgB,CAAC","sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { installSnap } from '@metamask/snaps-simulation';\nimport type {\n InstalledSnap,\n InstallSnapOptions,\n SnapHelpers,\n} from '@metamask/snaps-simulation';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\n\nimport { rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n #options: SnapsEnvironmentOptions;\n\n #server: Server | undefined;\n\n #instance: (InstalledSnap & SnapHelpers) | undefined;\n\n /**\n * Constructor.\n *\n * @param options - The environment options.\n * @param context - The environment context.\n */\n constructor(options: JestEnvironmentConfig, context: EnvironmentContext) {\n super(options, context);\n this.#options = getOptions(options.projectConfig.testEnvironmentOptions);\n }\n\n /**\n * Set up the environment. This starts the built-in HTTP server, and creates a\n * new browser instance.\n */\n async setup() {\n await super.setup();\n\n if (this.#options.server.enabled) {\n log('Starting server.');\n this.#server = await startServer(this.#options.server);\n }\n\n this.global.snapsEnvironment = this;\n }\n\n /**\n * Tear down the environment. This closes the browser, and stops the built-in\n * HTTP server.\n */\n async teardown() {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#server?.close();\n await super.teardown();\n }\n\n /**\n * Install a Snap in the environment. This will terminate any previously\n * installed Snaps, and run the Snap code in a new execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n * @returns The installed Snap.\n */\n async installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n >(\n snapId: string = this.snapId,\n options: Partial<InstallSnapOptions<Service>> = {},\n ) {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#instance = await installSnap(snapId as SnapId, options);\n return this.#instance;\n }\n\n /**\n * Get the snap ID for the current environment, which is used if no snap ID is\n * passed to {@link installSnap}. This assumes that the built-in server is\n * running.\n *\n * @returns The snap ID.\n * @throws If the server is not running.\n */\n get snapId() {\n assert(\n this.#server,\n 'You must specify a snap ID, because the built-in server is not running.',\n );\n\n const { port } = this.#server.address() as AddressInfo;\n return `local:http://localhost:${port}`;\n }\n}\n\nexport default SnapsEnvironment;\n"]}
|
package/dist/environment.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
|
|
2
2
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
3
|
-
import type { InstalledSnap, InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
3
|
+
import type { InstalledSnap, InstallSnapOptions, SnapHelpers } from "@metamask/snaps-simulation";
|
|
4
4
|
import NodeEnvironment from "jest-environment-node";
|
|
5
5
|
declare global {
|
|
6
6
|
const snapsEnvironment: SnapsEnvironment;
|
|
@@ -38,7 +38,7 @@ export declare class SnapsEnvironment extends NodeEnvironment {
|
|
|
38
38
|
* @template Service - The type of the execution service.
|
|
39
39
|
* @returns The installed Snap.
|
|
40
40
|
*/
|
|
41
|
-
installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap>;
|
|
41
|
+
installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap & SnapHelpers>;
|
|
42
42
|
/**
|
|
43
43
|
* Get the snap ID for the current environment, which is used if no snap ID is
|
|
44
44
|
* passed to {@link installSnap}. This assumes that the built-in server is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.cts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;
|
|
1
|
+
{"version":3,"file":"environment.d.cts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAG5E,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,eAAe,8BAA8B;AAQpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAKD,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,kBAAkB;IAKvE;;;OAGG;IACG,KAAK;IAWX;;;OAGG;IACG,QAAQ;IAMd;;;;;;;;;;;;;OAaG;IACG,WAAW,CACf,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
|
package/dist/environment.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EnvironmentContext, JestEnvironmentConfig } from "@jest/environment";
|
|
2
2
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
3
|
-
import type { InstalledSnap, InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
3
|
+
import type { InstalledSnap, InstallSnapOptions, SnapHelpers } from "@metamask/snaps-simulation";
|
|
4
4
|
import NodeEnvironment from "jest-environment-node";
|
|
5
5
|
declare global {
|
|
6
6
|
const snapsEnvironment: SnapsEnvironment;
|
|
@@ -38,7 +38,7 @@ export declare class SnapsEnvironment extends NodeEnvironment {
|
|
|
38
38
|
* @template Service - The type of the execution service.
|
|
39
39
|
* @returns The installed Snap.
|
|
40
40
|
*/
|
|
41
|
-
installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap>;
|
|
41
|
+
installSnap<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService>>(snapId?: string, options?: Partial<InstallSnapOptions<Service>>): Promise<InstalledSnap & SnapHelpers>;
|
|
42
42
|
/**
|
|
43
43
|
* Get the snap ID for the current environment, which is used if no snap ID is
|
|
44
44
|
* passed to {@link installSnap}. This assumes that the built-in server is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.d.mts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;
|
|
1
|
+
{"version":3,"file":"environment.d.mts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACtB,0BAA0B;AAC3B,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAG5E,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,mCAAmC;AAGpC,OAAO,eAAe,8BAA8B;AAQpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAKD,qBAAa,gBAAiB,SAAQ,eAAe;;IAOnD;;;;;OAKG;gBACS,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,kBAAkB;IAKvE;;;OAGG;IACG,KAAK;IAWX;;;OAGG;IACG,QAAQ;IAMd;;;;;;;;;;;;;OAaG;IACG,WAAW,CACf,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
|
package/dist/environment.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.mjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"environment.mjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,OAAO,EAAE,WAAW,EAAE,mCAAmC;AAMzD,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,wBAAwB;AAE7D,OAAO,gBAAe,8BAA8B;;AAGpD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,8BAAoB;AAEtD,OAAO,EAAE,UAAU,EAAE,sBAAkB;AAMvC,mBAAmB;AAEnB,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IAOnD;;;;;OAKG;IACH,YAAY,OAA8B,EAAE,OAA2B;QACrE,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAb1B,4CAAkC;QAElC,2CAA4B;QAE5B,6CAAqD;QAUnD,uBAAA,IAAI,6BAAY,UAAU,CAAC,OAAO,CAAC,aAAa,CAAC,sBAAsB,CAAC,MAAA,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;QAEpB,IAAI,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACjC,GAAG,CAAC,kBAAkB,CAAC,CAAC;YACxB,uBAAA,IAAI,4BAAW,MAAM,WAAW,CAAC,uBAAA,IAAI,iCAAS,CAAC,MAAM,CAAC,MAAA,CAAC;QACzD,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,gBAAgB,GAAG,IAAI,CAAC;IACtC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,gCAAQ,EAAE,KAAK,EAAE,CAAC;QACtB,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzB,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,WAAW,CAKf,SAAiB,IAAI,CAAC,MAAM,EAC5B,UAAgD,EAAE;QAElD,MAAM,uBAAA,IAAI,kCAAU,EAAE,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC3D,uBAAA,IAAI,8BAAa,MAAM,WAAW,CAAC,MAAgB,EAAE,OAAO,CAAC,MAAA,CAAC;QAC9D,OAAO,uBAAA,IAAI,kCAAU,CAAC;IACxB,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,MAAM;QACR,MAAM,CACJ,uBAAA,IAAI,gCAAQ,EACZ,yEAAyE,CAC1E,CAAC;QAEF,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAA,IAAI,gCAAQ,CAAC,OAAO,EAAiB,CAAC;QACvD,OAAO,0BAA0B,IAAI,EAAE,CAAC;IAC1C,CAAC;CACF;;AAED,eAAe,gBAAgB,CAAC","sourcesContent":["import type {\n EnvironmentContext,\n JestEnvironmentConfig,\n} from '@jest/environment';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { installSnap } from '@metamask/snaps-simulation';\nimport type {\n InstalledSnap,\n InstallSnapOptions,\n SnapHelpers,\n} from '@metamask/snaps-simulation';\nimport { assert, createModuleLogger } from '@metamask/utils';\nimport type { Server } from 'http';\nimport NodeEnvironment from 'jest-environment-node';\nimport type { AddressInfo } from 'net';\n\nimport { rootLogger, startServer } from './internals';\nimport type { SnapsEnvironmentOptions } from './options';\nimport { getOptions } from './options';\n\n/* eslint-disable */\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n/* eslint-enable */\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n #options: SnapsEnvironmentOptions;\n\n #server: Server | undefined;\n\n #instance: (InstalledSnap & SnapHelpers) | undefined;\n\n /**\n * Constructor.\n *\n * @param options - The environment options.\n * @param context - The environment context.\n */\n constructor(options: JestEnvironmentConfig, context: EnvironmentContext) {\n super(options, context);\n this.#options = getOptions(options.projectConfig.testEnvironmentOptions);\n }\n\n /**\n * Set up the environment. This starts the built-in HTTP server, and creates a\n * new browser instance.\n */\n async setup() {\n await super.setup();\n\n if (this.#options.server.enabled) {\n log('Starting server.');\n this.#server = await startServer(this.#options.server);\n }\n\n this.global.snapsEnvironment = this;\n }\n\n /**\n * Tear down the environment. This closes the browser, and stops the built-in\n * HTTP server.\n */\n async teardown() {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#server?.close();\n await super.teardown();\n }\n\n /**\n * Install a Snap in the environment. This will terminate any previously\n * installed Snaps, and run the Snap code in a new execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n * @returns The installed Snap.\n */\n async installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n >(\n snapId: string = this.snapId,\n options: Partial<InstallSnapOptions<Service>> = {},\n ) {\n await this.#instance?.executionService.terminateAllSnaps();\n this.#instance = await installSnap(snapId as SnapId, options);\n return this.#instance;\n }\n\n /**\n * Get the snap ID for the current environment, which is used if no snap ID is\n * passed to {@link installSnap}. This assumes that the built-in server is\n * running.\n *\n * @returns The snap ID.\n * @throws If the server is not running.\n */\n get snapId() {\n assert(\n this.#server,\n 'You must specify a snap ID, because the built-in server is not running.',\n );\n\n const { port } = this.#server.address() as AddressInfo;\n return `local:http://localhost:${port}`;\n }\n}\n\nexport default SnapsEnvironment;\n"]}
|
package/dist/helpers.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.installSnap = void 0;
|
|
4
|
-
const snaps_simulation_1 = require("@metamask/snaps-simulation");
|
|
5
4
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
6
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
7
5
|
const utils_1 = require("@metamask/utils");
|
|
8
6
|
const internals_1 = require("./internals/index.cjs");
|
|
9
7
|
const log = (0, utils_1.createModuleLogger)(internals_1.rootLogger, 'helpers');
|
|
@@ -20,14 +18,6 @@ function getOptions(snapId, options) {
|
|
|
20
18
|
}
|
|
21
19
|
return [snapId, options];
|
|
22
20
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Ensure that the actual response contains `getInterface`.
|
|
25
|
-
*
|
|
26
|
-
* @param response - The response of the handler.
|
|
27
|
-
*/
|
|
28
|
-
function assertIsResponseWithInterface(response) {
|
|
29
|
-
(0, utils_1.assertStruct)(response, snaps_simulation_1.SnapResponseWithInterfaceStruct);
|
|
30
|
-
}
|
|
31
21
|
/**
|
|
32
22
|
* Load a snap into the environment. This is the main entry point for testing
|
|
33
23
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
|
@@ -62,110 +52,20 @@ function assertIsResponseWithInterface(response) {
|
|
|
62
52
|
*/
|
|
63
53
|
async function installSnap(snapId, options = {}) {
|
|
64
54
|
const resolvedOptions = getOptions(snapId, options);
|
|
65
|
-
const {
|
|
66
|
-
const onTransaction = async (request) => {
|
|
67
|
-
log('Sending transaction %o.', request);
|
|
68
|
-
const { origin: transactionOrigin, chainId, ...transaction } = (0, superstruct_1.create)(request, snaps_simulation_1.TransactionOptionsStruct);
|
|
69
|
-
const response = await (0, snaps_simulation_1.handleRequest)({
|
|
70
|
-
snapId: installedSnapId,
|
|
71
|
-
store,
|
|
72
|
-
executionService,
|
|
73
|
-
runSaga,
|
|
74
|
-
controllerMessenger,
|
|
75
|
-
handler: snaps_utils_1.HandlerType.OnTransaction,
|
|
76
|
-
request: {
|
|
77
|
-
method: '',
|
|
78
|
-
params: {
|
|
79
|
-
chainId,
|
|
80
|
-
transaction,
|
|
81
|
-
transactionOrigin,
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
assertIsResponseWithInterface(response);
|
|
86
|
-
return response;
|
|
87
|
-
};
|
|
88
|
-
const onCronjob = (request) => {
|
|
89
|
-
log('Running cronjob %o.', options);
|
|
90
|
-
return (0, snaps_simulation_1.handleRequest)({
|
|
91
|
-
snapId: installedSnapId,
|
|
92
|
-
store,
|
|
93
|
-
executionService,
|
|
94
|
-
controllerMessenger,
|
|
95
|
-
runSaga,
|
|
96
|
-
handler: snaps_utils_1.HandlerType.OnCronjob,
|
|
97
|
-
request,
|
|
98
|
-
});
|
|
99
|
-
};
|
|
55
|
+
const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onHomePage, mockJsonRpc, close, } = await (0, internals_1.getEnvironment)().installSnap(...resolvedOptions);
|
|
100
56
|
return {
|
|
101
|
-
request
|
|
102
|
-
log('Sending request %o.', request);
|
|
103
|
-
return (0, snaps_simulation_1.handleRequest)({
|
|
104
|
-
snapId: installedSnapId,
|
|
105
|
-
store,
|
|
106
|
-
executionService,
|
|
107
|
-
controllerMessenger,
|
|
108
|
-
runSaga,
|
|
109
|
-
handler: snaps_utils_1.HandlerType.OnRpcRequest,
|
|
110
|
-
request,
|
|
111
|
-
});
|
|
112
|
-
},
|
|
57
|
+
request,
|
|
113
58
|
onTransaction,
|
|
114
|
-
sendTransaction
|
|
115
|
-
onSignature
|
|
116
|
-
log('Requesting signature %o.', request);
|
|
117
|
-
const { origin: signatureOrigin, ...signature } = (0, superstruct_1.create)(request, snaps_simulation_1.SignatureOptionsStruct);
|
|
118
|
-
const response = await (0, snaps_simulation_1.handleRequest)({
|
|
119
|
-
snapId: installedSnapId,
|
|
120
|
-
store,
|
|
121
|
-
executionService,
|
|
122
|
-
controllerMessenger,
|
|
123
|
-
runSaga,
|
|
124
|
-
handler: snaps_utils_1.HandlerType.OnSignature,
|
|
125
|
-
request: {
|
|
126
|
-
method: '',
|
|
127
|
-
params: {
|
|
128
|
-
signature,
|
|
129
|
-
signatureOrigin,
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
});
|
|
133
|
-
assertIsResponseWithInterface(response);
|
|
134
|
-
return response;
|
|
135
|
-
},
|
|
59
|
+
sendTransaction,
|
|
60
|
+
onSignature,
|
|
136
61
|
onCronjob,
|
|
137
|
-
runCronjob
|
|
138
|
-
onHomePage
|
|
139
|
-
|
|
140
|
-
const response = await (0, snaps_simulation_1.handleRequest)({
|
|
141
|
-
snapId: installedSnapId,
|
|
142
|
-
store,
|
|
143
|
-
executionService,
|
|
144
|
-
controllerMessenger,
|
|
145
|
-
runSaga,
|
|
146
|
-
handler: snaps_utils_1.HandlerType.OnHomePage,
|
|
147
|
-
request: {
|
|
148
|
-
method: '',
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
assertIsResponseWithInterface(response);
|
|
152
|
-
return response;
|
|
153
|
-
},
|
|
154
|
-
mockJsonRpc(mock) {
|
|
155
|
-
log('Mocking JSON-RPC request %o.', mock);
|
|
156
|
-
const { method, result } = (0, superstruct_1.create)(mock, snaps_simulation_1.JsonRpcMockOptionsStruct);
|
|
157
|
-
store.dispatch((0, snaps_simulation_1.addJsonRpcMock)({ method, result }));
|
|
158
|
-
return {
|
|
159
|
-
unmock() {
|
|
160
|
-
log('Unmocking JSON-RPC request %o.', mock);
|
|
161
|
-
store.dispatch((0, snaps_simulation_1.removeJsonRpcMock)(method));
|
|
162
|
-
},
|
|
163
|
-
};
|
|
164
|
-
},
|
|
62
|
+
runCronjob,
|
|
63
|
+
onHomePage,
|
|
64
|
+
mockJsonRpc,
|
|
165
65
|
close: async () => {
|
|
166
66
|
log('Closing execution service.');
|
|
167
67
|
(0, snaps_utils_1.logInfo)('Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.');
|
|
168
|
-
await
|
|
68
|
+
await close();
|
|
169
69
|
},
|
|
170
70
|
};
|
|
171
71
|
}
|
package/dist/helpers.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAGA,iEAQoC;AACpC,uDAA6D;AAC7D,uDAA+C;AAC/C,2CAAmE;AAEnE,qDAAyD;AAUzD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAKjB,MAAiE,EACjE,OAA6C;IAE7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC;AAED;;;;GAIG;AACH,SAAS,6BAA6B,CACpC,QAAsB;IAEtB,IAAA,oBAAY,EAAC,QAAQ,EAAE,kDAA+B,CAAC,CAAC;AAC1D,CAAC;AAqGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACI,KAAK,UAAU,WAAW,CAK/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,EACJ,MAAM,EAAE,eAAe,EACvB,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,GACpB,GAAG,MAAM,IAAA,0BAAc,GAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;IAE3D,MAAM,aAAa,GAAG,KAAK,EACzB,OAA2B,EACS,EAAE;QACtC,GAAG,CAAC,yBAAyB,EAAE,OAAO,CAAC,CAAC;QAExC,MAAM,EACJ,MAAM,EAAE,iBAAiB,EACzB,OAAO,EACP,GAAG,WAAW,EACf,GAAG,IAAA,oBAAM,EAAC,OAAO,EAAE,2CAAwB,CAAC,CAAC;QAE9C,MAAM,QAAQ,GAAG,MAAM,IAAA,gCAAa,EAAC;YACnC,MAAM,EAAE,eAAe;YACvB,KAAK;YACL,gBAAgB;YAChB,OAAO;YACP,mBAAmB;YACnB,OAAO,EAAE,yBAAW,CAAC,aAAa;YAClC,OAAO,EAAE;gBACP,MAAM,EAAE,EAAE;gBACV,MAAM,EAAE;oBACN,OAAO;oBACP,WAAW;oBACX,iBAAiB;iBAClB;aACF;SACF,CAAC,CAAC;QAEH,6BAA6B,CAAC,QAAQ,CAAC,CAAC;QAExC,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,CAAC,OAAuB,EAAE,EAAE;QAC5C,GAAG,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;QAEpC,OAAO,IAAA,gCAAa,EAAC;YACnB,MAAM,EAAE,eAAe;YACvB,KAAK;YACL,gBAAgB;YAChB,mBAAmB;YACnB,OAAO;YACP,OAAO,EAAE,yBAAW,CAAC,SAAS;YAC9B,OAAO;SACR,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;YACnB,GAAG,CAAC,qBAAqB,EAAE,OAAO,CAAC,CAAC;YAEpC,OAAO,IAAA,gCAAa,EAAC;gBACnB,MAAM,EAAE,eAAe;gBACvB,KAAK;gBACL,gBAAgB;gBAChB,mBAAmB;gBACnB,OAAO;gBACP,OAAO,EAAE,yBAAW,CAAC,YAAY;gBACjC,OAAO;aACR,CAAC,CAAC;QACL,CAAC;QAED,aAAa;QACb,eAAe,EAAE,aAAa;QAE9B,WAAW,EAAE,KAAK,EAChB,OAAgB,EACoB,EAAE;YACtC,GAAG,CAAC,0BAA0B,EAAE,OAAO,CAAC,CAAC;YAEzC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE,GAAG,IAAA,oBAAM,EACtD,OAAO,EACP,yCAAsB,CACvB,CAAC;YAEF,MAAM,QAAQ,GAAG,MAAM,IAAA,gCAAa,EAAC;gBACnC,MAAM,EAAE,eAAe;gBACvB,KAAK;gBACL,gBAAgB;gBAChB,mBAAmB;gBACnB,OAAO;gBACP,OAAO,EAAE,yBAAW,CAAC,WAAW;gBAChC,OAAO,EAAE;oBACP,MAAM,EAAE,EAAE;oBACV,MAAM,EAAE;wBACN,SAAS;wBACT,eAAe;qBAChB;iBACF;aACF,CAAC,CAAC;YAEH,6BAA6B,CAAC,QAAQ,CAAC,CAAC;YAExC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,SAAS;QACT,UAAU,EAAE,SAAS;QAErB,UAAU,EAAE,KAAK,IAAwC,EAAE;YACzD,GAAG,CAAC,sBAAsB,CAAC,CAAC;YAE5B,MAAM,QAAQ,GAAG,MAAM,IAAA,gCAAa,EAAC;gBACnC,MAAM,EAAE,eAAe;gBACvB,KAAK;gBACL,gBAAgB;gBAChB,mBAAmB;gBACnB,OAAO;gBACP,OAAO,EAAE,yBAAW,CAAC,UAAU;gBAC/B,OAAO,EAAE;oBACP,MAAM,EAAE,EAAE;iBACX;aACF,CAAC,CAAC;YAEH,6BAA6B,CAAC,QAAQ,CAAC,CAAC;YAExC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,WAAW,CAAC,IAAwB;YAClC,GAAG,CAAC,8BAA8B,EAAE,IAAI,CAAC,CAAC;YAE1C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,oBAAM,EAAC,IAAI,EAAE,2CAAwB,CAAC,CAAC;YAClE,KAAK,CAAC,QAAQ,CAAC,IAAA,iCAAc,EAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;YAEnD,OAAO;gBACL,MAAM;oBACJ,GAAG,CAAC,gCAAgC,EAAE,IAAI,CAAC,CAAC;oBAE5C,KAAK,CAAC,QAAQ,CAAC,IAAA,oCAAiB,EAAC,MAAM,CAAC,CAAC,CAAC;gBAC5C,CAAC;aACF,CAAC;QACJ,CAAC;QAED,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,IAAA,qBAAO,EACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,gBAAgB,CAAC,iBAAiB,EAAE,CAAC;QAC7C,CAAC;KACF,CAAC;AACJ,CAAC;AAhKD,kCAgKC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { InstallSnapOptions } from '@metamask/snaps-simulation';\nimport {\n JsonRpcMockOptionsStruct,\n SignatureOptionsStruct,\n handleRequest,\n TransactionOptionsStruct,\n addJsonRpcMock,\n removeJsonRpcMock,\n SnapResponseWithInterfaceStruct,\n} from '@metamask/snaps-simulation';\nimport { HandlerType, logInfo } from '@metamask/snaps-utils';\nimport { create } from '@metamask/superstruct';\nimport { assertStruct, createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger, getEnvironment } from './internals';\nimport type {\n SnapResponseWithInterface,\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 * Ensure that the actual response contains `getInterface`.\n *\n * @param response - The response of the handler.\n */\nfunction assertIsResponseWithInterface(\n response: SnapResponse,\n): asserts response is SnapResponseWithInterface {\n assertStruct(response, SnapResponseWithInterfaceStruct);\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<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await 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 assertIsResponseWithInterface(response);\n\n return response;\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 (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await 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 assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\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"]}
|
|
1
|
+
{"version":3,"file":"helpers.cjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAGA,uDAAgD;AAChD,2CAAqD;AAErD,qDAAyD;AAEzD,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,SAAS,CAAC,CAAC;AAEtD;;;;;;GAMG;AACH,SAAS,UAAU,CAKjB,MAAiE,EACjE,OAA6C;IAE7C,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC3B,CAAC;AAqGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACI,KAAK,UAAU,WAAW,CAK/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpD,MAAM,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,UAAU,EACV,WAAW,EACX,KAAK,GACN,GAAG,MAAM,IAAA,0BAAc,GAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;IAE3D,OAAO;QACL,OAAO;QACP,aAAa;QACb,eAAe;QACf,WAAW;QACX,SAAS;QACT,UAAU;QACV,UAAU;QACV,WAAW;QACX,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,IAAA,qBAAO,EACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,KAAK,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC;AAvCD,kCAuCC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { InstallSnapOptions, Snap } from '@metamask/snaps-simulation';\nimport { logInfo } from '@metamask/snaps-utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { rootLogger, getEnvironment } from './internals';\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 request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onHomePage,\n mockJsonRpc,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onHomePage,\n mockJsonRpc,\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 close();\n },\n };\n}\n"]}
|
package/dist/helpers.d.cts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
2
2
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
3
|
-
import type { InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
4
|
-
import type { Snap } from "./types/index.cjs";
|
|
3
|
+
import type { InstallSnapOptions, Snap } from "@metamask/snaps-simulation";
|
|
5
4
|
/**
|
|
6
5
|
* Load a snap into the environment. This is the main entry point for testing
|
|
7
6
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
package/dist/helpers.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"helpers.d.cts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,mCAAmC;AA8B3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EACD,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
package/dist/helpers.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
2
2
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
3
|
-
import type { InstallSnapOptions } from "@metamask/snaps-simulation";
|
|
4
|
-
import type { Snap } from "./types/index.mjs";
|
|
3
|
+
import type { InstallSnapOptions, Snap } from "@metamask/snaps-simulation";
|
|
5
4
|
/**
|
|
6
5
|
* Load a snap into the environment. This is the main entry point for testing
|
|
7
6
|
* snaps: It returns a {@link Snap} object that can be used to interact with the
|
package/dist/helpers.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,
|
|
1
|
+
{"version":3,"file":"helpers.d.mts","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,mCAAmC;AA8B3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EACD,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,YAAY,CAClD,OAAO,wBAAwB,CAChC,EAED,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAAC"}
|