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