UNPKG

@metamask/snaps-jest

Version:

A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers

1 lines 2.66 kB
{"version":3,"file":"options.cjs","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AACA,uDAQ+B;AAE/B,MAAM,6BAA6B,GAAG,IAAA,kBAAI,EAAC;IACzC,MAAM,EAAE,IAAA,uBAAS,EACf,IAAA,oBAAM,EAAC;QACL,OAAO,EAAE,IAAA,uBAAS,EAAC,IAAA,qBAAO,GAAE,EAAE,IAAI,CAAC;QACnC,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,CAAC;QAC5B,IAAI,EAAE,IAAA,uBAAS,EAAC,IAAA,oBAAM,GAAE,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC;KACzC,CAAC,EACF,EAAE,CACH;CACF,CAAC,CAAC;AA+BH;;;;;;;GAOG;AACH,SAAgB,UAAU,CAAC,sBAA+C;IACxE,OAAO,IAAA,oBAAM,EAAC,sBAAsB,EAAE,6BAA6B,CAAC,CAAC;AACvE,CAAC;AAFD,gCAEC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '@metamask/superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n\nexport type {\n SimulationAccount,\n SimulationAsset,\n} from '@metamask/snaps-simulation';\n"]}