msw 2.12.13 → 2.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.
- package/lib/browser/index.d.mts +29 -19
- package/lib/browser/index.d.ts +29 -19
- package/lib/browser/index.js +1763 -1321
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +1769 -1321
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{HttpResponse-Dj6ibgFJ.d.ts → HttpResponse-CksOMVAa.d.ts} +5 -5
- package/lib/core/{HttpResponse-Be4eT3x6.d.mts → HttpResponse-DlRR1D-f.d.mts} +5 -5
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/experimental/compat.d.mts +17 -0
- package/lib/core/experimental/compat.d.ts +17 -0
- package/lib/core/experimental/compat.js +54 -0
- package/lib/core/experimental/compat.js.map +1 -0
- package/lib/core/experimental/compat.mjs +36 -0
- package/lib/core/experimental/compat.mjs.map +1 -0
- package/lib/core/experimental/define-network.d.mts +75 -0
- package/lib/core/experimental/define-network.d.ts +75 -0
- package/lib/core/experimental/define-network.js +124 -0
- package/lib/core/experimental/define-network.js.map +1 -0
- package/lib/core/experimental/define-network.mjs +107 -0
- package/lib/core/experimental/define-network.mjs.map +1 -0
- package/lib/core/experimental/frames/http-frame.d.mts +77 -0
- package/lib/core/experimental/frames/http-frame.d.ts +77 -0
- package/lib/core/experimental/frames/http-frame.js +194 -0
- package/lib/core/experimental/frames/http-frame.js.map +1 -0
- package/lib/core/experimental/frames/http-frame.mjs +176 -0
- package/lib/core/experimental/frames/http-frame.mjs.map +1 -0
- package/lib/core/experimental/frames/network-frame.d.mts +12 -0
- package/lib/core/experimental/frames/network-frame.d.ts +12 -0
- package/lib/core/{handlers/common.js → experimental/frames/network-frame.js} +19 -3
- package/lib/core/experimental/frames/network-frame.js.map +1 -0
- package/lib/core/experimental/frames/network-frame.mjs +13 -0
- package/lib/core/experimental/frames/network-frame.mjs.map +1 -0
- package/lib/core/experimental/frames/websocket-frame.d.mts +55 -0
- package/lib/core/experimental/frames/websocket-frame.d.ts +55 -0
- package/lib/core/experimental/frames/websocket-frame.js +129 -0
- package/lib/core/experimental/frames/websocket-frame.js.map +1 -0
- package/lib/core/experimental/frames/websocket-frame.mjs +116 -0
- package/lib/core/experimental/frames/websocket-frame.mjs.map +1 -0
- package/lib/core/experimental/handlers-controller.d.mts +35 -0
- package/lib/core/experimental/handlers-controller.d.ts +35 -0
- package/lib/core/experimental/handlers-controller.js +121 -0
- package/lib/core/experimental/handlers-controller.js.map +1 -0
- package/lib/core/experimental/handlers-controller.mjs +101 -0
- package/lib/core/experimental/handlers-controller.mjs.map +1 -0
- package/lib/core/experimental/index.d.mts +17 -0
- package/lib/core/experimental/index.d.ts +17 -0
- package/lib/core/experimental/index.js +36 -0
- package/lib/core/experimental/index.js.map +1 -0
- package/lib/core/experimental/index.mjs +20 -0
- package/lib/core/experimental/index.mjs.map +1 -0
- package/lib/core/experimental/on-unhandled-frame.d.mts +12 -0
- package/lib/core/experimental/on-unhandled-frame.d.ts +12 -0
- package/lib/core/experimental/on-unhandled-frame.js +90 -0
- package/lib/core/experimental/on-unhandled-frame.js.map +1 -0
- package/lib/core/experimental/on-unhandled-frame.mjs +70 -0
- package/lib/core/experimental/on-unhandled-frame.mjs.map +1 -0
- package/lib/core/experimental/request-utils.d.mts +12 -0
- package/lib/core/experimental/request-utils.d.ts +12 -0
- package/lib/core/experimental/request-utils.js +50 -0
- package/lib/core/experimental/request-utils.js.map +1 -0
- package/lib/core/experimental/request-utils.mjs +30 -0
- package/lib/core/experimental/request-utils.mjs.map +1 -0
- package/lib/core/experimental/setup-api.d.mts +33 -0
- package/lib/core/experimental/setup-api.d.ts +33 -0
- package/lib/core/experimental/setup-api.js +61 -0
- package/lib/core/experimental/setup-api.js.map +1 -0
- package/lib/core/experimental/setup-api.mjs +43 -0
- package/lib/core/experimental/setup-api.mjs.map +1 -0
- package/lib/core/experimental/sources/interceptor-source.d.mts +28 -0
- package/lib/core/experimental/sources/interceptor-source.d.ts +28 -0
- package/lib/core/experimental/sources/interceptor-source.js +142 -0
- package/lib/core/experimental/sources/interceptor-source.js.map +1 -0
- package/lib/core/experimental/sources/interceptor-source.mjs +124 -0
- package/lib/core/experimental/sources/interceptor-source.mjs.map +1 -0
- package/lib/core/experimental/sources/network-source.d.mts +31 -0
- package/lib/core/experimental/sources/network-source.d.ts +31 -0
- package/lib/core/experimental/sources/network-source.js +50 -0
- package/lib/core/experimental/sources/network-source.js.map +1 -0
- package/lib/core/experimental/sources/network-source.mjs +30 -0
- package/lib/core/experimental/sources/network-source.mjs.map +1 -0
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +1 -1
- package/lib/core/graphql.d.ts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +1 -1
- package/lib/core/handlers/GraphQLHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/RequestHandler.js +5 -6
- package/lib/core/handlers/RequestHandler.js.map +1 -1
- package/lib/core/handlers/RequestHandler.mjs +5 -6
- package/lib/core/handlers/RequestHandler.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +8 -4
- package/lib/core/handlers/WebSocketHandler.d.ts +8 -4
- package/lib/core/handlers/WebSocketHandler.js +18 -5
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +18 -5
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +7 -12
- package/lib/core/index.d.ts +7 -12
- package/lib/core/index.js +2 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -1
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/network-frame-B7A0ggXE.d.mts +56 -0
- package/lib/core/network-frame-usYiHS0K.d.ts +56 -0
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +1 -1
- package/lib/core/sharedOptions.d.mts +6 -2
- package/lib/core/sharedOptions.d.ts +6 -2
- package/lib/core/sharedOptions.js.map +1 -1
- package/lib/core/sse.d.mts +1 -1
- package/lib/core/sse.d.ts +1 -1
- package/lib/core/sse.js.map +1 -1
- package/lib/core/sse.mjs.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.mts +1 -1
- package/lib/core/utils/HttpResponse/decorators.d.ts +1 -1
- package/lib/core/utils/cookieStore.js.map +1 -1
- package/lib/core/utils/cookieStore.mjs.map +1 -1
- package/lib/core/utils/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -1
- package/lib/core/utils/handleRequest.d.ts +2 -1
- package/lib/core/utils/internal/isHandlerKind.d.mts +3 -3
- package/lib/core/utils/internal/isHandlerKind.d.ts +3 -3
- package/lib/core/utils/internal/isHandlerKind.js +2 -1
- package/lib/core/utils/internal/isHandlerKind.js.map +1 -1
- package/lib/core/utils/internal/isHandlerKind.mjs +2 -1
- package/lib/core/utils/internal/isHandlerKind.mjs.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.mts +1 -1
- package/lib/core/utils/internal/parseMultipartData.d.ts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.mts +1 -1
- package/lib/core/utils/internal/requestHandlerUtils.d.ts +1 -1
- package/lib/core/utils/matching/matchRequestUrl.js +1 -1
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.d.mts +2 -2
- package/lib/core/utils/request/onUnhandledRequest.d.ts +2 -2
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.ts +1 -1
- package/lib/core/ws/handleWebSocketEvent.js +1 -1
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.js +39 -10
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +39 -10
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -1
- package/lib/core/ws.d.mts +3 -3
- package/lib/core/ws.d.ts +3 -3
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +2022 -1433
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +21 -29
- package/lib/native/index.d.ts +21 -29
- package/lib/native/index.js +48 -116
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +51 -118
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +55 -33
- package/lib/node/index.d.ts +55 -33
- package/lib/node/index.js +152 -154
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +156 -156
- package/lib/node/index.mjs.map +1 -1
- package/package.json +10 -2
- package/src/browser/{setupWorker/glossary.ts → glossary.ts} +16 -33
- package/src/browser/index.ts +2 -3
- package/src/browser/{setupWorker/setupWorker.node.test.ts → setup-worker.node.test.ts} +2 -4
- package/src/browser/setup-worker.ts +148 -0
- package/src/browser/sources/fallback-http-source.ts +56 -0
- package/src/browser/sources/service-worker-source.ts +455 -0
- package/src/browser/tsconfig.browser.json +7 -2
- package/src/browser/utils/deserializeRequest.ts +1 -1
- package/src/browser/{setupWorker/start/utils/getWorkerByRegistration.ts → utils/get-worker-by-registration.ts} +3 -1
- package/src/browser/{setupWorker/start/utils/getWorkerInstance.ts → utils/get-worker-instance.ts} +4 -4
- package/src/browser/utils/pruneGetRequestBody.test.ts +1 -3
- package/src/browser/utils/pruneGetRequestBody.ts +1 -1
- package/src/browser/utils/validate-worker-scope.ts +19 -0
- package/src/browser/utils/workerChannel.ts +2 -2
- package/src/core/experimental/compat.ts +50 -0
- package/src/core/experimental/define-network.test.ts +124 -0
- package/src/core/experimental/define-network.ts +215 -0
- package/src/core/experimental/frames/http-frame.test.ts +360 -0
- package/src/core/experimental/frames/http-frame.ts +271 -0
- package/src/core/experimental/frames/network-frame.ts +64 -0
- package/src/core/experimental/frames/websocket-frame.test.ts +280 -0
- package/src/core/experimental/frames/websocket-frame.ts +188 -0
- package/src/core/experimental/handlers-controller.test.ts +198 -0
- package/src/core/experimental/handlers-controller.ts +145 -0
- package/src/core/experimental/index.ts +16 -0
- package/src/core/experimental/on-unhandled-frame.test.ts +360 -0
- package/src/core/experimental/on-unhandled-frame.ts +110 -0
- package/src/core/experimental/request-utils.test.ts +70 -0
- package/src/core/experimental/request-utils.ts +39 -0
- package/src/core/experimental/setup-api.ts +59 -0
- package/src/core/experimental/sources/interceptor-source.ts +185 -0
- package/src/core/experimental/sources/network-source.test.ts +74 -0
- package/src/core/experimental/sources/network-source.ts +56 -0
- package/src/core/handlers/RequestHandler.ts +9 -10
- package/src/core/handlers/WebSocketHandler.ts +27 -11
- package/src/core/index.ts +3 -7
- package/src/core/sharedOptions.ts +9 -4
- package/src/core/sse.ts +1 -1
- package/src/core/utils/cookieStore.ts +2 -1
- package/src/core/utils/internal/isHandlerKind.test.ts +20 -22
- package/src/core/utils/internal/isHandlerKind.ts +5 -9
- package/src/core/utils/matching/matchRequestUrl.test.ts +87 -3
- package/src/core/utils/matching/matchRequestUrl.ts +2 -2
- package/src/core/utils/request/onUnhandledRequest.ts +2 -2
- package/src/core/ws/WebSocketClientManager.test.ts +2 -10
- package/src/core/ws/handleWebSocketEvent.ts +5 -1
- package/src/core/ws/utils/attachWebSocketLogger.ts +43 -11
- package/src/core/ws.test.ts +1 -3
- package/src/core/ws.ts +6 -6
- package/src/iife/index.ts +1 -1
- package/src/native/index.ts +34 -11
- package/src/node/async-handlers-controller.test.ts +50 -0
- package/src/node/async-handlers-controller.ts +69 -0
- package/src/node/glossary.ts +19 -18
- package/src/node/index.ts +6 -2
- package/src/node/setup-server-common.ts +100 -0
- package/src/node/setup-server.ts +91 -0
- package/src/tsconfig.core.json +8 -0
- package/src/tsconfig.node.json +8 -3
- package/src/tsconfig.src.json +0 -2
- package/src/tsconfig.worker.json +2 -1
- package/lib/core/SetupApi.d.mts +0 -44
- package/lib/core/SetupApi.d.ts +0 -44
- package/lib/core/SetupApi.js +0 -112
- package/lib/core/SetupApi.js.map +0 -1
- package/lib/core/SetupApi.mjs +0 -92
- package/lib/core/SetupApi.mjs.map +0 -1
- package/lib/core/handlers/common.d.mts +0 -3
- package/lib/core/handlers/common.d.ts +0 -3
- package/lib/core/handlers/common.js.map +0 -1
- package/lib/core/handlers/common.mjs +0 -1
- package/lib/core/handlers/common.mjs.map +0 -1
- package/src/browser/setupWorker/setupWorker.ts +0 -184
- package/src/browser/setupWorker/start/createFallbackRequestListener.ts +0 -71
- package/src/browser/setupWorker/start/createRequestListener.ts +0 -138
- package/src/browser/setupWorker/start/createResponseListener.ts +0 -57
- package/src/browser/setupWorker/start/createStartHandler.ts +0 -137
- package/src/browser/setupWorker/start/utils/enableMocking.ts +0 -30
- package/src/browser/setupWorker/start/utils/prepareStartHandler.test.ts +0 -59
- package/src/browser/setupWorker/start/utils/prepareStartHandler.ts +0 -44
- package/src/browser/setupWorker/start/utils/printStartMessage.test.ts +0 -84
- package/src/browser/setupWorker/start/utils/printStartMessage.ts +0 -51
- package/src/browser/setupWorker/start/utils/validateWorkerScope.ts +0 -18
- package/src/browser/setupWorker/stop/utils/printStopMessage.test.ts +0 -26
- package/src/browser/setupWorker/stop/utils/printStopMessage.ts +0 -13
- package/src/browser/utils/checkWorkerIntegrity.ts +0 -42
- package/src/core/SetupApi.ts +0 -127
- package/src/core/handlers/common.ts +0 -1
- package/src/node/SetupServerApi.ts +0 -87
- package/src/node/SetupServerCommonApi.ts +0 -169
- package/src/node/setupServer.ts +0 -15
package/lib/browser/index.js
CHANGED
|
@@ -124,1121 +124,1376 @@ function isNodeProcess() {
|
|
|
124
124
|
return false;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
// node_modules/.pnpm/@open-draft+
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
// node_modules/.pnpm/@open-draft+logger@0.3.0/node_modules/@open-draft/logger/lib/index.mjs
|
|
128
|
+
var __defProp2 = Object.defineProperty;
|
|
129
|
+
var __export2 = (target, all) => {
|
|
130
|
+
for (var name in all)
|
|
131
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
132
|
+
};
|
|
133
|
+
var colors_exports = {};
|
|
134
|
+
__export2(colors_exports, {
|
|
135
|
+
blue: () => blue,
|
|
136
|
+
gray: () => gray,
|
|
137
|
+
green: () => green,
|
|
138
|
+
red: () => red,
|
|
139
|
+
yellow: () => yellow
|
|
140
|
+
});
|
|
141
|
+
function yellow(text) {
|
|
142
|
+
return `\x1B[33m${text}\x1B[0m`;
|
|
143
|
+
}
|
|
144
|
+
function blue(text) {
|
|
145
|
+
return `\x1B[34m${text}\x1B[0m`;
|
|
146
|
+
}
|
|
147
|
+
function gray(text) {
|
|
148
|
+
return `\x1B[90m${text}\x1B[0m`;
|
|
149
|
+
}
|
|
150
|
+
function red(text) {
|
|
151
|
+
return `\x1B[31m${text}\x1B[0m`;
|
|
152
|
+
}
|
|
153
|
+
function green(text) {
|
|
154
|
+
return `\x1B[32m${text}\x1B[0m`;
|
|
155
|
+
}
|
|
156
|
+
var IS_NODE = isNodeProcess();
|
|
157
|
+
var Logger = class {
|
|
158
|
+
constructor(name) {
|
|
159
|
+
this.name = name;
|
|
160
|
+
this.prefix = `[${this.name}]`;
|
|
161
|
+
const LOGGER_NAME = getVariable("DEBUG");
|
|
162
|
+
const LOGGER_LEVEL = getVariable("LOG_LEVEL");
|
|
163
|
+
const isLoggingEnabled = LOGGER_NAME === "1" || LOGGER_NAME === "true" || typeof LOGGER_NAME !== "undefined" && this.name.startsWith(LOGGER_NAME);
|
|
164
|
+
if (isLoggingEnabled) {
|
|
165
|
+
this.debug = isDefinedAndNotEquals(LOGGER_LEVEL, "debug") ? noop : this.debug;
|
|
166
|
+
this.info = isDefinedAndNotEquals(LOGGER_LEVEL, "info") ? noop : this.info;
|
|
167
|
+
this.success = isDefinedAndNotEquals(LOGGER_LEVEL, "success") ? noop : this.success;
|
|
168
|
+
this.warning = isDefinedAndNotEquals(LOGGER_LEVEL, "warning") ? noop : this.warning;
|
|
169
|
+
this.error = isDefinedAndNotEquals(LOGGER_LEVEL, "error") ? noop : this.error;
|
|
170
|
+
} else {
|
|
171
|
+
this.info = noop;
|
|
172
|
+
this.success = noop;
|
|
173
|
+
this.warning = noop;
|
|
174
|
+
this.error = noop;
|
|
175
|
+
this.only = noop;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
prefix;
|
|
179
|
+
extend(domain) {
|
|
180
|
+
return new Logger(`${this.name}:${domain}`);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Print a debug message.
|
|
184
|
+
* @example
|
|
185
|
+
* logger.debug('no duplicates found, creating a document...')
|
|
186
|
+
*/
|
|
187
|
+
debug(message, ...positionals) {
|
|
188
|
+
this.logEntry({
|
|
189
|
+
level: "debug",
|
|
190
|
+
message: gray(message),
|
|
191
|
+
positionals,
|
|
192
|
+
prefix: this.prefix,
|
|
193
|
+
colors: {
|
|
194
|
+
prefix: "gray"
|
|
134
195
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Print an info message.
|
|
200
|
+
* @example
|
|
201
|
+
* logger.info('start parsing...')
|
|
202
|
+
*/
|
|
203
|
+
info(message, ...positionals) {
|
|
204
|
+
this.logEntry({
|
|
205
|
+
level: "info",
|
|
206
|
+
message,
|
|
207
|
+
positionals,
|
|
208
|
+
prefix: this.prefix,
|
|
209
|
+
colors: {
|
|
210
|
+
prefix: "blue"
|
|
147
211
|
}
|
|
148
|
-
|
|
149
|
-
|
|
212
|
+
});
|
|
213
|
+
const performance2 = new PerformanceEntry();
|
|
214
|
+
return (message2, ...positionals2) => {
|
|
215
|
+
performance2.measure();
|
|
216
|
+
this.logEntry({
|
|
217
|
+
level: "info",
|
|
218
|
+
message: `${message2} ${gray(`${performance2.deltaTime}ms`)}`,
|
|
219
|
+
positionals: positionals2,
|
|
220
|
+
prefix: this.prefix,
|
|
221
|
+
colors: {
|
|
222
|
+
prefix: "blue"
|
|
223
|
+
}
|
|
150
224
|
});
|
|
151
|
-
return reject(executor.rejectionReason = reason);
|
|
152
225
|
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Print a success message.
|
|
229
|
+
* @example
|
|
230
|
+
* logger.success('successfully created document')
|
|
231
|
+
*/
|
|
232
|
+
success(message, ...positionals) {
|
|
233
|
+
this.logEntry({
|
|
234
|
+
level: "info",
|
|
235
|
+
message,
|
|
236
|
+
positionals,
|
|
237
|
+
prefix: `\u2714 ${this.prefix}`,
|
|
238
|
+
colors: {
|
|
239
|
+
timestamp: "green",
|
|
240
|
+
prefix: "green"
|
|
241
|
+
}
|
|
165
242
|
});
|
|
166
|
-
this.#executor = deferredExecutor;
|
|
167
|
-
this.resolve = this.#executor.resolve;
|
|
168
|
-
this.reject = this.#executor.reject;
|
|
169
243
|
}
|
|
170
|
-
|
|
171
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Print a warning.
|
|
246
|
+
* @example
|
|
247
|
+
* logger.warning('found legacy document format')
|
|
248
|
+
*/
|
|
249
|
+
warning(message, ...positionals) {
|
|
250
|
+
this.logEntry({
|
|
251
|
+
level: "warning",
|
|
252
|
+
message,
|
|
253
|
+
positionals,
|
|
254
|
+
prefix: `\u26A0 ${this.prefix}`,
|
|
255
|
+
colors: {
|
|
256
|
+
timestamp: "yellow",
|
|
257
|
+
prefix: "yellow"
|
|
258
|
+
}
|
|
259
|
+
});
|
|
172
260
|
}
|
|
173
|
-
|
|
174
|
-
|
|
261
|
+
/**
|
|
262
|
+
* Print an error message.
|
|
263
|
+
* @example
|
|
264
|
+
* logger.error('something went wrong')
|
|
265
|
+
*/
|
|
266
|
+
error(message, ...positionals) {
|
|
267
|
+
this.logEntry({
|
|
268
|
+
level: "error",
|
|
269
|
+
message,
|
|
270
|
+
positionals,
|
|
271
|
+
prefix: `\u2716 ${this.prefix}`,
|
|
272
|
+
colors: {
|
|
273
|
+
timestamp: "red",
|
|
274
|
+
prefix: "red"
|
|
275
|
+
}
|
|
276
|
+
});
|
|
175
277
|
}
|
|
176
|
-
|
|
177
|
-
|
|
278
|
+
/**
|
|
279
|
+
* Execute the given callback only when the logging is enabled.
|
|
280
|
+
* This is skipped in its entirety and has no runtime cost otherwise.
|
|
281
|
+
* This executes regardless of the log level.
|
|
282
|
+
* @example
|
|
283
|
+
* logger.only(() => {
|
|
284
|
+
* logger.info('additional info')
|
|
285
|
+
* })
|
|
286
|
+
*/
|
|
287
|
+
only(callback) {
|
|
288
|
+
callback();
|
|
178
289
|
}
|
|
179
|
-
|
|
180
|
-
return
|
|
290
|
+
createEntry(level, message) {
|
|
291
|
+
return {
|
|
292
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
293
|
+
level,
|
|
294
|
+
message
|
|
295
|
+
};
|
|
181
296
|
}
|
|
182
|
-
|
|
183
|
-
|
|
297
|
+
logEntry(args) {
|
|
298
|
+
const {
|
|
299
|
+
level,
|
|
300
|
+
message,
|
|
301
|
+
prefix,
|
|
302
|
+
colors: customColors,
|
|
303
|
+
positionals = []
|
|
304
|
+
} = args;
|
|
305
|
+
const entry = this.createEntry(level, message);
|
|
306
|
+
const timestampColor = customColors?.timestamp || "gray";
|
|
307
|
+
const prefixColor = customColors?.prefix || "gray";
|
|
308
|
+
const colorize = {
|
|
309
|
+
timestamp: colors_exports[timestampColor],
|
|
310
|
+
prefix: colors_exports[prefixColor]
|
|
311
|
+
};
|
|
312
|
+
const write = this.getWriter(level);
|
|
313
|
+
write(
|
|
314
|
+
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "),
|
|
315
|
+
...positionals.map(serializeInput)
|
|
316
|
+
);
|
|
184
317
|
}
|
|
185
|
-
|
|
186
|
-
return
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
318
|
+
formatTimestamp(timestamp) {
|
|
319
|
+
return `${timestamp.toLocaleTimeString(
|
|
320
|
+
"en-GB"
|
|
321
|
+
)}:${timestamp.getMilliseconds()}`;
|
|
322
|
+
}
|
|
323
|
+
getWriter(level) {
|
|
324
|
+
switch (level) {
|
|
325
|
+
case "debug":
|
|
326
|
+
case "success":
|
|
327
|
+
case "info": {
|
|
328
|
+
return log;
|
|
329
|
+
}
|
|
330
|
+
case "warning": {
|
|
331
|
+
return warn;
|
|
332
|
+
}
|
|
333
|
+
case "error": {
|
|
334
|
+
return error;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
190
337
|
}
|
|
191
338
|
};
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
findWorker(scriptURL, mockServiceWorkerUrl) {
|
|
204
|
-
return scriptURL === mockServiceWorkerUrl;
|
|
339
|
+
var PerformanceEntry = class {
|
|
340
|
+
startTime;
|
|
341
|
+
endTime;
|
|
342
|
+
deltaTime;
|
|
343
|
+
constructor() {
|
|
344
|
+
this.startTime = performance.now();
|
|
345
|
+
}
|
|
346
|
+
measure() {
|
|
347
|
+
this.endTime = performance.now();
|
|
348
|
+
const deltaTime = this.endTime - this.startTime;
|
|
349
|
+
this.deltaTime = deltaTime.toFixed(2);
|
|
205
350
|
}
|
|
206
351
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return
|
|
352
|
+
var noop = () => void 0;
|
|
353
|
+
function log(message, ...positionals) {
|
|
354
|
+
if (IS_NODE) {
|
|
355
|
+
process.stdout.write(format(message, ...positionals) + "\n");
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
console.log(message, ...positionals);
|
|
359
|
+
}
|
|
360
|
+
function warn(message, ...positionals) {
|
|
361
|
+
if (IS_NODE) {
|
|
362
|
+
process.stderr.write(format(message, ...positionals) + "\n");
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
console.warn(message, ...positionals);
|
|
366
|
+
}
|
|
367
|
+
function error(message, ...positionals) {
|
|
368
|
+
if (IS_NODE) {
|
|
369
|
+
process.stderr.write(format(message, ...positionals) + "\n");
|
|
370
|
+
return;
|
|
219
371
|
}
|
|
372
|
+
console.error(message, ...positionals);
|
|
220
373
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
function getAbsoluteWorkerUrl(workerUrl) {
|
|
227
|
-
return new URL(workerUrl, location.href).href;
|
|
374
|
+
function getVariable(variableName) {
|
|
375
|
+
if (IS_NODE) {
|
|
376
|
+
return process.env[variableName];
|
|
377
|
+
}
|
|
378
|
+
return globalThis[variableName]?.toString();
|
|
228
379
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
function getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker) {
|
|
232
|
-
const allStates = [
|
|
233
|
-
registration.active,
|
|
234
|
-
registration.installing,
|
|
235
|
-
registration.waiting
|
|
236
|
-
];
|
|
237
|
-
const relevantStates = allStates.filter((state) => {
|
|
238
|
-
return state != null;
|
|
239
|
-
});
|
|
240
|
-
const worker = relevantStates.find((worker2) => {
|
|
241
|
-
return findWorker(worker2.scriptURL, absoluteWorkerUrl);
|
|
242
|
-
});
|
|
243
|
-
return worker || null;
|
|
380
|
+
function isDefinedAndNotEquals(value, expected) {
|
|
381
|
+
return value !== void 0 && value !== expected;
|
|
244
382
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const absoluteWorkerUrl = getAbsoluteWorkerUrl(url);
|
|
249
|
-
const mockRegistrations = await navigator.serviceWorker.getRegistrations().then(
|
|
250
|
-
(registrations) => registrations.filter(
|
|
251
|
-
(registration) => getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker)
|
|
252
|
-
)
|
|
253
|
-
);
|
|
254
|
-
if (!navigator.serviceWorker.controller && mockRegistrations.length > 0) {
|
|
255
|
-
location.reload();
|
|
383
|
+
function serializeInput(message) {
|
|
384
|
+
if (typeof message === "undefined") {
|
|
385
|
+
return "undefined";
|
|
256
386
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
existingRegistration.update();
|
|
260
|
-
return [
|
|
261
|
-
getWorkerByRegistration(
|
|
262
|
-
existingRegistration,
|
|
263
|
-
absoluteWorkerUrl,
|
|
264
|
-
findWorker
|
|
265
|
-
),
|
|
266
|
-
existingRegistration
|
|
267
|
-
];
|
|
387
|
+
if (message === null) {
|
|
388
|
+
return "null";
|
|
268
389
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
});
|
|
278
|
-
if (registrationError) {
|
|
279
|
-
const isWorkerMissing = registrationError.message.includes("(404)");
|
|
280
|
-
if (isWorkerMissing) {
|
|
281
|
-
const scopeUrl = new URL(options?.scope || "/", location.href);
|
|
282
|
-
throw new Error(
|
|
283
|
-
import_devUtils.devUtils.formatMessage(`Failed to register a Service Worker for scope ('${scopeUrl.href}') with script ('${absoluteWorkerUrl}'): Service Worker script does not exist at the given path.
|
|
284
|
-
|
|
285
|
-
Did you forget to run "npx msw init <PUBLIC_DIR>"?
|
|
390
|
+
if (typeof message === "string") {
|
|
391
|
+
return message;
|
|
392
|
+
}
|
|
393
|
+
if (typeof message === "object") {
|
|
394
|
+
return JSON.stringify(message);
|
|
395
|
+
}
|
|
396
|
+
return message.toString();
|
|
397
|
+
}
|
|
286
398
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
"Failed to register the Service Worker:\n\n%s",
|
|
293
|
-
registrationError.message
|
|
294
|
-
)
|
|
399
|
+
// node_modules/.pnpm/strict-event-emitter@0.5.1/node_modules/strict-event-emitter/lib/index.mjs
|
|
400
|
+
var MemoryLeakError = class extends Error {
|
|
401
|
+
constructor(emitter, type, count) {
|
|
402
|
+
super(
|
|
403
|
+
`Possible EventEmitter memory leak detected. ${count} ${type.toString()} listeners added. Use emitter.setMaxListeners() to increase limit`
|
|
295
404
|
);
|
|
405
|
+
this.emitter = emitter;
|
|
406
|
+
this.type = type;
|
|
407
|
+
this.count = count;
|
|
408
|
+
this.name = "MaxListenersExceededWarning";
|
|
296
409
|
}
|
|
297
|
-
return registrationResult;
|
|
298
410
|
};
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
function printStartMessage(args = {}) {
|
|
303
|
-
if (args.quiet) {
|
|
304
|
-
return;
|
|
411
|
+
var _Emitter = class {
|
|
412
|
+
static listenerCount(emitter, eventName) {
|
|
413
|
+
return emitter.listenerCount(eventName);
|
|
305
414
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
);
|
|
311
|
-
console.log(
|
|
312
|
-
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
313
|
-
"font-weight:bold",
|
|
314
|
-
"font-weight:normal"
|
|
315
|
-
);
|
|
316
|
-
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
317
|
-
if (args.workerUrl) {
|
|
318
|
-
console.log("Worker script URL:", args.workerUrl);
|
|
415
|
+
constructor() {
|
|
416
|
+
this.events = /* @__PURE__ */ new Map();
|
|
417
|
+
this.maxListeners = _Emitter.defaultMaxListeners;
|
|
418
|
+
this.hasWarnedAboutPotentialMemoryLeak = false;
|
|
319
419
|
}
|
|
320
|
-
|
|
321
|
-
|
|
420
|
+
_emitInternalEvent(internalEventName, eventName, listener) {
|
|
421
|
+
this.emit(
|
|
422
|
+
internalEventName,
|
|
423
|
+
...[eventName, listener]
|
|
424
|
+
);
|
|
322
425
|
}
|
|
323
|
-
|
|
324
|
-
|
|
426
|
+
_getListeners(eventName) {
|
|
427
|
+
return Array.prototype.concat.apply([], this.events.get(eventName)) || [];
|
|
325
428
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
context.workerChannel.postMessage("MOCK_ACTIVATE");
|
|
333
|
-
context.workerChannel.once("MOCKING_ENABLED", async (event) => {
|
|
334
|
-
context.isMockingEnabled = true;
|
|
335
|
-
const worker = await context.workerPromise;
|
|
336
|
-
printStartMessage({
|
|
337
|
-
quiet: options.quiet,
|
|
338
|
-
workerScope: context.registration?.scope,
|
|
339
|
-
workerUrl: worker.scriptURL,
|
|
340
|
-
client: event.data.client
|
|
341
|
-
});
|
|
342
|
-
mockingEnabledPromise.resolve(true);
|
|
343
|
-
});
|
|
344
|
-
return mockingEnabledPromise;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
// src/browser/utils/pruneGetRequestBody.ts
|
|
348
|
-
function pruneGetRequestBody(request) {
|
|
349
|
-
if (["HEAD", "GET"].includes(request.method)) {
|
|
350
|
-
return void 0;
|
|
429
|
+
_removeListener(listeners, listener) {
|
|
430
|
+
const index = listeners.indexOf(listener);
|
|
431
|
+
if (index > -1) {
|
|
432
|
+
listeners.splice(index, 1);
|
|
433
|
+
}
|
|
434
|
+
return [];
|
|
351
435
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
436
|
+
_wrapOnceListener(eventName, listener) {
|
|
437
|
+
const onceListener = (...data) => {
|
|
438
|
+
this.removeListener(eventName, onceListener);
|
|
439
|
+
return listener.apply(this, data);
|
|
440
|
+
};
|
|
441
|
+
Object.defineProperty(onceListener, "name", { value: listener.name });
|
|
442
|
+
return onceListener;
|
|
443
|
+
}
|
|
444
|
+
setMaxListeners(maxListeners) {
|
|
445
|
+
this.maxListeners = maxListeners;
|
|
446
|
+
return this;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Returns the current max listener value for the `Emitter` which is
|
|
450
|
+
* either set by `emitter.setMaxListeners(n)` or defaults to
|
|
451
|
+
* `Emitter.defaultMaxListeners`.
|
|
452
|
+
*/
|
|
453
|
+
getMaxListeners() {
|
|
454
|
+
return this.maxListeners;
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Returns an array listing the events for which the emitter has registered listeners.
|
|
458
|
+
* The values in the array will be strings or Symbols.
|
|
459
|
+
*/
|
|
460
|
+
eventNames() {
|
|
461
|
+
return Array.from(this.events.keys());
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Synchronously calls each of the listeners registered for the event named `eventName`,
|
|
465
|
+
* in the order they were registered, passing the supplied arguments to each.
|
|
466
|
+
* Returns `true` if the event has listeners, `false` otherwise.
|
|
467
|
+
*
|
|
468
|
+
* @example
|
|
469
|
+
* const emitter = new Emitter<{ hello: [string] }>()
|
|
470
|
+
* emitter.emit('hello', 'John')
|
|
471
|
+
*/
|
|
472
|
+
emit(eventName, ...data) {
|
|
473
|
+
const listeners = this._getListeners(eventName);
|
|
474
|
+
listeners.forEach((listener) => {
|
|
475
|
+
listener.apply(this, data);
|
|
371
476
|
});
|
|
372
|
-
|
|
373
|
-
message.port1.postMessage(stream, [stream]);
|
|
374
|
-
return true;
|
|
375
|
-
} catch {
|
|
376
|
-
return false;
|
|
477
|
+
return listeners.length > 0;
|
|
377
478
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
return async (event) => {
|
|
389
|
-
if (!context.isMockingEnabled && context.workerStoppedAt && event.data.interceptedAt > context.workerStoppedAt) {
|
|
390
|
-
event.postMessage("PASSTHROUGH");
|
|
391
|
-
return;
|
|
392
|
-
}
|
|
393
|
-
const requestId = event.data.id;
|
|
394
|
-
const request = deserializeRequest(event.data);
|
|
395
|
-
const requestCloneForLogs = request.clone();
|
|
396
|
-
const requestClone = request.clone();
|
|
397
|
-
import_RequestHandler.RequestHandler.cache.set(request, requestClone);
|
|
398
|
-
try {
|
|
399
|
-
await (0, import_handleRequest.handleRequest)(
|
|
400
|
-
request,
|
|
401
|
-
requestId,
|
|
402
|
-
context.getRequestHandlers().filter((0, import_isHandlerKind.isHandlerKind)("RequestHandler")),
|
|
403
|
-
options,
|
|
404
|
-
context.emitter,
|
|
405
|
-
{
|
|
406
|
-
resolutionContext: {
|
|
407
|
-
quiet: options.quiet
|
|
408
|
-
},
|
|
409
|
-
onPassthroughResponse() {
|
|
410
|
-
event.postMessage("PASSTHROUGH");
|
|
411
|
-
},
|
|
412
|
-
async onMockedResponse(response, { handler, parsedResult }) {
|
|
413
|
-
const responseClone = response.clone();
|
|
414
|
-
const responseCloneForLogs = response.clone();
|
|
415
|
-
const responseInit = (0, import_toResponseInit.toResponseInit)(response);
|
|
416
|
-
if (SUPPORTS_READABLE_STREAM_TRANSFER) {
|
|
417
|
-
const responseStreamOrNull = response.body;
|
|
418
|
-
event.postMessage(
|
|
419
|
-
"MOCK_RESPONSE",
|
|
420
|
-
{
|
|
421
|
-
...responseInit,
|
|
422
|
-
body: responseStreamOrNull
|
|
423
|
-
},
|
|
424
|
-
responseStreamOrNull ? [responseStreamOrNull] : void 0
|
|
425
|
-
);
|
|
426
|
-
} else {
|
|
427
|
-
const responseBufferOrNull = response.body === null ? null : await responseClone.arrayBuffer();
|
|
428
|
-
event.postMessage("MOCK_RESPONSE", {
|
|
429
|
-
...responseInit,
|
|
430
|
-
body: responseBufferOrNull
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
if (!options.quiet) {
|
|
434
|
-
context.emitter.once("response:mocked", () => {
|
|
435
|
-
handler.log({
|
|
436
|
-
request: requestCloneForLogs,
|
|
437
|
-
response: responseCloneForLogs,
|
|
438
|
-
parsedResult
|
|
439
|
-
});
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
479
|
+
addListener(eventName, listener) {
|
|
480
|
+
this._emitInternalEvent("newListener", eventName, listener);
|
|
481
|
+
const nextListeners = this._getListeners(eventName).concat(listener);
|
|
482
|
+
this.events.set(eventName, nextListeners);
|
|
483
|
+
if (this.maxListeners > 0 && this.listenerCount(eventName) > this.maxListeners && !this.hasWarnedAboutPotentialMemoryLeak) {
|
|
484
|
+
this.hasWarnedAboutPotentialMemoryLeak = true;
|
|
485
|
+
const memoryLeakWarning = new MemoryLeakError(
|
|
486
|
+
this,
|
|
487
|
+
eventName,
|
|
488
|
+
this.listenerCount(eventName)
|
|
444
489
|
);
|
|
445
|
-
|
|
446
|
-
if (error2 instanceof Error) {
|
|
447
|
-
import_devUtils3.devUtils.error(
|
|
448
|
-
`Uncaught exception in the request handler for "%s %s":
|
|
449
|
-
|
|
450
|
-
%s
|
|
451
|
-
|
|
452
|
-
This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/http/mocking-responses/error-responses`,
|
|
453
|
-
request.method,
|
|
454
|
-
request.url,
|
|
455
|
-
error2.stack ?? error2
|
|
456
|
-
);
|
|
457
|
-
event.postMessage("MOCK_RESPONSE", {
|
|
458
|
-
status: 500,
|
|
459
|
-
statusText: "Request Handler Error",
|
|
460
|
-
headers: {
|
|
461
|
-
"Content-Type": "application/json"
|
|
462
|
-
},
|
|
463
|
-
body: JSON.stringify({
|
|
464
|
-
name: error2.name,
|
|
465
|
-
message: error2.message,
|
|
466
|
-
stack: error2.stack
|
|
467
|
-
})
|
|
468
|
-
});
|
|
469
|
-
}
|
|
490
|
+
console.warn(memoryLeakWarning);
|
|
470
491
|
}
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`
|
|
490
|
-
);
|
|
492
|
+
return this;
|
|
493
|
+
}
|
|
494
|
+
on(eventName, listener) {
|
|
495
|
+
return this.addListener(eventName, listener);
|
|
496
|
+
}
|
|
497
|
+
once(eventName, listener) {
|
|
498
|
+
return this.addListener(
|
|
499
|
+
eventName,
|
|
500
|
+
this._wrapOnceListener(eventName, listener)
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
prependListener(eventName, listener) {
|
|
504
|
+
const listeners = this._getListeners(eventName);
|
|
505
|
+
if (listeners.length > 0) {
|
|
506
|
+
const nextListeners = [listener].concat(listeners);
|
|
507
|
+
this.events.set(eventName, nextListeners);
|
|
508
|
+
} else {
|
|
509
|
+
this.events.set(eventName, listeners.concat(listener));
|
|
491
510
|
}
|
|
492
|
-
|
|
493
|
-
});
|
|
494
|
-
return integrityCheckPromise;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-BTaNLFr0.mjs
|
|
498
|
-
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
499
|
-
var InterceptorError = class InterceptorError2 extends Error {
|
|
500
|
-
constructor(message) {
|
|
501
|
-
super(message);
|
|
502
|
-
this.name = "InterceptorError";
|
|
503
|
-
Object.setPrototypeOf(this, InterceptorError2.prototype);
|
|
511
|
+
return this;
|
|
504
512
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
513
|
+
prependOnceListener(eventName, listener) {
|
|
514
|
+
return this.prependListener(
|
|
515
|
+
eventName,
|
|
516
|
+
this._wrapOnceListener(eventName, listener)
|
|
517
|
+
);
|
|
509
518
|
}
|
|
510
|
-
|
|
511
|
-
|
|
519
|
+
removeListener(eventName, listener) {
|
|
520
|
+
const listeners = this._getListeners(eventName);
|
|
521
|
+
if (listeners.length > 0) {
|
|
522
|
+
this._removeListener(listeners, listener);
|
|
523
|
+
this.events.set(eventName, listeners);
|
|
524
|
+
this._emitInternalEvent("removeListener", eventName, listener);
|
|
525
|
+
}
|
|
526
|
+
return this;
|
|
512
527
|
}
|
|
513
|
-
|
|
514
|
-
|
|
528
|
+
/**
|
|
529
|
+
* Alias for `emitter.removeListener()`.
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* emitter.off('hello', listener)
|
|
533
|
+
*/
|
|
534
|
+
off(eventName, listener) {
|
|
535
|
+
return this.removeListener(eventName, listener);
|
|
515
536
|
}
|
|
516
|
-
|
|
517
|
-
|
|
537
|
+
removeAllListeners(eventName) {
|
|
538
|
+
if (eventName) {
|
|
539
|
+
this.events.delete(eventName);
|
|
540
|
+
} else {
|
|
541
|
+
this.events.clear();
|
|
542
|
+
}
|
|
543
|
+
return this;
|
|
518
544
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
this.
|
|
545
|
+
/**
|
|
546
|
+
* Returns a copy of the array of listeners for the event named `eventName`.
|
|
547
|
+
*/
|
|
548
|
+
listeners(eventName) {
|
|
549
|
+
return Array.from(this._getListeners(eventName));
|
|
524
550
|
}
|
|
525
|
-
|
|
526
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Returns the number of listeners listening to the event named `eventName`.
|
|
553
|
+
*/
|
|
554
|
+
listenerCount(eventName) {
|
|
555
|
+
return this._getListeners(eventName).length;
|
|
556
|
+
}
|
|
557
|
+
rawListeners(eventName) {
|
|
558
|
+
return this.listeners(eventName);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
var Emitter = _Emitter;
|
|
562
|
+
Emitter.defaultMaxListeners = 10;
|
|
563
|
+
|
|
564
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/createRequestId-DQcIlohW.mjs
|
|
565
|
+
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
566
|
+
function getGlobalSymbol(symbol) {
|
|
567
|
+
return globalThis[symbol] || void 0;
|
|
568
|
+
}
|
|
569
|
+
function setGlobalSymbol(symbol, value) {
|
|
570
|
+
globalThis[symbol] = value;
|
|
571
|
+
}
|
|
572
|
+
function deleteGlobalSymbol(symbol) {
|
|
573
|
+
delete globalThis[symbol];
|
|
574
|
+
}
|
|
575
|
+
var InterceptorReadyState = /* @__PURE__ */ (function(InterceptorReadyState$1) {
|
|
576
|
+
InterceptorReadyState$1["INACTIVE"] = "INACTIVE";
|
|
577
|
+
InterceptorReadyState$1["APPLYING"] = "APPLYING";
|
|
578
|
+
InterceptorReadyState$1["APPLIED"] = "APPLIED";
|
|
579
|
+
InterceptorReadyState$1["DISPOSING"] = "DISPOSING";
|
|
580
|
+
InterceptorReadyState$1["DISPOSED"] = "DISPOSED";
|
|
581
|
+
return InterceptorReadyState$1;
|
|
582
|
+
})({});
|
|
583
|
+
var Interceptor = class {
|
|
584
|
+
constructor(symbol) {
|
|
585
|
+
this.symbol = symbol;
|
|
586
|
+
this.readyState = InterceptorReadyState.INACTIVE;
|
|
587
|
+
this.emitter = new Emitter();
|
|
588
|
+
this.subscriptions = [];
|
|
589
|
+
this.logger = new Logger(symbol.description);
|
|
590
|
+
this.emitter.setMaxListeners(0);
|
|
591
|
+
this.logger.info("constructing the interceptor...");
|
|
527
592
|
}
|
|
528
593
|
/**
|
|
529
|
-
*
|
|
594
|
+
* Determine if this interceptor can be applied
|
|
595
|
+
* in the current environment.
|
|
530
596
|
*/
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
this.readyState = RequestController2.PASSTHROUGH;
|
|
534
|
-
await this.source.passthrough();
|
|
535
|
-
this.#handled.resolve();
|
|
597
|
+
checkEnvironment() {
|
|
598
|
+
return true;
|
|
536
599
|
}
|
|
537
600
|
/**
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
* @example
|
|
541
|
-
* controller.respondWith(new Response())
|
|
542
|
-
* controller.respondWith(Response.json({ id }))
|
|
543
|
-
* controller.respondWith(Response.error())
|
|
601
|
+
* Apply this interceptor to the current process.
|
|
602
|
+
* Returns an already running interceptor instance if it's present.
|
|
544
603
|
*/
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
this
|
|
549
|
-
|
|
604
|
+
apply() {
|
|
605
|
+
const logger = this.logger.extend("apply");
|
|
606
|
+
logger.info("applying the interceptor...");
|
|
607
|
+
if (this.readyState === InterceptorReadyState.APPLIED) {
|
|
608
|
+
logger.info("intercepted already applied!");
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (!this.checkEnvironment()) {
|
|
612
|
+
logger.info("the interceptor cannot be applied in this environment!");
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
this.readyState = InterceptorReadyState.APPLYING;
|
|
616
|
+
const runningInstance = this.getInstance();
|
|
617
|
+
if (runningInstance) {
|
|
618
|
+
logger.info("found a running instance, reusing...");
|
|
619
|
+
this.on = (event, listener) => {
|
|
620
|
+
logger.info('proxying the "%s" listener', event);
|
|
621
|
+
runningInstance.emitter.addListener(event, listener);
|
|
622
|
+
this.subscriptions.push(() => {
|
|
623
|
+
runningInstance.emitter.removeListener(event, listener);
|
|
624
|
+
logger.info('removed proxied "%s" listener!', event);
|
|
625
|
+
});
|
|
626
|
+
return this;
|
|
627
|
+
};
|
|
628
|
+
this.readyState = InterceptorReadyState.APPLIED;
|
|
629
|
+
return;
|
|
630
|
+
}
|
|
631
|
+
logger.info("no running instance found, setting up a new instance...");
|
|
632
|
+
this.setup();
|
|
633
|
+
this.setInstance();
|
|
634
|
+
this.readyState = InterceptorReadyState.APPLIED;
|
|
550
635
|
}
|
|
551
636
|
/**
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
* controller.errorWith()
|
|
556
|
-
* controller.errorWith(new Error('Oops!'))
|
|
557
|
-
* controller.errorWith({ message: 'Oops!'})
|
|
637
|
+
* Setup the module augments and stubs necessary for this interceptor.
|
|
638
|
+
* This method is not run if there's a running interceptor instance
|
|
639
|
+
* to prevent instantiating an interceptor multiple times.
|
|
558
640
|
*/
|
|
559
|
-
|
|
560
|
-
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to error the "%s %s" request with "%s": the request has already been handled (%d)', this.request.method, this.request.url, reason?.toString(), this.readyState);
|
|
561
|
-
this.readyState = RequestController2.ERROR;
|
|
562
|
-
this.source.errorWith(reason);
|
|
563
|
-
this.#handled.resolve();
|
|
564
|
-
}
|
|
565
|
-
};
|
|
566
|
-
function canParseUrl(url) {
|
|
567
|
-
try {
|
|
568
|
-
new URL(url);
|
|
569
|
-
return true;
|
|
570
|
-
} catch (_error) {
|
|
571
|
-
return false;
|
|
641
|
+
setup() {
|
|
572
642
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
204,
|
|
586
|
-
205,
|
|
587
|
-
304
|
|
588
|
-
];
|
|
643
|
+
/**
|
|
644
|
+
* Listen to the interceptor's public events.
|
|
645
|
+
*/
|
|
646
|
+
on(event, listener) {
|
|
647
|
+
const logger = this.logger.extend("on");
|
|
648
|
+
if (this.readyState === InterceptorReadyState.DISPOSING || this.readyState === InterceptorReadyState.DISPOSED) {
|
|
649
|
+
logger.info("cannot listen to events, already disposed!");
|
|
650
|
+
return this;
|
|
651
|
+
}
|
|
652
|
+
logger.info('adding "%s" event listener:', event, listener);
|
|
653
|
+
this.emitter.on(event, listener);
|
|
654
|
+
return this;
|
|
589
655
|
}
|
|
590
|
-
|
|
591
|
-
this.
|
|
592
|
-
|
|
593
|
-
302,
|
|
594
|
-
303,
|
|
595
|
-
307,
|
|
596
|
-
308
|
|
597
|
-
];
|
|
656
|
+
once(event, listener) {
|
|
657
|
+
this.emitter.once(event, listener);
|
|
658
|
+
return this;
|
|
598
659
|
}
|
|
599
|
-
|
|
600
|
-
|
|
660
|
+
off(event, listener) {
|
|
661
|
+
this.emitter.off(event, listener);
|
|
662
|
+
return this;
|
|
601
663
|
}
|
|
602
|
-
|
|
603
|
-
|
|
664
|
+
removeAllListeners(event) {
|
|
665
|
+
this.emitter.removeAllListeners(event);
|
|
666
|
+
return this;
|
|
604
667
|
}
|
|
605
668
|
/**
|
|
606
|
-
*
|
|
607
|
-
* code represents a response that can have a body.
|
|
669
|
+
* Disposes of any side-effects this interceptor has introduced.
|
|
608
670
|
*/
|
|
609
|
-
|
|
610
|
-
|
|
671
|
+
dispose() {
|
|
672
|
+
const logger = this.logger.extend("dispose");
|
|
673
|
+
if (this.readyState === InterceptorReadyState.DISPOSED) {
|
|
674
|
+
logger.info("cannot dispose, already disposed!");
|
|
675
|
+
return;
|
|
676
|
+
}
|
|
677
|
+
logger.info("disposing the interceptor...");
|
|
678
|
+
this.readyState = InterceptorReadyState.DISPOSING;
|
|
679
|
+
if (!this.getInstance()) {
|
|
680
|
+
logger.info("no interceptors running, skipping dispose...");
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
this.clearInstance();
|
|
684
|
+
logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
|
|
685
|
+
if (this.subscriptions.length > 0) {
|
|
686
|
+
logger.info("disposing of %d subscriptions...", this.subscriptions.length);
|
|
687
|
+
for (const dispose of this.subscriptions) dispose();
|
|
688
|
+
this.subscriptions = [];
|
|
689
|
+
logger.info("disposed of all subscriptions!", this.subscriptions.length);
|
|
690
|
+
}
|
|
691
|
+
this.emitter.removeAllListeners();
|
|
692
|
+
logger.info("destroyed the listener!");
|
|
693
|
+
this.readyState = InterceptorReadyState.DISPOSED;
|
|
611
694
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
else Object.defineProperty(response, "url", {
|
|
617
|
-
value: url,
|
|
618
|
-
enumerable: true,
|
|
619
|
-
configurable: true,
|
|
620
|
-
writable: false
|
|
621
|
-
});
|
|
695
|
+
getInstance() {
|
|
696
|
+
const instance = getGlobalSymbol(this.symbol);
|
|
697
|
+
this.logger.info("retrieved global instance:", instance?.constructor?.name);
|
|
698
|
+
return instance;
|
|
622
699
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
static parseRawHeaders(rawHeaders) {
|
|
627
|
-
const headers = new Headers();
|
|
628
|
-
for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
|
629
|
-
return headers;
|
|
700
|
+
setInstance() {
|
|
701
|
+
setGlobalSymbol(this.symbol, this);
|
|
702
|
+
this.logger.info("set global instance!", this.symbol.description);
|
|
630
703
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
const finalBody = FetchResponse2.isResponseWithBody(status) ? body : null;
|
|
635
|
-
super(finalBody, {
|
|
636
|
-
status: safeStatus,
|
|
637
|
-
statusText: init.statusText,
|
|
638
|
-
headers: init.headers
|
|
639
|
-
});
|
|
640
|
-
if (status !== safeStatus) {
|
|
641
|
-
const state = getValueBySymbol("state", this);
|
|
642
|
-
if (state) state.status = status;
|
|
643
|
-
else Object.defineProperty(this, "status", {
|
|
644
|
-
value: status,
|
|
645
|
-
enumerable: true,
|
|
646
|
-
configurable: true,
|
|
647
|
-
writable: false
|
|
648
|
-
});
|
|
649
|
-
}
|
|
650
|
-
FetchResponse2.setUrl(init.url, this);
|
|
704
|
+
clearInstance() {
|
|
705
|
+
deleteGlobalSymbol(this.symbol);
|
|
706
|
+
this.logger.info("cleared global instance!", this.symbol.description);
|
|
651
707
|
}
|
|
652
708
|
};
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
Reflect.set(request, kRawRequest, rawRequest);
|
|
709
|
+
function createRequestId() {
|
|
710
|
+
return Math.random().toString(16).slice(2);
|
|
656
711
|
}
|
|
657
712
|
|
|
658
|
-
// node_modules/.pnpm/@
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
gray: () => gray,
|
|
668
|
-
green: () => green,
|
|
669
|
-
red: () => red,
|
|
670
|
-
yellow: () => yellow
|
|
671
|
-
});
|
|
672
|
-
function yellow(text) {
|
|
673
|
-
return `\x1B[33m${text}\x1B[0m`;
|
|
674
|
-
}
|
|
675
|
-
function blue(text) {
|
|
676
|
-
return `\x1B[34m${text}\x1B[0m`;
|
|
713
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/resolveWebSocketUrl-C83-x9iE.mjs
|
|
714
|
+
function resolveWebSocketUrl(url) {
|
|
715
|
+
if (typeof url === "string") return resolveWebSocketUrl(new URL(url, typeof location !== "undefined" ? location.href : void 0));
|
|
716
|
+
if (url.protocol === "http:") url.protocol = "ws:";
|
|
717
|
+
else if (url.protocol === "https:") url.protocol = "wss:";
|
|
718
|
+
if (url.protocol !== "ws:" && url.protocol !== "wss:")
|
|
719
|
+
throw new SyntaxError(`Failed to construct 'WebSocket': The URL's scheme must be either 'http', 'https', 'ws', or 'wss'. '${url.protocol}' is not allowed.`);
|
|
720
|
+
if (url.hash !== "") throw new SyntaxError(`Failed to construct 'WebSocket': The URL contains a fragment identifier ('${url.hash}'). Fragment identifiers are not allowed in WebSocket URLs.`);
|
|
721
|
+
return url.href;
|
|
677
722
|
}
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
return
|
|
683
|
-
|
|
684
|
-
function green(text) {
|
|
685
|
-
return `\x1B[32m${text}\x1B[0m`;
|
|
723
|
+
|
|
724
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/hasConfigurableGlobal-npXitu1-.mjs
|
|
725
|
+
async function emitAsync(emitter, eventName, ...data) {
|
|
726
|
+
const listeners = emitter.listeners(eventName);
|
|
727
|
+
if (listeners.length === 0) return;
|
|
728
|
+
for (const listener of listeners) await listener.apply(emitter, data);
|
|
686
729
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
if (isLoggingEnabled) {
|
|
696
|
-
this.debug = isDefinedAndNotEquals(LOGGER_LEVEL, "debug") ? noop : this.debug;
|
|
697
|
-
this.info = isDefinedAndNotEquals(LOGGER_LEVEL, "info") ? noop : this.info;
|
|
698
|
-
this.success = isDefinedAndNotEquals(LOGGER_LEVEL, "success") ? noop : this.success;
|
|
699
|
-
this.warning = isDefinedAndNotEquals(LOGGER_LEVEL, "warning") ? noop : this.warning;
|
|
700
|
-
this.error = isDefinedAndNotEquals(LOGGER_LEVEL, "error") ? noop : this.error;
|
|
701
|
-
} else {
|
|
702
|
-
this.info = noop;
|
|
703
|
-
this.success = noop;
|
|
704
|
-
this.warning = noop;
|
|
705
|
-
this.error = noop;
|
|
706
|
-
this.only = noop;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
prefix;
|
|
710
|
-
extend(domain) {
|
|
711
|
-
return new Logger(`${this.name}:${domain}`);
|
|
730
|
+
function hasConfigurableGlobal(propertyName) {
|
|
731
|
+
const descriptor = Object.getOwnPropertyDescriptor(globalThis, propertyName);
|
|
732
|
+
if (typeof descriptor === "undefined") return false;
|
|
733
|
+
if (typeof descriptor.get === "function" && typeof descriptor.get() === "undefined") return false;
|
|
734
|
+
if (typeof descriptor.get === "undefined" && descriptor.value == null) return false;
|
|
735
|
+
if (typeof descriptor.set === "undefined" && !descriptor.configurable) {
|
|
736
|
+
console.error(`[MSW] Failed to apply interceptor: the global \`${propertyName}\` property is non-configurable. This is likely an issue with your environment. If you are using a framework, please open an issue about this in their repository.`);
|
|
737
|
+
return false;
|
|
712
738
|
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
prefix: this.prefix,
|
|
724
|
-
colors: {
|
|
725
|
-
prefix: "gray"
|
|
739
|
+
return true;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
// node_modules/.pnpm/@open-draft+deferred-promise@2.2.0/node_modules/@open-draft/deferred-promise/build/index.mjs
|
|
743
|
+
function createDeferredExecutor() {
|
|
744
|
+
const executor = (resolve, reject) => {
|
|
745
|
+
executor.state = "pending";
|
|
746
|
+
executor.resolve = (data) => {
|
|
747
|
+
if (executor.state !== "pending") {
|
|
748
|
+
return;
|
|
726
749
|
}
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
prefix: this.prefix,
|
|
740
|
-
colors: {
|
|
741
|
-
prefix: "blue"
|
|
750
|
+
executor.result = data;
|
|
751
|
+
const onFulfilled = (value) => {
|
|
752
|
+
executor.state = "fulfilled";
|
|
753
|
+
return value;
|
|
754
|
+
};
|
|
755
|
+
return resolve(
|
|
756
|
+
data instanceof Promise ? data : Promise.resolve(data).then(onFulfilled)
|
|
757
|
+
);
|
|
758
|
+
};
|
|
759
|
+
executor.reject = (reason) => {
|
|
760
|
+
if (executor.state !== "pending") {
|
|
761
|
+
return;
|
|
742
762
|
}
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
return (message2, ...positionals2) => {
|
|
746
|
-
performance2.measure();
|
|
747
|
-
this.logEntry({
|
|
748
|
-
level: "info",
|
|
749
|
-
message: `${message2} ${gray(`${performance2.deltaTime}ms`)}`,
|
|
750
|
-
positionals: positionals2,
|
|
751
|
-
prefix: this.prefix,
|
|
752
|
-
colors: {
|
|
753
|
-
prefix: "blue"
|
|
754
|
-
}
|
|
763
|
+
queueMicrotask(() => {
|
|
764
|
+
executor.state = "rejected";
|
|
755
765
|
});
|
|
766
|
+
return reject(executor.rejectionReason = reason);
|
|
756
767
|
};
|
|
757
|
-
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
colors: {
|
|
770
|
-
timestamp: "green",
|
|
771
|
-
prefix: "green"
|
|
772
|
-
}
|
|
768
|
+
};
|
|
769
|
+
return executor;
|
|
770
|
+
}
|
|
771
|
+
var DeferredPromise = class extends Promise {
|
|
772
|
+
#executor;
|
|
773
|
+
resolve;
|
|
774
|
+
reject;
|
|
775
|
+
constructor(executor = null) {
|
|
776
|
+
const deferredExecutor = createDeferredExecutor();
|
|
777
|
+
super((originalResolve, originalReject) => {
|
|
778
|
+
deferredExecutor(originalResolve, originalReject);
|
|
779
|
+
executor?.(deferredExecutor.resolve, deferredExecutor.reject);
|
|
773
780
|
});
|
|
781
|
+
this.#executor = deferredExecutor;
|
|
782
|
+
this.resolve = this.#executor.resolve;
|
|
783
|
+
this.reject = this.#executor.reject;
|
|
774
784
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
785
|
+
get state() {
|
|
786
|
+
return this.#executor.state;
|
|
787
|
+
}
|
|
788
|
+
get rejectionReason() {
|
|
789
|
+
return this.#executor.rejectionReason;
|
|
790
|
+
}
|
|
791
|
+
then(onFulfilled, onRejected) {
|
|
792
|
+
return this.#decorate(super.then(onFulfilled, onRejected));
|
|
793
|
+
}
|
|
794
|
+
catch(onRejected) {
|
|
795
|
+
return this.#decorate(super.catch(onRejected));
|
|
796
|
+
}
|
|
797
|
+
finally(onfinally) {
|
|
798
|
+
return this.#decorate(super.finally(onfinally));
|
|
799
|
+
}
|
|
800
|
+
#decorate(promise) {
|
|
801
|
+
return Object.defineProperties(promise, {
|
|
802
|
+
resolve: { configurable: true, value: this.resolve },
|
|
803
|
+
reject: { configurable: true, value: this.reject }
|
|
790
804
|
});
|
|
791
805
|
}
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
809
|
+
function bindEvent(target, event) {
|
|
810
|
+
Object.defineProperties(event, {
|
|
811
|
+
target: {
|
|
812
|
+
value: target,
|
|
813
|
+
enumerable: true,
|
|
814
|
+
writable: true
|
|
815
|
+
},
|
|
816
|
+
currentTarget: {
|
|
817
|
+
value: target,
|
|
818
|
+
enumerable: true,
|
|
819
|
+
writable: true
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
return event;
|
|
823
|
+
}
|
|
824
|
+
var kCancelable = Symbol("kCancelable");
|
|
825
|
+
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
826
|
+
var CancelableMessageEvent = class extends MessageEvent {
|
|
827
|
+
constructor(type, init) {
|
|
828
|
+
super(type, init);
|
|
829
|
+
this[kCancelable] = !!init.cancelable;
|
|
830
|
+
this[kDefaultPrevented] = false;
|
|
808
831
|
}
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
* This is skipped in its entirety and has no runtime cost otherwise.
|
|
812
|
-
* This executes regardless of the log level.
|
|
813
|
-
* @example
|
|
814
|
-
* logger.only(() => {
|
|
815
|
-
* logger.info('additional info')
|
|
816
|
-
* })
|
|
817
|
-
*/
|
|
818
|
-
only(callback) {
|
|
819
|
-
callback();
|
|
832
|
+
get cancelable() {
|
|
833
|
+
return this[kCancelable];
|
|
820
834
|
}
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
timestamp: /* @__PURE__ */ new Date(),
|
|
824
|
-
level,
|
|
825
|
-
message
|
|
826
|
-
};
|
|
835
|
+
set cancelable(nextCancelable) {
|
|
836
|
+
this[kCancelable] = nextCancelable;
|
|
827
837
|
}
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
level,
|
|
831
|
-
message,
|
|
832
|
-
prefix,
|
|
833
|
-
colors: customColors,
|
|
834
|
-
positionals = []
|
|
835
|
-
} = args;
|
|
836
|
-
const entry = this.createEntry(level, message);
|
|
837
|
-
const timestampColor = customColors?.timestamp || "gray";
|
|
838
|
-
const prefixColor = customColors?.prefix || "gray";
|
|
839
|
-
const colorize = {
|
|
840
|
-
timestamp: colors_exports[timestampColor],
|
|
841
|
-
prefix: colors_exports[prefixColor]
|
|
842
|
-
};
|
|
843
|
-
const write = this.getWriter(level);
|
|
844
|
-
write(
|
|
845
|
-
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "),
|
|
846
|
-
...positionals.map(serializeInput)
|
|
847
|
-
);
|
|
838
|
+
get defaultPrevented() {
|
|
839
|
+
return this[kDefaultPrevented];
|
|
848
840
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
"en-GB"
|
|
852
|
-
)}:${timestamp.getMilliseconds()}`;
|
|
841
|
+
set defaultPrevented(nextDefaultPrevented) {
|
|
842
|
+
this[kDefaultPrevented] = nextDefaultPrevented;
|
|
853
843
|
}
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
case "debug":
|
|
857
|
-
case "success":
|
|
858
|
-
case "info": {
|
|
859
|
-
return log;
|
|
860
|
-
}
|
|
861
|
-
case "warning": {
|
|
862
|
-
return warn;
|
|
863
|
-
}
|
|
864
|
-
case "error": {
|
|
865
|
-
return error;
|
|
866
|
-
}
|
|
867
|
-
}
|
|
844
|
+
preventDefault() {
|
|
845
|
+
if (this.cancelable && !this[kDefaultPrevented]) this[kDefaultPrevented] = true;
|
|
868
846
|
}
|
|
869
847
|
};
|
|
870
|
-
var
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
this.
|
|
876
|
-
}
|
|
877
|
-
measure() {
|
|
878
|
-
this.endTime = performance.now();
|
|
879
|
-
const deltaTime = this.endTime - this.startTime;
|
|
880
|
-
this.deltaTime = deltaTime.toFixed(2);
|
|
848
|
+
var CloseEvent = class extends Event {
|
|
849
|
+
constructor(type, init = {}) {
|
|
850
|
+
super(type, init);
|
|
851
|
+
this.code = init.code === void 0 ? 0 : init.code;
|
|
852
|
+
this.reason = init.reason === void 0 ? "" : init.reason;
|
|
853
|
+
this.wasClean = init.wasClean === void 0 ? false : init.wasClean;
|
|
881
854
|
}
|
|
882
855
|
};
|
|
883
|
-
var
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
856
|
+
var CancelableCloseEvent = class extends CloseEvent {
|
|
857
|
+
constructor(type, init = {}) {
|
|
858
|
+
super(type, init);
|
|
859
|
+
this[kCancelable] = !!init.cancelable;
|
|
860
|
+
this[kDefaultPrevented] = false;
|
|
888
861
|
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
function warn(message, ...positionals) {
|
|
892
|
-
if (IS_NODE) {
|
|
893
|
-
process.stderr.write(format(message, ...positionals) + "\n");
|
|
894
|
-
return;
|
|
862
|
+
get cancelable() {
|
|
863
|
+
return this[kCancelable];
|
|
895
864
|
}
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
function error(message, ...positionals) {
|
|
899
|
-
if (IS_NODE) {
|
|
900
|
-
process.stderr.write(format(message, ...positionals) + "\n");
|
|
901
|
-
return;
|
|
865
|
+
set cancelable(nextCancelable) {
|
|
866
|
+
this[kCancelable] = nextCancelable;
|
|
902
867
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
function getVariable(variableName) {
|
|
906
|
-
if (IS_NODE) {
|
|
907
|
-
return process.env[variableName];
|
|
868
|
+
get defaultPrevented() {
|
|
869
|
+
return this[kDefaultPrevented];
|
|
908
870
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
function isDefinedAndNotEquals(value, expected) {
|
|
912
|
-
return value !== void 0 && value !== expected;
|
|
913
|
-
}
|
|
914
|
-
function serializeInput(message) {
|
|
915
|
-
if (typeof message === "undefined") {
|
|
916
|
-
return "undefined";
|
|
871
|
+
set defaultPrevented(nextDefaultPrevented) {
|
|
872
|
+
this[kDefaultPrevented] = nextDefaultPrevented;
|
|
917
873
|
}
|
|
918
|
-
|
|
919
|
-
|
|
874
|
+
preventDefault() {
|
|
875
|
+
if (this.cancelable && !this[kDefaultPrevented]) this[kDefaultPrevented] = true;
|
|
920
876
|
}
|
|
921
|
-
|
|
922
|
-
|
|
877
|
+
};
|
|
878
|
+
var kEmitter$1 = Symbol("kEmitter");
|
|
879
|
+
var kBoundListener$1 = Symbol("kBoundListener");
|
|
880
|
+
var WebSocketClientConnection = class {
|
|
881
|
+
constructor(socket, transport) {
|
|
882
|
+
this.socket = socket;
|
|
883
|
+
this.transport = transport;
|
|
884
|
+
this.id = createRequestId();
|
|
885
|
+
this.url = new URL(socket.url);
|
|
886
|
+
this[kEmitter$1] = new EventTarget();
|
|
887
|
+
this.transport.addEventListener("outgoing", (event) => {
|
|
888
|
+
const message = bindEvent(this.socket, new CancelableMessageEvent("message", {
|
|
889
|
+
data: event.data,
|
|
890
|
+
origin: event.origin,
|
|
891
|
+
cancelable: true
|
|
892
|
+
}));
|
|
893
|
+
this[kEmitter$1].dispatchEvent(message);
|
|
894
|
+
if (message.defaultPrevented) event.preventDefault();
|
|
895
|
+
});
|
|
896
|
+
this.transport.addEventListener("close", (event) => {
|
|
897
|
+
this[kEmitter$1].dispatchEvent(bindEvent(this.socket, new CloseEvent("close", event)));
|
|
898
|
+
});
|
|
923
899
|
}
|
|
924
|
-
|
|
925
|
-
|
|
900
|
+
/**
|
|
901
|
+
* Listen for the outgoing events from the connected WebSocket client.
|
|
902
|
+
*/
|
|
903
|
+
addEventListener(type, listener, options) {
|
|
904
|
+
if (!Reflect.has(listener, kBoundListener$1)) {
|
|
905
|
+
const boundListener = listener.bind(this.socket);
|
|
906
|
+
Object.defineProperty(listener, kBoundListener$1, {
|
|
907
|
+
value: boundListener,
|
|
908
|
+
enumerable: false,
|
|
909
|
+
configurable: false
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
this[kEmitter$1].addEventListener(type, Reflect.get(listener, kBoundListener$1), options);
|
|
926
913
|
}
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
this.
|
|
938
|
-
|
|
939
|
-
|
|
914
|
+
/**
|
|
915
|
+
* Removes the listener for the given event.
|
|
916
|
+
*/
|
|
917
|
+
removeEventListener(event, listener, options) {
|
|
918
|
+
this[kEmitter$1].removeEventListener(event, Reflect.get(listener, kBoundListener$1), options);
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* Send data to the connected client.
|
|
922
|
+
*/
|
|
923
|
+
send(data) {
|
|
924
|
+
this.transport.send(data);
|
|
925
|
+
}
|
|
926
|
+
/**
|
|
927
|
+
* Close the WebSocket connection.
|
|
928
|
+
* @param {number} code A status code (see https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1).
|
|
929
|
+
* @param {string} reason A custom connection close reason.
|
|
930
|
+
*/
|
|
931
|
+
close(code, reason) {
|
|
932
|
+
this.transport.close(code, reason);
|
|
940
933
|
}
|
|
941
934
|
};
|
|
942
|
-
var
|
|
943
|
-
|
|
944
|
-
|
|
935
|
+
var WEBSOCKET_CLOSE_CODE_RANGE_ERROR = "InvalidAccessError: close code out of user configurable range";
|
|
936
|
+
var kPassthroughPromise = Symbol("kPassthroughPromise");
|
|
937
|
+
var kOnSend = Symbol("kOnSend");
|
|
938
|
+
var kClose = Symbol("kClose");
|
|
939
|
+
var WebSocketOverride = class extends EventTarget {
|
|
940
|
+
static {
|
|
941
|
+
this.CONNECTING = 0;
|
|
945
942
|
}
|
|
946
|
-
|
|
947
|
-
this.
|
|
948
|
-
this.maxListeners = _Emitter.defaultMaxListeners;
|
|
949
|
-
this.hasWarnedAboutPotentialMemoryLeak = false;
|
|
943
|
+
static {
|
|
944
|
+
this.OPEN = 1;
|
|
950
945
|
}
|
|
951
|
-
|
|
952
|
-
this.
|
|
953
|
-
internalEventName,
|
|
954
|
-
...[eventName, listener]
|
|
955
|
-
);
|
|
946
|
+
static {
|
|
947
|
+
this.CLOSING = 2;
|
|
956
948
|
}
|
|
957
|
-
|
|
958
|
-
|
|
949
|
+
static {
|
|
950
|
+
this.CLOSED = 3;
|
|
959
951
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
952
|
+
constructor(url, protocols) {
|
|
953
|
+
super();
|
|
954
|
+
this.CONNECTING = 0;
|
|
955
|
+
this.OPEN = 1;
|
|
956
|
+
this.CLOSING = 2;
|
|
957
|
+
this.CLOSED = 3;
|
|
958
|
+
this._onopen = null;
|
|
959
|
+
this._onmessage = null;
|
|
960
|
+
this._onerror = null;
|
|
961
|
+
this._onclose = null;
|
|
962
|
+
this.url = resolveWebSocketUrl(url);
|
|
963
|
+
this.protocol = "";
|
|
964
|
+
this.extensions = "";
|
|
965
|
+
this.binaryType = "blob";
|
|
966
|
+
this.readyState = this.CONNECTING;
|
|
967
|
+
this.bufferedAmount = 0;
|
|
968
|
+
this[kPassthroughPromise] = new DeferredPromise();
|
|
969
|
+
queueMicrotask(async () => {
|
|
970
|
+
if (await this[kPassthroughPromise]) return;
|
|
971
|
+
this.protocol = typeof protocols === "string" ? protocols : Array.isArray(protocols) && protocols.length > 0 ? protocols[0] : "";
|
|
972
|
+
if (this.readyState === this.CONNECTING) {
|
|
973
|
+
this.readyState = this.OPEN;
|
|
974
|
+
this.dispatchEvent(bindEvent(this, new Event("open")));
|
|
975
|
+
}
|
|
976
|
+
});
|
|
966
977
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
};
|
|
972
|
-
Object.defineProperty(onceListener, "name", { value: listener.name });
|
|
973
|
-
return onceListener;
|
|
978
|
+
set onopen(listener) {
|
|
979
|
+
this.removeEventListener("open", this._onopen);
|
|
980
|
+
this._onopen = listener;
|
|
981
|
+
if (listener !== null) this.addEventListener("open", listener);
|
|
974
982
|
}
|
|
975
|
-
|
|
976
|
-
this.
|
|
977
|
-
return this;
|
|
983
|
+
get onopen() {
|
|
984
|
+
return this._onopen;
|
|
978
985
|
}
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
*/
|
|
984
|
-
getMaxListeners() {
|
|
985
|
-
return this.maxListeners;
|
|
986
|
+
set onmessage(listener) {
|
|
987
|
+
this.removeEventListener("message", this._onmessage);
|
|
988
|
+
this._onmessage = listener;
|
|
989
|
+
if (listener !== null) this.addEventListener("message", listener);
|
|
986
990
|
}
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
991
|
+
get onmessage() {
|
|
992
|
+
return this._onmessage;
|
|
993
|
+
}
|
|
994
|
+
set onerror(listener) {
|
|
995
|
+
this.removeEventListener("error", this._onerror);
|
|
996
|
+
this._onerror = listener;
|
|
997
|
+
if (listener !== null) this.addEventListener("error", listener);
|
|
998
|
+
}
|
|
999
|
+
get onerror() {
|
|
1000
|
+
return this._onerror;
|
|
1001
|
+
}
|
|
1002
|
+
set onclose(listener) {
|
|
1003
|
+
this.removeEventListener("close", this._onclose);
|
|
1004
|
+
this._onclose = listener;
|
|
1005
|
+
if (listener !== null) this.addEventListener("close", listener);
|
|
1006
|
+
}
|
|
1007
|
+
get onclose() {
|
|
1008
|
+
return this._onclose;
|
|
993
1009
|
}
|
|
994
1010
|
/**
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1011
|
+
* @see https://websockets.spec.whatwg.org/#ref-for-dom-websocket-send%E2%91%A0
|
|
1012
|
+
*/
|
|
1013
|
+
send(data) {
|
|
1014
|
+
if (this.readyState === this.CONNECTING) {
|
|
1015
|
+
this.close();
|
|
1016
|
+
throw new DOMException("InvalidStateError");
|
|
1017
|
+
}
|
|
1018
|
+
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) return;
|
|
1019
|
+
this.bufferedAmount += getDataSize(data);
|
|
1020
|
+
queueMicrotask(() => {
|
|
1021
|
+
this.bufferedAmount = 0;
|
|
1022
|
+
this[kOnSend]?.(data);
|
|
1007
1023
|
});
|
|
1008
|
-
return listeners.length > 0;
|
|
1009
1024
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
this
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1025
|
+
close(code = 1e3, reason) {
|
|
1026
|
+
invariant(code, WEBSOCKET_CLOSE_CODE_RANGE_ERROR);
|
|
1027
|
+
invariant(code === 1e3 || code >= 3e3 && code <= 4999, WEBSOCKET_CLOSE_CODE_RANGE_ERROR);
|
|
1028
|
+
this[kClose](code, reason);
|
|
1029
|
+
}
|
|
1030
|
+
[kClose](code = 1e3, reason, wasClean = true) {
|
|
1031
|
+
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) return;
|
|
1032
|
+
this.readyState = this.CLOSING;
|
|
1033
|
+
queueMicrotask(() => {
|
|
1034
|
+
this.readyState = this.CLOSED;
|
|
1035
|
+
this.dispatchEvent(bindEvent(this, new CloseEvent("close", {
|
|
1036
|
+
code,
|
|
1037
|
+
reason,
|
|
1038
|
+
wasClean
|
|
1039
|
+
})));
|
|
1040
|
+
this._onopen = null;
|
|
1041
|
+
this._onmessage = null;
|
|
1042
|
+
this._onerror = null;
|
|
1043
|
+
this._onclose = null;
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
addEventListener(type, listener, options) {
|
|
1047
|
+
return super.addEventListener(type, listener, options);
|
|
1048
|
+
}
|
|
1049
|
+
removeEventListener(type, callback, options) {
|
|
1050
|
+
return super.removeEventListener(type, callback, options);
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
function getDataSize(data) {
|
|
1054
|
+
if (typeof data === "string") return data.length;
|
|
1055
|
+
if (data instanceof Blob) return data.size;
|
|
1056
|
+
return data.byteLength;
|
|
1057
|
+
}
|
|
1058
|
+
var kEmitter = Symbol("kEmitter");
|
|
1059
|
+
var kBoundListener = Symbol("kBoundListener");
|
|
1060
|
+
var kSend = Symbol("kSend");
|
|
1061
|
+
var WebSocketServerConnection = class {
|
|
1062
|
+
constructor(client, transport, createConnection) {
|
|
1063
|
+
this.client = client;
|
|
1064
|
+
this.transport = transport;
|
|
1065
|
+
this.createConnection = createConnection;
|
|
1066
|
+
this[kEmitter] = new EventTarget();
|
|
1067
|
+
this.mockCloseController = new AbortController();
|
|
1068
|
+
this.realCloseController = new AbortController();
|
|
1069
|
+
this.transport.addEventListener("outgoing", (event) => {
|
|
1070
|
+
if (typeof this.realWebSocket === "undefined") return;
|
|
1071
|
+
queueMicrotask(() => {
|
|
1072
|
+
if (!event.defaultPrevented)
|
|
1073
|
+
this[kSend](event.data);
|
|
1074
|
+
});
|
|
1075
|
+
});
|
|
1076
|
+
this.transport.addEventListener("incoming", this.handleIncomingMessage.bind(this));
|
|
1024
1077
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1078
|
+
/**
|
|
1079
|
+
* The `WebSocket` instance connected to the original server.
|
|
1080
|
+
* Accessing this before calling `server.connect()` will throw.
|
|
1081
|
+
*/
|
|
1082
|
+
get socket() {
|
|
1083
|
+
invariant(this.realWebSocket, 'Cannot access "socket" on the original WebSocket server object: the connection is not open. Did you forget to call `server.connect()`?');
|
|
1084
|
+
return this.realWebSocket;
|
|
1027
1085
|
}
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
);
|
|
1086
|
+
/**
|
|
1087
|
+
* Open connection to the original WebSocket server.
|
|
1088
|
+
*/
|
|
1089
|
+
connect() {
|
|
1090
|
+
invariant(!this.realWebSocket || this.realWebSocket.readyState !== WebSocket.OPEN, 'Failed to call "connect()" on the original WebSocket instance: the connection already open');
|
|
1091
|
+
const realWebSocket = this.createConnection();
|
|
1092
|
+
realWebSocket.binaryType = this.client.binaryType;
|
|
1093
|
+
realWebSocket.addEventListener("open", (event) => {
|
|
1094
|
+
this[kEmitter].dispatchEvent(bindEvent(this.realWebSocket, new Event("open", event)));
|
|
1095
|
+
}, { once: true });
|
|
1096
|
+
realWebSocket.addEventListener("message", (event) => {
|
|
1097
|
+
this.transport.dispatchEvent(bindEvent(this.realWebSocket, new MessageEvent("incoming", {
|
|
1098
|
+
data: event.data,
|
|
1099
|
+
origin: event.origin
|
|
1100
|
+
})));
|
|
1101
|
+
});
|
|
1102
|
+
this.client.addEventListener("close", (event) => {
|
|
1103
|
+
this.handleMockClose(event);
|
|
1104
|
+
}, { signal: this.mockCloseController.signal });
|
|
1105
|
+
realWebSocket.addEventListener("close", (event) => {
|
|
1106
|
+
this.handleRealClose(event);
|
|
1107
|
+
}, { signal: this.realCloseController.signal });
|
|
1108
|
+
realWebSocket.addEventListener("error", () => {
|
|
1109
|
+
const errorEvent = bindEvent(realWebSocket, new Event("error", { cancelable: true }));
|
|
1110
|
+
this[kEmitter].dispatchEvent(errorEvent);
|
|
1111
|
+
if (!errorEvent.defaultPrevented) this.client.dispatchEvent(bindEvent(this.client, new Event("error")));
|
|
1112
|
+
});
|
|
1113
|
+
this.realWebSocket = realWebSocket;
|
|
1033
1114
|
}
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1115
|
+
/**
|
|
1116
|
+
* Listen for the incoming events from the original WebSocket server.
|
|
1117
|
+
*/
|
|
1118
|
+
addEventListener(event, listener, options) {
|
|
1119
|
+
if (!Reflect.has(listener, kBoundListener)) {
|
|
1120
|
+
const boundListener = listener.bind(this.client);
|
|
1121
|
+
Object.defineProperty(listener, kBoundListener, {
|
|
1122
|
+
value: boundListener,
|
|
1123
|
+
enumerable: false
|
|
1124
|
+
});
|
|
1041
1125
|
}
|
|
1042
|
-
|
|
1126
|
+
this[kEmitter].addEventListener(event, Reflect.get(listener, kBoundListener), options);
|
|
1043
1127
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
);
|
|
1128
|
+
/**
|
|
1129
|
+
* Remove the listener for the given event.
|
|
1130
|
+
*/
|
|
1131
|
+
removeEventListener(event, listener, options) {
|
|
1132
|
+
this[kEmitter].removeEventListener(event, Reflect.get(listener, kBoundListener), options);
|
|
1049
1133
|
}
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1134
|
+
/**
|
|
1135
|
+
* Send data to the original WebSocket server.
|
|
1136
|
+
* @example
|
|
1137
|
+
* server.send('hello')
|
|
1138
|
+
* server.send(new Blob(['hello']))
|
|
1139
|
+
* server.send(new TextEncoder().encode('hello'))
|
|
1140
|
+
*/
|
|
1141
|
+
send(data) {
|
|
1142
|
+
this[kSend](data);
|
|
1143
|
+
}
|
|
1144
|
+
[kSend](data) {
|
|
1145
|
+
const { realWebSocket } = this;
|
|
1146
|
+
invariant(realWebSocket, 'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "server.connect()"?', this.client.url);
|
|
1147
|
+
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) return;
|
|
1148
|
+
if (realWebSocket.readyState === WebSocket.CONNECTING) {
|
|
1149
|
+
realWebSocket.addEventListener("open", () => {
|
|
1150
|
+
realWebSocket.send(data);
|
|
1151
|
+
}, { once: true });
|
|
1152
|
+
return;
|
|
1056
1153
|
}
|
|
1057
|
-
|
|
1154
|
+
realWebSocket.send(data);
|
|
1058
1155
|
}
|
|
1059
1156
|
/**
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1157
|
+
* Close the actual server connection.
|
|
1158
|
+
*/
|
|
1159
|
+
close() {
|
|
1160
|
+
const { realWebSocket } = this;
|
|
1161
|
+
invariant(realWebSocket, 'Failed to close server connection for "%s": the connection is not open. Did you forget to call "server.connect()"?', this.client.url);
|
|
1162
|
+
this.realCloseController.abort();
|
|
1163
|
+
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) return;
|
|
1164
|
+
realWebSocket.close();
|
|
1165
|
+
queueMicrotask(() => {
|
|
1166
|
+
this[kEmitter].dispatchEvent(bindEvent(this.realWebSocket, new CancelableCloseEvent("close", {
|
|
1167
|
+
code: 1e3,
|
|
1168
|
+
cancelable: true
|
|
1169
|
+
})));
|
|
1170
|
+
});
|
|
1067
1171
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1172
|
+
handleIncomingMessage(event) {
|
|
1173
|
+
const messageEvent = bindEvent(event.target, new CancelableMessageEvent("message", {
|
|
1174
|
+
data: event.data,
|
|
1175
|
+
origin: event.origin,
|
|
1176
|
+
cancelable: true
|
|
1177
|
+
}));
|
|
1178
|
+
this[kEmitter].dispatchEvent(messageEvent);
|
|
1179
|
+
if (!messageEvent.defaultPrevented) this.client.dispatchEvent(bindEvent(
|
|
1180
|
+
/**
|
|
1181
|
+
* @note Bind the forwarded original server events
|
|
1182
|
+
* to the mock WebSocket instance so it would
|
|
1183
|
+
* dispatch them straight away.
|
|
1184
|
+
*/
|
|
1185
|
+
this.client,
|
|
1186
|
+
new MessageEvent("message", {
|
|
1187
|
+
data: event.data,
|
|
1188
|
+
origin: event.origin
|
|
1189
|
+
})
|
|
1190
|
+
));
|
|
1191
|
+
}
|
|
1192
|
+
handleMockClose(_event) {
|
|
1193
|
+
if (this.realWebSocket) this.realWebSocket.close();
|
|
1194
|
+
}
|
|
1195
|
+
handleRealClose(event) {
|
|
1196
|
+
this.mockCloseController.abort();
|
|
1197
|
+
const closeEvent = bindEvent(this.realWebSocket, new CancelableCloseEvent("close", {
|
|
1198
|
+
code: event.code,
|
|
1199
|
+
reason: event.reason,
|
|
1200
|
+
wasClean: event.wasClean,
|
|
1201
|
+
cancelable: true
|
|
1202
|
+
}));
|
|
1203
|
+
this[kEmitter].dispatchEvent(closeEvent);
|
|
1204
|
+
if (!closeEvent.defaultPrevented) this.client[kClose](event.code, event.reason);
|
|
1075
1205
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1206
|
+
};
|
|
1207
|
+
var WebSocketClassTransport = class extends EventTarget {
|
|
1208
|
+
constructor(socket) {
|
|
1209
|
+
super();
|
|
1210
|
+
this.socket = socket;
|
|
1211
|
+
this.socket.addEventListener("close", (event) => {
|
|
1212
|
+
this.dispatchEvent(bindEvent(this.socket, new CloseEvent("close", event)));
|
|
1213
|
+
});
|
|
1214
|
+
this.socket[kOnSend] = (data) => {
|
|
1215
|
+
this.dispatchEvent(bindEvent(this.socket, new CancelableMessageEvent("outgoing", {
|
|
1216
|
+
data,
|
|
1217
|
+
origin: this.socket.url,
|
|
1218
|
+
cancelable: true
|
|
1219
|
+
})));
|
|
1220
|
+
};
|
|
1081
1221
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
return
|
|
1222
|
+
addEventListener(type, callback, options) {
|
|
1223
|
+
return super.addEventListener(type, callback, options);
|
|
1224
|
+
}
|
|
1225
|
+
dispatchEvent(event) {
|
|
1226
|
+
return super.dispatchEvent(event);
|
|
1227
|
+
}
|
|
1228
|
+
send(data) {
|
|
1229
|
+
queueMicrotask(() => {
|
|
1230
|
+
if (this.socket.readyState === this.socket.CLOSING || this.socket.readyState === this.socket.CLOSED) return;
|
|
1231
|
+
const dispatchEvent = () => {
|
|
1232
|
+
this.socket.dispatchEvent(bindEvent(
|
|
1233
|
+
/**
|
|
1234
|
+
* @note Setting this event's "target" to the
|
|
1235
|
+
* WebSocket override instance is important.
|
|
1236
|
+
* This way it can tell apart original incoming events
|
|
1237
|
+
* (must be forwarded to the transport) from the
|
|
1238
|
+
* mocked message events like the one below
|
|
1239
|
+
* (must be dispatched on the client instance).
|
|
1240
|
+
*/
|
|
1241
|
+
this.socket,
|
|
1242
|
+
new MessageEvent("message", {
|
|
1243
|
+
data,
|
|
1244
|
+
origin: this.socket.url
|
|
1245
|
+
})
|
|
1246
|
+
));
|
|
1247
|
+
};
|
|
1248
|
+
if (this.socket.readyState === this.socket.CONNECTING) this.socket.addEventListener("open", () => {
|
|
1249
|
+
dispatchEvent();
|
|
1250
|
+
}, { once: true });
|
|
1251
|
+
else dispatchEvent();
|
|
1252
|
+
});
|
|
1087
1253
|
}
|
|
1088
|
-
|
|
1089
|
-
|
|
1254
|
+
close(code, reason) {
|
|
1255
|
+
this.socket[kClose](code, reason);
|
|
1256
|
+
}
|
|
1257
|
+
};
|
|
1258
|
+
var WebSocketInterceptor = class WebSocketInterceptor2 extends Interceptor {
|
|
1259
|
+
static {
|
|
1260
|
+
this.symbol = Symbol("websocket");
|
|
1261
|
+
}
|
|
1262
|
+
constructor() {
|
|
1263
|
+
super(WebSocketInterceptor2.symbol);
|
|
1264
|
+
}
|
|
1265
|
+
checkEnvironment() {
|
|
1266
|
+
return hasConfigurableGlobal("WebSocket");
|
|
1267
|
+
}
|
|
1268
|
+
setup() {
|
|
1269
|
+
const originalWebSocketDescriptor = Object.getOwnPropertyDescriptor(globalThis, "WebSocket");
|
|
1270
|
+
const WebSocketProxy = new Proxy(globalThis.WebSocket, { construct: (target, args, newTarget) => {
|
|
1271
|
+
const [url, protocols] = args;
|
|
1272
|
+
const createConnection = () => {
|
|
1273
|
+
return Reflect.construct(target, args, newTarget);
|
|
1274
|
+
};
|
|
1275
|
+
const socket = new WebSocketOverride(url, protocols);
|
|
1276
|
+
const transport = new WebSocketClassTransport(socket);
|
|
1277
|
+
queueMicrotask(async () => {
|
|
1278
|
+
try {
|
|
1279
|
+
const server = new WebSocketServerConnection(socket, transport, createConnection);
|
|
1280
|
+
const hasConnectionListeners = this.emitter.listenerCount("connection") > 0;
|
|
1281
|
+
await emitAsync(this.emitter, "connection", {
|
|
1282
|
+
client: new WebSocketClientConnection(socket, transport),
|
|
1283
|
+
server,
|
|
1284
|
+
info: { protocols }
|
|
1285
|
+
});
|
|
1286
|
+
if (hasConnectionListeners) socket[kPassthroughPromise].resolve(false);
|
|
1287
|
+
else {
|
|
1288
|
+
socket[kPassthroughPromise].resolve(true);
|
|
1289
|
+
server.connect();
|
|
1290
|
+
server.addEventListener("open", () => {
|
|
1291
|
+
socket.dispatchEvent(bindEvent(socket, new Event("open")));
|
|
1292
|
+
if (server["realWebSocket"]) socket.protocol = server["realWebSocket"].protocol;
|
|
1293
|
+
});
|
|
1294
|
+
}
|
|
1295
|
+
} catch (error2) {
|
|
1296
|
+
if (error2 instanceof Error) {
|
|
1297
|
+
socket.dispatchEvent(new Event("error"));
|
|
1298
|
+
if (socket.readyState !== WebSocket.CLOSING && socket.readyState !== WebSocket.CLOSED) socket[kClose](1011, error2.message, false);
|
|
1299
|
+
console.error(error2);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
return socket;
|
|
1304
|
+
} });
|
|
1305
|
+
Object.defineProperty(globalThis, "WebSocket", {
|
|
1306
|
+
value: WebSocketProxy,
|
|
1307
|
+
configurable: true
|
|
1308
|
+
});
|
|
1309
|
+
this.subscriptions.push(() => {
|
|
1310
|
+
Object.defineProperty(globalThis, "WebSocket", originalWebSocketDescriptor);
|
|
1311
|
+
});
|
|
1090
1312
|
}
|
|
1091
1313
|
};
|
|
1092
|
-
var Emitter = _Emitter;
|
|
1093
|
-
Emitter.defaultMaxListeners = 10;
|
|
1094
1314
|
|
|
1095
|
-
//
|
|
1096
|
-
var
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1315
|
+
// src/browser/setup-worker.ts
|
|
1316
|
+
var import_define_network = require("../core/experimental/define-network");
|
|
1317
|
+
var import_interceptor_source2 = require("../core/experimental/sources/interceptor-source");
|
|
1318
|
+
var import_compat = require("../core/experimental/compat");
|
|
1319
|
+
var import_devUtils5 = require("../core/utils/internal/devUtils");
|
|
1320
|
+
|
|
1321
|
+
// src/browser/utils/supports.ts
|
|
1322
|
+
function supportsServiceWorker() {
|
|
1323
|
+
return typeof navigator !== "undefined" && "serviceWorker" in navigator && typeof location !== "undefined" && location.protocol !== "file:";
|
|
1102
1324
|
}
|
|
1103
|
-
function
|
|
1104
|
-
|
|
1325
|
+
function supportsReadableStreamTransfer() {
|
|
1326
|
+
try {
|
|
1327
|
+
const stream = new ReadableStream({
|
|
1328
|
+
start: (controller) => controller.close()
|
|
1329
|
+
});
|
|
1330
|
+
const message = new MessageChannel();
|
|
1331
|
+
message.port1.postMessage(stream, [stream]);
|
|
1332
|
+
return true;
|
|
1333
|
+
} catch {
|
|
1334
|
+
return false;
|
|
1335
|
+
}
|
|
1105
1336
|
}
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
this.
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
this.
|
|
1122
|
-
|
|
1337
|
+
|
|
1338
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/getRawRequest-BTaNLFr0.mjs
|
|
1339
|
+
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1340
|
+
var InterceptorError = class InterceptorError2 extends Error {
|
|
1341
|
+
constructor(message) {
|
|
1342
|
+
super(message);
|
|
1343
|
+
this.name = "InterceptorError";
|
|
1344
|
+
Object.setPrototypeOf(this, InterceptorError2.prototype);
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
var RequestController = class RequestController2 {
|
|
1348
|
+
static {
|
|
1349
|
+
this.PENDING = 0;
|
|
1350
|
+
}
|
|
1351
|
+
static {
|
|
1352
|
+
this.PASSTHROUGH = 1;
|
|
1353
|
+
}
|
|
1354
|
+
static {
|
|
1355
|
+
this.RESPONSE = 2;
|
|
1356
|
+
}
|
|
1357
|
+
static {
|
|
1358
|
+
this.ERROR = 3;
|
|
1359
|
+
}
|
|
1360
|
+
constructor(request, source) {
|
|
1361
|
+
this.request = request;
|
|
1362
|
+
this.source = source;
|
|
1363
|
+
this.readyState = RequestController2.PENDING;
|
|
1364
|
+
this.handled = new DeferredPromise();
|
|
1365
|
+
}
|
|
1366
|
+
get #handled() {
|
|
1367
|
+
return this.handled;
|
|
1123
1368
|
}
|
|
1124
1369
|
/**
|
|
1125
|
-
*
|
|
1126
|
-
* in the current environment.
|
|
1370
|
+
* Perform this request as-is.
|
|
1127
1371
|
*/
|
|
1128
|
-
|
|
1129
|
-
|
|
1372
|
+
async passthrough() {
|
|
1373
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to passthrough the "%s %s" request: the request has already been handled', this.request.method, this.request.url);
|
|
1374
|
+
this.readyState = RequestController2.PASSTHROUGH;
|
|
1375
|
+
await this.source.passthrough();
|
|
1376
|
+
this.#handled.resolve();
|
|
1130
1377
|
}
|
|
1131
1378
|
/**
|
|
1132
|
-
*
|
|
1133
|
-
*
|
|
1379
|
+
* Respond to this request with the given `Response` instance.
|
|
1380
|
+
*
|
|
1381
|
+
* @example
|
|
1382
|
+
* controller.respondWith(new Response())
|
|
1383
|
+
* controller.respondWith(Response.json({ id }))
|
|
1384
|
+
* controller.respondWith(Response.error())
|
|
1134
1385
|
*/
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
return;
|
|
1141
|
-
}
|
|
1142
|
-
if (!this.checkEnvironment()) {
|
|
1143
|
-
logger.info("the interceptor cannot be applied in this environment!");
|
|
1144
|
-
return;
|
|
1145
|
-
}
|
|
1146
|
-
this.readyState = InterceptorReadyState.APPLYING;
|
|
1147
|
-
const runningInstance = this.getInstance();
|
|
1148
|
-
if (runningInstance) {
|
|
1149
|
-
logger.info("found a running instance, reusing...");
|
|
1150
|
-
this.on = (event, listener) => {
|
|
1151
|
-
logger.info('proxying the "%s" listener', event);
|
|
1152
|
-
runningInstance.emitter.addListener(event, listener);
|
|
1153
|
-
this.subscriptions.push(() => {
|
|
1154
|
-
runningInstance.emitter.removeListener(event, listener);
|
|
1155
|
-
logger.info('removed proxied "%s" listener!', event);
|
|
1156
|
-
});
|
|
1157
|
-
return this;
|
|
1158
|
-
};
|
|
1159
|
-
this.readyState = InterceptorReadyState.APPLIED;
|
|
1160
|
-
return;
|
|
1161
|
-
}
|
|
1162
|
-
logger.info("no running instance found, setting up a new instance...");
|
|
1163
|
-
this.setup();
|
|
1164
|
-
this.setInstance();
|
|
1165
|
-
this.readyState = InterceptorReadyState.APPLIED;
|
|
1386
|
+
respondWith(response) {
|
|
1387
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to respond to the "%s %s" request with "%d %s": the request has already been handled (%d)', this.request.method, this.request.url, response.status, response.statusText || "OK", this.readyState);
|
|
1388
|
+
this.readyState = RequestController2.RESPONSE;
|
|
1389
|
+
this.#handled.resolve();
|
|
1390
|
+
this.source.respondWith(response);
|
|
1166
1391
|
}
|
|
1167
1392
|
/**
|
|
1168
|
-
*
|
|
1169
|
-
*
|
|
1170
|
-
*
|
|
1393
|
+
* Error this request with the given reason.
|
|
1394
|
+
*
|
|
1395
|
+
* @example
|
|
1396
|
+
* controller.errorWith()
|
|
1397
|
+
* controller.errorWith(new Error('Oops!'))
|
|
1398
|
+
* controller.errorWith({ message: 'Oops!'})
|
|
1171
1399
|
*/
|
|
1172
|
-
|
|
1400
|
+
errorWith(reason) {
|
|
1401
|
+
invariant.as(InterceptorError, this.readyState === RequestController2.PENDING, 'Failed to error the "%s %s" request with "%s": the request has already been handled (%d)', this.request.method, this.request.url, reason?.toString(), this.readyState);
|
|
1402
|
+
this.readyState = RequestController2.ERROR;
|
|
1403
|
+
this.source.errorWith(reason);
|
|
1404
|
+
this.#handled.resolve();
|
|
1405
|
+
}
|
|
1406
|
+
};
|
|
1407
|
+
function canParseUrl(url) {
|
|
1408
|
+
try {
|
|
1409
|
+
new URL(url);
|
|
1410
|
+
return true;
|
|
1411
|
+
} catch (_error) {
|
|
1412
|
+
return false;
|
|
1173
1413
|
}
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1414
|
+
}
|
|
1415
|
+
function getValueBySymbol(symbolName, source) {
|
|
1416
|
+
const symbol = Object.getOwnPropertySymbols(source).find((symbol$1) => {
|
|
1417
|
+
return symbol$1.description === symbolName;
|
|
1418
|
+
});
|
|
1419
|
+
if (symbol) return Reflect.get(source, symbol);
|
|
1420
|
+
}
|
|
1421
|
+
var FetchResponse = class FetchResponse2 extends Response {
|
|
1422
|
+
static {
|
|
1423
|
+
this.STATUS_CODES_WITHOUT_BODY = [
|
|
1424
|
+
101,
|
|
1425
|
+
103,
|
|
1426
|
+
204,
|
|
1427
|
+
205,
|
|
1428
|
+
304
|
|
1429
|
+
];
|
|
1186
1430
|
}
|
|
1187
|
-
|
|
1188
|
-
this.
|
|
1189
|
-
|
|
1431
|
+
static {
|
|
1432
|
+
this.STATUS_CODES_WITH_REDIRECT = [
|
|
1433
|
+
301,
|
|
1434
|
+
302,
|
|
1435
|
+
303,
|
|
1436
|
+
307,
|
|
1437
|
+
308
|
|
1438
|
+
];
|
|
1190
1439
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
return this;
|
|
1440
|
+
static isConfigurableStatusCode(status) {
|
|
1441
|
+
return status >= 200 && status <= 599;
|
|
1194
1442
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
return this;
|
|
1443
|
+
static isRedirectResponse(status) {
|
|
1444
|
+
return FetchResponse2.STATUS_CODES_WITH_REDIRECT.includes(status);
|
|
1198
1445
|
}
|
|
1199
1446
|
/**
|
|
1200
|
-
*
|
|
1447
|
+
* Returns a boolean indicating whether the given response status
|
|
1448
|
+
* code represents a response that can have a body.
|
|
1201
1449
|
*/
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
if (this.readyState === InterceptorReadyState.DISPOSED) {
|
|
1205
|
-
logger.info("cannot dispose, already disposed!");
|
|
1206
|
-
return;
|
|
1207
|
-
}
|
|
1208
|
-
logger.info("disposing the interceptor...");
|
|
1209
|
-
this.readyState = InterceptorReadyState.DISPOSING;
|
|
1210
|
-
if (!this.getInstance()) {
|
|
1211
|
-
logger.info("no interceptors running, skipping dispose...");
|
|
1212
|
-
return;
|
|
1213
|
-
}
|
|
1214
|
-
this.clearInstance();
|
|
1215
|
-
logger.info("global symbol deleted:", getGlobalSymbol(this.symbol));
|
|
1216
|
-
if (this.subscriptions.length > 0) {
|
|
1217
|
-
logger.info("disposing of %d subscriptions...", this.subscriptions.length);
|
|
1218
|
-
for (const dispose of this.subscriptions) dispose();
|
|
1219
|
-
this.subscriptions = [];
|
|
1220
|
-
logger.info("disposed of all subscriptions!", this.subscriptions.length);
|
|
1221
|
-
}
|
|
1222
|
-
this.emitter.removeAllListeners();
|
|
1223
|
-
logger.info("destroyed the listener!");
|
|
1224
|
-
this.readyState = InterceptorReadyState.DISPOSED;
|
|
1450
|
+
static isResponseWithBody(status) {
|
|
1451
|
+
return !FetchResponse2.STATUS_CODES_WITHOUT_BODY.includes(status);
|
|
1225
1452
|
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1453
|
+
static setUrl(url, response) {
|
|
1454
|
+
if (!url || url === "about:" || !canParseUrl(url)) return;
|
|
1455
|
+
const state = getValueBySymbol("state", response);
|
|
1456
|
+
if (state) state.urlList.push(new URL(url));
|
|
1457
|
+
else Object.defineProperty(response, "url", {
|
|
1458
|
+
value: url,
|
|
1459
|
+
enumerable: true,
|
|
1460
|
+
configurable: true,
|
|
1461
|
+
writable: false
|
|
1462
|
+
});
|
|
1230
1463
|
}
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1464
|
+
/**
|
|
1465
|
+
* Parses the given raw HTTP headers into a Fetch API `Headers` instance.
|
|
1466
|
+
*/
|
|
1467
|
+
static parseRawHeaders(rawHeaders) {
|
|
1468
|
+
const headers = new Headers();
|
|
1469
|
+
for (let line = 0; line < rawHeaders.length; line += 2) headers.append(rawHeaders[line], rawHeaders[line + 1]);
|
|
1470
|
+
return headers;
|
|
1234
1471
|
}
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1472
|
+
constructor(body, init = {}) {
|
|
1473
|
+
const status = init.status ?? 200;
|
|
1474
|
+
const safeStatus = FetchResponse2.isConfigurableStatusCode(status) ? status : 200;
|
|
1475
|
+
const finalBody = FetchResponse2.isResponseWithBody(status) ? body : null;
|
|
1476
|
+
super(finalBody, {
|
|
1477
|
+
status: safeStatus,
|
|
1478
|
+
statusText: init.statusText,
|
|
1479
|
+
headers: init.headers
|
|
1480
|
+
});
|
|
1481
|
+
if (status !== safeStatus) {
|
|
1482
|
+
const state = getValueBySymbol("state", this);
|
|
1483
|
+
if (state) state.status = status;
|
|
1484
|
+
else Object.defineProperty(this, "status", {
|
|
1485
|
+
value: status,
|
|
1486
|
+
enumerable: true,
|
|
1487
|
+
configurable: true,
|
|
1488
|
+
writable: false
|
|
1489
|
+
});
|
|
1490
|
+
}
|
|
1491
|
+
FetchResponse2.setUrl(init.url, this);
|
|
1238
1492
|
}
|
|
1239
1493
|
};
|
|
1240
|
-
|
|
1241
|
-
|
|
1494
|
+
var kRawRequest = Symbol("kRawRequest");
|
|
1495
|
+
function setRawRequest(request, rawRequest) {
|
|
1496
|
+
Reflect.set(request, kRawRequest, rawRequest);
|
|
1242
1497
|
}
|
|
1243
1498
|
|
|
1244
1499
|
// node_modules/.pnpm/@mswjs+interceptors@0.41.2/node_modules/@mswjs/interceptors/lib/browser/bufferUtils-BiiO6HZv.mjs
|
|
@@ -1253,181 +1508,103 @@ function toArrayBuffer(array) {
|
|
|
1253
1508
|
return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
|
|
1254
1509
|
}
|
|
1255
1510
|
|
|
1256
|
-
//
|
|
1257
|
-
var
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
setup() {
|
|
1264
|
-
const logger = this.logger.extend("setup");
|
|
1265
|
-
logger.info("applying all %d interceptors...", this.interceptors.length);
|
|
1266
|
-
for (const interceptor of this.interceptors) {
|
|
1267
|
-
logger.info('applying "%s" interceptor...', interceptor.constructor.name);
|
|
1268
|
-
interceptor.apply();
|
|
1269
|
-
logger.info("adding interceptor dispose subscription");
|
|
1270
|
-
this.subscriptions.push(() => interceptor.dispose());
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
on(event, listener) {
|
|
1274
|
-
for (const interceptor of this.interceptors) interceptor.on(event, listener);
|
|
1275
|
-
return this;
|
|
1276
|
-
}
|
|
1277
|
-
once(event, listener) {
|
|
1278
|
-
for (const interceptor of this.interceptors) interceptor.once(event, listener);
|
|
1279
|
-
return this;
|
|
1280
|
-
}
|
|
1281
|
-
off(event, listener) {
|
|
1282
|
-
for (const interceptor of this.interceptors) interceptor.off(event, listener);
|
|
1283
|
-
return this;
|
|
1284
|
-
}
|
|
1285
|
-
removeAllListeners(event) {
|
|
1286
|
-
for (const interceptors of this.interceptors) interceptors.removeAllListeners(event);
|
|
1287
|
-
return this;
|
|
1288
|
-
}
|
|
1289
|
-
};
|
|
1511
|
+
// src/browser/sources/service-worker-source.ts
|
|
1512
|
+
var import_network_source = require("../core/experimental/sources/network-source");
|
|
1513
|
+
var import_RequestHandler = require("../core/handlers/RequestHandler");
|
|
1514
|
+
var import_http_frame = require("../core/experimental/frames/http-frame");
|
|
1515
|
+
var import_HttpResponse = require("../core/HttpResponse");
|
|
1516
|
+
var import_toResponseInit = require("../core/utils/toResponseInit");
|
|
1517
|
+
var import_devUtils3 = require("../core/utils/internal/devUtils");
|
|
1290
1518
|
|
|
1291
|
-
//
|
|
1292
|
-
function
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
/**
|
|
1301
|
-
* Responses may be streams here, but when we create a response object
|
|
1302
|
-
* with null-body status codes, like 204, 205, 304 Response will
|
|
1303
|
-
* throw when passed a non-null body, so ensure it's null here
|
|
1304
|
-
* for those codes
|
|
1305
|
-
*/
|
|
1306
|
-
FetchResponse.isResponseWithBody(responseMessage.response.status) ? responseMessage.response.body : null,
|
|
1307
|
-
{
|
|
1308
|
-
...responseMessage.response,
|
|
1309
|
-
/**
|
|
1310
|
-
* Set response URL if it's not set already.
|
|
1311
|
-
* @see https://github.com/mswjs/msw/issues/2030
|
|
1312
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
|
|
1313
|
-
*/
|
|
1314
|
-
url: request.url
|
|
1315
|
-
}
|
|
1316
|
-
);
|
|
1317
|
-
context.emitter.emit(
|
|
1318
|
-
responseMessage.isMockedResponse ? "response:mocked" : "response:bypass",
|
|
1319
|
-
{
|
|
1320
|
-
requestId: responseMessage.request.id,
|
|
1321
|
-
request,
|
|
1322
|
-
response
|
|
1323
|
-
}
|
|
1324
|
-
);
|
|
1325
|
-
};
|
|
1519
|
+
// node_modules/.pnpm/until-async@3.0.2/node_modules/until-async/lib/index.js
|
|
1520
|
+
async function until(callback) {
|
|
1521
|
+
try {
|
|
1522
|
+
return [null, await callback().catch((error2) => {
|
|
1523
|
+
throw error2;
|
|
1524
|
+
})];
|
|
1525
|
+
} catch (error2) {
|
|
1526
|
+
return [error2, null];
|
|
1527
|
+
}
|
|
1326
1528
|
}
|
|
1327
1529
|
|
|
1328
|
-
// src/browser/
|
|
1329
|
-
var
|
|
1330
|
-
function validateWorkerScope(registration, options) {
|
|
1331
|
-
if (!options?.quiet && !location.href.startsWith(registration.scope)) {
|
|
1332
|
-
import_devUtils5.devUtils.warn(
|
|
1333
|
-
`Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
|
|
1530
|
+
// src/browser/utils/get-worker-instance.ts
|
|
1531
|
+
var import_devUtils = require("../core/utils/internal/devUtils");
|
|
1334
1532
|
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
}
|
|
1533
|
+
// src/browser/utils/getAbsoluteWorkerUrl.ts
|
|
1534
|
+
function getAbsoluteWorkerUrl(workerUrl) {
|
|
1535
|
+
return new URL(workerUrl, location.href).href;
|
|
1339
1536
|
}
|
|
1340
1537
|
|
|
1341
|
-
// src/browser/
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
const [worker, registration] = instance;
|
|
1357
|
-
if (!worker) {
|
|
1358
|
-
const missingWorkerMessage = customOptions?.findWorker ? import_devUtils6.devUtils.formatMessage(
|
|
1359
|
-
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
1360
|
-
|
|
1361
|
-
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
1362
|
-
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
1363
|
-
`,
|
|
1364
|
-
options.serviceWorker.url
|
|
1365
|
-
) : import_devUtils6.devUtils.formatMessage(
|
|
1366
|
-
`Failed to locate the Service Worker registration.
|
|
1538
|
+
// src/browser/utils/get-worker-by-registration.ts
|
|
1539
|
+
function getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker) {
|
|
1540
|
+
const allStates = [
|
|
1541
|
+
registration.active,
|
|
1542
|
+
registration.installing,
|
|
1543
|
+
registration.waiting
|
|
1544
|
+
];
|
|
1545
|
+
const relevantStates = allStates.filter((state) => {
|
|
1546
|
+
return state != null;
|
|
1547
|
+
});
|
|
1548
|
+
const worker = relevantStates.find((worker2) => {
|
|
1549
|
+
return findWorker(worker2.scriptURL, absoluteWorkerUrl);
|
|
1550
|
+
});
|
|
1551
|
+
return worker || null;
|
|
1552
|
+
}
|
|
1367
1553
|
|
|
1368
|
-
|
|
1554
|
+
// src/browser/utils/get-worker-instance.ts
|
|
1555
|
+
var getWorkerInstance = async (url, options = {}, findWorker) => {
|
|
1556
|
+
const absoluteWorkerUrl = getAbsoluteWorkerUrl(url);
|
|
1557
|
+
const mockRegistrations = await navigator.serviceWorker.getRegistrations().then(
|
|
1558
|
+
(registrations) => registrations.filter(
|
|
1559
|
+
(registration) => getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker)
|
|
1560
|
+
)
|
|
1561
|
+
);
|
|
1562
|
+
if (!navigator.serviceWorker.controller && mockRegistrations.length > 0) {
|
|
1563
|
+
location.reload();
|
|
1564
|
+
}
|
|
1565
|
+
const [existingRegistration] = mockRegistrations;
|
|
1566
|
+
if (existingRegistration) {
|
|
1567
|
+
existingRegistration.update();
|
|
1568
|
+
return [
|
|
1569
|
+
getWorkerByRegistration(
|
|
1570
|
+
existingRegistration,
|
|
1571
|
+
absoluteWorkerUrl,
|
|
1572
|
+
findWorker
|
|
1573
|
+
),
|
|
1574
|
+
existingRegistration
|
|
1575
|
+
];
|
|
1576
|
+
}
|
|
1577
|
+
const [registrationError, registrationResult] = await until(async () => {
|
|
1578
|
+
const registration = await navigator.serviceWorker.register(url, options);
|
|
1579
|
+
return [
|
|
1580
|
+
// Compare existing worker registration by its worker URL,
|
|
1581
|
+
// to prevent irrelevant workers to resolve here (such as Codesandbox worker).
|
|
1582
|
+
getWorkerByRegistration(registration, absoluteWorkerUrl, findWorker),
|
|
1583
|
+
registration
|
|
1584
|
+
];
|
|
1585
|
+
});
|
|
1586
|
+
if (registrationError) {
|
|
1587
|
+
const isWorkerMissing = registrationError.message.includes("(404)");
|
|
1588
|
+
if (isWorkerMissing) {
|
|
1589
|
+
const scopeUrl = new URL(options?.scope || "/", location.href);
|
|
1590
|
+
throw new Error(
|
|
1591
|
+
import_devUtils.devUtils.formatMessage(`Failed to register a Service Worker for scope ('${scopeUrl.href}') with script ('${absoluteWorkerUrl}'): Service Worker script does not exist at the given path.
|
|
1369
1592
|
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
);
|
|
1374
|
-
throw new Error(missingWorkerMessage);
|
|
1375
|
-
}
|
|
1376
|
-
context.workerPromise.resolve(worker);
|
|
1377
|
-
context.registration = registration;
|
|
1378
|
-
window.addEventListener("beforeunload", () => {
|
|
1379
|
-
if (worker.state !== "redundant") {
|
|
1380
|
-
context.workerChannel.postMessage("CLIENT_CLOSED");
|
|
1381
|
-
}
|
|
1382
|
-
window.clearInterval(context.keepAliveInterval);
|
|
1383
|
-
window.postMessage({ type: "msw/worker:stop" });
|
|
1384
|
-
});
|
|
1385
|
-
await checkWorkerIntegrity(context).catch((error2) => {
|
|
1386
|
-
import_devUtils6.devUtils.error(
|
|
1387
|
-
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
1388
|
-
);
|
|
1389
|
-
console.error(error2);
|
|
1390
|
-
});
|
|
1391
|
-
context.keepAliveInterval = window.setInterval(
|
|
1392
|
-
() => context.workerChannel.postMessage("KEEPALIVE_REQUEST"),
|
|
1393
|
-
5e3
|
|
1593
|
+
Did you forget to run "npx msw init <PUBLIC_DIR>"?
|
|
1594
|
+
|
|
1595
|
+
Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/init`)
|
|
1394
1596
|
);
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
if (pendingInstance) {
|
|
1402
|
-
const activationPromise = new DeferredPromise();
|
|
1403
|
-
pendingInstance.addEventListener("statechange", () => {
|
|
1404
|
-
if (pendingInstance.state === "activated") {
|
|
1405
|
-
activationPromise.resolve();
|
|
1406
|
-
}
|
|
1407
|
-
});
|
|
1408
|
-
await activationPromise;
|
|
1409
|
-
}
|
|
1410
|
-
await enableMocking(context, options).catch((error2) => {
|
|
1411
|
-
import_devUtils6.devUtils.error(
|
|
1412
|
-
"Failed to enable mocking. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
1413
|
-
);
|
|
1414
|
-
throw error2;
|
|
1415
|
-
});
|
|
1416
|
-
return registration;
|
|
1417
|
-
}
|
|
1597
|
+
}
|
|
1598
|
+
throw new Error(
|
|
1599
|
+
import_devUtils.devUtils.formatMessage(
|
|
1600
|
+
"Failed to register the Service Worker:\n\n%s",
|
|
1601
|
+
registrationError.message
|
|
1602
|
+
)
|
|
1418
1603
|
);
|
|
1419
|
-
|
|
1420
|
-
|
|
1604
|
+
}
|
|
1605
|
+
return registrationResult;
|
|
1421
1606
|
};
|
|
1422
1607
|
|
|
1423
|
-
// src/browser/setupWorker/setupWorker.ts
|
|
1424
|
-
var import_devUtils8 = require("../core/utils/internal/devUtils");
|
|
1425
|
-
var import_SetupApi = require("../core/SetupApi");
|
|
1426
|
-
var import_mergeRight2 = require("../core/utils/internal/mergeRight");
|
|
1427
|
-
var import_webSocketInterceptor = require("../core/ws/webSocketInterceptor");
|
|
1428
|
-
var import_handleWebSocketEvent = require("../core/ws/handleWebSocketEvent");
|
|
1429
|
-
var import_attachWebSocketLogger = require("../core/ws/utils/attachWebSocketLogger");
|
|
1430
|
-
|
|
1431
1608
|
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/lens-list.mjs
|
|
1432
1609
|
var LensList = class {
|
|
1433
1610
|
#list;
|
|
@@ -1498,7 +1675,7 @@ var LensList = class {
|
|
|
1498
1675
|
};
|
|
1499
1676
|
|
|
1500
1677
|
// node_modules/.pnpm/rettime@0.10.1/node_modules/rettime/build/index.mjs
|
|
1501
|
-
var
|
|
1678
|
+
var kDefaultPrevented2 = Symbol("kDefaultPrevented");
|
|
1502
1679
|
var kPropagationStopped = Symbol("kPropagationStopped");
|
|
1503
1680
|
var kImmediatePropagationStopped = Symbol("kImmediatePropagationStopped");
|
|
1504
1681
|
var TypedEvent = class extends MessageEvent {
|
|
@@ -1508,19 +1685,19 @@ var TypedEvent = class extends MessageEvent {
|
|
|
1508
1685
|
* correctly associated and inferred from the event.
|
|
1509
1686
|
*/
|
|
1510
1687
|
#returnType;
|
|
1511
|
-
[
|
|
1688
|
+
[kDefaultPrevented2];
|
|
1512
1689
|
[kPropagationStopped];
|
|
1513
1690
|
[kImmediatePropagationStopped];
|
|
1514
1691
|
constructor(...args) {
|
|
1515
1692
|
super(args[0], args[1]);
|
|
1516
|
-
this[
|
|
1693
|
+
this[kDefaultPrevented2] = false;
|
|
1517
1694
|
}
|
|
1518
1695
|
get defaultPrevented() {
|
|
1519
|
-
return this[
|
|
1696
|
+
return this[kDefaultPrevented2];
|
|
1520
1697
|
}
|
|
1521
1698
|
preventDefault() {
|
|
1522
1699
|
super.preventDefault();
|
|
1523
|
-
this[
|
|
1700
|
+
this[kDefaultPrevented2] = true;
|
|
1524
1701
|
}
|
|
1525
1702
|
stopImmediatePropagation() {
|
|
1526
1703
|
super.stopImmediatePropagation();
|
|
@@ -1769,24 +1946,331 @@ var WorkerChannel = class extends Emitter2 {
|
|
|
1769
1946
|
}
|
|
1770
1947
|
};
|
|
1771
1948
|
|
|
1772
|
-
//
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1949
|
+
// src/browser/utils/pruneGetRequestBody.ts
|
|
1950
|
+
function pruneGetRequestBody(request) {
|
|
1951
|
+
if (["HEAD", "GET"].includes(request.method)) {
|
|
1952
|
+
return void 0;
|
|
1953
|
+
}
|
|
1954
|
+
return request.body;
|
|
1777
1955
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1956
|
+
|
|
1957
|
+
// src/browser/utils/deserializeRequest.ts
|
|
1958
|
+
function deserializeRequest(serializedRequest) {
|
|
1959
|
+
return new Request(serializedRequest.url, {
|
|
1960
|
+
...serializedRequest,
|
|
1961
|
+
body: pruneGetRequestBody(serializedRequest)
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
// src/browser/utils/validate-worker-scope.ts
|
|
1966
|
+
var import_devUtils2 = require("../core/utils/internal/devUtils");
|
|
1967
|
+
function validateWorkerScope(registration) {
|
|
1968
|
+
if (!location.href.startsWith(registration.scope)) {
|
|
1969
|
+
import_devUtils2.devUtils.warn(
|
|
1970
|
+
`Cannot intercept requests on this page because it's outside of the worker's scope ("${registration.scope}"). If you wish to mock API requests on this page, you must resolve this scope issue.
|
|
1971
|
+
|
|
1972
|
+
- (Recommended) Register the worker at the root level ("/") of your application.
|
|
1973
|
+
- Set the "Service-Worker-Allowed" response header to allow out-of-scope workers.`
|
|
1974
|
+
);
|
|
1786
1975
|
}
|
|
1787
|
-
return true;
|
|
1788
1976
|
}
|
|
1789
1977
|
|
|
1978
|
+
// src/browser/sources/service-worker-source.ts
|
|
1979
|
+
var ServiceWorkerSource = class extends import_network_source.NetworkSource {
|
|
1980
|
+
constructor(options) {
|
|
1981
|
+
super();
|
|
1982
|
+
this.options = options;
|
|
1983
|
+
invariant(
|
|
1984
|
+
supportsServiceWorker(),
|
|
1985
|
+
"Failed to use Service Worker as the network source: the Service Worker API is not supported in this environment"
|
|
1986
|
+
);
|
|
1987
|
+
this.#frames = /* @__PURE__ */ new Map();
|
|
1988
|
+
this.workerPromise = new DeferredPromise();
|
|
1989
|
+
this.#channel = new WorkerChannel({
|
|
1990
|
+
worker: this.workerPromise.then(([worker]) => worker)
|
|
1991
|
+
});
|
|
1992
|
+
}
|
|
1993
|
+
#frames;
|
|
1994
|
+
#channel;
|
|
1995
|
+
#clientPromise;
|
|
1996
|
+
#keepAliveInterval;
|
|
1997
|
+
#stoppedAt;
|
|
1998
|
+
workerPromise;
|
|
1999
|
+
async enable() {
|
|
2000
|
+
this.#stoppedAt = void 0;
|
|
2001
|
+
if (this.workerPromise.state !== "pending") {
|
|
2002
|
+
import_devUtils3.devUtils.warn(
|
|
2003
|
+
'Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.'
|
|
2004
|
+
);
|
|
2005
|
+
return this.workerPromise.then(([, registration2]) => registration2);
|
|
2006
|
+
}
|
|
2007
|
+
this.#channel.removeAllListeners();
|
|
2008
|
+
const [worker, registration] = await this.#startWorker();
|
|
2009
|
+
if (worker.state !== "activated") {
|
|
2010
|
+
const controller = new AbortController();
|
|
2011
|
+
const activationPromise = new DeferredPromise();
|
|
2012
|
+
activationPromise.then(() => controller.abort());
|
|
2013
|
+
worker.addEventListener(
|
|
2014
|
+
"statechange",
|
|
2015
|
+
() => {
|
|
2016
|
+
if (worker.state === "activated") {
|
|
2017
|
+
activationPromise.resolve();
|
|
2018
|
+
}
|
|
2019
|
+
},
|
|
2020
|
+
{ signal: controller.signal }
|
|
2021
|
+
);
|
|
2022
|
+
await activationPromise;
|
|
2023
|
+
}
|
|
2024
|
+
this.#channel.postMessage("MOCK_ACTIVATE");
|
|
2025
|
+
const clientConfirmationPromise = new DeferredPromise();
|
|
2026
|
+
this.#clientPromise = clientConfirmationPromise;
|
|
2027
|
+
this.#channel.once("MOCKING_ENABLED", (event) => {
|
|
2028
|
+
clientConfirmationPromise.resolve(event.data.client);
|
|
2029
|
+
});
|
|
2030
|
+
await clientConfirmationPromise;
|
|
2031
|
+
if (!this.options.quiet) {
|
|
2032
|
+
this.#printStartMessage();
|
|
2033
|
+
}
|
|
2034
|
+
return registration;
|
|
2035
|
+
}
|
|
2036
|
+
disable() {
|
|
2037
|
+
if (typeof this.#stoppedAt !== "undefined") {
|
|
2038
|
+
import_devUtils3.devUtils.warn(
|
|
2039
|
+
`Found a redundant "worker.stop()" call. Notice that stopping the worker after it has already been stopped has no effect. Consider removing this "worker.stop()" call.`
|
|
2040
|
+
);
|
|
2041
|
+
return;
|
|
2042
|
+
}
|
|
2043
|
+
this.#stoppedAt = Date.now();
|
|
2044
|
+
this.#frames.clear();
|
|
2045
|
+
this.workerPromise = new DeferredPromise();
|
|
2046
|
+
if (!this.options.quiet) {
|
|
2047
|
+
this.#printStopMessage();
|
|
2048
|
+
}
|
|
2049
|
+
}
|
|
2050
|
+
async #startWorker() {
|
|
2051
|
+
if (this.#keepAliveInterval) {
|
|
2052
|
+
clearInterval(this.#keepAliveInterval);
|
|
2053
|
+
}
|
|
2054
|
+
const workerUrl = this.options.serviceWorker.url;
|
|
2055
|
+
const [worker, registration] = await getWorkerInstance(
|
|
2056
|
+
workerUrl,
|
|
2057
|
+
this.options.serviceWorker.options,
|
|
2058
|
+
this.options.findWorker || this.#defaultFindWorker
|
|
2059
|
+
);
|
|
2060
|
+
if (worker == null) {
|
|
2061
|
+
const missingWorkerMessage = this.options?.findWorker ? import_devUtils3.devUtils.formatMessage(
|
|
2062
|
+
`Failed to locate the Service Worker registration using a custom "findWorker" predicate.
|
|
2063
|
+
|
|
2064
|
+
Please ensure that the custom predicate properly locates the Service Worker registration at "%s".
|
|
2065
|
+
More details: https://mswjs.io/docs/api/setup-worker/start#findworker
|
|
2066
|
+
`,
|
|
2067
|
+
workerUrl
|
|
2068
|
+
) : import_devUtils3.devUtils.formatMessage(
|
|
2069
|
+
`Failed to locate the Service Worker registration.
|
|
2070
|
+
|
|
2071
|
+
This most likely means that the worker script URL "%s" cannot resolve against the actual public hostname (%s). This may happen if your application runs behind a proxy, or has a dynamic hostname.
|
|
2072
|
+
|
|
2073
|
+
Please consider using a custom "serviceWorker.url" option to point to the actual worker script location, or a custom "findWorker" option to resolve the Service Worker registration manually. More details: https://mswjs.io/docs/api/setup-worker/start`,
|
|
2074
|
+
workerUrl,
|
|
2075
|
+
location.host
|
|
2076
|
+
);
|
|
2077
|
+
throw new Error(missingWorkerMessage);
|
|
2078
|
+
}
|
|
2079
|
+
this.workerPromise.resolve([worker, registration]);
|
|
2080
|
+
this.#channel.on("REQUEST", this.#handleRequest.bind(this));
|
|
2081
|
+
this.#channel.on("RESPONSE", this.#handleResponse.bind(this));
|
|
2082
|
+
window.addEventListener("beforeunload", () => {
|
|
2083
|
+
if (worker.state !== "redundant") {
|
|
2084
|
+
this.#channel.postMessage("CLIENT_CLOSED");
|
|
2085
|
+
}
|
|
2086
|
+
clearInterval(this.#keepAliveInterval);
|
|
2087
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
2088
|
+
});
|
|
2089
|
+
await this.#checkWorkerIntegrity().catch((error2) => {
|
|
2090
|
+
import_devUtils3.devUtils.error(
|
|
2091
|
+
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues) and include the original error below."
|
|
2092
|
+
);
|
|
2093
|
+
console.error(error2);
|
|
2094
|
+
});
|
|
2095
|
+
this.#keepAliveInterval = window.setInterval(() => {
|
|
2096
|
+
this.#channel.postMessage("KEEPALIVE_REQUEST");
|
|
2097
|
+
}, 5e3);
|
|
2098
|
+
if (!this.options.quiet) {
|
|
2099
|
+
validateWorkerScope(registration);
|
|
2100
|
+
}
|
|
2101
|
+
return [worker, registration];
|
|
2102
|
+
}
|
|
2103
|
+
async #handleRequest(event) {
|
|
2104
|
+
if (this.#stoppedAt && event.data.interceptedAt > this.#stoppedAt) {
|
|
2105
|
+
return event.postMessage("PASSTHROUGH");
|
|
2106
|
+
}
|
|
2107
|
+
const request = deserializeRequest(event.data);
|
|
2108
|
+
import_RequestHandler.RequestHandler.cache.set(request, request.clone());
|
|
2109
|
+
const frame = new ServiceWorkerHttpNetworkFrame({
|
|
2110
|
+
event,
|
|
2111
|
+
request
|
|
2112
|
+
});
|
|
2113
|
+
this.#frames.set(event.data.id, frame);
|
|
2114
|
+
await this.queue(frame);
|
|
2115
|
+
}
|
|
2116
|
+
async #handleResponse(event) {
|
|
2117
|
+
const { request, response, isMockedResponse } = event.data;
|
|
2118
|
+
if (response.type?.includes("opaque")) {
|
|
2119
|
+
this.#frames.delete(request.id);
|
|
2120
|
+
return;
|
|
2121
|
+
}
|
|
2122
|
+
const frame = this.#frames.get(request.id);
|
|
2123
|
+
this.#frames.delete(request.id);
|
|
2124
|
+
if (frame == null) {
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
const fetchRequest = deserializeRequest(request);
|
|
2128
|
+
const fetchResponse = response.status === 0 ? Response.error() : new FetchResponse(
|
|
2129
|
+
/**
|
|
2130
|
+
* Responses may be streams here, but when we create a response object
|
|
2131
|
+
* with null-body status codes, like 204, 205, 304 Response will
|
|
2132
|
+
* throw when passed a non-null body, so ensure it's null here
|
|
2133
|
+
* for those codes
|
|
2134
|
+
*/
|
|
2135
|
+
FetchResponse.isResponseWithBody(response.status) ? response.body : null,
|
|
2136
|
+
{
|
|
2137
|
+
...response,
|
|
2138
|
+
/**
|
|
2139
|
+
* Set response URL if it's not set already.
|
|
2140
|
+
* @see https://github.com/mswjs/msw/issues/2030
|
|
2141
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Response/url
|
|
2142
|
+
*/
|
|
2143
|
+
url: request.url
|
|
2144
|
+
}
|
|
2145
|
+
);
|
|
2146
|
+
frame.events.emit(
|
|
2147
|
+
new import_http_frame.ResponseEvent(
|
|
2148
|
+
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
2149
|
+
{
|
|
2150
|
+
requestId: frame.data.id,
|
|
2151
|
+
request: fetchRequest,
|
|
2152
|
+
response: fetchResponse,
|
|
2153
|
+
isMockedResponse
|
|
2154
|
+
}
|
|
2155
|
+
)
|
|
2156
|
+
);
|
|
2157
|
+
}
|
|
2158
|
+
#defaultFindWorker = (workerUrl, mockServiceWorkerUrl) => {
|
|
2159
|
+
return workerUrl === mockServiceWorkerUrl;
|
|
2160
|
+
};
|
|
2161
|
+
async #checkWorkerIntegrity() {
|
|
2162
|
+
const integrityCheckPromise = new DeferredPromise();
|
|
2163
|
+
this.#channel.postMessage("INTEGRITY_CHECK_REQUEST");
|
|
2164
|
+
this.#channel.once("INTEGRITY_CHECK_RESPONSE", (event) => {
|
|
2165
|
+
const { checksum, packageVersion } = event.data;
|
|
2166
|
+
if (checksum !== "4db4a41e972cec1b64cc569c66952d82") {
|
|
2167
|
+
import_devUtils3.devUtils.warn(
|
|
2168
|
+
`The currently registered Service Worker has been generated by a different version of MSW (${packageVersion}) and may not be fully compatible with the installed version.
|
|
2169
|
+
|
|
2170
|
+
It's recommended you update your worker script by running this command:
|
|
2171
|
+
|
|
2172
|
+
\u2022 npx msw init <PUBLIC_DIR>
|
|
2173
|
+
|
|
2174
|
+
You can also automate this process and make the worker script update automatically upon the library installations. Read more: https://mswjs.io/docs/cli/init.`
|
|
2175
|
+
);
|
|
2176
|
+
}
|
|
2177
|
+
integrityCheckPromise.resolve();
|
|
2178
|
+
});
|
|
2179
|
+
return integrityCheckPromise;
|
|
2180
|
+
}
|
|
2181
|
+
async #printStartMessage() {
|
|
2182
|
+
if (this.workerPromise.state === "rejected") {
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
invariant(
|
|
2186
|
+
this.#clientPromise != null,
|
|
2187
|
+
"[ServiceWorkerSource] Failed to print a start message: client confirmation not received"
|
|
2188
|
+
);
|
|
2189
|
+
const client = await this.#clientPromise;
|
|
2190
|
+
const [worker, registration] = await this.workerPromise;
|
|
2191
|
+
console.groupCollapsed(
|
|
2192
|
+
`%c${import_devUtils3.devUtils.formatMessage("Mocking enabled.")}`,
|
|
2193
|
+
"color:orangered;font-weight:bold;"
|
|
2194
|
+
);
|
|
2195
|
+
console.log(
|
|
2196
|
+
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
2197
|
+
"font-weight:bold",
|
|
2198
|
+
"font-weight:normal"
|
|
2199
|
+
);
|
|
2200
|
+
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
2201
|
+
console.log("Worker script URL:", worker.scriptURL);
|
|
2202
|
+
console.log("Worker scope:", registration.scope);
|
|
2203
|
+
if (client) {
|
|
2204
|
+
console.log("Client ID: %s (%s)", client.id, client.frameType);
|
|
2205
|
+
}
|
|
2206
|
+
console.groupEnd();
|
|
2207
|
+
}
|
|
2208
|
+
#printStopMessage() {
|
|
2209
|
+
console.log(
|
|
2210
|
+
`%c${import_devUtils3.devUtils.formatMessage("Mocking disabled.")}`,
|
|
2211
|
+
"color:orangered;font-weight:bold;"
|
|
2212
|
+
);
|
|
2213
|
+
}
|
|
2214
|
+
};
|
|
2215
|
+
var ServiceWorkerHttpNetworkFrame = class extends import_http_frame.HttpNetworkFrame {
|
|
2216
|
+
#event;
|
|
2217
|
+
constructor(options) {
|
|
2218
|
+
super({ request: options.request });
|
|
2219
|
+
this.#event = options.event;
|
|
2220
|
+
}
|
|
2221
|
+
passthrough() {
|
|
2222
|
+
this.#event.postMessage("PASSTHROUGH");
|
|
2223
|
+
}
|
|
2224
|
+
respondWith(response) {
|
|
2225
|
+
if (response) {
|
|
2226
|
+
this.#respondWith(response);
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
errorWith(reason) {
|
|
2230
|
+
if (reason instanceof Response) {
|
|
2231
|
+
return this.respondWith(reason);
|
|
2232
|
+
}
|
|
2233
|
+
import_devUtils3.devUtils.warn(
|
|
2234
|
+
`Uncaught exception in the request handler for "%s %s". This exception has been gracefully handled as a 500 response, however, it's strongly recommended to resolve this error, as it indicates a mistake in your code. If you wish to mock an error response, please see this guide: https://mswjs.io/docs/http/mocking-responses/error-responses`,
|
|
2235
|
+
this.data.request.method,
|
|
2236
|
+
this.data.request.url
|
|
2237
|
+
);
|
|
2238
|
+
const error2 = reason instanceof Error ? reason : new Error(reason?.toString() || "Request failure");
|
|
2239
|
+
this.respondWith(
|
|
2240
|
+
import_HttpResponse.HttpResponse.json(
|
|
2241
|
+
{
|
|
2242
|
+
name: error2.name,
|
|
2243
|
+
message: error2.message,
|
|
2244
|
+
stack: error2.stack
|
|
2245
|
+
},
|
|
2246
|
+
{
|
|
2247
|
+
status: 500,
|
|
2248
|
+
statusText: "Request Handler Error"
|
|
2249
|
+
}
|
|
2250
|
+
)
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
async #respondWith(response) {
|
|
2254
|
+
let responseBody;
|
|
2255
|
+
let transfer;
|
|
2256
|
+
const responseInit = (0, import_toResponseInit.toResponseInit)(response);
|
|
2257
|
+
if (supportsReadableStreamTransfer()) {
|
|
2258
|
+
responseBody = response.body;
|
|
2259
|
+
transfer = response.body == null ? void 0 : [response.body];
|
|
2260
|
+
} else {
|
|
2261
|
+
responseBody = response.body == null ? null : await response.clone().arrayBuffer();
|
|
2262
|
+
}
|
|
2263
|
+
this.#event.postMessage(
|
|
2264
|
+
"MOCK_RESPONSE",
|
|
2265
|
+
{
|
|
2266
|
+
...responseInit,
|
|
2267
|
+
body: responseBody
|
|
2268
|
+
},
|
|
2269
|
+
transfer
|
|
2270
|
+
);
|
|
2271
|
+
}
|
|
2272
|
+
};
|
|
2273
|
+
|
|
1790
2274
|
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
1791
2275
|
var until2 = async (promise) => {
|
|
1792
2276
|
try {
|
|
@@ -1833,7 +2317,7 @@ function isNodeLikeError(error2) {
|
|
|
1833
2317
|
if (!(error2 instanceof Error)) return false;
|
|
1834
2318
|
return "code" in error2 && "errno" in error2;
|
|
1835
2319
|
}
|
|
1836
|
-
async function
|
|
2320
|
+
async function handleRequest(options) {
|
|
1837
2321
|
const handleResponse = async (response) => {
|
|
1838
2322
|
if (response instanceof Error) {
|
|
1839
2323
|
await options.controller.errorWith(response);
|
|
@@ -2088,7 +2572,7 @@ var FetchInterceptor = class FetchInterceptor2 extends Interceptor {
|
|
|
2088
2572
|
this.logger.info("[%s] %s", request.method, request.url);
|
|
2089
2573
|
this.logger.info("awaiting for the mocked response...");
|
|
2090
2574
|
this.logger.info('emitting the "request" event for %s listener(s)...', this.emitter.listenerCount("request"));
|
|
2091
|
-
await
|
|
2575
|
+
await handleRequest({
|
|
2092
2576
|
request,
|
|
2093
2577
|
requestId,
|
|
2094
2578
|
emitter: this.emitter,
|
|
@@ -2679,7 +3163,7 @@ function createXMLHttpRequestProxy({ emitter, logger }) {
|
|
|
2679
3163
|
});
|
|
2680
3164
|
this.logger.info("awaiting mocked response...");
|
|
2681
3165
|
this.logger.info('emitting the "request" event for %s listener(s)...', emitter.listenerCount("request"));
|
|
2682
|
-
await
|
|
3166
|
+
await handleRequest({
|
|
2683
3167
|
request,
|
|
2684
3168
|
requestId,
|
|
2685
3169
|
controller,
|
|
@@ -2731,181 +3215,139 @@ var XMLHttpRequestInterceptor = class XMLHttpRequestInterceptor2 extends Interce
|
|
|
2731
3215
|
}
|
|
2732
3216
|
};
|
|
2733
3217
|
|
|
2734
|
-
// src/browser/
|
|
2735
|
-
var
|
|
2736
|
-
var
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
options,
|
|
2749
|
-
context.emitter,
|
|
2750
|
-
{
|
|
2751
|
-
resolutionContext: {
|
|
2752
|
-
quiet: options.quiet
|
|
2753
|
-
},
|
|
2754
|
-
onMockedResponse(_, { handler, parsedResult }) {
|
|
2755
|
-
if (!options.quiet) {
|
|
2756
|
-
context.emitter.once("response:mocked", ({ response: response2 }) => {
|
|
2757
|
-
handler.log({
|
|
2758
|
-
request: requestCloneForLogs,
|
|
2759
|
-
response: response2,
|
|
2760
|
-
parsedResult
|
|
2761
|
-
});
|
|
2762
|
-
});
|
|
2763
|
-
}
|
|
2764
|
-
}
|
|
2765
|
-
}
|
|
2766
|
-
);
|
|
2767
|
-
if (response) {
|
|
2768
|
-
controller.respondWith(response);
|
|
3218
|
+
// src/browser/sources/fallback-http-source.ts
|
|
3219
|
+
var import_interceptor_source = require("../core/experimental/sources/interceptor-source");
|
|
3220
|
+
var import_devUtils4 = require("../core/utils/internal/devUtils");
|
|
3221
|
+
var FallbackHttpSource = class extends import_interceptor_source.InterceptorSource {
|
|
3222
|
+
constructor(options) {
|
|
3223
|
+
super({
|
|
3224
|
+
interceptors: [new XMLHttpRequestInterceptor(), new FetchInterceptor()]
|
|
3225
|
+
});
|
|
3226
|
+
this.options = options;
|
|
3227
|
+
}
|
|
3228
|
+
enable() {
|
|
3229
|
+
super.enable();
|
|
3230
|
+
if (!this.options.quiet) {
|
|
3231
|
+
this.#printStartMessage();
|
|
2769
3232
|
}
|
|
2770
|
-
}
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
(
|
|
2774
|
-
|
|
2775
|
-
isMockedResponse ? "response:mocked" : "response:bypass",
|
|
2776
|
-
{
|
|
2777
|
-
response,
|
|
2778
|
-
request,
|
|
2779
|
-
requestId
|
|
2780
|
-
}
|
|
2781
|
-
);
|
|
3233
|
+
}
|
|
3234
|
+
disable() {
|
|
3235
|
+
super.disable();
|
|
3236
|
+
if (!this.options.quiet) {
|
|
3237
|
+
this.#printStopMessage();
|
|
2782
3238
|
}
|
|
2783
|
-
);
|
|
2784
|
-
interceptor.apply();
|
|
2785
|
-
return interceptor;
|
|
2786
|
-
}
|
|
2787
|
-
|
|
2788
|
-
// src/browser/setupWorker/stop/utils/printStopMessage.ts
|
|
2789
|
-
var import_devUtils7 = require("../core/utils/internal/devUtils");
|
|
2790
|
-
function printStopMessage(args = {}) {
|
|
2791
|
-
if (args.quiet) {
|
|
2792
|
-
return;
|
|
2793
3239
|
}
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
}
|
|
2799
|
-
|
|
2800
|
-
// src/browser/setupWorker/setupWorker.ts
|
|
2801
|
-
var SetupWorkerApi = class extends import_SetupApi.SetupApi {
|
|
2802
|
-
context;
|
|
2803
|
-
constructor(...handlers) {
|
|
2804
|
-
super(...handlers);
|
|
2805
|
-
invariant(
|
|
2806
|
-
!isNodeProcess(),
|
|
2807
|
-
import_devUtils8.devUtils.formatMessage(
|
|
2808
|
-
"Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead."
|
|
2809
|
-
)
|
|
3240
|
+
#printStartMessage() {
|
|
3241
|
+
console.groupCollapsed(
|
|
3242
|
+
`%c${import_devUtils4.devUtils.formatMessage("Mocking enabled (fallback mode).")}`,
|
|
3243
|
+
"color:orangered;font-weight:bold;"
|
|
2810
3244
|
);
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
isMockingEnabled: false,
|
|
2819
|
-
startOptions: null,
|
|
2820
|
-
workerPromise,
|
|
2821
|
-
registration: void 0,
|
|
2822
|
-
getRequestHandlers: () => {
|
|
2823
|
-
return this.handlersController.currentHandlers();
|
|
2824
|
-
},
|
|
2825
|
-
emitter: this.emitter,
|
|
2826
|
-
workerChannel: new WorkerChannel({
|
|
2827
|
-
worker: workerPromise
|
|
2828
|
-
})
|
|
2829
|
-
};
|
|
3245
|
+
console.log(
|
|
3246
|
+
"%cDocumentation: %chttps://mswjs.io/docs",
|
|
3247
|
+
"font-weight:bold",
|
|
3248
|
+
"font-weight:normal"
|
|
3249
|
+
);
|
|
3250
|
+
console.log("Found an issue? https://github.com/mswjs/msw/issues");
|
|
3251
|
+
console.groupEnd();
|
|
2830
3252
|
}
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
);
|
|
2836
|
-
}
|
|
2837
|
-
if (this.context.isMockingEnabled) {
|
|
2838
|
-
import_devUtils8.devUtils.warn(
|
|
2839
|
-
`Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.`
|
|
2840
|
-
);
|
|
2841
|
-
return this.context.registration;
|
|
2842
|
-
}
|
|
2843
|
-
this.context.workerStoppedAt = void 0;
|
|
2844
|
-
this.context.startOptions = (0, import_mergeRight2.mergeRight)(
|
|
2845
|
-
DEFAULT_START_OPTIONS,
|
|
2846
|
-
options
|
|
3253
|
+
#printStopMessage() {
|
|
3254
|
+
console.log(
|
|
3255
|
+
`%c${import_devUtils4.devUtils.formatMessage("Mocking disabled.")}`,
|
|
3256
|
+
"color:orangered;font-weight:bold;"
|
|
2847
3257
|
);
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
3258
|
+
}
|
|
3259
|
+
};
|
|
3260
|
+
|
|
3261
|
+
// src/browser/setup-worker.ts
|
|
3262
|
+
var DEFAULT_WORKER_URL = "/mockServiceWorker.js";
|
|
3263
|
+
function setupWorker(...handlers) {
|
|
3264
|
+
invariant(
|
|
3265
|
+
!isNodeProcess(),
|
|
3266
|
+
import_devUtils5.devUtils.formatMessage(
|
|
3267
|
+
"Failed to execute `setupWorker` in a non-browser environment"
|
|
3268
|
+
)
|
|
3269
|
+
);
|
|
3270
|
+
const network = (0, import_define_network.defineNetwork)({
|
|
3271
|
+
sources: [],
|
|
3272
|
+
handlers
|
|
3273
|
+
});
|
|
3274
|
+
return {
|
|
3275
|
+
async start(options) {
|
|
3276
|
+
if (options?.waitUntilReady != null) {
|
|
3277
|
+
import_devUtils5.devUtils.warn(
|
|
3278
|
+
`The "waitUntilReady" option has been deprecated. Please remove it from this "worker.start()" call. Follow the recommended Browser integration (https://mswjs.io/docs/integrations/browser) to eliminate any race conditions between the Service Worker registration and any requests made by your application on initial render.`
|
|
3279
|
+
);
|
|
2861
3280
|
}
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
const
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
3281
|
+
if (network.readyState === import_define_network.NetworkReadyState.ENABLED) {
|
|
3282
|
+
import_devUtils5.devUtils.warn(
|
|
3283
|
+
'Found a redundant "worker.start()" call. Note that starting the worker while mocking is already enabled will have no effect. Consider removing this "worker.start()" call.'
|
|
3284
|
+
);
|
|
3285
|
+
return;
|
|
3286
|
+
}
|
|
3287
|
+
const httpSource = supportsServiceWorker() ? new ServiceWorkerSource({
|
|
3288
|
+
serviceWorker: {
|
|
3289
|
+
url: options?.serviceWorker?.url?.toString() || DEFAULT_WORKER_URL,
|
|
3290
|
+
options: options?.serviceWorker?.options
|
|
3291
|
+
},
|
|
3292
|
+
findWorker: options?.findWorker,
|
|
3293
|
+
quiet: options?.quiet
|
|
3294
|
+
}) : new FallbackHttpSource({
|
|
3295
|
+
quiet: options?.quiet
|
|
2874
3296
|
});
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
3297
|
+
network.configure({
|
|
3298
|
+
sources: [
|
|
3299
|
+
httpSource,
|
|
3300
|
+
new import_interceptor_source2.InterceptorSource({
|
|
3301
|
+
interceptors: [new WebSocketInterceptor()]
|
|
3302
|
+
})
|
|
3303
|
+
],
|
|
3304
|
+
onUnhandledFrame: (0, import_compat.fromLegacyOnUnhandledRequest)(() => {
|
|
3305
|
+
return options?.onUnhandledRequest || "warn";
|
|
3306
|
+
}),
|
|
3307
|
+
context: {
|
|
3308
|
+
quiet: options?.quiet
|
|
3309
|
+
}
|
|
2879
3310
|
});
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
3311
|
+
await network.enable();
|
|
3312
|
+
if (httpSource instanceof ServiceWorkerSource) {
|
|
3313
|
+
const [, registration] = await httpSource.workerPromise;
|
|
3314
|
+
return registration;
|
|
3315
|
+
}
|
|
3316
|
+
},
|
|
3317
|
+
stop() {
|
|
3318
|
+
if (network.readyState === import_define_network.NetworkReadyState.DISABLED) {
|
|
3319
|
+
import_devUtils5.devUtils.warn(
|
|
3320
|
+
`Found a redundant "worker.stop()" call. Notice that stopping the worker after it has already been stopped has no effect. Consider removing this "worker.stop()" call.`
|
|
3321
|
+
);
|
|
3322
|
+
return;
|
|
3323
|
+
}
|
|
3324
|
+
network.disable();
|
|
3325
|
+
window.postMessage({ type: "msw/worker:stop" });
|
|
3326
|
+
},
|
|
3327
|
+
events: network.events,
|
|
3328
|
+
use: network.use.bind(network),
|
|
3329
|
+
resetHandlers: network.resetHandlers.bind(network),
|
|
3330
|
+
restoreHandlers: network.restoreHandlers.bind(network),
|
|
3331
|
+
listHandlers: network.listHandlers.bind(network)
|
|
3332
|
+
};
|
|
3333
|
+
}
|
|
3334
|
+
var SetupWorkerApi = class {
|
|
3335
|
+
start;
|
|
3336
|
+
stop;
|
|
3337
|
+
use;
|
|
3338
|
+
resetHandlers;
|
|
3339
|
+
restoreHandlers;
|
|
3340
|
+
listHandlers;
|
|
3341
|
+
events;
|
|
3342
|
+
constructor() {
|
|
3343
|
+
const worker = setupWorker();
|
|
3344
|
+
this.start = worker.start.bind(worker);
|
|
3345
|
+
this.stop = worker.stop.bind(worker);
|
|
3346
|
+
this.use = worker.use.bind(worker);
|
|
3347
|
+
this.resetHandlers = worker.resetHandlers.bind(worker);
|
|
3348
|
+
this.restoreHandlers = worker.restoreHandlers.bind(worker);
|
|
3349
|
+
this.listHandlers = worker.listHandlers.bind(worker);
|
|
3350
|
+
this.events = worker.events;
|
|
2906
3351
|
}
|
|
2907
3352
|
};
|
|
2908
|
-
function setupWorker(...handlers) {
|
|
2909
|
-
return new SetupWorkerApi(...handlers);
|
|
2910
|
-
}
|
|
2911
3353
|
//# sourceMappingURL=index.js.map
|