@metamask/snaps-jest 8.3.0 → 8.3.1
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 +11 -2
- package/dist/environment.cjs +96 -0
- package/dist/environment.cjs.map +1 -0
- package/dist/{types/environment.d.ts → environment.d.cts} +5 -4
- package/dist/environment.d.cts.map +1 -0
- package/dist/environment.d.mts +53 -0
- package/dist/environment.d.mts.map +1 -0
- package/dist/environment.mjs +94 -44
- package/dist/environment.mjs.map +1 -1
- package/dist/global.cjs +4 -0
- package/dist/global.cjs.map +1 -0
- package/dist/{types/global.d.ts → global.d.cts} +2 -1
- package/dist/global.d.cts.map +1 -0
- package/dist/global.d.mts +70 -0
- package/dist/global.d.mts.map +1 -0
- package/dist/global.mjs +2 -1
- package/dist/global.mjs.map +1 -1
- package/dist/helpers.cjs +240 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/{types/helpers.d.ts → helpers.d.cts} +5 -4
- package/dist/helpers.d.cts.map +1 -0
- package/dist/helpers.d.mts +132 -0
- package/dist/helpers.d.mts.map +1 -0
- package/dist/helpers.mjs +228 -56
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +29 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -67
- package/dist/index.mjs.map +1 -1
- package/dist/internals/environment.cjs +18 -0
- package/dist/internals/environment.cjs.map +1 -0
- package/dist/{types/internals/environment.d.ts → internals/environment.d.cts} +1 -0
- package/dist/internals/environment.d.cts.map +1 -0
- package/dist/internals/environment.d.mts +8 -0
- package/dist/internals/environment.d.mts.map +1 -0
- package/dist/internals/environment.mjs +13 -7
- package/dist/internals/environment.mjs.map +1 -1
- package/dist/internals/index.cjs +23 -0
- package/dist/internals/index.cjs.map +1 -0
- package/dist/internals/index.d.cts +7 -0
- package/dist/internals/index.d.cts.map +1 -0
- package/dist/internals/index.d.mts +7 -0
- package/dist/internals/index.d.mts.map +1 -0
- package/dist/internals/index.mjs +6 -149
- package/dist/internals/index.mjs.map +1 -1
- package/dist/internals/logger.cjs +6 -0
- package/dist/internals/logger.cjs.map +1 -0
- package/dist/{types/internals/logger.d.ts → internals/logger.d.cts} +1 -0
- package/dist/internals/logger.d.cts.map +1 -0
- package/dist/internals/logger.d.mts +3 -0
- package/dist/internals/logger.d.mts.map +1 -0
- package/dist/internals/logger.mjs +2 -7
- package/dist/internals/logger.mjs.map +1 -1
- package/dist/internals/request.cjs +143 -0
- package/dist/internals/request.cjs.map +1 -0
- package/dist/{types/internals/request.d.ts → internals/request.d.cts} +7 -6
- package/dist/internals/request.d.cts.map +1 -0
- package/dist/internals/request.d.mts +56 -0
- package/dist/internals/request.d.mts.map +1 -0
- package/dist/internals/request.mjs +137 -41
- package/dist/internals/request.mjs.map +1 -1
- package/dist/internals/server.cjs +74 -0
- package/dist/internals/server.cjs.map +1 -0
- package/dist/{types/internals/server.d.ts → internals/server.d.cts} +3 -2
- package/dist/internals/server.d.cts.map +1 -0
- package/dist/internals/server.d.mts +15 -0
- package/dist/internals/server.d.mts.map +1 -0
- package/dist/internals/server.mjs +73 -8
- package/dist/internals/server.mjs.map +1 -1
- package/dist/internals/simulation/constants.cjs +21 -0
- package/dist/internals/simulation/constants.cjs.map +1 -0
- package/dist/{types/internals/simulation/constants.d.ts → internals/simulation/constants.d.cts} +1 -0
- package/dist/internals/simulation/constants.d.cts.map +1 -0
- package/dist/internals/simulation/constants.d.mts +18 -0
- package/dist/internals/simulation/constants.d.mts.map +1 -0
- package/dist/internals/simulation/constants.mjs +17 -13
- package/dist/internals/simulation/constants.mjs.map +1 -1
- package/dist/internals/simulation/controllers.cjs +101 -0
- package/dist/internals/simulation/controllers.cjs.map +1 -0
- package/dist/{types/internals/simulation/controllers.d.ts → internals/simulation/controllers.d.cts} +11 -10
- package/dist/internals/simulation/controllers.d.cts.map +1 -0
- package/dist/internals/simulation/controllers.d.mts +41 -0
- package/dist/internals/simulation/controllers.d.mts.map +1 -0
- package/dist/internals/simulation/controllers.mjs +95 -24
- package/dist/internals/simulation/controllers.mjs.map +1 -1
- package/dist/internals/simulation/files.cjs +94 -0
- package/dist/internals/simulation/files.cjs.map +1 -0
- package/dist/{types/internals/simulation/files.d.ts → internals/simulation/files.d.cts} +6 -4
- package/dist/internals/simulation/files.d.cts.map +1 -0
- package/dist/internals/simulation/files.d.mts +49 -0
- package/dist/internals/simulation/files.d.mts.map +1 -0
- package/dist/internals/simulation/files.mjs +90 -13
- package/dist/internals/simulation/files.mjs.map +1 -1
- package/dist/internals/simulation/index.cjs +22 -0
- package/dist/internals/simulation/index.cjs.map +1 -0
- package/dist/internals/simulation/index.d.cts +6 -0
- package/dist/internals/simulation/index.d.cts.map +1 -0
- package/dist/internals/simulation/index.d.mts +6 -0
- package/dist/internals/simulation/index.d.mts.map +1 -0
- package/dist/internals/simulation/index.mjs +5 -110
- package/dist/internals/simulation/index.mjs.map +1 -1
- package/dist/internals/simulation/interface.cjs +527 -0
- package/dist/internals/simulation/interface.cjs.map +1 -0
- package/dist/{types/internals/simulation/interface.d.ts → internals/simulation/interface.d.cts} +9 -8
- package/dist/internals/simulation/interface.d.cts.map +1 -0
- package/dist/internals/simulation/interface.d.mts +152 -0
- package/dist/internals/simulation/interface.d.mts.map +1 -0
- package/dist/internals/simulation/interface.mjs +512 -36
- package/dist/internals/simulation/interface.mjs.map +1 -1
- package/dist/internals/simulation/methods/constants.cjs +72 -0
- package/dist/internals/simulation/methods/constants.cjs.map +1 -0
- package/dist/{types/internals/simulation/methods/constants.d.ts → internals/simulation/methods/constants.d.cts} +1 -0
- package/dist/internals/simulation/methods/constants.d.cts.map +1 -0
- package/dist/internals/simulation/methods/constants.d.mts +11 -0
- package/dist/internals/simulation/methods/constants.d.mts.map +1 -0
- package/dist/internals/simulation/methods/constants.mjs +68 -11
- package/dist/internals/simulation/methods/constants.mjs.map +1 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.cjs +18 -0
- package/dist/internals/simulation/methods/hooks/get-preferences.cjs.map +1 -0
- package/dist/{types/internals/simulation/methods/hooks/get-preferences.d.ts → internals/simulation/methods/hooks/get-preferences.d.cts} +2 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.d.cts.map +1 -0
- package/dist/internals/simulation/methods/hooks/get-preferences.d.mts +14 -0
- package/dist/internals/simulation/methods/hooks/get-preferences.d.mts.map +1 -0
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs +13 -7
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs.map +1 -1
- package/dist/internals/simulation/methods/hooks/index.cjs +22 -0
- package/dist/internals/simulation/methods/hooks/index.cjs.map +1 -0
- package/dist/internals/simulation/methods/hooks/index.d.cts +6 -0
- package/dist/internals/simulation/methods/hooks/index.d.cts.map +1 -0
- package/dist/internals/simulation/methods/hooks/index.d.mts +6 -0
- package/dist/internals/simulation/methods/hooks/index.d.mts.map +1 -0
- package/dist/internals/simulation/methods/hooks/index.mjs +5 -38
- package/dist/internals/simulation/methods/hooks/index.mjs.map +1 -1
- package/dist/internals/simulation/methods/hooks/interface.cjs +24 -0
- package/dist/internals/simulation/methods/hooks/interface.cjs.map +1 -0
- package/dist/{types/internals/simulation/methods/hooks/interface.d.ts → internals/simulation/methods/hooks/interface.d.cts} +3 -2
- package/dist/internals/simulation/methods/hooks/interface.d.cts.map +1 -0
- package/dist/internals/simulation/methods/hooks/interface.d.mts +17 -0
- package/dist/internals/simulation/methods/hooks/interface.d.mts.map +1 -0
- package/dist/internals/simulation/methods/hooks/interface.mjs +18 -9
- package/dist/internals/simulation/methods/hooks/interface.mjs.map +1 -1
- package/dist/internals/simulation/methods/hooks/notifications.cjs +58 -0
- package/dist/internals/simulation/methods/hooks/notifications.cjs.map +1 -0
- package/dist/{types/internals/simulation/methods/hooks/notifications.d.ts → internals/simulation/methods/hooks/notifications.d.cts} +5 -4
- package/dist/internals/simulation/methods/hooks/notifications.d.cts.map +1 -0
- package/dist/internals/simulation/methods/hooks/notifications.d.mts +17 -0
- package/dist/internals/simulation/methods/hooks/notifications.d.mts.map +1 -0
- package/dist/internals/simulation/methods/hooks/notifications.mjs +54 -15
- package/dist/internals/simulation/methods/hooks/notifications.mjs.map +1 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.cjs +38 -0
- package/dist/internals/simulation/methods/hooks/request-user-approval.cjs.map +1 -0
- package/dist/{types/internals/simulation/methods/hooks/request-user-approval.d.ts → internals/simulation/methods/hooks/request-user-approval.d.cts} +2 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts.map +1 -0
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts +16 -0
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts.map +1 -0
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +34 -13
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs.map +1 -1
- package/dist/internals/simulation/methods/hooks/state.cjs +84 -0
- package/dist/internals/simulation/methods/hooks/state.cjs.map +1 -0
- package/dist/{types/internals/simulation/methods/hooks/state.d.ts → internals/simulation/methods/hooks/state.d.cts} +3 -2
- package/dist/internals/simulation/methods/hooks/state.d.cts.map +1 -0
- package/dist/internals/simulation/methods/hooks/state.d.mts +24 -0
- package/dist/internals/simulation/methods/hooks/state.d.mts.map +1 -0
- package/dist/internals/simulation/methods/hooks/state.mjs +78 -17
- package/dist/internals/simulation/methods/hooks/state.mjs.map +1 -1
- package/dist/internals/simulation/methods/index.cjs +18 -0
- package/dist/internals/simulation/methods/index.cjs.map +1 -0
- package/dist/internals/simulation/methods/index.d.cts +2 -0
- package/dist/internals/simulation/methods/index.d.cts.map +1 -0
- package/dist/internals/simulation/methods/index.d.mts +2 -0
- package/dist/internals/simulation/methods/index.d.mts.map +1 -0
- package/dist/internals/simulation/methods/index.mjs +1 -27
- package/dist/internals/simulation/methods/index.mjs.map +1 -1
- package/dist/internals/simulation/methods/specifications.cjs +85 -0
- package/dist/internals/simulation/methods/specifications.cjs.map +1 -0
- package/dist/{types/internals/simulation/methods/specifications.d.ts → internals/simulation/methods/specifications.d.cts} +6 -5
- package/dist/internals/simulation/methods/specifications.d.cts.map +1 -0
- package/dist/internals/simulation/methods/specifications.d.mts +57 -0
- package/dist/internals/simulation/methods/specifications.d.mts.map +1 -0
- package/dist/internals/simulation/methods/specifications.mjs +77 -26
- package/dist/internals/simulation/methods/specifications.mjs.map +1 -1
- package/dist/internals/simulation/middleware/engine.cjs +37 -0
- package/dist/internals/simulation/middleware/engine.cjs.map +1 -0
- package/dist/{types/internals/simulation/middleware/engine.d.ts → internals/simulation/middleware/engine.d.cts} +7 -6
- package/dist/internals/simulation/middleware/engine.d.cts.map +1 -0
- package/dist/internals/simulation/middleware/engine.d.mts +27 -0
- package/dist/internals/simulation/middleware/engine.d.mts.map +1 -0
- package/dist/internals/simulation/middleware/engine.mjs +33 -14
- package/dist/internals/simulation/middleware/engine.mjs.map +1 -1
- package/dist/internals/simulation/middleware/index.cjs +18 -0
- package/dist/internals/simulation/middleware/index.cjs.map +1 -0
- package/dist/internals/simulation/middleware/index.d.cts +2 -0
- package/dist/internals/simulation/middleware/index.d.cts.map +1 -0
- package/dist/internals/simulation/middleware/index.d.mts +2 -0
- package/dist/internals/simulation/middleware/index.d.mts.map +1 -0
- package/dist/internals/simulation/middleware/index.mjs +1 -15
- package/dist/internals/simulation/middleware/index.mjs.map +1 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.cjs +34 -0
- package/dist/internals/simulation/middleware/internal-methods/accounts.cjs.map +1 -0
- package/dist/{types/internals/simulation/middleware/internal-methods/accounts.d.ts → internals/simulation/middleware/internal-methods/accounts.d.cts} +4 -2
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts +20 -0
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs +29 -7
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs.map +1 -1
- package/dist/internals/simulation/middleware/internal-methods/index.cjs +18 -0
- package/dist/internals/simulation/middleware/internal-methods/index.cjs.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/index.d.cts +2 -0
- package/dist/internals/simulation/middleware/internal-methods/index.d.cts.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/index.d.mts +2 -0
- package/dist/internals/simulation/middleware/internal-methods/index.d.mts.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/index.mjs +1 -10
- package/dist/internals/simulation/middleware/internal-methods/index.mjs.map +1 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.cjs +44 -0
- package/dist/internals/simulation/middleware/internal-methods/middleware.cjs.map +1 -0
- package/dist/{types/internals/simulation/middleware/internal-methods/middleware.d.ts → internals/simulation/middleware/internal-methods/middleware.d.cts} +3 -2
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts +23 -0
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs +38 -8
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs.map +1 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs +28 -0
- package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs.map +1 -0
- package/dist/{types/internals/simulation/middleware/internal-methods/provider-state.d.ts → internals/simulation/middleware/internal-methods/provider-state.d.cts} +4 -2
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts +16 -0
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs +23 -7
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs.map +1 -1
- package/dist/internals/simulation/middleware/mock.cjs +22 -0
- package/dist/internals/simulation/middleware/mock.cjs.map +1 -0
- package/dist/{types/internals/simulation/middleware/mock.d.ts → internals/simulation/middleware/mock.d.cts} +4 -3
- package/dist/internals/simulation/middleware/mock.d.cts.map +1 -0
- package/dist/internals/simulation/middleware/mock.d.mts +11 -0
- package/dist/internals/simulation/middleware/mock.d.mts.map +1 -0
- package/dist/internals/simulation/middleware/mock.mjs +17 -8
- package/dist/internals/simulation/middleware/mock.mjs.map +1 -1
- package/dist/internals/simulation/options.cjs +25 -0
- package/dist/internals/simulation/options.cjs.map +1 -0
- package/dist/{types/internals/simulation/options.d.ts → internals/simulation/options.d.cts} +3 -2
- package/dist/internals/simulation/options.d.cts.map +1 -0
- package/dist/internals/simulation/options.d.mts +40 -0
- package/dist/internals/simulation/options.d.mts.map +1 -0
- package/dist/internals/simulation/options.mjs +20 -8
- package/dist/internals/simulation/options.mjs.map +1 -1
- package/dist/internals/simulation/simulation.cjs +155 -0
- package/dist/internals/simulation/simulation.cjs.map +1 -0
- package/dist/{types/internals/simulation/simulation.d.ts → internals/simulation/simulation.d.cts} +11 -9
- package/dist/internals/simulation/simulation.d.cts.map +1 -0
- package/dist/internals/simulation/simulation.d.mts +103 -0
- package/dist/internals/simulation/simulation.d.mts.map +1 -0
- package/dist/internals/simulation/simulation.mjs +149 -38
- package/dist/internals/simulation/simulation.mjs.map +1 -1
- package/dist/internals/simulation/store/index.cjs +21 -0
- package/dist/internals/simulation/store/index.cjs.map +1 -0
- package/dist/internals/simulation/store/index.d.cts +5 -0
- package/dist/internals/simulation/store/index.d.cts.map +1 -0
- package/dist/internals/simulation/store/index.d.mts +5 -0
- package/dist/internals/simulation/store/index.d.mts.map +1 -0
- package/dist/internals/simulation/store/index.mjs +4 -43
- package/dist/internals/simulation/store/index.mjs.map +1 -1
- package/dist/internals/simulation/store/mocks.cjs +39 -0
- package/dist/internals/simulation/store/mocks.cjs.map +1 -0
- package/dist/{types/internals/simulation/store/mocks.d.ts → internals/simulation/store/mocks.d.cts} +6 -5
- package/dist/internals/simulation/store/mocks.d.cts.map +1 -0
- package/dist/internals/simulation/store/mocks.d.mts +36 -0
- package/dist/internals/simulation/store/mocks.d.mts.map +1 -0
- package/dist/internals/simulation/store/mocks.mjs +33 -14
- package/dist/internals/simulation/store/mocks.mjs.map +1 -1
- package/dist/internals/simulation/store/notifications.cjs +35 -0
- package/dist/internals/simulation/store/notifications.cjs.map +1 -0
- package/dist/{types/internals/simulation/store/notifications.d.ts → internals/simulation/store/notifications.d.cts} +6 -5
- package/dist/internals/simulation/store/notifications.d.cts.map +1 -0
- package/dist/internals/simulation/store/notifications.d.mts +45 -0
- package/dist/internals/simulation/store/notifications.d.mts.map +1 -0
- package/dist/internals/simulation/store/notifications.mjs +30 -14
- package/dist/internals/simulation/store/notifications.mjs.map +1 -1
- package/dist/internals/simulation/store/state.cjs +54 -0
- package/dist/internals/simulation/store/state.cjs.map +1 -0
- package/dist/{types/internals/simulation/store/state.d.ts → internals/simulation/store/state.d.cts} +6 -5
- package/dist/internals/simulation/store/state.d.cts.map +1 -0
- package/dist/internals/simulation/store/state.d.mts +56 -0
- package/dist/internals/simulation/store/state.d.mts.map +1 -0
- package/dist/internals/simulation/store/state.mjs +48 -12
- package/dist/internals/simulation/store/state.mjs.map +1 -1
- package/dist/internals/simulation/store/store.cjs +51 -0
- package/dist/internals/simulation/store/store.cjs.map +1 -0
- package/dist/{types/internals/simulation/store/store.d.ts → internals/simulation/store/store.d.cts} +2 -1
- package/dist/internals/simulation/store/store.d.cts.map +1 -0
- package/dist/internals/simulation/store/store.d.mts +22 -0
- package/dist/internals/simulation/store/store.d.mts.map +1 -0
- package/dist/internals/simulation/store/store.mjs +44 -11
- package/dist/internals/simulation/store/store.mjs.map +1 -1
- package/dist/internals/simulation/store/ui.cjs +24 -0
- package/dist/internals/simulation/store/ui.cjs.map +1 -0
- package/dist/{types/internals/simulation/store/ui.d.ts → internals/simulation/store/ui.d.cts} +6 -5
- package/dist/internals/simulation/store/ui.d.cts.map +1 -0
- package/dist/internals/simulation/store/ui.d.mts +27 -0
- package/dist/internals/simulation/store/ui.d.mts.map +1 -0
- package/dist/internals/simulation/store/ui.mjs +19 -14
- package/dist/internals/simulation/store/ui.mjs.map +1 -1
- package/dist/internals/structs.cjs +157 -0
- package/dist/internals/structs.cjs.map +1 -0
- package/dist/{types/internals/structs.d.ts → internals/structs.d.cts} +28 -27
- package/dist/internals/structs.d.cts.map +1 -0
- package/dist/internals/structs.d.mts +205 -0
- package/dist/internals/structs.d.mts.map +1 -0
- package/dist/internals/structs.mjs +153 -21
- package/dist/internals/structs.mjs.map +1 -1
- package/dist/matchers.cjs +160 -0
- package/dist/matchers.cjs.map +1 -0
- package/dist/{types/matchers.d.ts → matchers.d.cts} +4 -3
- package/dist/matchers.d.cts.map +1 -0
- package/dist/matchers.d.mts +28 -0
- package/dist/matchers.d.mts.map +1 -0
- package/dist/matchers.mjs +152 -47
- package/dist/matchers.mjs.map +1 -1
- package/dist/options.cjs +24 -0
- package/dist/options.cjs.map +1 -0
- package/dist/{types/options.d.ts → options.d.cts} +2 -1
- package/dist/options.d.cts.map +1 -0
- package/dist/options.d.mts +61 -0
- package/dist/options.d.mts.map +1 -0
- package/dist/options.mjs +19 -7
- package/dist/options.mjs.map +1 -1
- package/dist/setup.cjs +7 -0
- package/dist/setup.cjs.map +1 -0
- package/dist/setup.d.cts +2 -0
- package/dist/setup.d.cts.map +1 -0
- package/dist/setup.d.mts +2 -0
- package/dist/setup.d.mts.map +1 -0
- package/dist/setup.mjs +4 -37
- package/dist/setup.mjs.map +1 -1
- package/dist/types/index.cjs +18 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +2 -0
- package/dist/types/index.d.cts.map +1 -0
- package/dist/types/index.d.mts +2 -0
- package/dist/types/index.d.mts.map +1 -0
- package/dist/types/index.mjs +2 -0
- package/dist/types/index.mjs.map +1 -0
- package/dist/types/types.cjs +3 -0
- package/dist/types/types.cjs.map +1 -0
- package/dist/types/{types.d.ts → types.d.cts} +7 -6
- package/dist/types/types.d.cts.map +1 -0
- package/dist/types/types.d.mts +386 -0
- package/dist/types/types.d.mts.map +1 -0
- package/dist/types/types.mjs +2 -0
- package/dist/types/types.mjs.map +1 -0
- package/jest-preset.js +1 -1
- package/package.json +25 -23
- package/dist/chunk-24CGIQLL.mjs +0 -30
- package/dist/chunk-24CGIQLL.mjs.map +0 -1
- package/dist/chunk-2JTGBHPR.js +0 -14
- package/dist/chunk-2JTGBHPR.js.map +0 -1
- package/dist/chunk-2RJYSYUB.js +0 -28
- package/dist/chunk-2RJYSYUB.js.map +0 -1
- package/dist/chunk-2YE2P5BZ.js +0 -36
- package/dist/chunk-2YE2P5BZ.js.map +0 -1
- package/dist/chunk-3FNLFVV2.js +0 -15
- package/dist/chunk-3FNLFVV2.js.map +0 -1
- package/dist/chunk-3J2IBWXV.mjs +0 -39
- package/dist/chunk-3J2IBWXV.mjs.map +0 -1
- package/dist/chunk-3NP6BDGK.js +0 -167
- package/dist/chunk-3NP6BDGK.js.map +0 -1
- package/dist/chunk-55J6XMHW.js +0 -1
- package/dist/chunk-55J6XMHW.js.map +0 -1
- package/dist/chunk-57SGDM5B.mjs +0 -69
- package/dist/chunk-57SGDM5B.mjs.map +0 -1
- package/dist/chunk-5U5WB3SM.mjs +0 -41
- package/dist/chunk-5U5WB3SM.mjs.map +0 -1
- package/dist/chunk-5ZFHFICZ.mjs +0 -1
- package/dist/chunk-5ZFHFICZ.mjs.map +0 -1
- package/dist/chunk-6HHV6YFQ.mjs +0 -1
- package/dist/chunk-6HHV6YFQ.mjs.map +0 -1
- package/dist/chunk-6JPBXAHM.mjs +0 -509
- package/dist/chunk-6JPBXAHM.mjs.map +0 -1
- package/dist/chunk-6V6MFT67.js +0 -38
- package/dist/chunk-6V6MFT67.js.map +0 -1
- package/dist/chunk-7PCHIR6O.mjs +0 -181
- package/dist/chunk-7PCHIR6O.mjs.map +0 -1
- package/dist/chunk-ALRZENWP.mjs +0 -42
- package/dist/chunk-ALRZENWP.mjs.map +0 -1
- package/dist/chunk-AMAL4SJH.js +0 -153
- package/dist/chunk-AMAL4SJH.js.map +0 -1
- package/dist/chunk-C26TYXXD.mjs +0 -240
- package/dist/chunk-C26TYXXD.mjs.map +0 -1
- package/dist/chunk-CACRY3TX.mjs +0 -104
- package/dist/chunk-CACRY3TX.mjs.map +0 -1
- package/dist/chunk-CKRORVDW.js +0 -1
- package/dist/chunk-CKRORVDW.js.map +0 -1
- package/dist/chunk-D653LBAY.js +0 -34
- package/dist/chunk-D653LBAY.js.map +0 -1
- package/dist/chunk-DR6Y7IVX.js +0 -1
- package/dist/chunk-DR6Y7IVX.js.map +0 -1
- package/dist/chunk-DUVKGPX5.js +0 -509
- package/dist/chunk-DUVKGPX5.js.map +0 -1
- package/dist/chunk-EMTW3H54.js +0 -20
- package/dist/chunk-EMTW3H54.js.map +0 -1
- package/dist/chunk-FP4H3ADT.mjs +0 -20
- package/dist/chunk-FP4H3ADT.mjs.map +0 -1
- package/dist/chunk-FQWOVTBB.mjs +0 -22
- package/dist/chunk-FQWOVTBB.mjs.map +0 -1
- package/dist/chunk-G333FBBL.mjs +0 -38
- package/dist/chunk-G333FBBL.mjs.map +0 -1
- package/dist/chunk-GECE47HW.js +0 -1
- package/dist/chunk-GECE47HW.js.map +0 -1
- package/dist/chunk-GLPGOEVE.js +0 -240
- package/dist/chunk-GLPGOEVE.js.map +0 -1
- package/dist/chunk-GMTKFAWO.js +0 -42
- package/dist/chunk-GMTKFAWO.js.map +0 -1
- package/dist/chunk-H2464AXT.mjs +0 -33
- package/dist/chunk-H2464AXT.mjs.map +0 -1
- package/dist/chunk-HROOL3VI.js +0 -1
- package/dist/chunk-HROOL3VI.js.map +0 -1
- package/dist/chunk-IWJ4HKDR.mjs +0 -50
- package/dist/chunk-IWJ4HKDR.mjs.map +0 -1
- package/dist/chunk-IXKO6X55.mjs +0 -15
- package/dist/chunk-IXKO6X55.mjs.map +0 -1
- package/dist/chunk-J3I5KZIF.js +0 -22
- package/dist/chunk-J3I5KZIF.js.map +0 -1
- package/dist/chunk-J4ZPUCLX.mjs +0 -8
- package/dist/chunk-J4ZPUCLX.mjs.map +0 -1
- package/dist/chunk-JMDSN227.mjs +0 -25
- package/dist/chunk-JMDSN227.mjs.map +0 -1
- package/dist/chunk-K7MK6LQU.js +0 -54
- package/dist/chunk-K7MK6LQU.js.map +0 -1
- package/dist/chunk-KIQOUUEZ.mjs +0 -1
- package/dist/chunk-KIQOUUEZ.mjs.map +0 -1
- package/dist/chunk-KOPPL55J.mjs +0 -28
- package/dist/chunk-KOPPL55J.mjs.map +0 -1
- package/dist/chunk-KPRLFCKD.js +0 -13
- package/dist/chunk-KPRLFCKD.js.map +0 -1
- package/dist/chunk-LACTK6EO.js +0 -33
- package/dist/chunk-LACTK6EO.js.map +0 -1
- package/dist/chunk-LB4R3BUA.mjs +0 -36
- package/dist/chunk-LB4R3BUA.mjs.map +0 -1
- package/dist/chunk-LBC2OGSN.js +0 -48
- package/dist/chunk-LBC2OGSN.js.map +0 -1
- package/dist/chunk-LPMHPAZK.js +0 -203
- package/dist/chunk-LPMHPAZK.js.map +0 -1
- package/dist/chunk-LSKT2AUS.mjs +0 -97
- package/dist/chunk-LSKT2AUS.mjs.map +0 -1
- package/dist/chunk-LVNNGMJ2.mjs +0 -13
- package/dist/chunk-LVNNGMJ2.mjs.map +0 -1
- package/dist/chunk-MF43OG3Z.mjs +0 -1
- package/dist/chunk-MF43OG3Z.mjs.map +0 -1
- package/dist/chunk-MPZOXW6I.mjs +0 -48
- package/dist/chunk-MPZOXW6I.mjs.map +0 -1
- package/dist/chunk-N6MAO223.js +0 -60
- package/dist/chunk-N6MAO223.js.map +0 -1
- package/dist/chunk-NTOY6Y4Q.mjs +0 -1
- package/dist/chunk-NTOY6Y4Q.mjs.map +0 -1
- package/dist/chunk-OHRFO2BL.mjs +0 -89
- package/dist/chunk-OHRFO2BL.mjs.map +0 -1
- package/dist/chunk-OO6IVUCV.js +0 -104
- package/dist/chunk-OO6IVUCV.js.map +0 -1
- package/dist/chunk-ORR7AE5X.mjs +0 -54
- package/dist/chunk-ORR7AE5X.mjs.map +0 -1
- package/dist/chunk-PDOVVC74.mjs +0 -153
- package/dist/chunk-PDOVVC74.mjs.map +0 -1
- package/dist/chunk-PHUTP7NB.js +0 -25
- package/dist/chunk-PHUTP7NB.js.map +0 -1
- package/dist/chunk-Q2OQXAUM.mjs +0 -35
- package/dist/chunk-Q2OQXAUM.mjs.map +0 -1
- package/dist/chunk-Q3I6P2ZF.mjs +0 -167
- package/dist/chunk-Q3I6P2ZF.mjs.map +0 -1
- package/dist/chunk-QRVFWATH.mjs +0 -14
- package/dist/chunk-QRVFWATH.mjs.map +0 -1
- package/dist/chunk-QYHQ2WWX.js +0 -89
- package/dist/chunk-QYHQ2WWX.js.map +0 -1
- package/dist/chunk-RJNNNCZJ.js +0 -39
- package/dist/chunk-RJNNNCZJ.js.map +0 -1
- package/dist/chunk-ROCGQYSK.mjs +0 -203
- package/dist/chunk-ROCGQYSK.mjs.map +0 -1
- package/dist/chunk-RQKT6BQ2.mjs +0 -1
- package/dist/chunk-RQKT6BQ2.mjs.map +0 -1
- package/dist/chunk-S2HLITUN.js +0 -1
- package/dist/chunk-S2HLITUN.js.map +0 -1
- package/dist/chunk-SB5EPHE3.js +0 -41
- package/dist/chunk-SB5EPHE3.js.map +0 -1
- package/dist/chunk-SLU4FNKX.mjs +0 -60
- package/dist/chunk-SLU4FNKX.mjs.map +0 -1
- package/dist/chunk-SNXRXX2O.js +0 -30
- package/dist/chunk-SNXRXX2O.js.map +0 -1
- package/dist/chunk-SW65QYFV.js +0 -50
- package/dist/chunk-SW65QYFV.js.map +0 -1
- package/dist/chunk-TGZ7WOTJ.mjs +0 -1
- package/dist/chunk-TGZ7WOTJ.mjs.map +0 -1
- package/dist/chunk-TZB4LBT7.js +0 -8
- package/dist/chunk-TZB4LBT7.js.map +0 -1
- package/dist/chunk-UDOXICJK.mjs +0 -1
- package/dist/chunk-UDOXICJK.mjs.map +0 -1
- package/dist/chunk-VHJZERIC.js +0 -1
- package/dist/chunk-VHJZERIC.js.map +0 -1
- package/dist/chunk-VOYBI6T4.mjs +0 -22
- package/dist/chunk-VOYBI6T4.mjs.map +0 -1
- package/dist/chunk-WDYPMEZB.js +0 -22
- package/dist/chunk-WDYPMEZB.js.map +0 -1
- package/dist/chunk-WHGYMK5B.js +0 -1
- package/dist/chunk-WHGYMK5B.js.map +0 -1
- package/dist/chunk-WZ57PU2K.js +0 -97
- package/dist/chunk-WZ57PU2K.js.map +0 -1
- package/dist/chunk-XAOCS6ZD.js +0 -69
- package/dist/chunk-XAOCS6ZD.js.map +0 -1
- package/dist/chunk-XK5HPZZC.mjs +0 -14
- package/dist/chunk-XK5HPZZC.mjs.map +0 -1
- package/dist/chunk-XP4YGQJA.js +0 -14
- package/dist/chunk-XP4YGQJA.js.map +0 -1
- package/dist/chunk-Y2U3ZPCK.js +0 -181
- package/dist/chunk-Y2U3ZPCK.js.map +0 -1
- package/dist/chunk-Y3JC4WGW.js +0 -35
- package/dist/chunk-Y3JC4WGW.js.map +0 -1
- package/dist/chunk-ZG33OGC3.mjs +0 -1
- package/dist/chunk-ZG33OGC3.mjs.map +0 -1
- package/dist/chunk-ZJQSGRNK.mjs +0 -34
- package/dist/chunk-ZJQSGRNK.mjs.map +0 -1
- package/dist/chunk-ZTX624YO.js +0 -1
- package/dist/chunk-ZTX624YO.js.map +0 -1
- package/dist/environment.js +0 -46
- package/dist/environment.js.map +0 -1
- package/dist/global.js +0 -2
- package/dist/global.js.map +0 -1
- package/dist/helpers.js +0 -57
- package/dist/helpers.js.map +0 -1
- package/dist/index.js +0 -68
- package/dist/index.js.map +0 -1
- package/dist/internals/environment.js +0 -8
- package/dist/internals/environment.js.map +0 -1
- package/dist/internals/index.js +0 -150
- package/dist/internals/index.js.map +0 -1
- package/dist/internals/logger.js +0 -8
- package/dist/internals/logger.js.map +0 -1
- package/dist/internals/request.js +0 -42
- package/dist/internals/request.js.map +0 -1
- package/dist/internals/server.js +0 -9
- package/dist/internals/server.js.map +0 -1
- package/dist/internals/simulation/constants.js +0 -14
- package/dist/internals/simulation/constants.js.map +0 -1
- package/dist/internals/simulation/controllers.js +0 -25
- package/dist/internals/simulation/controllers.js.map +0 -1
- package/dist/internals/simulation/files.js +0 -14
- package/dist/internals/simulation/files.js.map +0 -1
- package/dist/internals/simulation/index.js +0 -111
- package/dist/internals/simulation/index.js.map +0 -1
- package/dist/internals/simulation/interface.js +0 -37
- package/dist/internals/simulation/interface.js.map +0 -1
- package/dist/internals/simulation/methods/constants.js +0 -12
- package/dist/internals/simulation/methods/constants.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.js +0 -8
- package/dist/internals/simulation/methods/hooks/get-preferences.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.js +0 -39
- package/dist/internals/simulation/methods/hooks/index.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.js +0 -10
- package/dist/internals/simulation/methods/hooks/interface.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.js +0 -16
- package/dist/internals/simulation/methods/hooks/notifications.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.js +0 -14
- package/dist/internals/simulation/methods/hooks/request-user-approval.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.js +0 -18
- package/dist/internals/simulation/methods/hooks/state.js.map +0 -1
- package/dist/internals/simulation/methods/index.js +0 -28
- package/dist/internals/simulation/methods/index.js.map +0 -1
- package/dist/internals/simulation/methods/specifications.js +0 -27
- package/dist/internals/simulation/methods/specifications.js.map +0 -1
- package/dist/internals/simulation/middleware/engine.js +0 -15
- package/dist/internals/simulation/middleware/engine.js.map +0 -1
- package/dist/internals/simulation/middleware/index.js +0 -16
- package/dist/internals/simulation/middleware/index.js.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.js +0 -8
- package/dist/internals/simulation/middleware/internal-methods/accounts.js.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.js +0 -11
- package/dist/internals/simulation/middleware/internal-methods/index.js.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.js +0 -10
- package/dist/internals/simulation/middleware/internal-methods/middleware.js.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.js +0 -8
- package/dist/internals/simulation/middleware/internal-methods/provider-state.js.map +0 -1
- package/dist/internals/simulation/middleware/mock.js +0 -9
- package/dist/internals/simulation/middleware/mock.js.map +0 -1
- package/dist/internals/simulation/options.js +0 -9
- package/dist/internals/simulation/options.js.map +0 -1
- package/dist/internals/simulation/simulation.js +0 -39
- package/dist/internals/simulation/simulation.js.map +0 -1
- package/dist/internals/simulation/store/index.js +0 -44
- package/dist/internals/simulation/store/index.js.map +0 -1
- package/dist/internals/simulation/store/mocks.js +0 -16
- package/dist/internals/simulation/store/mocks.js.map +0 -1
- package/dist/internals/simulation/store/notifications.js +0 -16
- package/dist/internals/simulation/store/notifications.js.map +0 -1
- package/dist/internals/simulation/store/state.js +0 -14
- package/dist/internals/simulation/store/state.js.map +0 -1
- package/dist/internals/simulation/store/store.js +0 -12
- package/dist/internals/simulation/store/store.js.map +0 -1
- package/dist/internals/simulation/store/ui.js +0 -16
- package/dist/internals/simulation/store/ui.js.map +0 -1
- package/dist/internals/structs.js +0 -22
- package/dist/internals/structs.js.map +0 -1
- package/dist/matchers.js +0 -49
- package/dist/matchers.js.map +0 -1
- package/dist/options.js +0 -8
- package/dist/options.js.map +0 -1
- package/dist/setup.js +0 -38
- package/dist/setup.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/index.d.ts +0 -5
- package/dist/types/internals/index.d.ts +0 -6
- package/dist/types/internals/simulation/index.d.ts +0 -5
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +0 -5
- package/dist/types/internals/simulation/methods/index.d.ts +0 -1
- package/dist/types/internals/simulation/middleware/index.d.ts +0 -1
- package/dist/types/internals/simulation/middleware/internal-methods/index.d.ts +0 -1
- package/dist/types/internals/simulation/store/index.d.ts +0 -4
- package/dist/types/setup.d.ts +0 -1
- package/dist/types/vendor/readable-stream.d.js +0 -1
- package/dist/types/vendor/readable-stream.d.js.map +0 -1
- package/dist/types/vendor/readable-stream.d.mjs +0 -1
- package/dist/types/vendor/readable-stream.d.mjs.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/types.mjs +0 -2
- package/dist/types.mjs.map +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable no-invalid-this */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.toRender = exports.toSendNotification = exports.toRespondWithError = exports.toRespondWith = void 0;
|
|
5
|
+
const globals_1 = require("@jest/globals");
|
|
6
|
+
const jsx_1 = require("@metamask/snaps-sdk/jsx");
|
|
7
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
9
|
+
const utils_1 = require("@metamask/utils");
|
|
10
|
+
const jest_matcher_utils_1 = require("jest-matcher-utils");
|
|
11
|
+
const internals_1 = require("./internals/index.cjs");
|
|
12
|
+
/**
|
|
13
|
+
* Ensure that the actual value is a response from the `request` function.
|
|
14
|
+
*
|
|
15
|
+
* @param actual - The actual value.
|
|
16
|
+
* @param matcherName - The name of the matcher.
|
|
17
|
+
* @param options - The matcher options.
|
|
18
|
+
*/
|
|
19
|
+
function assertActualIsSnapResponse(actual, matcherName, options) {
|
|
20
|
+
if (!(0, superstruct_1.is)(actual, internals_1.SnapResponseStruct)) {
|
|
21
|
+
throw new Error((0, jest_matcher_utils_1.matcherErrorMessage)((0, jest_matcher_utils_1.matcherHint)(matcherName, undefined, undefined, options), `${(0, jest_matcher_utils_1.RECEIVED_COLOR)('received')} value must be a response from the \`request\` function`, (0, jest_matcher_utils_1.printWithType)('Received', actual, jest_matcher_utils_1.printReceived)));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Ensure that the actual value is a response from the `request` function, and
|
|
26
|
+
* that it has a `ui` property.
|
|
27
|
+
*
|
|
28
|
+
* @param actual - The actual value.
|
|
29
|
+
* @param matcherName - The name of the matcher.
|
|
30
|
+
* @param options - The matcher options.
|
|
31
|
+
*/
|
|
32
|
+
function assertHasInterface(actual, matcherName, options) {
|
|
33
|
+
if (!(0, superstruct_1.is)(actual, internals_1.InterfaceStruct) || !actual.content) {
|
|
34
|
+
throw new Error((0, jest_matcher_utils_1.matcherErrorMessage)((0, jest_matcher_utils_1.matcherHint)(matcherName, undefined, undefined, options), `${(0, jest_matcher_utils_1.RECEIVED_COLOR)('received')} value must have a \`content\` property`, (0, jest_matcher_utils_1.printWithType)('Received', actual, jest_matcher_utils_1.printReceived)));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Check if a JSON-RPC response matches the expected value. This matcher is
|
|
39
|
+
* intended to be used with the `expect` global.
|
|
40
|
+
*
|
|
41
|
+
* @param actual - The actual response.
|
|
42
|
+
* @param expected - The expected response.
|
|
43
|
+
* @returns The status and message.
|
|
44
|
+
*/
|
|
45
|
+
const toRespondWith = function (actual, expected) {
|
|
46
|
+
assertActualIsSnapResponse(actual, 'toRespondWith');
|
|
47
|
+
const { response } = actual;
|
|
48
|
+
if ((0, utils_1.hasProperty)(response, 'error')) {
|
|
49
|
+
const message = () => `${this.utils.matcherHint('.toRespondWith')}\n\n` +
|
|
50
|
+
`Expected response: ${this.utils.printExpected(expected)}\n` +
|
|
51
|
+
`Received error: ${this.utils.printReceived(response.error)}`;
|
|
52
|
+
return { message, pass: false };
|
|
53
|
+
}
|
|
54
|
+
const pass = this.equals(response.result, expected);
|
|
55
|
+
const message = pass
|
|
56
|
+
? () => `${this.utils.matcherHint('.not.toRespondWith')}\n\n` +
|
|
57
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
58
|
+
`Received: ${this.utils.printReceived(response.result)}`
|
|
59
|
+
: () => `${this.utils.matcherHint('.toRespondWith')}\n\n` +
|
|
60
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
61
|
+
`Received: ${this.utils.printReceived(response.result)}`;
|
|
62
|
+
return { message, pass };
|
|
63
|
+
};
|
|
64
|
+
exports.toRespondWith = toRespondWith;
|
|
65
|
+
const toRespondWithError = function (actual, expected) {
|
|
66
|
+
assertActualIsSnapResponse(actual, 'toRespondWithError');
|
|
67
|
+
const { response } = actual;
|
|
68
|
+
if ((0, utils_1.hasProperty)(response, 'result')) {
|
|
69
|
+
const message = () => `${this.utils.matcherHint('.toRespondWithError')}\n\n` +
|
|
70
|
+
`Expected error: ${this.utils.printExpected(expected)}\n` +
|
|
71
|
+
`Received result: ${this.utils.printReceived(response.result)}`;
|
|
72
|
+
return { message, pass: false };
|
|
73
|
+
}
|
|
74
|
+
const pass = this.equals(response.error, expected);
|
|
75
|
+
const message = pass
|
|
76
|
+
? () => `${this.utils.matcherHint('.not.toRespondWithError')}\n\n` +
|
|
77
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
78
|
+
`Received: ${this.utils.printReceived(response.error)}`
|
|
79
|
+
: () => `${this.utils.matcherHint('.toRespondWithError')}\n\n` +
|
|
80
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
81
|
+
`Received: ${this.utils.printReceived(response.error)}`;
|
|
82
|
+
return { message, pass };
|
|
83
|
+
};
|
|
84
|
+
exports.toRespondWithError = toRespondWithError;
|
|
85
|
+
/**
|
|
86
|
+
* Check if the snap sent a notification with the expected message. This matcher
|
|
87
|
+
* is intended to be used with the `expect` global.
|
|
88
|
+
*
|
|
89
|
+
* @param actual - The actual response.
|
|
90
|
+
* @param expected - The expected notification message.
|
|
91
|
+
* @param type - The expected notification type.
|
|
92
|
+
* @returns The status and message.
|
|
93
|
+
*/
|
|
94
|
+
const toSendNotification = function (actual, expected, type) {
|
|
95
|
+
assertActualIsSnapResponse(actual, 'toSendNotification');
|
|
96
|
+
const { notifications } = actual;
|
|
97
|
+
const pass = notifications.some((notification) => this.equals(notification.message, expected) &&
|
|
98
|
+
(type === undefined || notification.type === type));
|
|
99
|
+
const message = pass
|
|
100
|
+
? () => `${this.utils.matcherHint('.not.toSendNotification')}\n\n` +
|
|
101
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
102
|
+
`Expected type: ${this.utils.printExpected(type)}\n` +
|
|
103
|
+
`Received: ${this.utils.printReceived(notifications)}`
|
|
104
|
+
: () => `${this.utils.matcherHint('.toSendNotification')}\n\n` +
|
|
105
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
106
|
+
`Expected type: ${this.utils.printExpected(type)}\n` +
|
|
107
|
+
`Received: ${this.utils.printReceived(notifications)}`;
|
|
108
|
+
return { message, pass };
|
|
109
|
+
};
|
|
110
|
+
exports.toSendNotification = toSendNotification;
|
|
111
|
+
const toRenderLegacy = function (actual, expected) {
|
|
112
|
+
assertHasInterface(actual, 'toRender');
|
|
113
|
+
const { content } = actual;
|
|
114
|
+
const expectedElement = (0, snaps_utils_1.getJsxElementFromComponent)(expected);
|
|
115
|
+
const pass = this.equals(content, expectedElement);
|
|
116
|
+
// This is typed as `string | null`, but in practice it's always a string.
|
|
117
|
+
// The function only returns `null` if both the expected and actual values
|
|
118
|
+
// are numbers, bigints, or booleans, which is never the case here.
|
|
119
|
+
const difference = (0, jest_matcher_utils_1.diff)(expectedElement, content);
|
|
120
|
+
const message = pass
|
|
121
|
+
? () => `${this.utils.matcherHint('.not.toRender')}\n\n` +
|
|
122
|
+
`Expected:\n${this.utils.printExpected(expectedElement)}\n\n` +
|
|
123
|
+
`Received:\n${this.utils.printReceived(content)}` +
|
|
124
|
+
`\n\nDifference:\n\n${difference}`
|
|
125
|
+
: () => `${this.utils.matcherHint('.toRender')}\n\n` +
|
|
126
|
+
`Expected:\n${this.utils.printExpected(expectedElement)}\n\n` +
|
|
127
|
+
`Received:\n${this.utils.printReceived(content)}` +
|
|
128
|
+
`\n\nDifference:\n\n${difference}`;
|
|
129
|
+
return { message, pass };
|
|
130
|
+
};
|
|
131
|
+
const toRender = function (actual, expected) {
|
|
132
|
+
assertHasInterface(actual, 'toRender');
|
|
133
|
+
if (!(0, jsx_1.isJSXElementUnsafe)(expected)) {
|
|
134
|
+
return toRenderLegacy.call(this, actual, expected);
|
|
135
|
+
}
|
|
136
|
+
const { content } = actual;
|
|
137
|
+
const pass = this.equals(content, expected);
|
|
138
|
+
// This is typed as `string | null`, but in practice it's always a string.
|
|
139
|
+
// The function only returns `null` if both the expected and actual values
|
|
140
|
+
// are numbers, bigints, or booleans, which is never the case here.
|
|
141
|
+
const difference = (0, jest_matcher_utils_1.diff)((0, snaps_utils_1.serialiseJsx)(expected), (0, snaps_utils_1.serialiseJsx)(content));
|
|
142
|
+
const message = pass
|
|
143
|
+
? () => `${this.utils.matcherHint('.not.toRender')}\n\n` +
|
|
144
|
+
`Expected:\n${(0, jest_matcher_utils_1.EXPECTED_COLOR)((0, snaps_utils_1.serialiseJsx)(expected))}\n\n` +
|
|
145
|
+
`Received:\n${(0, jest_matcher_utils_1.RECEIVED_COLOR)((0, snaps_utils_1.serialiseJsx)(content))}` +
|
|
146
|
+
`\n\nDifference:\n\n${difference}`
|
|
147
|
+
: () => `${this.utils.matcherHint('.toRender')}\n\n` +
|
|
148
|
+
`Expected:\n${(0, jest_matcher_utils_1.EXPECTED_COLOR)((0, snaps_utils_1.serialiseJsx)(expected))}\n\n` +
|
|
149
|
+
`Received:\n${(0, jest_matcher_utils_1.RECEIVED_COLOR)((0, snaps_utils_1.serialiseJsx)(content))}` +
|
|
150
|
+
`\n\nDifference:\n\n${difference}`;
|
|
151
|
+
return { message, pass };
|
|
152
|
+
};
|
|
153
|
+
exports.toRender = toRender;
|
|
154
|
+
globals_1.expect.extend({
|
|
155
|
+
toRespondWith: exports.toRespondWith,
|
|
156
|
+
toRespondWithError: exports.toRespondWithError,
|
|
157
|
+
toSendNotification: exports.toSendNotification,
|
|
158
|
+
toRender: exports.toRender,
|
|
159
|
+
});
|
|
160
|
+
//# sourceMappingURL=matchers.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.cjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAMpC,2CAAuC;AAQvC,iDAA6D;AAC7D,uDAG+B;AAC/B,uDAA2C;AAE3C,2CAA8C;AAE9C,2DAQ4B;AAE5B,qDAAkE;AAGlE;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,IAAA,gBAAE,EAAC,MAAM,EAAE,8BAAkB,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,IAAA,wCAAmB,EACjB,IAAA,gCAAW,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,IAAA,mCAAc,EACf,UAAU,CACX,yDAAyD,EAC1D,IAAA,kCAAa,EAAC,UAAU,EAAE,MAAM,EAAE,kCAAa,CAAC,CACjD,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CACzB,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,IAAA,gBAAE,EAAC,MAAM,EAAE,2BAAe,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,IAAA,wCAAmB,EACjB,IAAA,gCAAW,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,IAAA,mCAAc,EAAC,UAAU,CAAC,yCAAyC,EACtE,IAAA,kCAAa,EAAC,UAAU,EAAE,MAAM,EAAE,kCAAa,CAAC,CACjD,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACI,MAAM,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file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { MatcherFunction } from
|
|
2
|
-
import type { NotificationType, EnumToUnion, ComponentOrElement } from
|
|
3
|
-
import type { Json } from
|
|
1
|
+
import type { MatcherFunction } from "@jest/expect";
|
|
2
|
+
import type { NotificationType, EnumToUnion, ComponentOrElement } from "@metamask/snaps-sdk";
|
|
3
|
+
import type { Json } from "@metamask/utils";
|
|
4
4
|
/**
|
|
5
5
|
* Check if a JSON-RPC response matches the expected value. This matcher is
|
|
6
6
|
* intended to be used with the `expect` global.
|
|
@@ -25,3 +25,4 @@ export declare const toSendNotification: MatcherFunction<[
|
|
|
25
25
|
type?: EnumToUnion<NotificationType> | undefined
|
|
26
26
|
]>;
|
|
27
27
|
export declare const toRender: MatcherFunction<[expected: ComponentOrElement]>;
|
|
28
|
+
//# sourceMappingURL=matchers.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.d.cts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAEnB,4BAA4B;AAQ7B,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAiE5C;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IAAC,QAAQ,EAAE,MAAM;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;CAAC,CAwBrE,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAgClE,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { MatcherFunction } from "@jest/expect";
|
|
2
|
+
import type { NotificationType, EnumToUnion, ComponentOrElement } from "@metamask/snaps-sdk";
|
|
3
|
+
import type { Json } from "@metamask/utils";
|
|
4
|
+
/**
|
|
5
|
+
* Check if a JSON-RPC response matches the expected value. This matcher is
|
|
6
|
+
* intended to be used with the `expect` global.
|
|
7
|
+
*
|
|
8
|
+
* @param actual - The actual response.
|
|
9
|
+
* @param expected - The expected response.
|
|
10
|
+
* @returns The status and message.
|
|
11
|
+
*/
|
|
12
|
+
export declare const toRespondWith: MatcherFunction<[expected: Json]>;
|
|
13
|
+
export declare const toRespondWithError: MatcherFunction<[expected: Json]>;
|
|
14
|
+
/**
|
|
15
|
+
* Check if the snap sent a notification with the expected message. This matcher
|
|
16
|
+
* is intended to be used with the `expect` global.
|
|
17
|
+
*
|
|
18
|
+
* @param actual - The actual response.
|
|
19
|
+
* @param expected - The expected notification message.
|
|
20
|
+
* @param type - The expected notification type.
|
|
21
|
+
* @returns The status and message.
|
|
22
|
+
*/
|
|
23
|
+
export declare const toSendNotification: MatcherFunction<[
|
|
24
|
+
expected: string,
|
|
25
|
+
type?: EnumToUnion<NotificationType> | undefined
|
|
26
|
+
]>;
|
|
27
|
+
export declare const toRender: MatcherFunction<[expected: ComponentOrElement]>;
|
|
28
|
+
//# sourceMappingURL=matchers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matchers.d.mts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAEnB,4BAA4B;AAQ7B,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAiE5C;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IAAC,QAAQ,EAAE,MAAM;IAAE,IAAI,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;CAAC,CAwBrE,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAgClE,CAAC"}
|
package/dist/matchers.mjs
CHANGED
|
@@ -1,49 +1,154 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "
|
|
7
|
-
import "
|
|
8
|
-
import "
|
|
9
|
-
import "./
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
/* eslint-disable no-invalid-this */
|
|
2
|
+
import $jestglobals from "@jest/globals";
|
|
3
|
+
const { expect } = $jestglobals;
|
|
4
|
+
import { isJSXElementUnsafe } from "@metamask/snaps-sdk/jsx";
|
|
5
|
+
import { getJsxElementFromComponent, serialiseJsx } from "@metamask/snaps-utils";
|
|
6
|
+
import { is } from "@metamask/superstruct";
|
|
7
|
+
import { hasProperty } from "@metamask/utils";
|
|
8
|
+
import { EXPECTED_COLOR, diff, matcherErrorMessage, matcherHint, printReceived, printWithType, RECEIVED_COLOR } from "jest-matcher-utils";
|
|
9
|
+
import { InterfaceStruct, SnapResponseStruct } from "./internals/index.mjs";
|
|
10
|
+
/**
|
|
11
|
+
* Ensure that the actual value is a response from the `request` function.
|
|
12
|
+
*
|
|
13
|
+
* @param actual - The actual value.
|
|
14
|
+
* @param matcherName - The name of the matcher.
|
|
15
|
+
* @param options - The matcher options.
|
|
16
|
+
*/
|
|
17
|
+
function assertActualIsSnapResponse(actual, matcherName, options) {
|
|
18
|
+
if (!is(actual, SnapResponseStruct)) {
|
|
19
|
+
throw new Error(matcherErrorMessage(matcherHint(matcherName, undefined, undefined, options), `${RECEIVED_COLOR('received')} value must be a response from the \`request\` function`, printWithType('Received', actual, printReceived)));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Ensure that the actual value is a response from the `request` function, and
|
|
24
|
+
* that it has a `ui` property.
|
|
25
|
+
*
|
|
26
|
+
* @param actual - The actual value.
|
|
27
|
+
* @param matcherName - The name of the matcher.
|
|
28
|
+
* @param options - The matcher options.
|
|
29
|
+
*/
|
|
30
|
+
function assertHasInterface(actual, matcherName, options) {
|
|
31
|
+
if (!is(actual, InterfaceStruct) || !actual.content) {
|
|
32
|
+
throw new Error(matcherErrorMessage(matcherHint(matcherName, undefined, undefined, options), `${RECEIVED_COLOR('received')} value must have a \`content\` property`, printWithType('Received', actual, printReceived)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if a JSON-RPC response matches the expected value. This matcher is
|
|
37
|
+
* intended to be used with the `expect` global.
|
|
38
|
+
*
|
|
39
|
+
* @param actual - The actual response.
|
|
40
|
+
* @param expected - The expected response.
|
|
41
|
+
* @returns The status and message.
|
|
42
|
+
*/
|
|
43
|
+
export const toRespondWith = function (actual, expected) {
|
|
44
|
+
assertActualIsSnapResponse(actual, 'toRespondWith');
|
|
45
|
+
const { response } = actual;
|
|
46
|
+
if (hasProperty(response, 'error')) {
|
|
47
|
+
const message = () => `${this.utils.matcherHint('.toRespondWith')}\n\n` +
|
|
48
|
+
`Expected response: ${this.utils.printExpected(expected)}\n` +
|
|
49
|
+
`Received error: ${this.utils.printReceived(response.error)}`;
|
|
50
|
+
return { message, pass: false };
|
|
51
|
+
}
|
|
52
|
+
const pass = this.equals(response.result, expected);
|
|
53
|
+
const message = pass
|
|
54
|
+
? () => `${this.utils.matcherHint('.not.toRespondWith')}\n\n` +
|
|
55
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
56
|
+
`Received: ${this.utils.printReceived(response.result)}`
|
|
57
|
+
: () => `${this.utils.matcherHint('.toRespondWith')}\n\n` +
|
|
58
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
59
|
+
`Received: ${this.utils.printReceived(response.result)}`;
|
|
60
|
+
return { message, pass };
|
|
48
61
|
};
|
|
62
|
+
export const toRespondWithError = function (actual, expected) {
|
|
63
|
+
assertActualIsSnapResponse(actual, 'toRespondWithError');
|
|
64
|
+
const { response } = actual;
|
|
65
|
+
if (hasProperty(response, 'result')) {
|
|
66
|
+
const message = () => `${this.utils.matcherHint('.toRespondWithError')}\n\n` +
|
|
67
|
+
`Expected error: ${this.utils.printExpected(expected)}\n` +
|
|
68
|
+
`Received result: ${this.utils.printReceived(response.result)}`;
|
|
69
|
+
return { message, pass: false };
|
|
70
|
+
}
|
|
71
|
+
const pass = this.equals(response.error, expected);
|
|
72
|
+
const message = pass
|
|
73
|
+
? () => `${this.utils.matcherHint('.not.toRespondWithError')}\n\n` +
|
|
74
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
75
|
+
`Received: ${this.utils.printReceived(response.error)}`
|
|
76
|
+
: () => `${this.utils.matcherHint('.toRespondWithError')}\n\n` +
|
|
77
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
78
|
+
`Received: ${this.utils.printReceived(response.error)}`;
|
|
79
|
+
return { message, pass };
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Check if the snap sent a notification with the expected message. This matcher
|
|
83
|
+
* is intended to be used with the `expect` global.
|
|
84
|
+
*
|
|
85
|
+
* @param actual - The actual response.
|
|
86
|
+
* @param expected - The expected notification message.
|
|
87
|
+
* @param type - The expected notification type.
|
|
88
|
+
* @returns The status and message.
|
|
89
|
+
*/
|
|
90
|
+
export const toSendNotification = function (actual, expected, type) {
|
|
91
|
+
assertActualIsSnapResponse(actual, 'toSendNotification');
|
|
92
|
+
const { notifications } = actual;
|
|
93
|
+
const pass = notifications.some((notification) => this.equals(notification.message, expected) &&
|
|
94
|
+
(type === undefined || notification.type === type));
|
|
95
|
+
const message = pass
|
|
96
|
+
? () => `${this.utils.matcherHint('.not.toSendNotification')}\n\n` +
|
|
97
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
98
|
+
`Expected type: ${this.utils.printExpected(type)}\n` +
|
|
99
|
+
`Received: ${this.utils.printReceived(notifications)}`
|
|
100
|
+
: () => `${this.utils.matcherHint('.toSendNotification')}\n\n` +
|
|
101
|
+
`Expected: ${this.utils.printExpected(expected)}\n` +
|
|
102
|
+
`Expected type: ${this.utils.printExpected(type)}\n` +
|
|
103
|
+
`Received: ${this.utils.printReceived(notifications)}`;
|
|
104
|
+
return { message, pass };
|
|
105
|
+
};
|
|
106
|
+
const toRenderLegacy = function (actual, expected) {
|
|
107
|
+
assertHasInterface(actual, 'toRender');
|
|
108
|
+
const { content } = actual;
|
|
109
|
+
const expectedElement = getJsxElementFromComponent(expected);
|
|
110
|
+
const pass = this.equals(content, expectedElement);
|
|
111
|
+
// This is typed as `string | null`, but in practice it's always a string.
|
|
112
|
+
// The function only returns `null` if both the expected and actual values
|
|
113
|
+
// are numbers, bigints, or booleans, which is never the case here.
|
|
114
|
+
const difference = diff(expectedElement, content);
|
|
115
|
+
const message = pass
|
|
116
|
+
? () => `${this.utils.matcherHint('.not.toRender')}\n\n` +
|
|
117
|
+
`Expected:\n${this.utils.printExpected(expectedElement)}\n\n` +
|
|
118
|
+
`Received:\n${this.utils.printReceived(content)}` +
|
|
119
|
+
`\n\nDifference:\n\n${difference}`
|
|
120
|
+
: () => `${this.utils.matcherHint('.toRender')}\n\n` +
|
|
121
|
+
`Expected:\n${this.utils.printExpected(expectedElement)}\n\n` +
|
|
122
|
+
`Received:\n${this.utils.printReceived(content)}` +
|
|
123
|
+
`\n\nDifference:\n\n${difference}`;
|
|
124
|
+
return { message, pass };
|
|
125
|
+
};
|
|
126
|
+
export const toRender = function (actual, expected) {
|
|
127
|
+
assertHasInterface(actual, 'toRender');
|
|
128
|
+
if (!isJSXElementUnsafe(expected)) {
|
|
129
|
+
return toRenderLegacy.call(this, actual, expected);
|
|
130
|
+
}
|
|
131
|
+
const { content } = actual;
|
|
132
|
+
const pass = this.equals(content, expected);
|
|
133
|
+
// This is typed as `string | null`, but in practice it's always a string.
|
|
134
|
+
// The function only returns `null` if both the expected and actual values
|
|
135
|
+
// are numbers, bigints, or booleans, which is never the case here.
|
|
136
|
+
const difference = diff(serialiseJsx(expected), serialiseJsx(content));
|
|
137
|
+
const message = pass
|
|
138
|
+
? () => `${this.utils.matcherHint('.not.toRender')}\n\n` +
|
|
139
|
+
`Expected:\n${EXPECTED_COLOR(serialiseJsx(expected))}\n\n` +
|
|
140
|
+
`Received:\n${RECEIVED_COLOR(serialiseJsx(content))}` +
|
|
141
|
+
`\n\nDifference:\n\n${difference}`
|
|
142
|
+
: () => `${this.utils.matcherHint('.toRender')}\n\n` +
|
|
143
|
+
`Expected:\n${EXPECTED_COLOR(serialiseJsx(expected))}\n\n` +
|
|
144
|
+
`Received:\n${RECEIVED_COLOR(serialiseJsx(content))}` +
|
|
145
|
+
`\n\nDifference:\n\n${difference}`;
|
|
146
|
+
return { message, pass };
|
|
147
|
+
};
|
|
148
|
+
expect.extend({
|
|
149
|
+
toRespondWith,
|
|
150
|
+
toRespondWithError,
|
|
151
|
+
toSendNotification,
|
|
152
|
+
toRender,
|
|
153
|
+
});
|
|
49
154
|
//# sourceMappingURL=matchers.mjs.map
|
package/dist/matchers.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"matchers.mjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA,oCAAoC;;;AAcpC,OAAO,EAAE,kBAAkB,EAAE,gCAAgC;AAC7D,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,O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EZ,MAAM,OAAO,GAAG,IAAI;QAClB,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,eAAe,CAAC,MAAM;YAChD,cAAc,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE;QACtC,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM;YAC5C,cAAc,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,CAAC;IACZ,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,QAAQ;CACT,CAAC,CAAC","sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
|
package/dist/options.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getOptions = void 0;
|
|
4
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
+
const SnapsEnvironmentOptionsStruct = (0, superstruct_1.type)({
|
|
6
|
+
server: (0, superstruct_1.defaulted)((0, superstruct_1.object)({
|
|
7
|
+
enabled: (0, superstruct_1.defaulted)((0, superstruct_1.boolean)(), true),
|
|
8
|
+
port: (0, superstruct_1.defaulted)((0, superstruct_1.number)(), 0),
|
|
9
|
+
root: (0, superstruct_1.defaulted)((0, superstruct_1.string)(), process.cwd()),
|
|
10
|
+
}), {}),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Get the environment options. This validates the options, and returns the
|
|
14
|
+
* default options if none are provided.
|
|
15
|
+
*
|
|
16
|
+
* @param testEnvironmentOptions - The test environment options as defined in
|
|
17
|
+
* the Jest configuration.
|
|
18
|
+
* @returns The environment options.
|
|
19
|
+
*/
|
|
20
|
+
function getOptions(testEnvironmentOptions) {
|
|
21
|
+
return (0, superstruct_1.create)(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);
|
|
22
|
+
}
|
|
23
|
+
exports.getOptions = getOptions;
|
|
24
|
+
//# sourceMappingURL=options.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AACA,uDAQ+B;AAE/B,MAAM,6BAA6B,GAAG,IAAA,kBAAI,EAAC;IACzC,MAAM,EAAE,IAAA,uBAAS,EACf,IAAA,oBAAM,EAAC;QACL,OAAO,EAAE,IAAA,uBAAS,EAAC,IAAA,qBAAO,GAAE,EAAE,IAAI,CAAC;QACnC,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,CAAC;QAC5B,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KACzC,CAAC,EACF,EAAE,CACH;CACF,CAAC,CAAC;AA+BH;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,sBAA+C;IACxE,OAAO,IAAA,oBAAM,EAAC,sBAAsB,EAAE,6BAA6B,CAAC,CAAC;AACvE,CAAC;AAFD,gCAEC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '@metamask/superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Infer } from
|
|
1
|
+
import type { Infer } from "@metamask/superstruct";
|
|
2
2
|
declare const SnapsEnvironmentOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
3
3
|
server: {
|
|
4
4
|
port: number;
|
|
@@ -58,3 +58,4 @@ export declare function getOptions(testEnvironmentOptions: Record<string, unknow
|
|
|
58
58
|
};
|
|
59
59
|
};
|
|
60
60
|
export {};
|
|
61
|
+
//# sourceMappingURL=options.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.cts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAWnD,QAAA,MAAM,6BAA6B;;;;;;;;;;;;;;;;EASjC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;EAEzE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Infer } from "@metamask/superstruct";
|
|
2
|
+
declare const SnapsEnvironmentOptionsStruct: import("@metamask/superstruct").Struct<{
|
|
3
|
+
server: {
|
|
4
|
+
port: number;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
root: string;
|
|
7
|
+
};
|
|
8
|
+
}, {
|
|
9
|
+
server: import("@metamask/superstruct").Struct<{
|
|
10
|
+
port: number;
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
root: string;
|
|
13
|
+
}, {
|
|
14
|
+
enabled: import("@metamask/superstruct").Struct<boolean, null>;
|
|
15
|
+
port: import("@metamask/superstruct").Struct<number, null>;
|
|
16
|
+
root: import("@metamask/superstruct").Struct<string, null>;
|
|
17
|
+
}>;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* The options for the environment. These can be specified in the Jest
|
|
21
|
+
* configuration under `testEnvironmentOptions`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* {
|
|
25
|
+
* "testEnvironment": "@metamask/snaps-jest",
|
|
26
|
+
* "testEnvironmentOptions": {
|
|
27
|
+
* "executionEnvironmentUrl": "http://localhost:8080",
|
|
28
|
+
* "server": {
|
|
29
|
+
* "port": 8080,
|
|
30
|
+
* /* ... *\/
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* @property server - The options for the built-in HTTP server.
|
|
35
|
+
* @property server.enabled - Whether to run the built-in HTTP server. Defaults
|
|
36
|
+
* to `true`.
|
|
37
|
+
* @property server.port - The port to use for the built-in HTTP server. If this
|
|
38
|
+
* is not provided, a random available port will be used.
|
|
39
|
+
* @property server.root - The root directory to serve from the built-in HTTP
|
|
40
|
+
* server. Defaults to the current working directory. This is assumed to be the
|
|
41
|
+
* directory containing the snap manifest and `dist` files. If this is a
|
|
42
|
+
* relative path, it will be resolved relative to the current working directory.
|
|
43
|
+
*/
|
|
44
|
+
export type SnapsEnvironmentOptions = Infer<typeof SnapsEnvironmentOptionsStruct>;
|
|
45
|
+
/**
|
|
46
|
+
* Get the environment options. This validates the options, and returns the
|
|
47
|
+
* default options if none are provided.
|
|
48
|
+
*
|
|
49
|
+
* @param testEnvironmentOptions - The test environment options as defined in
|
|
50
|
+
* the Jest configuration.
|
|
51
|
+
* @returns The environment options.
|
|
52
|
+
*/
|
|
53
|
+
export declare function getOptions(testEnvironmentOptions: Record<string, unknown>): {
|
|
54
|
+
server: {
|
|
55
|
+
port: number;
|
|
56
|
+
enabled: boolean;
|
|
57
|
+
root: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=options.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.mts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAWnD,QAAA,MAAM,6BAA6B;;;;;;;;;;;;;;;;EASjC,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,uBAAuB,GAAG,KAAK,CACzC,OAAO,6BAA6B,CACrC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;EAEzE"}
|
package/dist/options.mjs
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
1
|
+
import { boolean, create, defaulted, number, object, string, type } from "@metamask/superstruct";
|
|
2
|
+
const SnapsEnvironmentOptionsStruct = type({
|
|
3
|
+
server: defaulted(object({
|
|
4
|
+
enabled: defaulted(boolean(), true),
|
|
5
|
+
port: defaulted(number(), 0),
|
|
6
|
+
root: defaulted(string(), process.cwd()),
|
|
7
|
+
}), {}),
|
|
8
|
+
});
|
|
9
|
+
/**
|
|
10
|
+
* Get the environment options. This validates the options, and returns the
|
|
11
|
+
* default options if none are provided.
|
|
12
|
+
*
|
|
13
|
+
* @param testEnvironmentOptions - The test environment options as defined in
|
|
14
|
+
* the Jest configuration.
|
|
15
|
+
* @returns The environment options.
|
|
16
|
+
*/
|
|
17
|
+
export function getOptions(testEnvironmentOptions) {
|
|
18
|
+
return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);
|
|
19
|
+
}
|
|
8
20
|
//# sourceMappingURL=options.mjs.map
|