@depup/msw 3.0.0-depup.0 → 3.0.2-depup.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.
@@ -7,7 +7,7 @@
7
7
  * - Please do NOT modify this file.
8
8
  */
9
9
 
10
- const PACKAGE_VERSION = '3.0.0'
10
+ const PACKAGE_VERSION = '3.0.2'
11
11
  const INTEGRITY_CHECKSUM = '5cd5cf8b54c3a90f82960cedcd637772'
12
12
  const IS_MOCKED_RESPONSE = Symbol('isMockedResponse')
13
13
 
package/lib/node/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { m as devUtils } from "../_chunks/cookie-store.js";
1
+ import { h as devUtils } from "../_chunks/cookie-store.js";
2
2
  import { c as HandlersController, s as defineNetwork, t as InterceptorSource } from "../_chunks/interceptor-source.js";
3
3
  import { invariant } from "outvariant";
4
4
  import { WebSocketInterceptor } from "@mswjs/interceptors/WebSocket";
package/lib/vite/index.js CHANGED
@@ -4,7 +4,6 @@ import { fileURLToPath } from "node:url";
4
4
  const WORKER_FILENAME = "mockServiceWorker.js";
5
5
  const WORKER_SCRIPT_PATH = new URL("../mockServiceWorker.js", import.meta.url);
6
6
  const VIRTUAL_MODULE_ID = "virtual:msw";
7
- const VIRTUAL_OPTIONS_ID = "virtual:msw/options";
8
7
  const RUNTIME_PATH = fileURLToPath(new URL("./runtime.js", import.meta.url));
9
8
  /**
10
9
  * A Vite plugin for Mock Service Worker.
@@ -41,18 +40,22 @@ function msw(options = {}) {
41
40
  const environmentsUsingNetwork = /* @__PURE__ */ new Set();
42
41
  return {
43
42
  name: "msw",
44
- async resolveId(id) {
43
+ resolveId(id) {
45
44
  if (mode === "worker-only") return;
46
- if (id === VIRTUAL_OPTIONS_ID) return `\0${VIRTUAL_OPTIONS_ID}`;
47
- if (id === VIRTUAL_MODULE_ID) return this.resolve(RUNTIME_PATH);
45
+ if (id === VIRTUAL_MODULE_ID) return `\0${VIRTUAL_MODULE_ID}`;
48
46
  },
49
47
  load(id) {
50
- if (mode === "worker-only" || id !== `\0${VIRTUAL_OPTIONS_ID}`) return;
51
- if (this.environment.config.consumer === "server") return `export { defaultNetworkOptions } from 'msw/node'`;
48
+ if (mode === "worker-only" || id !== `\0${VIRTUAL_MODULE_ID}`) return;
49
+ if (this.environment.config.consumer === "server") return `
50
+ import { defaultNetworkOptions } from 'msw/node'
51
+ import { createNetwork } from ${JSON.stringify(RUNTIME_PATH)}
52
+ export const network = await createNetwork(defaultNetworkOptions)
53
+ `;
52
54
  environmentsUsingNetwork.add(this.environment.name);
53
55
  return `
54
56
  import { createDefaultNetworkOptions } from 'msw/browser'
55
- export const defaultNetworkOptions = createDefaultNetworkOptions(${JSON.stringify(workerUrl)})
57
+ import { createNetwork } from ${JSON.stringify(RUNTIME_PATH)}
58
+ export const network = await createNetwork(createDefaultNetworkOptions(${JSON.stringify(workerUrl)}))
56
59
  `;
57
60
  },
58
61
  configResolved(config) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/vite/plugin.ts"],"sourcesContent":["import * as fs from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport type { Plugin } from 'vite'\n\nconst WORKER_FILENAME = 'mockServiceWorker.js'\nconst WORKER_SCRIPT_PATH = new URL('../mockServiceWorker.js', import.meta.url)\nconst VIRTUAL_MODULE_ID = 'virtual:msw'\nconst VIRTUAL_OPTIONS_ID = 'virtual:msw/options'\nconst RUNTIME_PATH = fileURLToPath(new URL('./runtime.js', import.meta.url))\n\nexport interface MswPluginOptions {\n /**\n * Use automatic integration or only provide the worker script for manual setup.\n * In worker-only mode, virtual modules are disabled.\n * @default \"auto\"\n */\n mode?: 'auto' | 'worker-only'\n}\n\n/**\n * A Vite plugin for Mock Service Worker.\n *\n * @example\n * // vite.config.ts\n * import { msw } from 'msw/vite'\n *\n * export default defineConfig({\n * plugins: [msw()]\n * })\n *\n * @example\n * // src/{client,server}.ts\n * if (import.meta.env.DEV) {\n * const { network } = await import('virtual:msw')\n * const { handlers } = await import('./mocks/handlers')\n *\n * network.configure({ handlers })\n * await network.enable()\n * }\n *\n * @remarks\n * The worker script is served during development and emitted next to any\n * client bundle that imports `virtual:msw`. Guard mocking setup with\n * `import.meta.env.DEV` to exclude both from production builds.\n *\n * For application TypeScript projects that do not include the Vite config,\n * add `/// <reference types=\"msw/vite/client\" />` to an included declaration file.\n */\nexport function msw(options: MswPluginOptions = {}): Plugin {\n const mode = options.mode ?? 'auto'\n let workerUrl = `/${WORKER_FILENAME}`\n const environmentsUsingNetwork = new Set<string>()\n\n return {\n name: 'msw',\n async resolveId(id) {\n if (mode === 'worker-only') {\n return\n }\n\n if (id === VIRTUAL_OPTIONS_ID) {\n return `\\0${VIRTUAL_OPTIONS_ID}`\n }\n\n if (id === VIRTUAL_MODULE_ID) {\n return this.resolve(RUNTIME_PATH)\n }\n },\n load(id) {\n if (mode === 'worker-only' || id !== `\\0${VIRTUAL_OPTIONS_ID}`) {\n return\n }\n\n if (this.environment.config.consumer === 'server') {\n return `export { defaultNetworkOptions } from 'msw/node'`\n }\n\n environmentsUsingNetwork.add(this.environment.name)\n\n return `\nimport { createDefaultNetworkOptions } from 'msw/browser'\nexport const defaultNetworkOptions = createDefaultNetworkOptions(${JSON.stringify(workerUrl)})\n`\n },\n configResolved(config) {\n // Keep relative build bases relative and service workers on the app's origin.\n const base =\n config.base === './'\n ? config.base\n : new URL(config.base, 'http://localhost').pathname\n workerUrl = `${base}${WORKER_FILENAME}`\n },\n generateBundle() {\n if (this.environment.config.consumer !== 'client') {\n return\n }\n\n // In \"auto\" mode, the worker is only useful to bundles that contain the\n // network. A user guard (e.g. `import.meta.env.DEV`) that drops the\n // `virtual:msw` import drops the worker too.\n if (\n mode === 'auto' &&\n !environmentsUsingNetwork.has(this.environment.name)\n ) {\n return\n }\n\n this.emitFile({\n type: 'asset',\n fileName: WORKER_FILENAME,\n source: fs.readFileSync(WORKER_SCRIPT_PATH, 'utf8'),\n })\n },\n configureServer(server) {\n const workerScript = fs.readFileSync(WORKER_SCRIPT_PATH, 'utf8')\n server.middlewares.use((request, response, next) => {\n const requestUrl = new URL(request.url ?? '/', 'http://localhost')\n\n if (requestUrl.pathname !== workerUrl) {\n next()\n return\n }\n\n response.writeHead(200, {\n 'cache-control': 'no-cache',\n 'content-type': 'application/javascript; charset=utf-8',\n 'service-worker-allowed': '/',\n })\n response.end(workerScript)\n })\n },\n }\n}\n"],"mappings":";;;AAIA,MAAM,kBAAkB;AACxB,MAAM,qBAAqB,IAAI,IAAI,2BAA2B,YAAY,GAAG;AAC7E,MAAM,oBAAoB;AAC1B,MAAM,qBAAqB;AAC3B,MAAM,eAAe,cAAc,IAAI,IAAI,gBAAgB,YAAY,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwC3E,SAAgB,IAAI,UAA4B,CAAC,GAAW;CAC1D,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI,YAAY,IAAI;CACpB,MAAM,2CAA2B,IAAI,IAAY;CAEjD,OAAO;EACL,MAAM;EACN,MAAM,UAAU,IAAI;GAClB,IAAI,SAAS,eACX;GAGF,IAAI,OAAO,oBACT,OAAO,KAAK;GAGd,IAAI,OAAO,mBACT,OAAO,KAAK,QAAQ,YAAY;EAEpC;EACA,KAAK,IAAI;GACP,IAAI,SAAS,iBAAiB,OAAO,KAAK,sBACxC;GAGF,IAAI,KAAK,YAAY,OAAO,aAAa,UACvC,OAAO;GAGT,yBAAyB,IAAI,KAAK,YAAY,IAAI;GAElD,OAAO;;mEAEsD,KAAK,UAAU,SAAS,EAAE;;EAEzF;EACA,eAAe,QAAQ;GAMrB,YAAY,GAHV,OAAO,SAAS,OACZ,OAAO,OACP,IAAI,IAAI,OAAO,MAAM,kBAAkB,CAAC,CAAC,WACzB;EACxB;EACA,iBAAiB;GACf,IAAI,KAAK,YAAY,OAAO,aAAa,UACvC;GAMF,IACE,SAAS,UACT,CAAC,yBAAyB,IAAI,KAAK,YAAY,IAAI,GAEnD;GAGF,KAAK,SAAS;IACZ,MAAM;IACN,UAAU;IACV,QAAQ,GAAG,aAAa,oBAAoB,MAAM;GACpD,CAAC;EACH;EACA,gBAAgB,QAAQ;GACtB,MAAM,eAAe,GAAG,aAAa,oBAAoB,MAAM;GAC/D,OAAO,YAAY,KAAK,SAAS,UAAU,SAAS;IAGlD,IAAI,IAFmB,IAAI,QAAQ,OAAO,KAAK,kBAElC,CAAC,CAAC,aAAa,WAAW;KACrC,KAAK;KACL;IACF;IAEA,SAAS,UAAU,KAAK;KACtB,iBAAiB;KACjB,gBAAgB;KAChB,0BAA0B;IAC5B,CAAC;IACD,SAAS,IAAI,YAAY;GAC3B,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/vite/plugin.ts"],"sourcesContent":["import * as fs from 'node:fs'\nimport { fileURLToPath } from 'node:url'\nimport type { Plugin } from 'vite'\n\nconst WORKER_FILENAME = 'mockServiceWorker.js'\nconst WORKER_SCRIPT_PATH = new URL('../mockServiceWorker.js', import.meta.url)\nconst VIRTUAL_MODULE_ID = 'virtual:msw'\nconst RUNTIME_PATH = fileURLToPath(new URL('./runtime.js', import.meta.url))\n\nexport interface MswPluginOptions {\n /**\n * Use automatic integration or only provide the worker script for manual setup.\n * In worker-only mode, virtual modules are disabled.\n * @default \"auto\"\n */\n mode?: 'auto' | 'worker-only'\n}\n\n/**\n * A Vite plugin for Mock Service Worker.\n *\n * @example\n * // vite.config.ts\n * import { msw } from 'msw/vite'\n *\n * export default defineConfig({\n * plugins: [msw()]\n * })\n *\n * @example\n * // src/{client,server}.ts\n * if (import.meta.env.DEV) {\n * const { network } = await import('virtual:msw')\n * const { handlers } = await import('./mocks/handlers')\n *\n * network.configure({ handlers })\n * await network.enable()\n * }\n *\n * @remarks\n * The worker script is served during development and emitted next to any\n * client bundle that imports `virtual:msw`. Guard mocking setup with\n * `import.meta.env.DEV` to exclude both from production builds.\n *\n * For application TypeScript projects that do not include the Vite config,\n * add `/// <reference types=\"msw/vite/client\" />` to an included declaration file.\n */\nexport function msw(options: MswPluginOptions = {}): Plugin {\n const mode = options.mode ?? 'auto'\n let workerUrl = `/${WORKER_FILENAME}`\n const environmentsUsingNetwork = new Set<string>()\n\n return {\n name: 'msw',\n resolveId(id) {\n if (mode === 'worker-only') {\n return\n }\n\n if (id === VIRTUAL_MODULE_ID) {\n return `\\0${VIRTUAL_MODULE_ID}`\n }\n },\n load(id) {\n if (mode === 'worker-only' || id !== `\\0${VIRTUAL_MODULE_ID}`) {\n return\n }\n\n // Tools like Vitest import the runtime natively when it's installed\n // in \"node_modules\". Provide it with the environment's options from here\n // so it never has to import a virtual module that only Vite can resolve.\n if (this.environment.config.consumer === 'server') {\n return `\nimport { defaultNetworkOptions } from 'msw/node'\nimport { createNetwork } from ${JSON.stringify(RUNTIME_PATH)}\nexport const network = await createNetwork(defaultNetworkOptions)\n`\n }\n\n environmentsUsingNetwork.add(this.environment.name)\n\n return `\nimport { createDefaultNetworkOptions } from 'msw/browser'\nimport { createNetwork } from ${JSON.stringify(RUNTIME_PATH)}\nexport const network = await createNetwork(createDefaultNetworkOptions(${JSON.stringify(workerUrl)}))\n`\n },\n configResolved(config) {\n // Keep relative build bases relative and service workers on the app's origin.\n const base =\n config.base === './'\n ? config.base\n : new URL(config.base, 'http://localhost').pathname\n workerUrl = `${base}${WORKER_FILENAME}`\n },\n generateBundle() {\n if (this.environment.config.consumer !== 'client') {\n return\n }\n\n // In \"auto\" mode, the worker is only useful to bundles that contain the\n // network. A user guard (e.g. `import.meta.env.DEV`) that drops the\n // `virtual:msw` import drops the worker too.\n if (\n mode === 'auto' &&\n !environmentsUsingNetwork.has(this.environment.name)\n ) {\n return\n }\n\n this.emitFile({\n type: 'asset',\n fileName: WORKER_FILENAME,\n source: fs.readFileSync(WORKER_SCRIPT_PATH, 'utf8'),\n })\n },\n configureServer(server) {\n const workerScript = fs.readFileSync(WORKER_SCRIPT_PATH, 'utf8')\n server.middlewares.use((request, response, next) => {\n const requestUrl = new URL(request.url ?? '/', 'http://localhost')\n\n if (requestUrl.pathname !== workerUrl) {\n next()\n return\n }\n\n response.writeHead(200, {\n 'cache-control': 'no-cache',\n 'content-type': 'application/javascript; charset=utf-8',\n 'service-worker-allowed': '/',\n })\n response.end(workerScript)\n })\n },\n }\n}\n"],"mappings":";;;AAIA,MAAM,kBAAkB;AACxB,MAAM,qBAAqB,IAAI,IAAI,2BAA2B,YAAY,GAAG;AAC7E,MAAM,oBAAoB;AAC1B,MAAM,eAAe,cAAc,IAAI,IAAI,gBAAgB,YAAY,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwC3E,SAAgB,IAAI,UAA4B,CAAC,GAAW;CAC1D,MAAM,OAAO,QAAQ,QAAQ;CAC7B,IAAI,YAAY,IAAI;CACpB,MAAM,2CAA2B,IAAI,IAAY;CAEjD,OAAO;EACL,MAAM;EACN,UAAU,IAAI;GACZ,IAAI,SAAS,eACX;GAGF,IAAI,OAAO,mBACT,OAAO,KAAK;EAEhB;EACA,KAAK,IAAI;GACP,IAAI,SAAS,iBAAiB,OAAO,KAAK,qBACxC;GAMF,IAAI,KAAK,YAAY,OAAO,aAAa,UACvC,OAAO;;gCAEiB,KAAK,UAAU,YAAY,EAAE;;;GAKvD,yBAAyB,IAAI,KAAK,YAAY,IAAI;GAElD,OAAO;;gCAEmB,KAAK,UAAU,YAAY,EAAE;yEACY,KAAK,UAAU,SAAS,EAAE;;EAE/F;EACA,eAAe,QAAQ;GAMrB,YAAY,GAHV,OAAO,SAAS,OACZ,OAAO,OACP,IAAI,IAAI,OAAO,MAAM,kBAAkB,CAAC,CAAC,WACzB;EACxB;EACA,iBAAiB;GACf,IAAI,KAAK,YAAY,OAAO,aAAa,UACvC;GAMF,IACE,SAAS,UACT,CAAC,yBAAyB,IAAI,KAAK,YAAY,IAAI,GAEnD;GAGF,KAAK,SAAS;IACZ,MAAM;IACN,UAAU;IACV,QAAQ,GAAG,aAAa,oBAAoB,MAAM;GACpD,CAAC;EACH;EACA,gBAAgB,QAAQ;GACtB,MAAM,eAAe,GAAG,aAAa,oBAAoB,MAAM;GAC/D,OAAO,YAAY,KAAK,SAAS,UAAU,SAAS;IAGlD,IAAI,IAFmB,IAAI,QAAQ,OAAO,KAAK,kBAElC,CAAC,CAAC,aAAa,WAAW;KACrC,KAAK;KACL;IACF;IAEA,SAAS,UAAU,KAAK;KACtB,iBAAiB;KACjB,gBAAgB;KAChB,0BAA0B;IAC5B,CAAC;IACD,SAAS,IAAI,YAAY;GAC3B,CAAC;EACH;CACF;AACF"}
@@ -1,6 +1,5 @@
1
- import { NetworkApi } from "msw/experimental";
2
- import { defaultNetworkOptions } from "virtual:msw/options";
1
+ import { defineNetwork } from "msw/experimental";
3
2
  //#region src/vite/runtime.d.ts
4
- export declare const network: NetworkApi<typeof defaultNetworkOptions.sources>;
3
+ export declare function createNetwork(options: Parameters<typeof defineNetwork>[0]): Promise<ReturnType<typeof defineNetwork>>;
5
4
  //#endregion
6
5
  //# sourceMappingURL=runtime.d.ts.map
@@ -1,77 +1,79 @@
1
1
  import { NetworkReadyState, defineNetwork } from "msw/experimental";
2
- import { defaultNetworkOptions } from "virtual:msw/options";
3
2
  //#region src/vite/runtime.ts
4
3
  const hot = import.meta.hot;
5
4
  const hotData = hot?.data;
6
- while (hotData?.disposeNetwork) {
7
- const disposePrevious = hotData.disposeNetwork;
8
- await disposePrevious();
9
- if (hotData.disposeNetwork === disposePrevious) break;
10
- }
11
- const network = defineNetwork(defaultNetworkOptions);
12
- if (hot && hotData) {
13
- let resumeAfterUpdate = false;
14
- let retired = false;
15
- let pendingOperation;
16
- const configure = network.configure;
17
- const enable = network.enable;
18
- const disable = network.disable;
19
- const runOperation = (action) => {
20
- const result = pendingOperation ? pendingOperation.then(action) : action();
21
- if (result instanceof Promise) {
22
- const operation = result.finally(() => {
23
- if (pendingOperation === operation) pendingOperation = void 0;
5
+ async function createNetwork(options) {
6
+ while (hotData?.disposeNetwork) {
7
+ const disposePrevious = hotData.disposeNetwork;
8
+ await disposePrevious();
9
+ if (hotData.disposeNetwork === disposePrevious) break;
10
+ }
11
+ const network = defineNetwork(options);
12
+ if (hot && hotData) {
13
+ let resumeAfterUpdate = false;
14
+ let retired = false;
15
+ let pendingOperation;
16
+ const configure = network.configure;
17
+ const enable = network.enable;
18
+ const disable = network.disable;
19
+ const runOperation = (action) => {
20
+ const result = pendingOperation ? pendingOperation.then(action) : action();
21
+ if (result instanceof Promise) {
22
+ const operation = result.finally(() => {
23
+ if (pendingOperation === operation) pendingOperation = void 0;
24
+ });
25
+ pendingOperation = operation;
26
+ return operation;
27
+ }
28
+ };
29
+ const stop = () => {
30
+ if (network.readyState === NetworkReadyState.ENABLED) return disable();
31
+ };
32
+ network.configure = (options) => {
33
+ runOperation(() => {
34
+ if (retired) return;
35
+ const stopped = stop();
36
+ if (stopped instanceof Promise) return stopped.then(() => configure(options));
37
+ configure(options);
38
+ });
39
+ };
40
+ network.enable = async () => {
41
+ await runOperation(() => {
42
+ if (!retired && network.readyState === NetworkReadyState.DISABLED) return enable();
24
43
  });
25
- pendingOperation = operation;
26
- return operation;
27
- }
28
- };
29
- const stop = () => {
30
- if (network.readyState === NetworkReadyState.ENABLED) return disable();
31
- };
32
- network.configure = (options) => {
33
- runOperation(() => {
34
- if (retired) return;
35
- const stopped = stop();
36
- if (stopped instanceof Promise) return stopped.then(() => configure(options));
37
- configure(options);
38
- });
39
- };
40
- network.enable = async () => {
41
- await runOperation(() => {
42
- if (!retired && network.readyState === NetworkReadyState.DISABLED) return enable();
43
- });
44
- };
45
- network.disable = async () => {
46
- await runOperation(stop);
47
- };
48
- const disableNetwork = async () => {
49
- await network.disable();
50
- };
51
- const beforeUpdate = async () => {
52
- resumeAfterUpdate = network.readyState === NetworkReadyState.ENABLED;
53
- await disableNetwork();
54
- };
55
- const afterUpdate = async () => {
56
- const shouldResume = resumeAfterUpdate;
57
- resumeAfterUpdate = false;
58
- if (shouldResume && network.readyState === NetworkReadyState.DISABLED) await network.enable();
59
- };
60
- hot.on("vite:beforeUpdate", beforeUpdate);
61
- hot.on("vite:afterUpdate", afterUpdate);
62
- hot.on("vite:beforeFullReload", disableNetwork);
63
- const disposeNetwork = async () => {
64
- retired = true;
65
- resumeAfterUpdate = false;
66
- hot.off("vite:beforeUpdate", beforeUpdate);
67
- hot.off("vite:afterUpdate", afterUpdate);
68
- hot.off("vite:beforeFullReload", disableNetwork);
69
- await disableNetwork();
70
- };
71
- hotData.disposeNetwork = disposeNetwork;
72
- hot.dispose(disposeNetwork);
44
+ };
45
+ network.disable = async () => {
46
+ await runOperation(stop);
47
+ };
48
+ const disableNetwork = async () => {
49
+ await network.disable();
50
+ };
51
+ const beforeUpdate = async () => {
52
+ resumeAfterUpdate = network.readyState === NetworkReadyState.ENABLED;
53
+ await disableNetwork();
54
+ };
55
+ const afterUpdate = async () => {
56
+ const shouldResume = resumeAfterUpdate;
57
+ resumeAfterUpdate = false;
58
+ if (shouldResume && network.readyState === NetworkReadyState.DISABLED) await network.enable();
59
+ };
60
+ hot.on("vite:beforeUpdate", beforeUpdate);
61
+ hot.on("vite:afterUpdate", afterUpdate);
62
+ hot.on("vite:beforeFullReload", disableNetwork);
63
+ const disposeNetwork = async () => {
64
+ retired = true;
65
+ resumeAfterUpdate = false;
66
+ hot.off("vite:beforeUpdate", beforeUpdate);
67
+ hot.off("vite:afterUpdate", afterUpdate);
68
+ hot.off("vite:beforeFullReload", disableNetwork);
69
+ await disableNetwork();
70
+ };
71
+ hotData.disposeNetwork = disposeNetwork;
72
+ hot.dispose(disposeNetwork);
73
+ }
74
+ return network;
73
75
  }
74
76
  //#endregion
75
- export { network };
77
+ export { createNetwork };
76
78
 
77
79
  //# sourceMappingURL=runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","names":[],"sources":["../../src/vite/runtime.ts"],"sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport {\n defineNetwork,\n NetworkReadyState,\n type NetworkApi,\n} from 'msw/experimental'\nimport { defaultNetworkOptions } from 'virtual:msw/options'\n\nconst hot = import.meta.hot\nconst hotData: { disposeNetwork?: () => Promise<void> } | undefined = hot?.data\n\n// SSR imports can re-evaluate this module before the old HMR listener runs.\nwhile (hotData?.disposeNetwork) {\n const disposePrevious = hotData.disposeNetwork\n await disposePrevious()\n\n if (hotData.disposeNetwork === disposePrevious) {\n break\n }\n}\n\nexport const network: NetworkApi<typeof defaultNetworkOptions.sources> =\n defineNetwork<typeof defaultNetworkOptions.sources>(defaultNetworkOptions)\n\nif (hot && hotData) {\n let resumeAfterUpdate = false\n let retired = false\n let pendingOperation: Promise<void> | undefined\n const configure = network.configure\n const enable = network.enable\n const disable = network.disable\n\n const runOperation = (action: () => void | Promise<void>) => {\n const result = pendingOperation ? pendingOperation.then(action) : action()\n\n if (result instanceof Promise) {\n const operation = result.finally(() => {\n if (pendingOperation === operation) {\n pendingOperation = undefined\n }\n })\n pendingOperation = operation\n\n return operation\n }\n }\n\n const stop = () => {\n if (network.readyState === NetworkReadyState.ENABLED) {\n return disable()\n }\n }\n\n // An SSR entry may be re-evaluated while this module remains cached.\n network.configure = (options) => {\n void runOperation(() => {\n if (retired) {\n return\n }\n\n const stopped = stop()\n\n if (stopped instanceof Promise) {\n return stopped.then(() => configure(options))\n }\n\n configure(options)\n })\n }\n network.enable = async () => {\n await runOperation(() => {\n if (!retired && network.readyState === NetworkReadyState.DISABLED) {\n return enable()\n }\n })\n }\n network.disable = async () => {\n await runOperation(stop)\n }\n\n const disableNetwork = async () => {\n await network.disable()\n }\n\n const beforeUpdate = async () => {\n resumeAfterUpdate = network.readyState === NetworkReadyState.ENABLED\n await disableNetwork()\n }\n\n const afterUpdate = async () => {\n const shouldResume = resumeAfterUpdate\n resumeAfterUpdate = false\n\n if (shouldResume && network.readyState === NetworkReadyState.DISABLED) {\n await network.enable()\n }\n }\n\n hot.on('vite:beforeUpdate', beforeUpdate)\n hot.on('vite:afterUpdate', afterUpdate)\n hot.on('vite:beforeFullReload', disableNetwork)\n\n const disposeNetwork = async () => {\n retired = true\n resumeAfterUpdate = false\n\n hot.off('vite:beforeUpdate', beforeUpdate)\n hot.off('vite:afterUpdate', afterUpdate)\n hot.off('vite:beforeFullReload', disableNetwork)\n\n await disableNetwork()\n }\n\n hotData.disposeNetwork = disposeNetwork\n hot.dispose(disposeNetwork)\n}\n"],"mappings":";;;AASA,MAAM,MAAM,YAAY;AACxB,MAAM,UAAgE,KAAK;AAG3E,OAAO,SAAS,gBAAgB;CAC9B,MAAM,kBAAkB,QAAQ;CAChC,MAAM,gBAAgB;CAEtB,IAAI,QAAQ,mBAAmB,iBAC7B;AAEJ;AAEA,MAAa,UACX,cAAoD,qBAAqB;AAE3E,IAAI,OAAO,SAAS;CAClB,IAAI,oBAAoB;CACxB,IAAI,UAAU;CACd,IAAI;CACJ,MAAM,YAAY,QAAQ;CAC1B,MAAM,SAAS,QAAQ;CACvB,MAAM,UAAU,QAAQ;CAExB,MAAM,gBAAgB,WAAuC;EAC3D,MAAM,SAAS,mBAAmB,iBAAiB,KAAK,MAAM,IAAI,OAAO;EAEzE,IAAI,kBAAkB,SAAS;GAC7B,MAAM,YAAY,OAAO,cAAc;IACrC,IAAI,qBAAqB,WACvB,mBAAmB,KAAA;GAEvB,CAAC;GACD,mBAAmB;GAEnB,OAAO;EACT;CACF;CAEA,MAAM,aAAa;EACjB,IAAI,QAAQ,eAAe,kBAAkB,SAC3C,OAAO,QAAQ;CAEnB;CAGA,QAAQ,aAAa,YAAY;EAC/B,mBAAwB;GACtB,IAAI,SACF;GAGF,MAAM,UAAU,KAAK;GAErB,IAAI,mBAAmB,SACrB,OAAO,QAAQ,WAAW,UAAU,OAAO,CAAC;GAG9C,UAAU,OAAO;EACnB,CAAC;CACH;CACA,QAAQ,SAAS,YAAY;EAC3B,MAAM,mBAAmB;GACvB,IAAI,CAAC,WAAW,QAAQ,eAAe,kBAAkB,UACvD,OAAO,OAAO;EAElB,CAAC;CACH;CACA,QAAQ,UAAU,YAAY;EAC5B,MAAM,aAAa,IAAI;CACzB;CAEA,MAAM,iBAAiB,YAAY;EACjC,MAAM,QAAQ,QAAQ;CACxB;CAEA,MAAM,eAAe,YAAY;EAC/B,oBAAoB,QAAQ,eAAe,kBAAkB;EAC7D,MAAM,eAAe;CACvB;CAEA,MAAM,cAAc,YAAY;EAC9B,MAAM,eAAe;EACrB,oBAAoB;EAEpB,IAAI,gBAAgB,QAAQ,eAAe,kBAAkB,UAC3D,MAAM,QAAQ,OAAO;CAEzB;CAEA,IAAI,GAAG,qBAAqB,YAAY;CACxC,IAAI,GAAG,oBAAoB,WAAW;CACtC,IAAI,GAAG,yBAAyB,cAAc;CAE9C,MAAM,iBAAiB,YAAY;EACjC,UAAU;EACV,oBAAoB;EAEpB,IAAI,IAAI,qBAAqB,YAAY;EACzC,IAAI,IAAI,oBAAoB,WAAW;EACvC,IAAI,IAAI,yBAAyB,cAAc;EAE/C,MAAM,eAAe;CACvB;CAEA,QAAQ,iBAAiB;CACzB,IAAI,QAAQ,cAAc;AAC5B"}
1
+ {"version":3,"file":"runtime.js","names":[],"sources":["../../src/vite/runtime.ts"],"sourcesContent":["/// <reference types=\"vite/client\" />\n\nimport { defineNetwork, NetworkReadyState } from 'msw/experimental'\n\nconst hot = import.meta.hot\nconst hotData: { disposeNetwork?: () => Promise<void> } | undefined = hot?.data\n\nexport async function createNetwork(\n options: Parameters<typeof defineNetwork>[0],\n): Promise<ReturnType<typeof defineNetwork>> {\n // SSR imports can re-evaluate the network before the old HMR listener runs.\n while (hotData?.disposeNetwork) {\n const disposePrevious = hotData.disposeNetwork\n await disposePrevious()\n\n if (hotData.disposeNetwork === disposePrevious) {\n break\n }\n }\n\n const network = defineNetwork(options)\n\n if (hot && hotData) {\n let resumeAfterUpdate = false\n let retired = false\n let pendingOperation: Promise<void> | undefined\n const configure = network.configure\n const enable = network.enable\n const disable = network.disable\n\n const runOperation = (action: () => void | Promise<void>) => {\n const result = pendingOperation ? pendingOperation.then(action) : action()\n\n if (result instanceof Promise) {\n const operation = result.finally(() => {\n if (pendingOperation === operation) {\n pendingOperation = undefined\n }\n })\n pendingOperation = operation\n\n return operation\n }\n }\n\n const stop = () => {\n if (network.readyState === NetworkReadyState.ENABLED) {\n return disable()\n }\n }\n\n // An SSR entry may be re-evaluated while this module remains cached.\n network.configure = (options) => {\n void runOperation(() => {\n if (retired) {\n return\n }\n\n const stopped = stop()\n\n if (stopped instanceof Promise) {\n return stopped.then(() => configure(options))\n }\n\n configure(options)\n })\n }\n network.enable = async () => {\n await runOperation(() => {\n if (!retired && network.readyState === NetworkReadyState.DISABLED) {\n return enable()\n }\n })\n }\n network.disable = async () => {\n await runOperation(stop)\n }\n\n const disableNetwork = async () => {\n await network.disable()\n }\n\n const beforeUpdate = async () => {\n resumeAfterUpdate = network.readyState === NetworkReadyState.ENABLED\n await disableNetwork()\n }\n\n const afterUpdate = async () => {\n const shouldResume = resumeAfterUpdate\n resumeAfterUpdate = false\n\n if (shouldResume && network.readyState === NetworkReadyState.DISABLED) {\n await network.enable()\n }\n }\n\n hot.on('vite:beforeUpdate', beforeUpdate)\n hot.on('vite:afterUpdate', afterUpdate)\n hot.on('vite:beforeFullReload', disableNetwork)\n\n const disposeNetwork = async () => {\n retired = true\n resumeAfterUpdate = false\n\n hot.off('vite:beforeUpdate', beforeUpdate)\n hot.off('vite:afterUpdate', afterUpdate)\n hot.off('vite:beforeFullReload', disableNetwork)\n\n await disableNetwork()\n }\n\n hotData.disposeNetwork = disposeNetwork\n hot.dispose(disposeNetwork)\n }\n\n return network\n}\n"],"mappings":";;AAIA,MAAM,MAAM,YAAY;AACxB,MAAM,UAAgE,KAAK;AAE3E,eAAsB,cACpB,SAC2C;CAE3C,OAAO,SAAS,gBAAgB;EAC9B,MAAM,kBAAkB,QAAQ;EAChC,MAAM,gBAAgB;EAEtB,IAAI,QAAQ,mBAAmB,iBAC7B;CAEJ;CAEA,MAAM,UAAU,cAAc,OAAO;CAErC,IAAI,OAAO,SAAS;EAClB,IAAI,oBAAoB;EACxB,IAAI,UAAU;EACd,IAAI;EACJ,MAAM,YAAY,QAAQ;EAC1B,MAAM,SAAS,QAAQ;EACvB,MAAM,UAAU,QAAQ;EAExB,MAAM,gBAAgB,WAAuC;GAC3D,MAAM,SAAS,mBAAmB,iBAAiB,KAAK,MAAM,IAAI,OAAO;GAEzE,IAAI,kBAAkB,SAAS;IAC7B,MAAM,YAAY,OAAO,cAAc;KACrC,IAAI,qBAAqB,WACvB,mBAAmB,KAAA;IAEvB,CAAC;IACD,mBAAmB;IAEnB,OAAO;GACT;EACF;EAEA,MAAM,aAAa;GACjB,IAAI,QAAQ,eAAe,kBAAkB,SAC3C,OAAO,QAAQ;EAEnB;EAGA,QAAQ,aAAa,YAAY;GAC/B,mBAAwB;IACtB,IAAI,SACF;IAGF,MAAM,UAAU,KAAK;IAErB,IAAI,mBAAmB,SACrB,OAAO,QAAQ,WAAW,UAAU,OAAO,CAAC;IAG9C,UAAU,OAAO;GACnB,CAAC;EACH;EACA,QAAQ,SAAS,YAAY;GAC3B,MAAM,mBAAmB;IACvB,IAAI,CAAC,WAAW,QAAQ,eAAe,kBAAkB,UACvD,OAAO,OAAO;GAElB,CAAC;EACH;EACA,QAAQ,UAAU,YAAY;GAC5B,MAAM,aAAa,IAAI;EACzB;EAEA,MAAM,iBAAiB,YAAY;GACjC,MAAM,QAAQ,QAAQ;EACxB;EAEA,MAAM,eAAe,YAAY;GAC/B,oBAAoB,QAAQ,eAAe,kBAAkB;GAC7D,MAAM,eAAe;EACvB;EAEA,MAAM,cAAc,YAAY;GAC9B,MAAM,eAAe;GACrB,oBAAoB;GAEpB,IAAI,gBAAgB,QAAQ,eAAe,kBAAkB,UAC3D,MAAM,QAAQ,OAAO;EAEzB;EAEA,IAAI,GAAG,qBAAqB,YAAY;EACxC,IAAI,GAAG,oBAAoB,WAAW;EACtC,IAAI,GAAG,yBAAyB,cAAc;EAE9C,MAAM,iBAAiB,YAAY;GACjC,UAAU;GACV,oBAAoB;GAEpB,IAAI,IAAI,qBAAqB,YAAY;GACzC,IAAI,IAAI,oBAAoB,WAAW;GACvC,IAAI,IAAI,yBAAyB,cAAc;GAE/C,MAAM,eAAe;EACvB;EAEA,QAAQ,iBAAiB;EACzB,IAAI,QAAQ,cAAc;CAC5B;CAEA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depup/msw",
3
- "version": "3.0.0-depup.0",
4
- "description": "Seamless REST/GraphQL API mocking library for browser and Node.js. (with updated dependencies)",
3
+ "version": "3.0.2-depup.0",
4
+ "description": "The industry standard for API mocking in JavaScript. (with updated dependencies)",
5
5
  "type": "module",
6
6
  "main": "./lib/core/index.js",
7
7
  "types": "./lib/core/index.d.ts",
@@ -125,7 +125,7 @@
125
125
  "dependencies": {
126
126
  "@inquirer/confirm": "^6.3.2",
127
127
  "@msw/url": "^0.1.2",
128
- "@mswjs/interceptors": "^0.45.5",
128
+ "@mswjs/interceptors": "^0.45.6",
129
129
  "cookie": "^2.0.1",
130
130
  "headers-polyfill": "^5.0.1",
131
131
  "is-node-process": "^1.2.0",
@@ -167,7 +167,7 @@
167
167
  "json-bigint": "^1.0.0",
168
168
  "knip": "^6.34.0",
169
169
  "lint-staged": "^17.1.1",
170
- "msw": "^3.0.0",
170
+ "msw": "^3.0.2",
171
171
  "oxlint": "^1.75.0",
172
172
  "page-with": "^0.6.1",
173
173
  "prettier": "^3.9.6",
@@ -238,8 +238,8 @@
238
238
  },
239
239
  "depsUpdated": 2,
240
240
  "originalPackage": "msw",
241
- "originalVersion": "3.0.0",
242
- "processedAt": "2026-09-28T16:11:25.377Z",
241
+ "originalVersion": "3.0.2",
242
+ "processedAt": "2026-10-03T08:12:25.616Z",
243
243
  "smokeTest": "passed"
244
244
  }
245
245
  }
@@ -1,3 +1,4 @@
1
+ import { FetchRequest } from '@mswjs/interceptors'
1
2
  import { http } from '#http/http'
2
3
  import { graphql } from '../../../graphql'
3
4
  import { ws } from '../../../ws'
@@ -169,6 +170,54 @@ test('resolves a non-matching request', async () => {
169
170
  ])
170
171
  })
171
172
 
173
+ /**
174
+ * @todo Revisit the `http.all()` handler below once `http.connect()`
175
+ * is supported: a matching CONNECT handler must take precedence.
176
+ */
177
+ test('passes through an unhandled CONNECT request without applying the unhandled frame strategy', async () => {
178
+ class HttpFrame extends HttpNetworkFrame {
179
+ respondWith = vi.fn()
180
+ passthrough = vi.fn()
181
+ errorWith = vi.fn()
182
+ }
183
+
184
+ const frame = new HttpFrame({
185
+ request: new FetchRequest('http://localhost/127.0.0.1:443', {
186
+ method: 'CONNECT',
187
+ }),
188
+ })
189
+ const { events } = spyOnNetworkFrame(frame)
190
+ const unhandledFrameCallback = vi.fn()
191
+
192
+ const matches = await frame.resolve(
193
+ [
194
+ http.all('*', () => {
195
+ return new Response(null, { status: 204 })
196
+ }),
197
+ ],
198
+ unhandledFrameCallback,
199
+ { quiet: true },
200
+ )
201
+
202
+ expect.soft(matches).toBe(null)
203
+ expect.soft(frame.passthrough).toHaveBeenCalledOnce()
204
+ expect.soft(frame.respondWith).not.toHaveBeenCalled()
205
+ expect.soft(frame.errorWith).not.toHaveBeenCalled()
206
+ expect.soft(unhandledFrameCallback).not.toHaveBeenCalled()
207
+ expect.soft(events).toEqual([
208
+ expect.objectContaining({
209
+ type: 'request:start',
210
+ requestId: frame.data.id,
211
+ request: frame.data.request,
212
+ }),
213
+ expect.objectContaining({
214
+ type: 'request:end',
215
+ requestId: frame.data.id,
216
+ request: frame.data.request,
217
+ }),
218
+ ])
219
+ })
220
+
172
221
  test('resolves a matched passthrough', async () => {
173
222
  class HttpFrame extends HttpNetworkFrame {
174
223
  respondWith = vi.fn()
@@ -6,6 +6,7 @@ import {
6
6
  type NetworkFrameResolutionContext,
7
7
  } from './network-frame'
8
8
  import { toPublicUrl } from '../../utils/request/to-public-url'
9
+ import { isStringEqual } from '../../utils/internal/is-string-equal'
9
10
  import { executeHandlers } from '../../utils/execute-handlers'
10
11
  import { storeResponseCookies } from '../../utils/request/store-response-cookies'
11
12
  import { shouldBypassRequest } from '../request-utils'
@@ -191,6 +192,24 @@ export abstract class HttpNetworkFrame extends NetworkFrame<
191
192
 
192
193
  // No matching handlers.
193
194
  if (lookupResult == null) {
195
+ /**
196
+ * @note Unhandled CONNECT requests establish a tunnel through a proxy.
197
+ * They are transport, not the request the developer cares about, so
198
+ * they pass through silently regardless of the unhandled frame strategy.
199
+ * The request sent through the tunnel gets its own resolution.
200
+ */
201
+ if (isStringEqual(request.method, 'CONNECT')) {
202
+ this.events.emit(
203
+ new RequestEvent('request:end', {
204
+ requestId,
205
+ request,
206
+ }),
207
+ )
208
+
209
+ this.passthrough()
210
+ return null
211
+ }
212
+
194
213
  this.events.emit(
195
214
  new RequestEvent('request:unhandled', {
196
215
  requestId,
@@ -1,5 +1,5 @@
1
1
  // @vitest-environment jsdom
2
- import { createRequestId } from '@mswjs/interceptors'
2
+ import { createRequestId, FetchRequest } from '@mswjs/interceptors'
3
3
  import type { HttpRequestResolverExtras } from './http-handler'
4
4
  import { HttpHandler } from './http-handler'
5
5
  import { HttpResponse } from './index'
@@ -70,6 +70,24 @@ describe('parse', () => {
70
70
  })
71
71
 
72
72
  describe('predicate', () => {
73
+ /**
74
+ * @todo Decide whether `http.all()` matches CONNECT requests
75
+ * once `http.connect()` is supported.
76
+ */
77
+ test('returns false given a CONNECT request', async () => {
78
+ const handler = new HttpHandler(/.+/, '*', resolver)
79
+ const request = new FetchRequest('http://localhost/127.0.0.1:443', {
80
+ method: 'CONNECT',
81
+ })
82
+
83
+ await expect(
84
+ handler.predicate({
85
+ request,
86
+ parsedResult: await handler.parse({ request }),
87
+ }),
88
+ ).resolves.toBe(false)
89
+ })
90
+
73
91
  test('returns true given a matching request', async () => {
74
92
  const handler = new HttpHandler('POST', '/login', resolver)
75
93
  const request = new Request(new URL('/login', location.href), {
@@ -122,6 +122,19 @@ export class HttpHandler extends RequestHandler<
122
122
  request: Request
123
123
  resolutionContext?: ResponseResolutionContext
124
124
  }) {
125
+ /**
126
+ * @note CONNECT requests target an authority ("host:port"), not a URL.
127
+ * HTTP handlers never match them.
128
+ * @todo Match the authority against the handler path once
129
+ * `http.connect()` is supported instead of bailing out.
130
+ */
131
+ if (isStringEqual(args.request.method, 'CONNECT')) {
132
+ return {
133
+ match: { matches: false, params: {} },
134
+ cookies: {},
135
+ }
136
+ }
137
+
125
138
  const url = new URL(args.request.url)
126
139
  const cookies = getAllRequestCookies(args.request)
127
140
 
@@ -454,6 +454,9 @@ document.querySelector('output').textContent = String(network.readyState)
454
454
  let completedUpdates = 0
455
455
 
456
456
  if (import.meta.hot) {
457
+ import.meta.hot.on('vite:beforeUpdate', () => {
458
+ document.body.dataset.disabledBeforeUpdate = String(network.readyState === 0)
459
+ })
457
460
  import.meta.hot.on('vite:afterUpdate', () => {
458
461
  document.body.dataset.completedUpdates = String(++completedUpdates)
459
462
  })
@@ -519,18 +522,33 @@ document.querySelector('button').onclick = async () => {
519
522
  await page.getByRole('button', { name: 'Enable' }).click()
520
523
 
521
524
  await expect.poll(() => page.locator('output').textContent()).toBe('mocked')
525
+ await page.evaluate(() => {
526
+ delete document.body.dataset.disabledBeforeUpdate
527
+ })
522
528
  server.environments.client.hot.send({ type: 'update', updates: [] })
523
529
 
524
530
  await expect
525
531
  .poll(() => page.locator('body').getAttribute('data-completed-updates'))
526
532
  .toBe('2')
527
533
  await expect(
528
- page.evaluate(async () => {
529
- const response = await fetch('/resource')
530
-
531
- return response.text()
532
- }),
533
- ).resolves.toBe('mocked')
534
+ page.locator('body').getAttribute('data-disabled-before-update'),
535
+ ).resolves.toBe('true')
536
+ /**
537
+ * @note The runtime re-enables the network after the update asynchronously:
538
+ * the worker has to be re-activated before it can respond with mocks.
539
+ * Until then, requests reach the dev server. Poll for the mocked response.
540
+ */
541
+ await expect
542
+ .poll(
543
+ () =>
544
+ page.evaluate(async () => {
545
+ const response = await fetch('/resource')
546
+
547
+ return response.text()
548
+ }),
549
+ { timeout: 10_000 },
550
+ )
551
+ .toBe('mocked')
534
552
  await expect(
535
553
  page.evaluate(async () => {
536
554
  const registrations = await navigator.serviceWorker.getRegistrations()
@@ -766,7 +784,7 @@ test('serves only the worker in worker-only mode with an absolute base URL', asy
766
784
  server.environments.client.pluginContainer.resolveId('virtual:msw'),
767
785
  ).resolves.toBeNull()
768
786
  await expect(
769
- server.environments.ssr.pluginContainer.resolveId('virtual:msw/options'),
787
+ server.environments.ssr.pluginContainer.resolveId('virtual:msw'),
770
788
  ).resolves.toBeNull()
771
789
  })
772
790
 
@@ -5,7 +5,6 @@ import type { Plugin } from 'vite'
5
5
  const WORKER_FILENAME = 'mockServiceWorker.js'
6
6
  const WORKER_SCRIPT_PATH = new URL('../mockServiceWorker.js', import.meta.url)
7
7
  const VIRTUAL_MODULE_ID = 'virtual:msw'
8
- const VIRTUAL_OPTIONS_ID = 'virtual:msw/options'
9
8
  const RUNTIME_PATH = fileURLToPath(new URL('./runtime.js', import.meta.url))
10
9
 
11
10
  export interface MswPluginOptions {
@@ -53,33 +52,37 @@ export function msw(options: MswPluginOptions = {}): Plugin {
53
52
 
54
53
  return {
55
54
  name: 'msw',
56
- async resolveId(id) {
55
+ resolveId(id) {
57
56
  if (mode === 'worker-only') {
58
57
  return
59
58
  }
60
59
 
61
- if (id === VIRTUAL_OPTIONS_ID) {
62
- return `\0${VIRTUAL_OPTIONS_ID}`
63
- }
64
-
65
60
  if (id === VIRTUAL_MODULE_ID) {
66
- return this.resolve(RUNTIME_PATH)
61
+ return `\0${VIRTUAL_MODULE_ID}`
67
62
  }
68
63
  },
69
64
  load(id) {
70
- if (mode === 'worker-only' || id !== `\0${VIRTUAL_OPTIONS_ID}`) {
65
+ if (mode === 'worker-only' || id !== `\0${VIRTUAL_MODULE_ID}`) {
71
66
  return
72
67
  }
73
68
 
69
+ // Tools like Vitest import the runtime natively when it's installed
70
+ // in "node_modules". Provide it with the environment's options from here
71
+ // so it never has to import a virtual module that only Vite can resolve.
74
72
  if (this.environment.config.consumer === 'server') {
75
- return `export { defaultNetworkOptions } from 'msw/node'`
73
+ return `
74
+ import { defaultNetworkOptions } from 'msw/node'
75
+ import { createNetwork } from ${JSON.stringify(RUNTIME_PATH)}
76
+ export const network = await createNetwork(defaultNetworkOptions)
77
+ `
76
78
  }
77
79
 
78
80
  environmentsUsingNetwork.add(this.environment.name)
79
81
 
80
82
  return `
81
83
  import { createDefaultNetworkOptions } from 'msw/browser'
82
- export const defaultNetworkOptions = createDefaultNetworkOptions(${JSON.stringify(workerUrl)})
84
+ import { createNetwork } from ${JSON.stringify(RUNTIME_PATH)}
85
+ export const network = await createNetwork(createDefaultNetworkOptions(${JSON.stringify(workerUrl)}))
83
86
  `
84
87
  },
85
88
  configResolved(config) {