@metamask/snaps-jest 8.14.1 → 8.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [8.15.0]
11
+
12
+ ### Added
13
+
14
+ - Add support for `wallet_switchEthereumChain` ([#2634](https://github.com/MetaMask/snaps/pull/2634))
15
+
10
16
  ## [8.14.1]
11
17
 
12
18
  ### Fixed
@@ -363,7 +369,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
363
369
  - The version of the package no longer needs to match the version of all other
364
370
  MetaMask Snaps packages.
365
371
 
366
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.14.1...HEAD
372
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.15.0...HEAD
373
+ [8.15.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.14.1...@metamask/snaps-jest@8.15.0
367
374
  [8.14.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.14.0...@metamask/snaps-jest@8.14.1
368
375
  [8.14.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.13.0...@metamask/snaps-jest@8.14.0
369
376
  [8.13.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.12.0...@metamask/snaps-jest@8.13.0
@@ -28,7 +28,6 @@ const node_1 = require("@metamask/snaps-utils/node");
28
28
  const utils_1 = require("@metamask/utils");
29
29
  const express_1 = __importStar(require("express/index.js"));
30
30
  const fs_1 = require("fs");
31
- const http_1 = require("http");
32
31
  const path_1 = require("path");
33
32
  const logger_1 = require("./logger.cjs");
34
33
  /**
@@ -79,15 +78,15 @@ async function startServer(options) {
79
78
  next();
80
79
  });
81
80
  app.use((0, express_1.static)((0, path_1.resolve)(process.cwd(), options.root)));
82
- const server = (0, http_1.createServer)(app);
83
81
  return await new Promise((resolve, reject) => {
84
- server.listen(options.port, () => {
82
+ const server = app.listen(options.port, (error) => {
83
+ if (error) {
84
+ log(error);
85
+ reject(error);
86
+ return;
87
+ }
85
88
  resolve(server);
86
89
  });
87
- server.on('error', (error) => {
88
- log(error);
89
- reject(error);
90
- });
91
90
  });
92
91
  }
93
92
  exports.startServer = startServer;
@@ -1 +1 @@
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,CAAC,CAAC,MAAM,IAAA,kBAAW,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,uBAAuB,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,cAAW,EAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAiB,MAAM,aAAE;SACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;SAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEpB,IAAA,2BAAoB,EAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAA,cAAW,EAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE1E,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC,Q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K,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
+ {"version":3,"file":"server.cjs","sourceRoot":"","sources":["../../src/internals/server.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,qDAIoC;AACpC,2CAAqD;AACrD,4DAA2D;AAC3D,2BAAoC;AAEpC,+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,CAAC,CAAC,MAAM,IAAA,kBAAW,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,mBAAmB,IAAI,uBAAuB,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,cAAW,EAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IAC7D,MAAM,QAAQ,GAAiB,MAAM,aAAE;SACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;SAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAEpB,IAAA,2BAAoB,EAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,QAAQ,GAAG,IAAA,cAAW,EAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAE1E,IAAI,CAAC,CAAC,MAAM,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC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,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 { 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 return await new Promise<Server>((resolve, reject) => {\n const server = app.listen(options.port, (error) => {\n if (error) {\n log(error);\n reject(error);\n return;\n }\n\n resolve(server);\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;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
+ {"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;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;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
+ {"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;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"}
@@ -9,7 +9,6 @@ import { createModuleLogger } from "@metamask/utils";
9
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
- import { createServer } from "http";
13
12
  import { resolve as pathResolve } from "path";
14
13
  import { rootLogger } from "./logger.mjs";
15
14
  /**
@@ -60,15 +59,15 @@ export async function startServer(options) {
60
59
  next();
61
60
  });
62
61
  app.use(expressStatic(pathResolve(process.cwd(), options.root)));
63
- const server = createServer(app);
64
62
  return await new Promise((resolve, reject) => {
65
- server.listen(options.port, () => {
63
+ const server = app.listen(options.port, (error) => {
64
+ if (error) {
65
+ log(error);
66
+ reject(error);
67
+ return;
68
+ }
66
69
  resolve(server);
67
70
  });
68
- server.on('error', (error) => {
69
- log(error);
70
- reject(error);
71
- });
72
71
  });
73
72
  }
74
73
  //# sourceMappingURL=server.mjs.map
@@ -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,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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,CAAC,CAAC;QACpD,QAAQ,CAAC,MAAM,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;QAC5D,QAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAC;QAChE,QAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAC;QAEhE,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEjE,MAAM,MAAM,GAAG,YAAY,CAAC,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","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
+ {"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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AAE,QAAQ,EAAE,IAAI,EAAE,EAAE;QACnC,QAAQ,CAAC,MAAM,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAC;QACpD,QAAQ,CAAC,MAAM,CAAC,kCAAkC,EAAE,MAAM,CAAC,CAAC;QAC5D,QAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAC;QAChE,QAAQ,CAAC,MAAM,CAAC,8BAA8B,EAAE,cAAc,CAAC,CAAC;QAEhE,IAAI,EAAE,CAAC;IACT,CAAC,CAAC,CAAC;IAEH,GAAG,CAAC,GAAG,CAAC,aAAa,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAEjE,OAAO,MAAM,IAAI,OAAO,CAAS,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE;YAChD,IAAI,KAAK,EAAE,CAAC;gBACV,GAAG,CAAC,KAAK,CAAC,CAAC;gBACX,MAAM,CAAC,KAAK,CAAC,CAAC;gBACd,OAAO;YACT,CAAC;YAED,OAAO,CAAC,MAAM,CAAC,CAAC;QAClB,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 { 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 return await new Promise<Server>((resolve, reject) => {\n const server = app.listen(options.port, (error) => {\n if (error) {\n log(error);\n reject(error);\n return;\n }\n\n resolve(server);\n });\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-jest",
3
- "version": "8.14.1",
3
+ "version": "8.15.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",
@@ -60,21 +60,21 @@
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": "^11.2.0",
64
- "@metamask/snaps-sdk": "^6.22.0",
65
- "@metamask/snaps-simulation": "^2.4.1",
63
+ "@metamask/snaps-controllers": "^12.1.0",
64
+ "@metamask/snaps-sdk": "^6.24.0",
65
+ "@metamask/snaps-simulation": "^2.6.0",
66
66
  "@metamask/superstruct": "^3.2.1",
67
- "@metamask/utils": "^11.2.0",
68
- "express": "^4.21.2",
67
+ "@metamask/utils": "^11.4.0",
68
+ "express": "^5.1.0",
69
69
  "jest-environment-node": "^29.5.0",
70
70
  "jest-matcher-utils": "^29.5.0",
71
71
  "redux": "^4.2.1"
72
72
  },
73
73
  "devDependencies": {
74
74
  "@jest/types": "^29.6.3",
75
- "@lavamoat/allow-scripts": "^3.0.4",
76
- "@metamask/auto-changelog": "^5.0.1",
77
- "@metamask/snaps-utils": "^9.2.0",
75
+ "@lavamoat/allow-scripts": "^3.3.3",
76
+ "@metamask/auto-changelog": "^5.0.2",
77
+ "@metamask/snaps-utils": "^9.3.0",
78
78
  "@swc/core": "1.3.78",
79
79
  "@swc/jest": "^0.2.26",
80
80
  "@ts-bridge/cli": "^0.6.1",