@metamask/snaps-jest 8.12.0 → 8.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/environment.cjs +0 -1
  3. package/dist/environment.cjs.map +1 -1
  4. package/dist/environment.d.cts.map +1 -1
  5. package/dist/environment.d.mts.map +1 -1
  6. package/dist/environment.mjs +0 -1
  7. package/dist/environment.mjs.map +1 -1
  8. package/dist/global.cjs +1 -1
  9. package/dist/global.cjs.map +1 -1
  10. package/dist/global.d.cts +2 -0
  11. package/dist/global.d.cts.map +1 -1
  12. package/dist/global.d.mts +2 -0
  13. package/dist/global.d.mts.map +1 -1
  14. package/dist/global.mjs +1 -1
  15. package/dist/global.mjs.map +1 -1
  16. package/dist/helpers.cjs +4 -0
  17. package/dist/helpers.cjs.map +1 -1
  18. package/dist/helpers.d.cts.map +1 -1
  19. package/dist/helpers.d.mts.map +1 -1
  20. package/dist/helpers.mjs +4 -0
  21. package/dist/helpers.mjs.map +1 -1
  22. package/dist/index.cjs +1 -1
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.mjs +1 -1
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/internals/server.cjs +24 -4
  27. package/dist/internals/server.cjs.map +1 -1
  28. package/dist/internals/server.d.cts.map +1 -1
  29. package/dist/internals/server.d.mts.map +1 -1
  30. package/dist/internals/server.mjs +2 -2
  31. package/dist/internals/server.mjs.map +1 -1
  32. package/dist/matchers.cjs +6 -2
  33. package/dist/matchers.cjs.map +1 -1
  34. package/dist/matchers.d.cts.map +1 -1
  35. package/dist/matchers.d.mts.map +1 -1
  36. package/dist/matchers.mjs +6 -2
  37. package/dist/matchers.mjs.map +1 -1
  38. package/dist/setup.cjs +1 -1
  39. package/dist/setup.cjs.map +1 -1
  40. package/dist/setup.mjs +1 -1
  41. package/dist/setup.mjs.map +1 -1
  42. package/jest-preset.js +0 -2
  43. package/package.json +10 -24
package/CHANGELOG.md CHANGED
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [8.13.0]
11
+
12
+ ### Added
13
+
14
+ - Add support for SIP-30 ([#3156](https://github.com/MetaMask/snaps/pull/3156), [#3165](https://github.com/MetaMask/snaps/pull/3165))
15
+ - Add the interface ID to the return value of `getInterface` ([#3174](https://github.com/MetaMask/snaps/pull/3174))
16
+
10
17
  ## [8.12.0]
11
18
 
12
19
  ### Changed
@@ -340,7 +347,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
340
347
  - The version of the package no longer needs to match the version of all other
341
348
  MetaMask Snaps packages.
342
349
 
343
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.12.0...HEAD
350
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.13.0...HEAD
351
+ [8.13.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.12.0...@metamask/snaps-jest@8.13.0
344
352
  [8.12.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.11.0...@metamask/snaps-jest@8.12.0
345
353
  [8.11.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.10.0...@metamask/snaps-jest@8.11.0
346
354
  [8.10.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.9.0...@metamask/snaps-jest@8.10.0
@@ -21,7 +21,6 @@ const utils_1 = require("@metamask/utils");
21
21
  const jest_environment_node_1 = __importDefault(require("jest-environment-node"));
22
22
  const internals_1 = require("./internals/index.cjs");
23
23
  const options_1 = require("./options.cjs");
24
- /* eslint-enable */
25
24
  const log = (0, utils_1.createModuleLogger)(internals_1.rootLogger, 'environment');
26
25
  class SnapsEnvironment extends jest_environment_node_1.default {
27
26
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment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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"]}
1
+ {"version":3,"file":"environment.cjs","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAMA,iEAAyD;AAMzD,2CAA6D;AAE7D,kFAAoD;AAGpD,qDAAsD;AAEtD,2CAAuC;AAMvC,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAU,EAAE,aAAa,CAAC,CAAC;AAE1D,MAAa,gBAAiB,SAAQ,+BAAe;IAOnD;;;;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EAAyE,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\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n readonly #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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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"]}
@@ -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;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"}
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;AAOpD,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,gBAAgB,EAAE,gBAAgB,CAAC;CAC1C;AAID,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,KACd,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAC,OAAO,wBAAwB,CAAC,EAElD,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
@@ -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,EA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,EAAE,KACX,YAAY,CAAC,OAAO,wBAAwB,CAAC,EAElD,MAAM,GAAE,MAAoB,EAC5B,OAAO,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM;IAOpD;;;;;;;OAOG;IACH,IAAI,MAAM,WAQT;CACF;AAED,eAAe,gBAAgB,CAAC"}
@@ -22,7 +22,6 @@ import $NodeEnvironment from "jest-environment-node";
22
22
  const NodeEnvironment = $importDefault($NodeEnvironment);
23
23
  import { rootLogger, startServer } from "./internals/index.mjs";
24
24
  import { getOptions } from "./options.mjs";
25
- /* eslint-enable */
26
25
  const log = createModuleLogger(rootLogger, 'environment');
27
26
  export class SnapsEnvironment extends NodeEnvironment {
28
27
  /**
@@ -1 +1 @@
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"]}
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,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;QAbjB,4CAAkC;QAE3C,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\ndeclare global {\n const snapsEnvironment: SnapsEnvironment;\n}\n\nconst log = createModuleLogger(rootLogger, 'environment');\n\nexport class SnapsEnvironment extends NodeEnvironment {\n readonly #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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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/global.cjs CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */
2
+ /* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  //# sourceMappingURL=global.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"global.cjs","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":";AAAA,oNAAoN","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */\n\nimport type {\n EnumToUnion,\n NotificationType,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\n\ninterface SnapsMatchers {\n /**\n * Assert that the response is a JSON-RPC response with the given result. This\n * is equivalent to calling `expect(response.result).toStrictEqual(result)`.\n *\n * @param response - The expected response result.\n * @throws If the response is not a JSON-RPC response with the given result.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWith('bar');\n */\n toRespondWith(response: unknown): void;\n\n /**\n * Assert that the response is a JSON-RPC response with the given error. This\n * is equivalent to calling `expect(response.error).toStrictEqual(error)`.\n *\n * @param error - The expected response error.\n * @throws If the response is not a JSON-RPC response with the given error.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWithError({\n * code: -32601,\n * message: 'The method does not exist / is not available.',\n * stack: expect.any(String),\n * data: { method: 'foo', cause: null },\n * });\n */\n toRespondWithError(error: unknown): void;\n\n /**\n * Assert that the Snap sent a notification with the expected message, and\n * optionally the expected notification type. This is equivalent to calling\n * `expect(response.notifications).toContainEqual({ message, type })`.\n *\n * @param message - The expected notification message.\n * @param type - The expected notification type, i.e., 'inApp' or 'native'.\n * @param title - The title of an expanded notification.\n * @param content - The content of an expanded notification.\n * @param footerLink - The footer link of an expanded notification (if it exists).\n * @throws If the snap did not send a notification with the expected message.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toSendNotification('bar', NotificationType.InApp);\n */\n toSendNotification(\n message: string,\n type: EnumToUnion<NotificationType>,\n title?: string,\n content?: JSXElement,\n footerLink?: { text: string; href: string },\n ): void;\n\n /**\n * Assert that the Snap rendered the expected component. This is equivalent to\n * calling `expect(interface.content).toStrictEqual(component)`.\n *\n * @param component - The expected rendered component.\n * @throws If the snap did not render the expected component.\n * @example\n * const response = request({ method: 'foo' });\n * const ui = await response.getInterface();\n * expect(ui).toRender(panel([heading('Hello, world!')]));\n */\n toRender(component: ComponentOrElement): void;\n}\n\n// Extend the `expect` interface with the new matchers. This is used when\n// importing `expect` from `@jest/globals`.\ndeclare module 'expect' {\n interface AsymmetricMatchers extends SnapsMatchers {}\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n}\n\n// Extend the Jest global namespace with the new matchers. This is used when\n// using the global `expect` function.\ndeclare global {\n namespace jest {\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n }\n}\n"]}
1
+ {"version":3,"file":"global.cjs","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":";AAAA,sNAAsN","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */\n\nimport type {\n EnumToUnion,\n NotificationType,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\n\ninterface SnapsMatchers {\n /**\n * Assert that the response is a JSON-RPC response with the given result. This\n * is equivalent to calling `expect(response.result).toStrictEqual(result)`.\n *\n * @param response - The expected response result.\n * @throws If the response is not a JSON-RPC response with the given result.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWith('bar');\n */\n toRespondWith(response: unknown): void;\n\n /**\n * Assert that the response is a JSON-RPC response with the given error. This\n * is equivalent to calling `expect(response.error).toStrictEqual(error)`.\n *\n * @param error - The expected response error.\n * @throws If the response is not a JSON-RPC response with the given error.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWithError({\n * code: -32601,\n * message: 'The method does not exist / is not available.',\n * stack: expect.any(String),\n * data: { method: 'foo', cause: null },\n * });\n */\n toRespondWithError(error: unknown): void;\n\n /**\n * Assert that the Snap sent a notification with the expected message, and\n * optionally the expected notification type. This is equivalent to calling\n * `expect(response.notifications).toContainEqual({ message, type })`.\n *\n * @param message - The expected notification message.\n * @param type - The expected notification type, i.e., 'inApp' or 'native'.\n * @param title - The title of an expanded notification.\n * @param content - The content of an expanded notification.\n * @param footerLink - The footer link of an expanded notification (if it exists).\n * @param footerLink.text - The text of the footer link.\n * @param footerLink.href - The href of the footer link.\n * @throws If the snap did not send a notification with the expected message.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toSendNotification('bar', NotificationType.InApp);\n */\n toSendNotification(\n message: string,\n type: EnumToUnion<NotificationType>,\n title?: string,\n content?: JSXElement,\n footerLink?: { text: string; href: string },\n ): void;\n\n /**\n * Assert that the Snap rendered the expected component. This is equivalent to\n * calling `expect(interface.content).toStrictEqual(component)`.\n *\n * @param component - The expected rendered component.\n * @throws If the snap did not render the expected component.\n * @example\n * const response = request({ method: 'foo' });\n * const ui = await response.getInterface();\n * expect(ui).toRender(panel([heading('Hello, world!')]));\n */\n toRender(component: ComponentOrElement): void;\n}\n\n// Extend the `expect` interface with the new matchers. This is used when\n// importing `expect` from `@jest/globals`.\ndeclare module 'expect' {\n interface AsymmetricMatchers extends SnapsMatchers {}\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n}\n\n// Extend the Jest global namespace with the new matchers. This is used when\n// using the global `expect` function.\ndeclare global {\n namespace jest {\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n }\n}\n"]}
package/dist/global.d.cts CHANGED
@@ -38,6 +38,8 @@ interface SnapsMatchers {
38
38
  * @param title - The title of an expanded notification.
39
39
  * @param content - The content of an expanded notification.
40
40
  * @param footerLink - The footer link of an expanded notification (if it exists).
41
+ * @param footerLink.text - The text of the footer link.
42
+ * @param footerLink.href - The href of the footer link.
41
43
  * @throws If the snap did not send a notification with the expected message.
42
44
  * @example
43
45
  * const response = await request({ method: 'foo' });
@@ -1 +1 @@
1
- {"version":3,"file":"global.d.cts","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,UAAU,aAAa;IACrB;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAChB,OAAO,EAAE,MA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,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;CAC/C;AAID,OAAO,QAAQ,QAAQ,CAAC;IACtB,UAAU,kBAAmB,SAAQ,aAAa;KAAG;IAKrD,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,aAAa;KAAG;CAC/C;AAID,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,IAAI,CAAC;QAIb,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,aAAa;SAAG;KAC/C;CACF"}
package/dist/global.d.mts CHANGED
@@ -38,6 +38,8 @@ interface SnapsMatchers {
38
38
  * @param title - The title of an expanded notification.
39
39
  * @param content - The content of an expanded notification.
40
40
  * @param footerLink - The footer link of an expanded notification (if it exists).
41
+ * @param footerLink.text - The text of the footer link.
42
+ * @param footerLink.href - The href of the footer link.
41
43
  * @throws If the snap did not send a notification with the expected message.
42
44
  * @example
43
45
  * const response = await request({ method: 'foo' });
@@ -1 +1 @@
1
- {"version":3,"file":"global.d.mts","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EACnB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,UAAU,aAAa;IACrB;;;;;;;;;OASG;IACH,aAAa,CAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAC;IAEvC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IAEzC;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,CAChB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,EACnC,KAAK,CAAC,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,UAAU,EACpB,UAAU,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAC1C,IAAI,CAAC;IA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;IACb,UAAU,IAAI,CAAC;QAIb,UAAU,QAAQ,CAAC,CAAC,CAAE,SAAQ,aAAa;SAAG;KAC/C;CACF"}
package/dist/global.mjs CHANGED
@@ -1,3 +1,3 @@
1
- /* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */
1
+ /* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */
2
2
  export {};
3
3
  //# sourceMappingURL=global.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"global.mjs","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAAA,oNAAoN","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */\n\nimport type {\n EnumToUnion,\n NotificationType,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\n\ninterface SnapsMatchers {\n /**\n * Assert that the response is a JSON-RPC response with the given result. This\n * is equivalent to calling `expect(response.result).toStrictEqual(result)`.\n *\n * @param response - The expected response result.\n * @throws If the response is not a JSON-RPC response with the given result.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWith('bar');\n */\n toRespondWith(response: unknown): void;\n\n /**\n * Assert that the response is a JSON-RPC response with the given error. This\n * is equivalent to calling `expect(response.error).toStrictEqual(error)`.\n *\n * @param error - The expected response error.\n * @throws If the response is not a JSON-RPC response with the given error.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWithError({\n * code: -32601,\n * message: 'The method does not exist / is not available.',\n * stack: expect.any(String),\n * data: { method: 'foo', cause: null },\n * });\n */\n toRespondWithError(error: unknown): void;\n\n /**\n * Assert that the Snap sent a notification with the expected message, and\n * optionally the expected notification type. This is equivalent to calling\n * `expect(response.notifications).toContainEqual({ message, type })`.\n *\n * @param message - The expected notification message.\n * @param type - The expected notification type, i.e., 'inApp' or 'native'.\n * @param title - The title of an expanded notification.\n * @param content - The content of an expanded notification.\n * @param footerLink - The footer link of an expanded notification (if it exists).\n * @throws If the snap did not send a notification with the expected message.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toSendNotification('bar', NotificationType.InApp);\n */\n toSendNotification(\n message: string,\n type: EnumToUnion<NotificationType>,\n title?: string,\n content?: JSXElement,\n footerLink?: { text: string; href: string },\n ): void;\n\n /**\n * Assert that the Snap rendered the expected component. This is equivalent to\n * calling `expect(interface.content).toStrictEqual(component)`.\n *\n * @param component - The expected rendered component.\n * @throws If the snap did not render the expected component.\n * @example\n * const response = request({ method: 'foo' });\n * const ui = await response.getInterface();\n * expect(ui).toRender(panel([heading('Hello, world!')]));\n */\n toRender(component: ComponentOrElement): void;\n}\n\n// Extend the `expect` interface with the new matchers. This is used when\n// importing `expect` from `@jest/globals`.\ndeclare module 'expect' {\n interface AsymmetricMatchers extends SnapsMatchers {}\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n}\n\n// Extend the Jest global namespace with the new matchers. This is used when\n// using the global `expect` function.\ndeclare global {\n namespace jest {\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n }\n}\n"]}
1
+ {"version":3,"file":"global.mjs","sourceRoot":"","sources":["../src/global.ts"],"names":[],"mappings":"AAAA,sNAAsN","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions, @typescript-eslint/naming-convention, @typescript-eslint/no-empty-object-type, @typescript-eslint/no-unused-vars, @typescript-eslint/no-namespace */\n\nimport type {\n EnumToUnion,\n NotificationType,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\n\ninterface SnapsMatchers {\n /**\n * Assert that the response is a JSON-RPC response with the given result. This\n * is equivalent to calling `expect(response.result).toStrictEqual(result)`.\n *\n * @param response - The expected response result.\n * @throws If the response is not a JSON-RPC response with the given result.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWith('bar');\n */\n toRespondWith(response: unknown): void;\n\n /**\n * Assert that the response is a JSON-RPC response with the given error. This\n * is equivalent to calling `expect(response.error).toStrictEqual(error)`.\n *\n * @param error - The expected response error.\n * @throws If the response is not a JSON-RPC response with the given error.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toRespondWithError({\n * code: -32601,\n * message: 'The method does not exist / is not available.',\n * stack: expect.any(String),\n * data: { method: 'foo', cause: null },\n * });\n */\n toRespondWithError(error: unknown): void;\n\n /**\n * Assert that the Snap sent a notification with the expected message, and\n * optionally the expected notification type. This is equivalent to calling\n * `expect(response.notifications).toContainEqual({ message, type })`.\n *\n * @param message - The expected notification message.\n * @param type - The expected notification type, i.e., 'inApp' or 'native'.\n * @param title - The title of an expanded notification.\n * @param content - The content of an expanded notification.\n * @param footerLink - The footer link of an expanded notification (if it exists).\n * @param footerLink.text - The text of the footer link.\n * @param footerLink.href - The href of the footer link.\n * @throws If the snap did not send a notification with the expected message.\n * @example\n * const response = await request({ method: 'foo' });\n * expect(response).toSendNotification('bar', NotificationType.InApp);\n */\n toSendNotification(\n message: string,\n type: EnumToUnion<NotificationType>,\n title?: string,\n content?: JSXElement,\n footerLink?: { text: string; href: string },\n ): void;\n\n /**\n * Assert that the Snap rendered the expected component. This is equivalent to\n * calling `expect(interface.content).toStrictEqual(component)`.\n *\n * @param component - The expected rendered component.\n * @throws If the snap did not render the expected component.\n * @example\n * const response = request({ method: 'foo' });\n * const ui = await response.getInterface();\n * expect(ui).toRender(panel([heading('Hello, world!')]));\n */\n toRender(component: ComponentOrElement): void;\n}\n\n// Extend the `expect` interface with the new matchers. This is used when\n// importing `expect` from `@jest/globals`.\ndeclare module 'expect' {\n interface AsymmetricMatchers extends SnapsMatchers {}\n\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n}\n\n// Extend the Jest global namespace with the new matchers. This is used when\n// using the global `expect` function.\ndeclare global {\n namespace jest {\n // Ideally we would use `Matchers<Result>` instead of `Matchers<R>`, but\n // TypeScript doesn't allow this:\n // TS2428: All declarations of 'Matchers' must have identical type parameters.\n interface Matchers<R> extends SnapsMatchers {}\n }\n}\n"]}
package/dist/helpers.cjs CHANGED
@@ -52,7 +52,11 @@ function getOptions(snapId, options) {
52
52
  */
53
53
  async function installSnap(snapId, options = {}) {
54
54
  const resolvedOptions = getOptions(snapId, options);
55
+ // TODO: Either fix this lint violation or explain why it's necessary to
56
+ // ignore.
57
+ /* eslint-disable @typescript-eslint/unbound-method */
55
58
  const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onBackgroundEvent, onHomePage, onSettingsPage, onKeyringRequest, onInstall, onUpdate, onNameLookup, mockJsonRpc, close, } = await (0, internals_1.getEnvironment)().installSnap(...resolvedOptions);
59
+ /* eslint-enable @typescript-eslint/unbound-method */
56
60
  return {
57
61
  request,
58
62
  onTransaction,
@@ -1 +1 @@
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,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,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,iBAAiB;QACjB,UAAU;QACV,cAAc;QACd,gBAAgB;QAChB,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,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;AAnDD,kCAmDC","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 onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\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 onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\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"]}
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;IAEpD,wEAAwE;IACxE,WAAW;IACX,sDAAsD;IACtD,MAAM,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,KAAK,GACN,GAAG,MAAM,IAAA,0BAAc,GAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;IAC3D,qDAAqD;IAErD,OAAO;QACL,OAAO;QACP,aAAa;QACb,eAAe;QACf,WAAW;QACX,SAAS;QACT,UAAU;QACV,iBAAiB;QACjB,UAAU;QACV,cAAc;QACd,gBAAgB;QAChB,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,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;AAxDD,kCAwDC","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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\n mockJsonRpc,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\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"]}
@@ -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,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"}
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,KACd,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAC,OAAO,wBAAwB,CAAC,EAClD,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,KACd,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAC,OAAO,wBAAwB,CAAC,EAElD,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -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,IAAI,EAAE,mCAAmC;AA8B3E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,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AM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,GAC7C,OAAO,CAAC,IAAI,CAAC,CAAC"}
package/dist/helpers.mjs CHANGED
@@ -49,7 +49,11 @@ function getOptions(snapId, options) {
49
49
  */
50
50
  export async function installSnap(snapId, options = {}) {
51
51
  const resolvedOptions = getOptions(snapId, options);
52
+ // TODO: Either fix this lint violation or explain why it's necessary to
53
+ // ignore.
54
+ /* eslint-disable @typescript-eslint/unbound-method */
52
55
  const { request, onTransaction, sendTransaction, onSignature, onCronjob, runCronjob, onBackgroundEvent, onHomePage, onSettingsPage, onKeyringRequest, onInstall, onUpdate, onNameLookup, mockJsonRpc, close, } = await getEnvironment().installSnap(...resolvedOptions);
56
+ /* eslint-enable @typescript-eslint/unbound-method */
53
57
  return {
54
58
  request,
55
59
  onTransaction,
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,8BAA8B;AAChD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,8BAAoB;AAEzD,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,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;AACH,MAAM,CAAC,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,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,KAAK,GACN,GAAG,MAAM,cAAc,EAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;IAE3D,OAAO;QACL,OAAO;QACP,aAAa;QACb,eAAe;QACf,WAAW;QACX,SAAS;QACT,UAAU;QACV,iBAAiB;QACjB,UAAU;QACV,cAAc;QACd,gBAAgB;QAChB,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,WAAW;QACX,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,OAAO,CACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,KAAK,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC","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 onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\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 onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\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"]}
1
+ {"version":3,"file":"helpers.mjs","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,OAAO,EAAE,8BAA8B;AAChD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,8BAAoB;AAEzD,MAAM,GAAG,GAAG,kBAAkB,CAAC,UAAU,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;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAK/B,MAAsD,EACtD,UAAgD,EAAE;IAElD,MAAM,eAAe,GAAG,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAEpD,wEAAwE;IACxE,WAAW;IACX,sDAAsD;IACtD,MAAM,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,WAAW,EACX,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,WAAW,EACX,KAAK,GACN,GAAG,MAAM,cAAc,EAAE,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,CAAC;IAC3D,qDAAqD;IAErD,OAAO;QACL,OAAO;QACP,aAAa;QACb,eAAe;QACf,WAAW;QACX,SAAS;QACT,UAAU;QACV,iBAAiB;QACjB,UAAU;QACV,cAAc;QACd,gBAAgB;QAChB,SAAS;QACT,QAAQ;QACR,YAAY;QACZ,WAAW;QACX,KAAK,EAAE,KAAK,IAAI,EAAE;YAChB,GAAG,CAAC,4BAA4B,CAAC,CAAC;YAClC,OAAO,CACL,uIAAuI,CACxI,CAAC;YAEF,MAAM,KAAK,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC","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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\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 (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n\n // TODO: Either fix this lint violation or explain why it's necessary to\n // ignore.\n /* eslint-disable @typescript-eslint/unbound-method */\n const {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\n mockJsonRpc,\n close,\n } = await getEnvironment().installSnap(...resolvedOptions);\n /* eslint-enable @typescript-eslint/unbound-method */\n\n return {\n request,\n onTransaction,\n sendTransaction,\n onSignature,\n onCronjob,\n runCronjob,\n onBackgroundEvent,\n onHomePage,\n onSettingsPage,\n onKeyringRequest,\n onInstall,\n onUpdate,\n onNameLookup,\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/index.cjs CHANGED
@@ -18,7 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.assertIsPromptDialog = exports.assertIsCustomDialog = exports.assertIsConfirmationDialog = exports.assertIsAlertDialog = exports.assertCustomDialogHasPartialFooter = exports.assertCustomDialogHasNoFooter = exports.TestEnvironment = exports.default = void 0;
21
- // eslint-disable-next-line import/no-unassigned-import
21
+ // eslint-disable-next-line import-x/no-unassigned-import
22
22
  require("./global.cjs");
23
23
  var environment_1 = require("./environment.cjs");
24
24
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(environment_1).default; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,uDAAuD;AACvD,wBAAkB;AAElB,iDAAoE;AAA3D,uHAAA,OAAO,OAAA;AAAE,+HAAA,OAAO,OAAmB;AAC5C,gDAA0B;AAC1B,gDAA0B;AAE1B,+DAOoC;AANlC,iIAAA,6BAA6B,OAAA;AAC7B,sIAAA,kCAAkC,OAAA;AAClC,uHAAA,mBAAmB,OAAA;AACnB,8HAAA,0BAA0B,OAAA;AAC1B,wHAAA,oBAAoB,OAAA;AACpB,wHAAA,oBAAoB,OAAA","sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport './global';\n\nexport { default, default as TestEnvironment } from './environment';\nexport * from './helpers';\nexport * from './options';\n\nexport {\n assertCustomDialogHasNoFooter,\n assertCustomDialogHasPartialFooter,\n assertIsAlertDialog,\n assertIsConfirmationDialog,\n assertIsCustomDialog,\n assertIsPromptDialog,\n} from '@metamask/snaps-simulation';\n\nexport type {\n CronjobOptions,\n DefaultSnapInterface,\n DefaultSnapInterfaceWithFooter,\n DefaultSnapInterfaceWithPartialFooter,\n DefaultSnapInterfaceWithoutFooter,\n FileOptions,\n RequestOptions,\n SignatureOptions,\n Snap,\n SnapAlertInterface,\n SnapConfirmationInterface,\n SnapHandlerInterface,\n SnapInterface,\n SnapInterfaceActions,\n SnapOptions,\n SnapPromptInterface,\n SnapResponse,\n SnapResponseType,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n SnapRequest,\n SnapRequestObject,\n TransactionOptions,\n} from '@metamask/snaps-simulation';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,yDAAyD;AACzD,wBAAkB;AAElB,iDAAoE;AAA3D,uHAAA,OAAO,OAAA;AAAE,+HAAA,OAAO,OAAmB;AAC5C,gDAA0B;AAC1B,gDAA0B;AAE1B,+DAOoC;AANlC,iIAAA,6BAA6B,OAAA;AAC7B,sIAAA,kCAAkC,OAAA;AAClC,uHAAA,mBAAmB,OAAA;AACnB,8HAAA,0BAA0B,OAAA;AAC1B,wHAAA,oBAAoB,OAAA;AACpB,wHAAA,oBAAoB,OAAA","sourcesContent":["// eslint-disable-next-line import-x/no-unassigned-import\nimport './global';\n\nexport { default, default as TestEnvironment } from './environment';\nexport * from './helpers';\nexport * from './options';\n\nexport {\n assertCustomDialogHasNoFooter,\n assertCustomDialogHasPartialFooter,\n assertIsAlertDialog,\n assertIsConfirmationDialog,\n assertIsCustomDialog,\n assertIsPromptDialog,\n} from '@metamask/snaps-simulation';\n\nexport type {\n CronjobOptions,\n DefaultSnapInterface,\n DefaultSnapInterfaceWithFooter,\n DefaultSnapInterfaceWithPartialFooter,\n DefaultSnapInterfaceWithoutFooter,\n FileOptions,\n RequestOptions,\n SignatureOptions,\n Snap,\n SnapAlertInterface,\n SnapConfirmationInterface,\n SnapHandlerInterface,\n SnapInterface,\n SnapInterfaceActions,\n SnapOptions,\n SnapPromptInterface,\n SnapResponse,\n SnapResponseType,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n SnapRequest,\n SnapRequestObject,\n TransactionOptions,\n} from '@metamask/snaps-simulation';\n"]}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- // eslint-disable-next-line import/no-unassigned-import
1
+ // eslint-disable-next-line import-x/no-unassigned-import
2
2
  import "./global.mjs";
3
3
  export { default, default as TestEnvironment } from "./environment.mjs";
4
4
  export * from "./helpers.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,sBAAkB;AAElB,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,0BAAsB;AACpE,8BAA0B;AAC1B,8BAA0B;AAE1B,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,mBAAmB,EACnB,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EACrB,mCAAmC","sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport './global';\n\nexport { default, default as TestEnvironment } from './environment';\nexport * from './helpers';\nexport * from './options';\n\nexport {\n assertCustomDialogHasNoFooter,\n assertCustomDialogHasPartialFooter,\n assertIsAlertDialog,\n assertIsConfirmationDialog,\n assertIsCustomDialog,\n assertIsPromptDialog,\n} from '@metamask/snaps-simulation';\n\nexport type {\n CronjobOptions,\n DefaultSnapInterface,\n DefaultSnapInterfaceWithFooter,\n DefaultSnapInterfaceWithPartialFooter,\n DefaultSnapInterfaceWithoutFooter,\n FileOptions,\n RequestOptions,\n SignatureOptions,\n Snap,\n SnapAlertInterface,\n SnapConfirmationInterface,\n SnapHandlerInterface,\n SnapInterface,\n SnapInterfaceActions,\n SnapOptions,\n SnapPromptInterface,\n SnapResponse,\n SnapResponseType,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n SnapRequest,\n SnapRequestObject,\n TransactionOptions,\n} from '@metamask/snaps-simulation';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,sBAAkB;AAElB,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,0BAAsB;AACpE,8BAA0B;AAC1B,8BAA0B;AAE1B,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EAClC,mBAAmB,EACnB,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EACrB,mCAAmC","sourcesContent":["// eslint-disable-next-line import-x/no-unassigned-import\nimport './global';\n\nexport { default, default as TestEnvironment } from './environment';\nexport * from './helpers';\nexport * from './options';\n\nexport {\n assertCustomDialogHasNoFooter,\n assertCustomDialogHasPartialFooter,\n assertIsAlertDialog,\n assertIsConfirmationDialog,\n assertIsCustomDialog,\n assertIsPromptDialog,\n} from '@metamask/snaps-simulation';\n\nexport type {\n CronjobOptions,\n DefaultSnapInterface,\n DefaultSnapInterfaceWithFooter,\n DefaultSnapInterfaceWithPartialFooter,\n DefaultSnapInterfaceWithoutFooter,\n FileOptions,\n RequestOptions,\n SignatureOptions,\n Snap,\n SnapAlertInterface,\n SnapConfirmationInterface,\n SnapHandlerInterface,\n SnapInterface,\n SnapInterfaceActions,\n SnapOptions,\n SnapPromptInterface,\n SnapResponse,\n SnapResponseType,\n SnapResponseWithInterface,\n SnapResponseWithoutInterface,\n SnapRequest,\n SnapRequestObject,\n TransactionOptions,\n} from '@metamask/snaps-simulation';\n"]}
@@ -1,12 +1,32 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
4
24
  };
5
25
  Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.startServer = void 0;
7
27
  const node_1 = require("@metamask/snaps-utils/node");
8
28
  const utils_1 = require("@metamask/utils");
9
- const express_1 = __importDefault(require("express/index.js"));
29
+ const express_1 = __importStar(require("express/index.js"));
10
30
  const fs_1 = require("fs");
11
31
  const http_1 = require("http");
12
32
  const path_1 = require("path");
@@ -58,7 +78,7 @@ async function startServer(options) {
58
78
  response.header('Access-Control-Allow-Headers', 'Content-Type');
59
79
  next();
60
80
  });
61
- app.use(express_1.default.static((0, path_1.resolve)(process.cwd(), options.root)));
81
+ app.use((0, express_1.static)((0, path_1.resolve)(process.cwd(), options.root)));
62
82
  const server = (0, http_1.createServer)(app);
63
83
  return await new Promise((resolve, reject) => {
64
84
  server.listen(options.port, () => {
@@ -1 +1 @@
1
- {"version":3,"file":"server.cjs","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";;;;;;AACA,qDAIoC;AACpC,2CAAqD;AACrD,+DAA8B;AAC9B,2BAAoC;AAEpC,+BAAoC;AACpC,+BAA8C;AAG9C,yCAAsC;AAOtC;;;;;;;;;GASG;AACH,KAAK,UAAU,UAAU,CAAC,IAAY;IACpC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC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,CAAC;QAChE,QAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAC;QAEhE,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,iBAAO,CAAC,MAAM,CAAC,IAAA,cAAW,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAElE,MAAM,MAAM,GAAG,IAAA,mBAAY,EAAC,GAAG,CAAC,CAAC;IACjC,OAAO,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE;YAC/B,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC3B,GAAG,CAAC,KAAK,CAAC,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA5BD,kCA4BC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n assertIsSnapManifest,\n isDirectory,\n isFile,\n} from '@metamask/snaps-utils/node';\nimport { createModuleLogger } from '@metamask/utils';\nimport express from 'express';\nimport { promises as fs } from 'fs';\nimport type { Server } from 'http';\nimport { createServer } from 'http';\nimport { resolve as pathResolve } from 'path';\n\nimport type { SnapsEnvironmentOptions } from '../options';\nimport { rootLogger } from './logger';\n\nexport type ServerOptions = Required<\n // We need a double `Required` for the type to be inferred correctly.\n Required<SnapsEnvironmentOptions>['server']\n>;\n\n/**\n * Check that:\n *\n * - The root directory exists.\n * - The root directory contains a `snap.manifest.json` file.\n * - The file path in the manifest exists.\n *\n * @param root - The root directory.\n * @throws If any of the checks fail.\n */\nasync function assertRoot(root: string) {\n if (!root) {\n throw new Error('You must specify a root directory.');\n }\n\n if (!(await isDirectory(root, false))) {\n throw new Error(`Root directory \"${root}\" is not a directory.`);\n }\n\n const manifestPath = pathResolve(root, 'snap.manifest.json');\n const manifest: SnapManifest = await fs\n .readFile(manifestPath, 'utf8')\n .then(JSON.parse);\n\n assertIsSnapManifest(manifest);\n const filePath = pathResolve(root, manifest.source.location.npm.filePath);\n\n if (!(await isFile(filePath))) {\n throw new Error(\n `File \"${filePath}\" does not exist, or is not a file. Did you forget to build your snap?`,\n );\n }\n}\n\n/**\n * Start an HTTP server on `localhost` with a random port. This is used to serve\n * the static files for the environment.\n *\n * @param options - The options to use.\n * @param options.port - The port to use for the server.\n * @param options.root - The root directory to serve from the server.\n * @returns The HTTP server.\n */\nexport async function startServer(options: ServerOptions) {\n await assertRoot(options.root);\n\n const log = createModuleLogger(rootLogger, 'server');\n const app = express();\n\n app.use((_request, response, next) => {\n response.header('Access-Control-Allow-Origin', '*');\n response.header('Access-Control-Allow-Credentials', 'true');\n response.header('Access-Control-Allow-Methods', 'GET, OPTIONS');\n response.header('Access-Control-Allow-Headers', 'Content-Type');\n\n next();\n });\n\n app.use(express.static(pathResolve(process.cwd(), options.root)));\n\n const server = createServer(app);\n return await new Promise<Server>((resolve, reject) => {\n server.listen(options.port, () => {\n resolve(server);\n });\n\n server.on('error', (error) => {\n log(error);\n reject(error);\n });\n });\n}\n"]}
1
+ {"version":3,"file":"server.cjs","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAIoC;AACpC,2CAAqD;AACrD,4DAA2D;AAC3D,2BAAoC;AAEpC,+BAAoC;AACpC,+BAA8C;AAE9C,yCAAsC;AAQtC;;;;;;;;;GASG;AACH,KAAK,UAAU,UAAU,CAAC,IAAY;IACpC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,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C,MAAM,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAC;QAEhE,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,IAAA,gBAAa,EAAC,IAAA,cAAW,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEjE,MAAM,MAAM,GAAG,IAAA,mBAAY,EAAC,GAAG,CAAC,CAAC;IACjC,OAAO,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE;YAC/B,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC3B,GAAG,CAAC,KAAK,CAAC,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA5BD,kCA4BC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n assertIsSnapManifest,\n isDirectory,\n isFile,\n} from '@metamask/snaps-utils/node';\nimport { createModuleLogger } from '@metamask/utils';\nimport express, { static as expressStatic } from 'express';\nimport { promises as fs } from 'fs';\nimport type { Server } from 'http';\nimport { createServer } from 'http';\nimport { resolve as pathResolve } from 'path';\n\nimport { rootLogger } from './logger';\nimport type { SnapsEnvironmentOptions } from '../options';\n\nexport type ServerOptions = Required<\n // We need a double `Required` for the type to be inferred correctly.\n Required<SnapsEnvironmentOptions>['server']\n>;\n\n/**\n * Check that:\n *\n * - The root directory exists.\n * - The root directory contains a `snap.manifest.json` file.\n * - The file path in the manifest exists.\n *\n * @param root - The root directory.\n * @throws If any of the checks fail.\n */\nasync function assertRoot(root: string) {\n if (!root) {\n throw new Error('You must specify a root directory.');\n }\n\n if (!(await isDirectory(root, false))) {\n throw new Error(`Root directory \"${root}\" is not a directory.`);\n }\n\n const manifestPath = pathResolve(root, 'snap.manifest.json');\n const manifest: SnapManifest = await fs\n .readFile(manifestPath, 'utf8')\n .then(JSON.parse);\n\n assertIsSnapManifest(manifest);\n const filePath = pathResolve(root, manifest.source.location.npm.filePath);\n\n if (!(await isFile(filePath))) {\n throw new Error(\n `File \"${filePath}\" does not exist, or is not a file. Did you forget to build your snap?`,\n );\n }\n}\n\n/**\n * Start an HTTP server on `localhost` with a random port. This is used to serve\n * the static files for the environment.\n *\n * @param options - The options to use.\n * @param options.port - The port to use for the server.\n * @param options.root - The root directory to serve from the server.\n * @returns The HTTP server.\n */\nexport async function startServer(options: ServerOptions) {\n await assertRoot(options.root);\n\n const log = createModuleLogger(rootLogger, 'server');\n const app = express();\n\n app.use((_request, response, next) => {\n response.header('Access-Control-Allow-Origin', '*');\n response.header('Access-Control-Allow-Credentials', 'true');\n response.header('Access-Control-Allow-Methods', 'GET, OPTIONS');\n response.header('Access-Control-Allow-Headers', 'Content-Type');\n\n next();\n });\n\n app.use(expressStatic(pathResolve(process.cwd(), options.root)));\n\n const server = createServer(app);\n return await new Promise<Server>((resolve, reject) => {\n server.listen(options.port, () => {\n resolve(server);\n });\n\n server.on('error', (error) => {\n log(error);\n reject(error);\n });\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.cts","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";AASA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa;AAInC,OAAO,KAAK,EAAE,uBAAuB,EAAE,uBAAmB;AAG1D,MAAM,MAAM,aAAa,GAAG,QAAQ,CAElC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,CAC5C,CAAC;AAoCF;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,gGA4BvD"}
1
+ {"version":3,"file":"server.d.cts","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";AASA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa;AAKnC,OAAO,KAAK,EAAE,uBAAuB,EAAE,uBAAmB;AAE1D,MAAM,MAAM,aAAa,GAAG,QAAQ,CAElC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,CAC5C,CAAC;AAoCF;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,gGA4BvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.mts","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";AASA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa;AAInC,OAAO,KAAK,EAAE,uBAAuB,EAAE,uBAAmB;AAG1D,MAAM,MAAM,aAAa,GAAG,QAAQ,CAElC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,CAC5C,CAAC;AAoCF;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,gGA4BvD"}
1
+ {"version":3,"file":"server.d.mts","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";AASA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa;AAKnC,OAAO,KAAK,EAAE,uBAAuB,EAAE,uBAAmB;AAE1D,MAAM,MAAM,aAAa,GAAG,QAAQ,CAElC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,QAAQ,CAAC,CAC5C,CAAC;AAoCF;;;;;;;;GAQG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,aAAa,gGA4BvD"}
@@ -6,7 +6,7 @@ function $importDefault(module) {
6
6
  }
7
7
  import { assertIsSnapManifest, isDirectory, isFile } from "@metamask/snaps-utils/node";
8
8
  import { createModuleLogger } from "@metamask/utils";
9
- import $express from "express/index.js";
9
+ import $express, { static as expressStatic } from "express/index.js";
10
10
  const express = $importDefault($express);
11
11
  import { promises as fs } from "fs";
12
12
  import { createServer } from "http";
@@ -59,7 +59,7 @@ export async function startServer(options) {
59
59
  response.header('Access-Control-Allow-Headers', 'Content-Type');
60
60
  next();
61
61
  });
62
- app.use(express.static(pathResolve(process.cwd(), options.root)));
62
+ app.use(expressStatic(pathResolve(process.cwd(), options.root)));
63
63
  const server = createServer(app);
64
64
  return await new Promise((resolve, reject) => {
65
65
  server.listen(options.port, () => {
@@ -1 +1 @@
1
- {"version":3,"file":"server.mjs","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,MAAM,EACP,mCAAmC;AACpC,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,QAAO,yBAAgB;;AAC9B,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AAEpC,OAAO,EAAE,YAAY,EAAE,aAAa;AACpC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,aAAa;AAG9C,OAAO,EAAE,UAAU,EAAE,qBAAiB;AAOtC;;;;;;;;;GASG;AACH,KAAK,UAAU,UAAU,CAAC,IAAY;IACpC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,CAAC,CAAC,MAAM,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,uBAAuB,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAiB,MAAM,EAAE;SACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;SAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEpB,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,WAAW,CAAC,IAAI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B,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC3B,GAAG,CAAC,KAAK,CAAC,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n assertIsSnapManifest,\n isDirectory,\n isFile,\n} from '@metamask/snaps-utils/node';\nimport { createModuleLogger } from '@metamask/utils';\nimport express from 'express';\nimport { promises as fs } from 'fs';\nimport type { Server } from 'http';\nimport { createServer } from 'http';\nimport { resolve as pathResolve } from 'path';\n\nimport type { SnapsEnvironmentOptions } from '../options';\nimport { rootLogger } from './logger';\n\nexport type ServerOptions = Required<\n // We need a double `Required` for the type to be inferred correctly.\n Required<SnapsEnvironmentOptions>['server']\n>;\n\n/**\n * Check that:\n *\n * - The root directory exists.\n * - The root directory contains a `snap.manifest.json` file.\n * - The file path in the manifest exists.\n *\n * @param root - The root directory.\n * @throws If any of the checks fail.\n */\nasync function assertRoot(root: string) {\n if (!root) {\n throw new Error('You must specify a root directory.');\n }\n\n if (!(await isDirectory(root, false))) {\n throw new Error(`Root directory \"${root}\" is not a directory.`);\n }\n\n const manifestPath = pathResolve(root, 'snap.manifest.json');\n const manifest: SnapManifest = await fs\n .readFile(manifestPath, 'utf8')\n .then(JSON.parse);\n\n assertIsSnapManifest(manifest);\n const filePath = pathResolve(root, manifest.source.location.npm.filePath);\n\n if (!(await isFile(filePath))) {\n throw new Error(\n `File \"${filePath}\" does not exist, or is not a file. Did you forget to build your snap?`,\n );\n }\n}\n\n/**\n * Start an HTTP server on `localhost` with a random port. This is used to serve\n * the static files for the environment.\n *\n * @param options - The options to use.\n * @param options.port - The port to use for the server.\n * @param options.root - The root directory to serve from the server.\n * @returns The HTTP server.\n */\nexport async function startServer(options: ServerOptions) {\n await assertRoot(options.root);\n\n const log = createModuleLogger(rootLogger, 'server');\n const app = express();\n\n app.use((_request, response, next) => {\n response.header('Access-Control-Allow-Origin', '*');\n response.header('Access-Control-Allow-Credentials', 'true');\n response.header('Access-Control-Allow-Methods', 'GET, OPTIONS');\n response.header('Access-Control-Allow-Headers', 'Content-Type');\n\n next();\n });\n\n app.use(express.static(pathResolve(process.cwd(), options.root)));\n\n const server = createServer(app);\n return await new Promise<Server>((resolve, reject) => {\n server.listen(options.port, () => {\n resolve(server);\n });\n\n server.on('error', (error) => {\n log(error);\n reject(error);\n });\n });\n}\n"]}
1
+ {"version":3,"file":"server.mjs","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,MAAM,EACP,mCAAmC;AACpC,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AACrD,OAAO,UAAS,EAAE,MAAM,IAAI,aAAa,EAAE,yBAAgB;;AAC3D,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,WAAW;AAEpC,OAAO,EAAE,YAAY,EAAE,aAAa;AACpC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,aAAa;AAE9C,OAAO,EAAE,UAAU,EAAE,qBAAiB;AAQtC;;;;;;;;;GASG;AACH,KAAK,UAAU,UAAU,CAAC,IAAY;IACpC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,CAAC,CAAC,MAAM,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,uBAAuB,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAiB,MAAM,EAAE;SACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;SAC9B,IAAI,C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;QACnD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE;YAC/B,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YAC3B,GAAG,CAAC,KAAK,CAAC,CAAC;YACX,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n assertIsSnapManifest,\n isDirectory,\n isFile,\n} from '@metamask/snaps-utils/node';\nimport { createModuleLogger } from '@metamask/utils';\nimport express, { static as expressStatic } from 'express';\nimport { promises as fs } from 'fs';\nimport type { Server } from 'http';\nimport { createServer } from 'http';\nimport { resolve as pathResolve } from 'path';\n\nimport { rootLogger } from './logger';\nimport type { SnapsEnvironmentOptions } from '../options';\n\nexport type ServerOptions = Required<\n // We need a double `Required` for the type to be inferred correctly.\n Required<SnapsEnvironmentOptions>['server']\n>;\n\n/**\n * Check that:\n *\n * - The root directory exists.\n * - The root directory contains a `snap.manifest.json` file.\n * - The file path in the manifest exists.\n *\n * @param root - The root directory.\n * @throws If any of the checks fail.\n */\nasync function assertRoot(root: string) {\n if (!root) {\n throw new Error('You must specify a root directory.');\n }\n\n if (!(await isDirectory(root, false))) {\n throw new Error(`Root directory \"${root}\" is not a directory.`);\n }\n\n const manifestPath = pathResolve(root, 'snap.manifest.json');\n const manifest: SnapManifest = await fs\n .readFile(manifestPath, 'utf8')\n .then(JSON.parse);\n\n assertIsSnapManifest(manifest);\n const filePath = pathResolve(root, manifest.source.location.npm.filePath);\n\n if (!(await isFile(filePath))) {\n throw new Error(\n `File \"${filePath}\" does not exist, or is not a file. Did you forget to build your snap?`,\n );\n }\n}\n\n/**\n * Start an HTTP server on `localhost` with a random port. This is used to serve\n * the static files for the environment.\n *\n * @param options - The options to use.\n * @param options.port - The port to use for the server.\n * @param options.root - The root directory to serve from the server.\n * @returns The HTTP server.\n */\nexport async function startServer(options: ServerOptions) {\n await assertRoot(options.root);\n\n const log = createModuleLogger(rootLogger, 'server');\n const app = express();\n\n app.use((_request, response, next) => {\n response.header('Access-Control-Allow-Origin', '*');\n response.header('Access-Control-Allow-Credentials', 'true');\n response.header('Access-Control-Allow-Methods', 'GET, OPTIONS');\n response.header('Access-Control-Allow-Headers', 'Content-Type');\n\n next();\n });\n\n app.use(expressStatic(pathResolve(process.cwd(), options.root)));\n\n const server = createServer(app);\n return await new Promise<Server>((resolve, reject) => {\n server.listen(options.port, () => {\n resolve(server);\n });\n\n server.on('error', (error) => {\n log(error);\n reject(error);\n });\n });\n}\n"]}
package/dist/matchers.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
- /* eslint-disable no-invalid-this */
2
+ // Note: Because this file imports from `@jest/globals`, it can only be used in
3
+ // a Jest environment. This is why it's not exported from the index file.
3
4
  Object.defineProperty(exports, "__esModule", { value: true });
4
5
  exports.toRender = exports.toSendNotification = exports.toRespondWithError = exports.toRespondWith = void 0;
5
6
  const globals_1 = require("@jest/globals");
@@ -186,7 +187,10 @@ const toRenderLegacy = function (actual, expected) {
186
187
  `\n\nDifference:\n\n${difference}`;
187
188
  return { message, pass };
188
189
  };
189
- const toRender = function (actual, expected) {
190
+ const toRender =
191
+ // This should not return a promise.
192
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
193
+ function (actual, expected) {
190
194
  assertHasInterface(actual, 'toRender');
191
195
  if (!(0, jsx_1.isJSXElementUnsafe)(expected)) {
192
196
  return toRenderLegacy.call(this, actual, expected);
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.cjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAMpC,2CAAuC;AAQvC,iDAA+E;AAE/E,iEAGoC;AACpC,uDAG+B;AAC/B,uDAA2C;AAE3C,2CAA8C;AAE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CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM;YAC5C,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAhCS,QAAA,QAAQ,YAgCjB;AAEJ,gBAAM,CAAC,MAAM,CAAC;IACZ,aAAa,EAAb,qBAAa;IACb,kBAAkB,EAAlB,0BAAkB;IAClB,kBAAkB,EAAlB,0BAAkB;IAClB,QAAQ,EAAR,gBAAQ;CACT,CAAC,CAAC","sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n EnumToUnion,\n ComponentOrElement,\n Component,\n NotificationType,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe, JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expectedMessage - The expected notification message.\n * @param expectedType - The expected notification type.\n * @param expectedTitle - The expected notification title.\n * @param expectedContent - The expected notification JSX content.\n * @param expectedFooterLink - The expected footer link object.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [\n expectedMessage: string,\n expectedType?: EnumToUnion<NotificationType> | undefined,\n expectedTitle?: string | undefined,\n expectedContent?: JSXElement | undefined,\n expectedFooterLink?: { text: string; href: string } | undefined,\n ]\n> = function (\n actual,\n expectedMessage,\n expectedType,\n expectedTitle,\n expectedContent,\n expectedFooterLink,\n) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n let jsxContent: JSXElement | undefined;\n\n if ('getInterface' in actual) {\n jsxContent = actual.getInterface().content;\n }\n\n const notificationValidator = (\n notification: SnapResponse['notifications'][number],\n ) => {\n const { type, message, title, footerLink } = notification as Record<\n string,\n unknown\n >;\n\n if (!this.equals(message, expectedMessage)) {\n return false;\n }\n\n if (expectedType && type !== expectedType) {\n return false;\n }\n\n if (title && !this.equals(title, expectedTitle)) {\n return false;\n }\n\n if (jsxContent && !this.equals(jsxContent, expectedContent)) {\n return false;\n }\n\n if (footerLink && !this.equals(footerLink, expectedFooterLink)) {\n return false;\n }\n\n return true;\n };\n\n const pass = notifications.some(notificationValidator);\n\n const transformedNotifications = notifications.map((notification) => {\n return {\n ...notification,\n // Ok to cast here as the function returns if the param is falsy\n content: serialiseJsx(jsxContent as SnapNode),\n };\n });\n\n const message = () => {\n let testMessage = pass\n ? `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n`\n : `${this.utils.matcherHint('.toSendNotification')}\\n\\n`;\n\n const {\n title,\n type,\n message: notifMessage,\n footerLink,\n content,\n } = transformedNotifications[0];\n\n testMessage += `Expected message: ${this.utils.printExpected(\n expectedMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Expected type: ${this.utils.printExpected(\n expectedType,\n )}\\n`;\n }\n\n if (title) {\n testMessage += `Expected title: ${this.utils.printExpected(\n expectedTitle,\n )}\\n`;\n\n // We want to check if the expected content is actually JSX content, otherwise `serialiseJsx` won't return something useful.\n if (is(expectedContent, JSXElementStruct)) {\n testMessage += `Expected content: ${this.utils.printExpected(\n serialiseJsx(expectedContent),\n )}\\n`;\n } else {\n testMessage += `Expected content: ${this.utils.printExpected(\n expectedContent,\n )}\\n`;\n }\n }\n\n if (footerLink) {\n testMessage += `Expected footer link: ${this.utils.printExpected(\n expectedFooterLink,\n )}\\n`;\n }\n\n testMessage += `Received message: ${this.utils.printExpected(\n notifMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Received type: ${this.utils.printReceived(type)}\\n`;\n }\n\n if (title) {\n testMessage += `Received title: ${this.utils.printReceived(title)}\\n`;\n testMessage += `Received content: ${this.utils.printReceived(\n serialiseJsx(content),\n )}\\n`;\n }\n\n if (footerLink) {\n testMessage += `Received footer link: ${this.utils.printReceived(\n footerLink,\n )}\\n`;\n }\n\n return testMessage;\n };\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
1
+ {"version":3,"file":"matchers.cjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,yEAAyE;;;AAGzE,2CAAuC;AAQvC,iDAA+E;AAE/E,iEAGoC;AACpC,uDAG+B;AAC/B,uDAA2C;AAE3C,2CAA8C;AAE9C,2DAQ4B;AAE5B;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,IAAA,gBAAE,EAAC,MAAM,EAAE,qCAAkB,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,IAAA,wCAAmB,EACjB,IAAA,gCAAW,EAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,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,kCAAe,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;;;;;;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tB,IAAA,0BAAY,EAAC,OAAO,CAAC,CACZ,CAAC;IAEZ,MAAM,OAAO,GAAG,IAAI;QAClB,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,eAAe,CAAC,MAAM;YAChD,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE;QACtC,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM;YAC5C,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,IAAA,mCAAc,EAAC,IAAA,0BAAY,EAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAlCS,QAAA,QAAQ,YAkCjB;AAEJ,gBAAM,CAAC,MAAM,CAAC;IACZ,aAAa,EAAb,qBAAa;IACb,kBAAkB,EAAlB,0BAAkB;IAClB,kBAAkB,EAAlB,0BAAkB;IAClB,QAAQ,EAAR,gBAAQ;CACT,CAAC,CAAC","sourcesContent":["// 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 EnumToUnion,\n ComponentOrElement,\n Component,\n NotificationType,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe, JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expectedMessage - The expected notification message.\n * @param expectedType - The expected notification type.\n * @param expectedTitle - The expected notification title.\n * @param expectedContent - The expected notification JSX content.\n * @param expectedFooterLink - The expected footer link object.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [\n expectedMessage: string,\n expectedType?: EnumToUnion<NotificationType> | undefined,\n expectedTitle?: string | undefined,\n expectedContent?: JSXElement | undefined,\n expectedFooterLink?: { text: string; href: string } | undefined,\n ]\n> = function (\n actual,\n expectedMessage,\n expectedType,\n expectedTitle,\n expectedContent,\n expectedFooterLink,\n) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n let jsxContent: JSXElement | undefined;\n\n if ('getInterface' in actual) {\n jsxContent = actual.getInterface().content;\n }\n\n const notificationValidator = (\n notification: SnapResponse['notifications'][number],\n ) => {\n const { type, message, title, footerLink } = notification as Record<\n string,\n unknown\n >;\n\n if (!this.equals(message, expectedMessage)) {\n return false;\n }\n\n if (expectedType && type !== expectedType) {\n return false;\n }\n\n if (title && !this.equals(title, expectedTitle)) {\n return false;\n }\n\n if (jsxContent && !this.equals(jsxContent, expectedContent)) {\n return false;\n }\n\n if (footerLink && !this.equals(footerLink, expectedFooterLink)) {\n return false;\n }\n\n return true;\n };\n\n const pass = notifications.some(notificationValidator);\n\n const transformedNotifications = notifications.map((notification) => {\n return {\n ...notification,\n // Ok to cast here as the function returns if the param is falsy\n content: serialiseJsx(jsxContent as SnapNode),\n };\n });\n\n const message = () => {\n let testMessage = pass\n ? `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n`\n : `${this.utils.matcherHint('.toSendNotification')}\\n\\n`;\n\n const {\n title,\n type,\n message: notifMessage,\n footerLink,\n content,\n } = transformedNotifications[0];\n\n testMessage += `Expected message: ${this.utils.printExpected(\n expectedMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Expected type: ${this.utils.printExpected(\n expectedType,\n )}\\n`;\n }\n\n if (title) {\n testMessage += `Expected title: ${this.utils.printExpected(\n expectedTitle,\n )}\\n`;\n\n // We want to check if the expected content is actually JSX content, otherwise `serialiseJsx` won't return something useful.\n if (is(expectedContent, JSXElementStruct)) {\n testMessage += `Expected content: ${this.utils.printExpected(\n serialiseJsx(expectedContent),\n )}\\n`;\n } else {\n testMessage += `Expected content: ${this.utils.printExpected(\n expectedContent,\n )}\\n`;\n }\n }\n\n if (footerLink) {\n testMessage += `Expected footer link: ${this.utils.printExpected(\n expectedFooterLink,\n )}\\n`;\n }\n\n testMessage += `Received message: ${this.utils.printExpected(\n notifMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Received type: ${this.utils.printReceived(type)}\\n`;\n }\n\n if (title) {\n testMessage += `Received title: ${this.utils.printReceived(title)}\\n`;\n testMessage += `Received content: ${this.utils.printReceived(\n serialiseJsx(content),\n )}\\n`;\n }\n\n if (footerLink) {\n testMessage += `Received footer link: ${this.utils.printReceived(\n footerLink,\n )}\\n`;\n }\n\n return testMessage;\n };\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 // This should not return a promise.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.d.cts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAElB,gBAAgB,EACjB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAY,gCAAgC;AAYpE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AA8D5C;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IACE,eAAe,EAAE,MAAM;IACvB,YAAY,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;IACxD,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS;IAClC,eAAe,CAAC,EAAE,UAAU,GAAG,SAAS;IACxC,kBAAkB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;CAChE,CAkIF,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAgClE,CAAC"}
1
+ {"version":3,"file":"matchers.d.cts","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,qBAAqB;AAEpD,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAElB,gBAAgB,EACjB,4BAA4B;AAC7B,OAAO,KAAK,EAAE,UAAU,EAAY,gCAAgC;AAYpE,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AA8D5C;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IACE,eAAe,EAAE,MAAM;IACvB,YAAY,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;IACxD,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS;IAClC,eAAe,CAAC,EAAE,UAAU,GAAG,SAAS;IACxC,kBAAkB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;CAChE,CAkIF,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAkClE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.d.mts","sourceRoot":"","sources":["../src/match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AQ,EAAE,IAAI,CAAC,CA4B3D,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,IAAI,CAAC,CA4BhE,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C;IACE,eAAe,EAAE,MAAM;IACvB,YAAY,CAAC,EAAE,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS;IACxD,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS;IAClC,eAAe,CAAC,EAAE,UAAU,GAAG,SAAS;IACxC,kBAAkB,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS;CAChE,CAkIF,CAAC;AAgCF,eAAO,MAAM,QAAQ,EAAE,eAAe,CAAC,CAAC,QAAQ,EAAE,kBAAkB,CAAC,CAkClE,CAAC"}
package/dist/matchers.mjs CHANGED
@@ -1,4 +1,5 @@
1
- /* eslint-disable no-invalid-this */
1
+ // Note: Because this file imports from `@jest/globals`, it can only be used in
2
+ // a Jest environment. This is why it's not exported from the index file.
2
3
  import $jestglobals from "@jest/globals";
3
4
  const { expect } = $jestglobals;
4
5
  import { isJSXElementUnsafe, JSXElementStruct } from "@metamask/snaps-sdk/jsx";
@@ -181,7 +182,10 @@ const toRenderLegacy = function (actual, expected) {
181
182
  `\n\nDifference:\n\n${difference}`;
182
183
  return { message, pass };
183
184
  };
184
- export const toRender = function (actual, expected) {
185
+ export const toRender =
186
+ // This should not return a promise.
187
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
188
+ function (actual, expected) {
185
189
  assertHasInterface(actual, 'toRender');
186
190
  if (!isJSXElementUnsafe(expected)) {
187
191
  return toRenderLegacy.call(this, actual, expected);
@@ -1 +1 @@
1
- {"version":3,"file":"matchers.mjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA,oCAAoC;;;AAcpC,OAAO,E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c,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 EnumToUnion,\n ComponentOrElement,\n Component,\n NotificationType,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe, JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expectedMessage - The expected notification message.\n * @param expectedType - The expected notification type.\n * @param expectedTitle - The expected notification title.\n * @param expectedContent - The expected notification JSX content.\n * @param expectedFooterLink - The expected footer link object.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [\n expectedMessage: string,\n expectedType?: EnumToUnion<NotificationType> | undefined,\n expectedTitle?: string | undefined,\n expectedContent?: JSXElement | undefined,\n expectedFooterLink?: { text: string; href: string } | undefined,\n ]\n> = function (\n actual,\n expectedMessage,\n expectedType,\n expectedTitle,\n expectedContent,\n expectedFooterLink,\n) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n let jsxContent: JSXElement | undefined;\n\n if ('getInterface' in actual) {\n jsxContent = actual.getInterface().content;\n }\n\n const notificationValidator = (\n notification: SnapResponse['notifications'][number],\n ) => {\n const { type, message, title, footerLink } = notification as Record<\n string,\n unknown\n >;\n\n if (!this.equals(message, expectedMessage)) {\n return false;\n }\n\n if (expectedType && type !== expectedType) {\n return false;\n }\n\n if (title && !this.equals(title, expectedTitle)) {\n return false;\n }\n\n if (jsxContent && !this.equals(jsxContent, expectedContent)) {\n return false;\n }\n\n if (footerLink && !this.equals(footerLink, expectedFooterLink)) {\n return false;\n }\n\n return true;\n };\n\n const pass = notifications.some(notificationValidator);\n\n const transformedNotifications = notifications.map((notification) => {\n return {\n ...notification,\n // Ok to cast here as the function returns if the param is falsy\n content: serialiseJsx(jsxContent as SnapNode),\n };\n });\n\n const message = () => {\n let testMessage = pass\n ? `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n`\n : `${this.utils.matcherHint('.toSendNotification')}\\n\\n`;\n\n const {\n title,\n type,\n message: notifMessage,\n footerLink,\n content,\n } = transformedNotifications[0];\n\n testMessage += `Expected message: ${this.utils.printExpected(\n expectedMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Expected type: ${this.utils.printExpected(\n expectedType,\n )}\\n`;\n }\n\n if (title) {\n testMessage += `Expected title: ${this.utils.printExpected(\n expectedTitle,\n )}\\n`;\n\n // We want to check if the expected content is actually JSX content, otherwise `serialiseJsx` won't return something useful.\n if (is(expectedContent, JSXElementStruct)) {\n testMessage += `Expected content: ${this.utils.printExpected(\n serialiseJsx(expectedContent),\n )}\\n`;\n } else {\n testMessage += `Expected content: ${this.utils.printExpected(\n expectedContent,\n )}\\n`;\n }\n }\n\n if (footerLink) {\n testMessage += `Expected footer link: ${this.utils.printExpected(\n expectedFooterLink,\n )}\\n`;\n }\n\n testMessage += `Received message: ${this.utils.printExpected(\n notifMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Received type: ${this.utils.printReceived(type)}\\n`;\n }\n\n if (title) {\n testMessage += `Received title: ${this.utils.printReceived(title)}\\n`;\n testMessage += `Received content: ${this.utils.printReceived(\n serialiseJsx(content),\n )}\\n`;\n }\n\n if (footerLink) {\n testMessage += `Received footer link: ${this.utils.printReceived(\n footerLink,\n )}\\n`;\n }\n\n return testMessage;\n };\n\n return { message, pass };\n};\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
1
+ {"version":3,"file":"matchers.mjs","sourceRoot":"","sources":["../src/matchers.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,yEAAyE;;;AAWzE,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,gCAAgC;AAE/E,OAAO,EACL,eAAe,EACf,kBAAkB,EACnB,mCAAmC;AACpC,OAAO,EACL,0BAA0B,EAC1B,YAAY,EACb,8BAA8B;AAC/B,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAE3C,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,OAAO,EACL,cAAc,EACd,IAAI,EACJ,mBAAmB,EACnB,WAAW,EACX,aAAa,EACb,aAAa,EACb,cAAc,EACf,2BAA2B;AAE5B;;;;;;GAMG;AACH,SAAS,0BAA0B,CACjC,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,mBAAmB,CACjB,WAAW,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,cAAc,CACf,UAAU,CACX,yDAAyD,EAC1D,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,aAAa,CAAC,CACjD,CACF,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,kBAAkB,CACzB,MAAe,EACf,WAAmB,EACnB,OAA4B;IAE5B,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CACb,mBAAmB,CACjB,WAAW,CAAC,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,EACvD,GAAG,cA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AAQ,CAAC,EACtB,YAAY,CAAC,OAAO,CAAC,CACZ,CAAC;IAEZ,MAAM,OAAO,GAAG,IAAI;QAClB,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,eAAe,CAAC,MAAM;YAChD,cAAc,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE;QACtC,CAAC,CAAC,GAAG,EAAE,CACH,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,MAAM;YAC5C,cAAc,cAAc,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,MAAM;YAC1D,cAAc,cAAc,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,EAAE;YACrD,sBAAsB,UAAU,EAAE,CAAC;IAEzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;AAC3B,CAAC,CAAC;AAEJ,MAAM,CAAC,MAAM,CAAC;IACZ,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,QAAQ;CACT,CAAC,CAAC","sourcesContent":["// 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 EnumToUnion,\n ComponentOrElement,\n Component,\n NotificationType,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement, SnapNode } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe, JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport type { SnapResponse } from '@metamask/snaps-simulation';\nimport {\n InterfaceStruct,\n SnapResponseStruct,\n} from '@metamask/snaps-simulation';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expectedMessage - The expected notification message.\n * @param expectedType - The expected notification type.\n * @param expectedTitle - The expected notification title.\n * @param expectedContent - The expected notification JSX content.\n * @param expectedFooterLink - The expected footer link object.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [\n expectedMessage: string,\n expectedType?: EnumToUnion<NotificationType> | undefined,\n expectedTitle?: string | undefined,\n expectedContent?: JSXElement | undefined,\n expectedFooterLink?: { text: string; href: string } | undefined,\n ]\n> = function (\n actual,\n expectedMessage,\n expectedType,\n expectedTitle,\n expectedContent,\n expectedFooterLink,\n) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n let jsxContent: JSXElement | undefined;\n\n if ('getInterface' in actual) {\n jsxContent = actual.getInterface().content;\n }\n\n const notificationValidator = (\n notification: SnapResponse['notifications'][number],\n ) => {\n const { type, message, title, footerLink } = notification as Record<\n string,\n unknown\n >;\n\n if (!this.equals(message, expectedMessage)) {\n return false;\n }\n\n if (expectedType && type !== expectedType) {\n return false;\n }\n\n if (title && !this.equals(title, expectedTitle)) {\n return false;\n }\n\n if (jsxContent && !this.equals(jsxContent, expectedContent)) {\n return false;\n }\n\n if (footerLink && !this.equals(footerLink, expectedFooterLink)) {\n return false;\n }\n\n return true;\n };\n\n const pass = notifications.some(notificationValidator);\n\n const transformedNotifications = notifications.map((notification) => {\n return {\n ...notification,\n // Ok to cast here as the function returns if the param is falsy\n content: serialiseJsx(jsxContent as SnapNode),\n };\n });\n\n const message = () => {\n let testMessage = pass\n ? `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n`\n : `${this.utils.matcherHint('.toSendNotification')}\\n\\n`;\n\n const {\n title,\n type,\n message: notifMessage,\n footerLink,\n content,\n } = transformedNotifications[0];\n\n testMessage += `Expected message: ${this.utils.printExpected(\n expectedMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Expected type: ${this.utils.printExpected(\n expectedType,\n )}\\n`;\n }\n\n if (title) {\n testMessage += `Expected title: ${this.utils.printExpected(\n expectedTitle,\n )}\\n`;\n\n // We want to check if the expected content is actually JSX content, otherwise `serialiseJsx` won't return something useful.\n if (is(expectedContent, JSXElementStruct)) {\n testMessage += `Expected content: ${this.utils.printExpected(\n serialiseJsx(expectedContent),\n )}\\n`;\n } else {\n testMessage += `Expected content: ${this.utils.printExpected(\n expectedContent,\n )}\\n`;\n }\n }\n\n if (footerLink) {\n testMessage += `Expected footer link: ${this.utils.printExpected(\n expectedFooterLink,\n )}\\n`;\n }\n\n testMessage += `Received message: ${this.utils.printExpected(\n notifMessage,\n )}\\n`;\n\n if (expectedType) {\n testMessage += `Received type: ${this.utils.printReceived(type)}\\n`;\n }\n\n if (title) {\n testMessage += `Received title: ${this.utils.printReceived(title)}\\n`;\n testMessage += `Received content: ${this.utils.printReceived(\n serialiseJsx(content),\n )}\\n`;\n }\n\n if (footerLink) {\n testMessage += `Received footer link: ${this.utils.printReceived(\n footerLink,\n )}\\n`;\n }\n\n return testMessage;\n };\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 // This should not return a promise.\n // eslint-disable-next-line @typescript-eslint/promise-function-async\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/setup.cjs CHANGED
@@ -2,6 +2,6 @@
2
2
  // Setup file for Jest. This file is used in the Jest preset configuration, and
3
3
  // not intended to be exported or used directly.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- // eslint-disable-next-line import/no-unassigned-import
5
+ // eslint-disable-next-line import-x/no-unassigned-import
6
6
  require("./matchers.cjs");
7
7
  //# sourceMappingURL=setup.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup.cjs","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,gDAAgD;;AAEhD,uDAAuD;AACvD,0BAAoB","sourcesContent":["// Setup file for Jest. This file is used in the Jest preset configuration, and\n// not intended to be exported or used directly.\n\n// eslint-disable-next-line import/no-unassigned-import\nimport './matchers';\n"]}
1
+ {"version":3,"file":"setup.cjs","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":";AAAA,+EAA+E;AAC/E,gDAAgD;;AAEhD,yDAAyD;AACzD,0BAAoB","sourcesContent":["// Setup file for Jest. This file is used in the Jest preset configuration, and\n// not intended to be exported or used directly.\n\n// eslint-disable-next-line import-x/no-unassigned-import\nimport './matchers';\n"]}
package/dist/setup.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // Setup file for Jest. This file is used in the Jest preset configuration, and
2
2
  // not intended to be exported or used directly.
3
- // eslint-disable-next-line import/no-unassigned-import
3
+ // eslint-disable-next-line import-x/no-unassigned-import
4
4
  import "./matchers.mjs";
5
5
  //# sourceMappingURL=setup.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"setup.mjs","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gDAAgD;AAEhD,uDAAuD;AACvD,wBAAoB","sourcesContent":["// Setup file for Jest. This file is used in the Jest preset configuration, and\n// not intended to be exported or used directly.\n\n// eslint-disable-next-line import/no-unassigned-import\nimport './matchers';\n"]}
1
+ {"version":3,"file":"setup.mjs","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,gDAAgD;AAEhD,yDAAyD;AACzD,wBAAoB","sourcesContent":["// Setup file for Jest. This file is used in the Jest preset configuration, and\n// not intended to be exported or used directly.\n\n// eslint-disable-next-line import-x/no-unassigned-import\nimport './matchers';\n"]}
package/jest-preset.js CHANGED
@@ -1,5 +1,3 @@
1
- /* eslint-disable jsdoc/valid-types */
2
-
3
1
  const { resolve } = require('path');
4
2
 
5
3
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-jest",
3
- "version": "8.12.0",
3
+ "version": "8.13.0",
4
4
  "description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -45,9 +45,9 @@
45
45
  "lint": "yarn lint:eslint && yarn lint:misc --check && yarn changelog:validate && yarn lint:dependencies",
46
46
  "lint:ci": "yarn lint",
47
47
  "lint:dependencies": "depcheck",
48
- "lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
48
+ "lint:eslint": "eslint . --cache",
49
49
  "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
50
- "lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
50
+ "lint:misc": "prettier --no-error-on-unmatched-pattern --log-level warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
51
51
  "publish:preview": "yarn npm publish --tag preview",
52
52
  "since-latest-release": "../../scripts/since-latest-release.sh",
53
53
  "test": "jest --reporters=jest-silent-reporter",
@@ -60,9 +60,9 @@
60
60
  "@jest/environment": "^29.5.0",
61
61
  "@jest/expect": "^29.5.0",
62
62
  "@jest/globals": "^29.5.0",
63
- "@metamask/snaps-controllers": "^10.0.0",
64
- "@metamask/snaps-sdk": "^6.18.0",
65
- "@metamask/snaps-simulation": "^2.2.0",
63
+ "@metamask/snaps-controllers": "^10.0.1",
64
+ "@metamask/snaps-sdk": "^6.19.0",
65
+ "@metamask/snaps-simulation": "^2.3.0",
66
66
  "@metamask/superstruct": "^3.1.0",
67
67
  "@metamask/utils": "^11.2.0",
68
68
  "express": "^4.18.2",
@@ -73,34 +73,20 @@
73
73
  "devDependencies": {
74
74
  "@jest/types": "^29.6.3",
75
75
  "@lavamoat/allow-scripts": "^3.0.4",
76
- "@metamask/auto-changelog": "^3.4.4",
77
- "@metamask/eslint-config": "^12.1.0",
78
- "@metamask/eslint-config-jest": "^12.1.0",
79
- "@metamask/eslint-config-nodejs": "^12.1.0",
80
- "@metamask/eslint-config-typescript": "^12.1.0",
81
- "@metamask/snaps-utils": "^9.0.0",
76
+ "@metamask/auto-changelog": "^4.1.0",
77
+ "@metamask/snaps-utils": "^9.0.1",
82
78
  "@swc/core": "1.3.78",
83
79
  "@swc/jest": "^0.2.26",
84
80
  "@ts-bridge/cli": "^0.6.1",
85
81
  "@types/jest": "^27.5.1",
86
82
  "@types/semver": "^7.5.0",
87
- "@typescript-eslint/eslint-plugin": "^5.42.1",
88
- "@typescript-eslint/parser": "^6.21.0",
89
83
  "deepmerge": "^4.2.2",
90
84
  "depcheck": "^1.4.7",
91
- "eslint": "^8.27.0",
92
- "eslint-config-prettier": "^8.5.0",
93
- "eslint-plugin-import": "^2.26.0",
94
- "eslint-plugin-jest": "^27.1.5",
95
- "eslint-plugin-jsdoc": "^41.1.2",
96
- "eslint-plugin-n": "^15.7.0",
97
- "eslint-plugin-prettier": "^4.2.1",
98
- "eslint-plugin-promise": "^6.1.1",
85
+ "eslint": "^9.11.0",
99
86
  "jest": "^29.0.2",
100
87
  "jest-it-up": "^2.0.0",
101
88
  "jest-silent-reporter": "^0.6.0",
102
- "prettier": "^2.8.8",
103
- "prettier-plugin-packagejson": "^2.5.2",
89
+ "prettier": "^3.3.3",
104
90
  "typescript": "~5.3.3"
105
91
  },
106
92
  "engines": {