msw 2.3.0-ws.rc-6 → 2.3.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/cli/init.js +0 -0
- package/config/scripts/postinstall.js +0 -0
- package/lib/browser/index.d.mts +6 -7
- package/lib/browser/index.d.ts +6 -7
- package/lib/browser/index.js +156 -83
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +156 -83
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-DGyzNtRQ.d.ts → GraphQLHandler-COiPfZ8k.d.ts} +1 -1
- package/lib/core/{GraphQLHandler-CzcXr7At.d.mts → GraphQLHandler-Dq_WRbKe.d.mts} +1 -1
- package/lib/core/{HttpResponse-BOzDwzB6.d.ts → HttpResponse-B07UKAkU.d.ts} +2 -2
- package/lib/core/{HttpResponse-CSyJ1cbO.d.mts → HttpResponse-C7niBMwb.d.mts} +2 -2
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/SetupApi.d.mts +12 -15
- package/lib/core/SetupApi.d.ts +12 -15
- package/lib/core/SetupApi.js +1 -3
- package/lib/core/SetupApi.js.map +1 -1
- package/lib/core/SetupApi.mjs +1 -3
- package/lib/core/SetupApi.mjs.map +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/graphql.d.mts +2 -2
- package/lib/core/graphql.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- 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/http.d.mts +1 -1
- package/lib/core/http.d.ts +1 -1
- package/lib/core/index.d.mts +2 -5
- package/lib/core/index.d.ts +2 -5
- package/lib/core/index.js +1 -5
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +1 -7
- package/lib/core/index.mjs.map +1 -1
- package/lib/core/passthrough.d.mts +1 -1
- package/lib/core/passthrough.d.ts +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/executeHandlers.d.mts +1 -1
- package/lib/core/utils/executeHandlers.d.ts +1 -1
- package/lib/core/utils/executeHandlers.js +0 -4
- package/lib/core/utils/executeHandlers.js.map +1 -1
- package/lib/core/utils/executeHandlers.mjs +0 -6
- package/lib/core/utils/executeHandlers.mjs.map +1 -1
- package/lib/core/utils/handleRequest.d.mts +2 -2
- package/lib/core/utils/handleRequest.d.ts +2 -2
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/internal/Disposable.d.mts +2 -2
- package/lib/core/utils/internal/Disposable.d.ts +2 -2
- package/lib/core/utils/internal/Disposable.js +5 -2
- package/lib/core/utils/internal/Disposable.js.map +1 -1
- package/lib/core/utils/internal/Disposable.mjs +5 -2
- package/lib/core/utils/internal/Disposable.mjs.map +1 -1
- package/lib/core/utils/internal/devUtils.d.mts +10 -1
- package/lib/core/utils/internal/devUtils.d.ts +10 -1
- package/lib/core/utils/internal/devUtils.js +7 -0
- package/lib/core/utils/internal/devUtils.js.map +1 -1
- package/lib/core/utils/internal/devUtils.mjs +7 -0
- package/lib/core/utils/internal/devUtils.mjs.map +1 -1
- package/lib/core/utils/internal/parseGraphQLRequest.d.mts +2 -2
- package/lib/core/utils/internal/parseGraphQLRequest.d.ts +2 -2
- 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/logging/getTimestamp.d.mts +1 -4
- package/lib/core/utils/logging/getTimestamp.d.ts +1 -4
- package/lib/core/utils/logging/getTimestamp.js +2 -6
- package/lib/core/utils/logging/getTimestamp.js.map +1 -1
- package/lib/core/utils/logging/getTimestamp.mjs +2 -6
- package/lib/core/utils/logging/getTimestamp.mjs.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.d.mts +1 -2
- package/lib/core/utils/matching/matchRequestUrl.d.ts +1 -2
- package/lib/core/utils/matching/matchRequestUrl.js +0 -4
- package/lib/core/utils/matching/matchRequestUrl.js.map +1 -1
- package/lib/core/utils/matching/matchRequestUrl.mjs +0 -4
- package/lib/core/utils/matching/matchRequestUrl.mjs.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.js +3 -3
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +4 -4
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/iife/index.js +177 -1103
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.d.mts +5 -6
- package/lib/native/index.d.ts +5 -6
- package/lib/native/index.js +5 -13
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +6 -14
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +7 -8
- package/lib/node/index.d.ts +7 -8
- package/lib/node/index.js +5 -13
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +6 -14
- package/lib/node/index.mjs.map +1 -1
- package/package.json +36 -29
- package/src/browser/setupWorker/glossary.ts +10 -10
- package/src/browser/setupWorker/setupWorker.ts +3 -34
- package/src/browser/setupWorker/stop/createStop.ts +0 -4
- package/src/core/SetupApi.ts +20 -28
- package/src/core/index.ts +1 -8
- package/src/core/utils/executeHandlers.ts +2 -6
- package/src/core/utils/handleRequest.ts +2 -1
- package/src/core/utils/internal/Disposable.ts +6 -3
- package/src/core/utils/internal/devUtils.test.ts +21 -0
- package/src/core/utils/internal/devUtils.ts +13 -0
- package/src/core/utils/logging/getTimestamp.test.ts +6 -20
- package/src/core/utils/logging/getTimestamp.ts +6 -11
- package/src/core/utils/matching/matchRequestUrl.test.ts +0 -44
- package/src/core/utils/matching/matchRequestUrl.ts +0 -4
- package/src/core/utils/request/onUnhandledRequest.test.ts +30 -4
- package/src/core/utils/request/onUnhandledRequest.ts +4 -4
- package/src/node/SetupServerApi.ts +7 -8
- package/src/node/SetupServerCommonApi.ts +8 -15
- package/src/node/glossary.ts +7 -5
- package/src/node/setupServer.ts +1 -2
- package/lib/core/handlers/WebSocketHandler.d.mts +0 -32
- package/lib/core/handlers/WebSocketHandler.d.ts +0 -32
- package/lib/core/handlers/WebSocketHandler.js +0 -62
- package/lib/core/handlers/WebSocketHandler.js.map +0 -1
- package/lib/core/handlers/WebSocketHandler.mjs +0 -44
- package/lib/core/handlers/WebSocketHandler.mjs.map +0 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +0 -58
- package/lib/core/ws/WebSocketClientManager.d.ts +0 -58
- package/lib/core/ws/WebSocketClientManager.js +0 -162
- package/lib/core/ws/WebSocketClientManager.js.map +0 -1
- package/lib/core/ws/WebSocketClientManager.mjs +0 -142
- package/lib/core/ws/WebSocketClientManager.mjs.map +0 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +0 -16
- package/lib/core/ws/handleWebSocketEvent.d.ts +0 -16
- package/lib/core/ws/handleWebSocketEvent.js +0 -56
- package/lib/core/ws/handleWebSocketEvent.js.map +0 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +0 -36
- package/lib/core/ws/handleWebSocketEvent.mjs.map +0 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +0 -34
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +0 -34
- package/lib/core/ws/utils/attachWebSocketLogger.js +0 -217
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +0 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +0 -197
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +0 -1
- package/lib/core/ws/utils/getMessageLength.d.mts +0 -11
- package/lib/core/ws/utils/getMessageLength.d.ts +0 -11
- package/lib/core/ws/utils/getMessageLength.js +0 -33
- package/lib/core/ws/utils/getMessageLength.js.map +0 -1
- package/lib/core/ws/utils/getMessageLength.mjs +0 -13
- package/lib/core/ws/utils/getMessageLength.mjs.map +0 -1
- package/lib/core/ws/utils/getPublicData.d.mts +0 -5
- package/lib/core/ws/utils/getPublicData.d.ts +0 -5
- package/lib/core/ws/utils/getPublicData.js +0 -36
- package/lib/core/ws/utils/getPublicData.js.map +0 -1
- package/lib/core/ws/utils/getPublicData.mjs +0 -16
- package/lib/core/ws/utils/getPublicData.mjs.map +0 -1
- package/lib/core/ws/utils/truncateMessage.d.mts +0 -3
- package/lib/core/ws/utils/truncateMessage.d.ts +0 -3
- package/lib/core/ws/utils/truncateMessage.js +0 -31
- package/lib/core/ws/utils/truncateMessage.js.map +0 -1
- package/lib/core/ws/utils/truncateMessage.mjs +0 -11
- package/lib/core/ws/utils/truncateMessage.mjs.map +0 -1
- package/lib/core/ws/webSocketInterceptor.d.mts +0 -5
- package/lib/core/ws/webSocketInterceptor.d.ts +0 -5
- package/lib/core/ws/webSocketInterceptor.js +0 -26
- package/lib/core/ws/webSocketInterceptor.js.map +0 -1
- package/lib/core/ws/webSocketInterceptor.mjs +0 -6
- package/lib/core/ws/webSocketInterceptor.mjs.map +0 -1
- package/lib/core/ws.d.mts +0 -49
- package/lib/core/ws.d.ts +0 -49
- package/lib/core/ws.js +0 -65
- package/lib/core/ws.js.map +0 -1
- package/lib/core/ws.mjs +0 -48
- package/lib/core/ws.mjs.map +0 -1
- package/src/core/handlers/WebSocketHandler.ts +0 -71
- package/src/core/ws/WebSocketClientManager.test.ts +0 -157
- package/src/core/ws/WebSocketClientManager.ts +0 -234
- package/src/core/ws/handleWebSocketEvent.ts +0 -56
- package/src/core/ws/utils/attachWebSocketLogger.ts +0 -269
- package/src/core/ws/utils/getMessageLength.test.ts +0 -16
- package/src/core/ws/utils/getMessageLength.ts +0 -19
- package/src/core/ws/utils/getPublicData.test.ts +0 -38
- package/src/core/ws/utils/getPublicData.ts +0 -17
- package/src/core/ws/utils/truncateMessage.test.ts +0 -12
- package/src/core/ws/utils/truncateMessage.ts +0 -9
- package/src/core/ws/webSocketInterceptor.ts +0 -3
- package/src/core/ws.test.ts +0 -23
- package/src/core/ws.ts +0 -124
package/lib/iife/index.js
CHANGED
|
@@ -32,7 +32,6 @@ var MockServiceWorker = (() => {
|
|
|
32
32
|
SET_TIMEOUT_MAX_ALLOWED_INT: () => SET_TIMEOUT_MAX_ALLOWED_INT,
|
|
33
33
|
SetupApi: () => SetupApi,
|
|
34
34
|
SetupWorkerApi: () => SetupWorkerApi,
|
|
35
|
-
WebSocketHandler: () => WebSocketHandler,
|
|
36
35
|
bypass: () => bypass,
|
|
37
36
|
cleanUrl: () => cleanUrl,
|
|
38
37
|
delay: () => delay,
|
|
@@ -42,8 +41,7 @@ var MockServiceWorker = (() => {
|
|
|
42
41
|
http: () => http,
|
|
43
42
|
matchRequestUrl: () => matchRequestUrl,
|
|
44
43
|
passthrough: () => passthrough,
|
|
45
|
-
setupWorker: () => setupWorker
|
|
46
|
-
ws: () => ws
|
|
44
|
+
setupWorker: () => setupWorker
|
|
47
45
|
});
|
|
48
46
|
|
|
49
47
|
// node_modules/.pnpm/outvariant@1.4.2/node_modules/outvariant/lib/index.mjs
|
|
@@ -145,6 +143,12 @@ var MockServiceWorker = (() => {
|
|
|
145
143
|
warn,
|
|
146
144
|
error
|
|
147
145
|
};
|
|
146
|
+
var InternalError = class extends Error {
|
|
147
|
+
constructor(message3) {
|
|
148
|
+
super(message3);
|
|
149
|
+
this.name = "InternalError";
|
|
150
|
+
}
|
|
151
|
+
};
|
|
148
152
|
|
|
149
153
|
// src/core/utils/internal/checkGlobals.ts
|
|
150
154
|
function checkGlobals() {
|
|
@@ -345,8 +349,11 @@ var MockServiceWorker = (() => {
|
|
|
345
349
|
// src/core/utils/internal/Disposable.ts
|
|
346
350
|
var Disposable = class {
|
|
347
351
|
subscriptions = [];
|
|
348
|
-
|
|
349
|
-
|
|
352
|
+
dispose() {
|
|
353
|
+
let subscription;
|
|
354
|
+
while (subscription = this.subscriptions.shift()) {
|
|
355
|
+
subscription();
|
|
356
|
+
}
|
|
350
357
|
}
|
|
351
358
|
};
|
|
352
359
|
|
|
@@ -404,9 +411,7 @@ var MockServiceWorker = (() => {
|
|
|
404
411
|
}
|
|
405
412
|
restoreHandlers() {
|
|
406
413
|
this.handlersController.currentHandlers().forEach((handler) => {
|
|
407
|
-
|
|
408
|
-
handler.isUsed = false;
|
|
409
|
-
}
|
|
414
|
+
handler.isUsed = false;
|
|
410
415
|
});
|
|
411
416
|
}
|
|
412
417
|
resetHandlers(...nextHandlers) {
|
|
@@ -627,13 +632,9 @@ var MockServiceWorker = (() => {
|
|
|
627
632
|
}
|
|
628
633
|
|
|
629
634
|
// src/core/utils/logging/getTimestamp.ts
|
|
630
|
-
function getTimestamp(
|
|
635
|
+
function getTimestamp() {
|
|
631
636
|
const now = /* @__PURE__ */ new Date();
|
|
632
|
-
|
|
633
|
-
if (options?.milliseconds) {
|
|
634
|
-
return `${timestamp}.${now.getMilliseconds().toString().padStart(3, "0")}`;
|
|
635
|
-
}
|
|
636
|
-
return timestamp;
|
|
637
|
+
return [now.getHours(), now.getMinutes(), now.getSeconds()].map(String).map((chunk) => chunk.slice(0, 2)).map((chunk) => chunk.padStart(2, "0")).join(":");
|
|
637
638
|
}
|
|
638
639
|
|
|
639
640
|
// src/core/utils/logging/serializeRequest.ts
|
|
@@ -1129,7 +1130,7 @@ var MockServiceWorker = (() => {
|
|
|
1129
1130
|
return stringToRegexp(path, keys, options);
|
|
1130
1131
|
}
|
|
1131
1132
|
|
|
1132
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1133
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.29.0/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
|
|
1133
1134
|
var encoder = new TextEncoder();
|
|
1134
1135
|
function encodeBuffer(text) {
|
|
1135
1136
|
return encoder.encode(text);
|
|
@@ -1144,6 +1145,17 @@ var MockServiceWorker = (() => {
|
|
|
1144
1145
|
array.byteOffset + array.byteLength
|
|
1145
1146
|
);
|
|
1146
1147
|
}
|
|
1148
|
+
|
|
1149
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.29.0/node_modules/@mswjs/interceptors/lib/browser/chunk-OMISYKWR.mjs
|
|
1150
|
+
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1151
|
+
function isPropertyAccessible(obj, key) {
|
|
1152
|
+
try {
|
|
1153
|
+
obj[key];
|
|
1154
|
+
return true;
|
|
1155
|
+
} catch (e) {
|
|
1156
|
+
return false;
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1147
1159
|
var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
|
|
1148
1160
|
101,
|
|
1149
1161
|
103,
|
|
@@ -1154,9 +1166,27 @@ var MockServiceWorker = (() => {
|
|
|
1154
1166
|
function isResponseWithoutBody(status) {
|
|
1155
1167
|
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
1156
1168
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1169
|
+
function createServerErrorResponse(body) {
|
|
1170
|
+
return new Response(
|
|
1171
|
+
JSON.stringify(
|
|
1172
|
+
body instanceof Error ? {
|
|
1173
|
+
name: body.name,
|
|
1174
|
+
message: body.message,
|
|
1175
|
+
stack: body.stack
|
|
1176
|
+
} : body
|
|
1177
|
+
),
|
|
1178
|
+
{
|
|
1179
|
+
status: 500,
|
|
1180
|
+
statusText: "Unhandled Exception",
|
|
1181
|
+
headers: {
|
|
1182
|
+
"Content-Type": "application/json"
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
);
|
|
1186
|
+
}
|
|
1187
|
+
function isResponseError(response) {
|
|
1188
|
+
return isPropertyAccessible(response, "type") && response.type === "error";
|
|
1189
|
+
}
|
|
1160
1190
|
|
|
1161
1191
|
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
1162
1192
|
function isNodeProcess() {
|
|
@@ -1445,7 +1475,7 @@ var MockServiceWorker = (() => {
|
|
|
1445
1475
|
return message3.toString();
|
|
1446
1476
|
}
|
|
1447
1477
|
|
|
1448
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1478
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.29.0/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
1449
1479
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
1450
1480
|
function getGlobalSymbol(symbol) {
|
|
1451
1481
|
return (
|
|
@@ -1593,7 +1623,7 @@ var MockServiceWorker = (() => {
|
|
|
1593
1623
|
return Math.random().toString(16).slice(2);
|
|
1594
1624
|
}
|
|
1595
1625
|
|
|
1596
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1626
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.29.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1597
1627
|
var BatchInterceptor = class extends Interceptor {
|
|
1598
1628
|
constructor(options) {
|
|
1599
1629
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -1701,9 +1731,6 @@ var MockServiceWorker = (() => {
|
|
|
1701
1731
|
params
|
|
1702
1732
|
};
|
|
1703
1733
|
}
|
|
1704
|
-
function isPath(value) {
|
|
1705
|
-
return typeof value === "string" || value instanceof RegExp;
|
|
1706
|
-
}
|
|
1707
1734
|
|
|
1708
1735
|
// src/core/utils/request/toPublicUrl.ts
|
|
1709
1736
|
function toPublicUrl(url) {
|
|
@@ -2087,7 +2114,7 @@ var MockServiceWorker = (() => {
|
|
|
2087
2114
|
return false;
|
|
2088
2115
|
}
|
|
2089
2116
|
}
|
|
2090
|
-
function
|
|
2117
|
+
function isPropertyAccessible2(object, method) {
|
|
2091
2118
|
try {
|
|
2092
2119
|
object[method];
|
|
2093
2120
|
return true;
|
|
@@ -2100,7 +2127,7 @@ var MockServiceWorker = (() => {
|
|
|
2100
2127
|
this.store = /* @__PURE__ */ new Map();
|
|
2101
2128
|
}
|
|
2102
2129
|
add(request, response) {
|
|
2103
|
-
if (
|
|
2130
|
+
if (isPropertyAccessible2(request, "credentials") && request.credentials === "omit") {
|
|
2104
2131
|
return;
|
|
2105
2132
|
}
|
|
2106
2133
|
const requestUrl = new URL(request.url);
|
|
@@ -2125,7 +2152,7 @@ var MockServiceWorker = (() => {
|
|
|
2125
2152
|
this.deleteExpiredCookies();
|
|
2126
2153
|
const requestUrl = new URL(request.url);
|
|
2127
2154
|
const originCookies = this.store.get(requestUrl.origin) || /* @__PURE__ */ new Map();
|
|
2128
|
-
if (!
|
|
2155
|
+
if (!isPropertyAccessible2(request, "credentials")) {
|
|
2129
2156
|
return originCookies;
|
|
2130
2157
|
}
|
|
2131
2158
|
switch (request.credentials) {
|
|
@@ -5626,215 +5653,6 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5626
5653
|
link: createGraphQLLink
|
|
5627
5654
|
};
|
|
5628
5655
|
|
|
5629
|
-
// src/core/handlers/WebSocketHandler.ts
|
|
5630
|
-
var kEmitter = Symbol("kEmitter");
|
|
5631
|
-
var kDispatchEvent = Symbol("kDispatchEvent");
|
|
5632
|
-
var kSender = Symbol("kSender");
|
|
5633
|
-
var WebSocketHandler = class {
|
|
5634
|
-
constructor(url) {
|
|
5635
|
-
this.url = url;
|
|
5636
|
-
this[kEmitter] = new Emitter();
|
|
5637
|
-
this.callFrame = getCallFrame(new Error());
|
|
5638
|
-
}
|
|
5639
|
-
callFrame;
|
|
5640
|
-
[kEmitter];
|
|
5641
|
-
parse(args) {
|
|
5642
|
-
const connection = args.event.data;
|
|
5643
|
-
const match2 = matchRequestUrl(connection.client.url, this.url);
|
|
5644
|
-
return {
|
|
5645
|
-
match: match2
|
|
5646
|
-
};
|
|
5647
|
-
}
|
|
5648
|
-
predicate(args) {
|
|
5649
|
-
return args.parsedResult.match.matches;
|
|
5650
|
-
}
|
|
5651
|
-
async [kDispatchEvent](event) {
|
|
5652
|
-
const parsedResult = this.parse({ event });
|
|
5653
|
-
const connection = event.data;
|
|
5654
|
-
const resolvedConnection = {
|
|
5655
|
-
client: connection.client,
|
|
5656
|
-
server: connection.server,
|
|
5657
|
-
params: parsedResult.match.params || {}
|
|
5658
|
-
};
|
|
5659
|
-
this[kEmitter].emit("connection", resolvedConnection);
|
|
5660
|
-
}
|
|
5661
|
-
};
|
|
5662
|
-
|
|
5663
|
-
// src/core/ws/WebSocketClientManager.ts
|
|
5664
|
-
var MSW_WEBSOCKET_CLIENTS_KEY = "msw:ws:clients";
|
|
5665
|
-
var WebSocketClientManager = class {
|
|
5666
|
-
constructor(channel, url) {
|
|
5667
|
-
this.channel = channel;
|
|
5668
|
-
this.url = url;
|
|
5669
|
-
this.inMemoryClients = /* @__PURE__ */ new Set();
|
|
5670
|
-
if (typeof localStorage !== "undefined") {
|
|
5671
|
-
localStorage.removeItem = new Proxy(localStorage.removeItem, {
|
|
5672
|
-
apply: (target, thisArg, args) => {
|
|
5673
|
-
const [key] = args;
|
|
5674
|
-
if (key === MSW_WEBSOCKET_CLIENTS_KEY) {
|
|
5675
|
-
this.inMemoryClients.clear();
|
|
5676
|
-
}
|
|
5677
|
-
return Reflect.apply(target, thisArg, args);
|
|
5678
|
-
}
|
|
5679
|
-
});
|
|
5680
|
-
}
|
|
5681
|
-
}
|
|
5682
|
-
inMemoryClients;
|
|
5683
|
-
/**
|
|
5684
|
-
* All active WebSocket client connections.
|
|
5685
|
-
*/
|
|
5686
|
-
get clients() {
|
|
5687
|
-
if (typeof localStorage !== "undefined") {
|
|
5688
|
-
const inMemoryClients = Array.from(this.inMemoryClients);
|
|
5689
|
-
console.log("get clients()", inMemoryClients, this.getSerializedClients());
|
|
5690
|
-
return new Set(
|
|
5691
|
-
inMemoryClients.concat(
|
|
5692
|
-
this.getSerializedClients().filter((serializedClient) => {
|
|
5693
|
-
if (inMemoryClients.every(
|
|
5694
|
-
(client) => client.id !== serializedClient.clientId
|
|
5695
|
-
)) {
|
|
5696
|
-
return serializedClient;
|
|
5697
|
-
}
|
|
5698
|
-
}).map((serializedClient) => {
|
|
5699
|
-
return new WebSocketRemoteClientConnection(
|
|
5700
|
-
serializedClient.clientId,
|
|
5701
|
-
new URL(serializedClient.url),
|
|
5702
|
-
this.channel
|
|
5703
|
-
);
|
|
5704
|
-
})
|
|
5705
|
-
)
|
|
5706
|
-
);
|
|
5707
|
-
}
|
|
5708
|
-
return this.inMemoryClients;
|
|
5709
|
-
}
|
|
5710
|
-
getSerializedClients() {
|
|
5711
|
-
invariant(
|
|
5712
|
-
typeof localStorage !== "undefined",
|
|
5713
|
-
"Failed to call WebSocketClientManager#getSerializedClients() in a non-browser environment. This is likely a bug in MSW. Please, report it on GitHub: https://github.com/mswjs/msw"
|
|
5714
|
-
);
|
|
5715
|
-
const clientsJson = localStorage.getItem(MSW_WEBSOCKET_CLIENTS_KEY);
|
|
5716
|
-
if (!clientsJson) {
|
|
5717
|
-
return [];
|
|
5718
|
-
}
|
|
5719
|
-
const allClients = JSON.parse(clientsJson);
|
|
5720
|
-
const matchingClients = allClients.filter((client) => {
|
|
5721
|
-
return matchRequestUrl(new URL(client.url), this.url).matches;
|
|
5722
|
-
});
|
|
5723
|
-
return matchingClients;
|
|
5724
|
-
}
|
|
5725
|
-
addClient(client) {
|
|
5726
|
-
this.inMemoryClients.add(client);
|
|
5727
|
-
if (typeof localStorage !== "undefined") {
|
|
5728
|
-
const serializedClients = this.getSerializedClients();
|
|
5729
|
-
const nextSerializedClients = serializedClients.concat({
|
|
5730
|
-
clientId: client.id,
|
|
5731
|
-
url: client.url.href
|
|
5732
|
-
});
|
|
5733
|
-
localStorage.setItem(
|
|
5734
|
-
MSW_WEBSOCKET_CLIENTS_KEY,
|
|
5735
|
-
JSON.stringify(nextSerializedClients)
|
|
5736
|
-
);
|
|
5737
|
-
}
|
|
5738
|
-
}
|
|
5739
|
-
/**
|
|
5740
|
-
* Adds the given `WebSocket` client connection to the set
|
|
5741
|
-
* of all connections. The given connection is always the complete
|
|
5742
|
-
* connection object because `addConnection()` is called only
|
|
5743
|
-
* for the opened connections in the same runtime.
|
|
5744
|
-
*/
|
|
5745
|
-
addConnection(client) {
|
|
5746
|
-
this.addClient(client);
|
|
5747
|
-
const handleExtraneousMessage = (message3) => {
|
|
5748
|
-
const { type, payload } = message3.data;
|
|
5749
|
-
if (typeof payload === "object" && "clientId" in payload && payload.clientId !== client.id) {
|
|
5750
|
-
return;
|
|
5751
|
-
}
|
|
5752
|
-
switch (type) {
|
|
5753
|
-
case "extraneous:send": {
|
|
5754
|
-
client.send(payload.data);
|
|
5755
|
-
break;
|
|
5756
|
-
}
|
|
5757
|
-
case "extraneous:close": {
|
|
5758
|
-
client.close(payload.code, payload.reason);
|
|
5759
|
-
break;
|
|
5760
|
-
}
|
|
5761
|
-
}
|
|
5762
|
-
};
|
|
5763
|
-
const abortController = new AbortController();
|
|
5764
|
-
this.channel.addEventListener("message", handleExtraneousMessage, {
|
|
5765
|
-
signal: abortController.signal
|
|
5766
|
-
});
|
|
5767
|
-
client.addEventListener("close", () => abortController.abort(), {
|
|
5768
|
-
once: true
|
|
5769
|
-
});
|
|
5770
|
-
}
|
|
5771
|
-
};
|
|
5772
|
-
var WebSocketRemoteClientConnection = class {
|
|
5773
|
-
constructor(id, url, channel) {
|
|
5774
|
-
this.id = id;
|
|
5775
|
-
this.url = url;
|
|
5776
|
-
this.channel = channel;
|
|
5777
|
-
}
|
|
5778
|
-
send(data) {
|
|
5779
|
-
this.channel.postMessage({
|
|
5780
|
-
type: "extraneous:send",
|
|
5781
|
-
payload: {
|
|
5782
|
-
clientId: this.id,
|
|
5783
|
-
data
|
|
5784
|
-
}
|
|
5785
|
-
});
|
|
5786
|
-
}
|
|
5787
|
-
close(code, reason) {
|
|
5788
|
-
this.channel.postMessage({
|
|
5789
|
-
type: "extraneous:close",
|
|
5790
|
-
payload: {
|
|
5791
|
-
clientId: this.id,
|
|
5792
|
-
code,
|
|
5793
|
-
reason
|
|
5794
|
-
}
|
|
5795
|
-
});
|
|
5796
|
-
}
|
|
5797
|
-
};
|
|
5798
|
-
|
|
5799
|
-
// src/core/ws.ts
|
|
5800
|
-
var wsBroadcastChannel = new BroadcastChannel("msw:ws-client-manager");
|
|
5801
|
-
function createWebSocketLinkHandler(url) {
|
|
5802
|
-
invariant(url, "Expected a WebSocket server URL but got undefined");
|
|
5803
|
-
invariant(
|
|
5804
|
-
isPath(url),
|
|
5805
|
-
"Expected a WebSocket server URL to be a valid path but got %s",
|
|
5806
|
-
typeof url
|
|
5807
|
-
);
|
|
5808
|
-
const clientManager = new WebSocketClientManager(wsBroadcastChannel, url);
|
|
5809
|
-
return {
|
|
5810
|
-
get clients() {
|
|
5811
|
-
return clientManager.clients;
|
|
5812
|
-
},
|
|
5813
|
-
on(event, listener) {
|
|
5814
|
-
const handler = new WebSocketHandler(url);
|
|
5815
|
-
handler[kEmitter].on("connection", ({ client }) => {
|
|
5816
|
-
clientManager.addConnection(client);
|
|
5817
|
-
});
|
|
5818
|
-
handler[kEmitter].on(event, listener);
|
|
5819
|
-
return handler;
|
|
5820
|
-
},
|
|
5821
|
-
broadcast(data) {
|
|
5822
|
-
this.broadcastExcept([], data);
|
|
5823
|
-
},
|
|
5824
|
-
broadcastExcept(clients, data) {
|
|
5825
|
-
const ignoreClients = Array.prototype.concat(clients).map((client) => client.id);
|
|
5826
|
-
clientManager.clients.forEach((otherClient) => {
|
|
5827
|
-
if (!ignoreClients.includes(otherClient.id)) {
|
|
5828
|
-
otherClient.send(data);
|
|
5829
|
-
}
|
|
5830
|
-
});
|
|
5831
|
-
}
|
|
5832
|
-
};
|
|
5833
|
-
}
|
|
5834
|
-
var ws = {
|
|
5835
|
-
link: createWebSocketLinkHandler
|
|
5836
|
-
};
|
|
5837
|
-
|
|
5838
5656
|
// node_modules/.pnpm/@open-draft+until@2.1.0/node_modules/@open-draft/until/lib/index.mjs
|
|
5839
5657
|
var until = async (promise) => {
|
|
5840
5658
|
try {
|
|
@@ -5857,9 +5675,6 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5857
5675
|
let matchingHandler = null;
|
|
5858
5676
|
let result = null;
|
|
5859
5677
|
for (const handler of handlers) {
|
|
5860
|
-
if (!(handler instanceof RequestHandler)) {
|
|
5861
|
-
continue;
|
|
5862
|
-
}
|
|
5863
5678
|
result = await handler.run({ request, requestId, resolutionContext });
|
|
5864
5679
|
if (result !== null) {
|
|
5865
5680
|
matchingHandler = handler;
|
|
@@ -5881,7 +5696,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5881
5696
|
// src/core/utils/request/onUnhandledRequest.ts
|
|
5882
5697
|
async function onUnhandledRequest(request, strategy = "warn") {
|
|
5883
5698
|
const url = new URL(request.url);
|
|
5884
|
-
const publicUrl = toPublicUrl(url);
|
|
5699
|
+
const publicUrl = toPublicUrl(url) + url.search;
|
|
5885
5700
|
const unhandledRequestMessage = `intercepted a request without a matching request handler:
|
|
5886
5701
|
|
|
5887
5702
|
\u2022 ${request.method} ${publicUrl}
|
|
@@ -5892,7 +5707,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
5892
5707
|
switch (strategy2) {
|
|
5893
5708
|
case "error": {
|
|
5894
5709
|
devUtils.error("Error: %s", unhandledRequestMessage);
|
|
5895
|
-
throw new
|
|
5710
|
+
throw new InternalError(
|
|
5896
5711
|
devUtils.formatMessage(
|
|
5897
5712
|
'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'
|
|
5898
5713
|
)
|
|
@@ -5905,7 +5720,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
5905
5720
|
case "bypass":
|
|
5906
5721
|
break;
|
|
5907
5722
|
default:
|
|
5908
|
-
throw new
|
|
5723
|
+
throw new InternalError(
|
|
5909
5724
|
devUtils.formatMessage(
|
|
5910
5725
|
'Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.',
|
|
5911
5726
|
strategy2
|
|
@@ -6604,7 +6419,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6604
6419
|
context.workerChannel.send("MOCK_DEACTIVATE");
|
|
6605
6420
|
context.isMockingEnabled = false;
|
|
6606
6421
|
window.clearInterval(context.keepAliveInterval);
|
|
6607
|
-
localStorage.removeItem(MSW_WEBSOCKET_CLIENTS_KEY);
|
|
6608
6422
|
printStopMessage({ quiet: context.startOptions?.quiet });
|
|
6609
6423
|
};
|
|
6610
6424
|
};
|
|
@@ -6714,7 +6528,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6714
6528
|
}
|
|
6715
6529
|
};
|
|
6716
6530
|
|
|
6717
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6531
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.29.0/node_modules/@mswjs/interceptors/lib/browser/chunk-OUWBQF3Z.mjs
|
|
6718
6532
|
var RequestController = class {
|
|
6719
6533
|
constructor(request) {
|
|
6720
6534
|
this.request = request;
|
|
@@ -6752,15 +6566,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6752
6566
|
}
|
|
6753
6567
|
}
|
|
6754
6568
|
|
|
6755
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6756
|
-
function isPropertyAccessible2(obj, key) {
|
|
6757
|
-
try {
|
|
6758
|
-
obj[key];
|
|
6759
|
-
return true;
|
|
6760
|
-
} catch (e) {
|
|
6761
|
-
return false;
|
|
6762
|
-
}
|
|
6763
|
-
}
|
|
6569
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.29.0/node_modules/@mswjs/interceptors/lib/browser/chunk-MAEPOYB6.mjs
|
|
6764
6570
|
function canParseUrl(url) {
|
|
6765
6571
|
try {
|
|
6766
6572
|
new URL(url);
|
|
@@ -6813,64 +6619,113 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6813
6619
|
{ once: true }
|
|
6814
6620
|
);
|
|
6815
6621
|
}
|
|
6816
|
-
const
|
|
6817
|
-
|
|
6818
|
-
|
|
6819
|
-
|
|
6622
|
+
const responsePromise = new DeferredPromise();
|
|
6623
|
+
const respondWith = (response) => {
|
|
6624
|
+
this.logger.info("responding with a mock response:", response);
|
|
6625
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
6626
|
+
this.logger.info('emitting the "response" event...');
|
|
6627
|
+
const responseClone = response.clone();
|
|
6628
|
+
this.emitter.emit("response", {
|
|
6629
|
+
response: responseClone,
|
|
6630
|
+
isMockedResponse: true,
|
|
6631
|
+
request: interactiveRequest,
|
|
6632
|
+
requestId
|
|
6633
|
+
});
|
|
6634
|
+
}
|
|
6635
|
+
Object.defineProperty(response, "url", {
|
|
6636
|
+
writable: false,
|
|
6637
|
+
enumerable: true,
|
|
6638
|
+
configurable: false,
|
|
6639
|
+
value: request.url
|
|
6820
6640
|
});
|
|
6821
|
-
|
|
6822
|
-
|
|
6823
|
-
|
|
6824
|
-
|
|
6825
|
-
|
|
6826
|
-
|
|
6827
|
-
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6641
|
+
responsePromise.resolve(response);
|
|
6642
|
+
};
|
|
6643
|
+
const errorWith = (reason) => {
|
|
6644
|
+
responsePromise.reject(reason);
|
|
6645
|
+
};
|
|
6646
|
+
const resolverResult = await until(
|
|
6647
|
+
async () => {
|
|
6648
|
+
const listenersFinished = emitAsync(this.emitter, "request", {
|
|
6649
|
+
request: interactiveRequest,
|
|
6650
|
+
requestId
|
|
6651
|
+
});
|
|
6652
|
+
await Promise.race([
|
|
6653
|
+
requestAborted,
|
|
6654
|
+
// Put the listeners invocation Promise in the same race condition
|
|
6655
|
+
// with the request abort Promise because otherwise awaiting the listeners
|
|
6656
|
+
// would always yield some response (or undefined).
|
|
6657
|
+
listenersFinished,
|
|
6658
|
+
requestController.responsePromise
|
|
6659
|
+
]);
|
|
6660
|
+
this.logger.info("all request listeners have been resolved!");
|
|
6661
|
+
const mockedResponse2 = await requestController.responsePromise;
|
|
6662
|
+
this.logger.info("event.respondWith called with:", mockedResponse2);
|
|
6663
|
+
return mockedResponse2;
|
|
6664
|
+
}
|
|
6665
|
+
);
|
|
6834
6666
|
if (requestAborted.state === "rejected") {
|
|
6835
|
-
|
|
6667
|
+
this.logger.info(
|
|
6668
|
+
"request has been aborted:",
|
|
6669
|
+
requestAborted.rejectionReason
|
|
6670
|
+
);
|
|
6671
|
+
responsePromise.reject(requestAborted.rejectionReason);
|
|
6672
|
+
return responsePromise;
|
|
6836
6673
|
}
|
|
6837
6674
|
if (resolverResult.error) {
|
|
6838
|
-
|
|
6675
|
+
this.logger.info(
|
|
6676
|
+
"request listerner threw an error:",
|
|
6677
|
+
resolverResult.error
|
|
6678
|
+
);
|
|
6679
|
+
if (resolverResult.error instanceof Response) {
|
|
6680
|
+
if (isResponseError(resolverResult.error)) {
|
|
6681
|
+
errorWith(createNetworkError(resolverResult.error));
|
|
6682
|
+
} else {
|
|
6683
|
+
respondWith(resolverResult.error);
|
|
6684
|
+
}
|
|
6685
|
+
}
|
|
6686
|
+
if (this.emitter.listenerCount("unhandledException") > 0) {
|
|
6687
|
+
await emitAsync(this.emitter, "unhandledException", {
|
|
6688
|
+
error: resolverResult.error,
|
|
6689
|
+
request,
|
|
6690
|
+
requestId,
|
|
6691
|
+
controller: {
|
|
6692
|
+
respondWith,
|
|
6693
|
+
errorWith
|
|
6694
|
+
}
|
|
6695
|
+
});
|
|
6696
|
+
if (responsePromise.state !== "pending") {
|
|
6697
|
+
return responsePromise;
|
|
6698
|
+
}
|
|
6699
|
+
}
|
|
6700
|
+
respondWith(createServerErrorResponse(resolverResult.error));
|
|
6701
|
+
return responsePromise;
|
|
6839
6702
|
}
|
|
6840
6703
|
const mockedResponse = resolverResult.data;
|
|
6841
6704
|
if (mockedResponse && !((_a2 = request.signal) == null ? void 0 : _a2.aborted)) {
|
|
6842
6705
|
this.logger.info("received mocked response:", mockedResponse);
|
|
6843
|
-
if (
|
|
6706
|
+
if (isResponseError(mockedResponse)) {
|
|
6844
6707
|
this.logger.info(
|
|
6845
6708
|
"received a network error response, rejecting the request promise..."
|
|
6846
6709
|
);
|
|
6847
|
-
|
|
6710
|
+
errorWith(createNetworkError(mockedResponse));
|
|
6711
|
+
} else {
|
|
6712
|
+
respondWith(mockedResponse);
|
|
6848
6713
|
}
|
|
6849
|
-
|
|
6850
|
-
this.emitter.emit("response", {
|
|
6851
|
-
response: responseClone,
|
|
6852
|
-
isMockedResponse: true,
|
|
6853
|
-
request: interactiveRequest,
|
|
6854
|
-
requestId
|
|
6855
|
-
});
|
|
6856
|
-
Object.defineProperty(mockedResponse, "url", {
|
|
6857
|
-
writable: false,
|
|
6858
|
-
enumerable: true,
|
|
6859
|
-
configurable: false,
|
|
6860
|
-
value: request.url
|
|
6861
|
-
});
|
|
6862
|
-
return mockedResponse;
|
|
6714
|
+
return responsePromise;
|
|
6863
6715
|
}
|
|
6864
6716
|
this.logger.info("no mocked response received!");
|
|
6865
6717
|
return pureFetch(request).then((response) => {
|
|
6866
|
-
|
|
6867
|
-
this.
|
|
6868
|
-
|
|
6869
|
-
|
|
6870
|
-
|
|
6871
|
-
|
|
6872
|
-
|
|
6873
|
-
|
|
6718
|
+
this.logger.info("original fetch performed", response);
|
|
6719
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
6720
|
+
this.logger.info('emitting the "response" event...');
|
|
6721
|
+
const responseClone = response.clone();
|
|
6722
|
+
this.emitter.emit("response", {
|
|
6723
|
+
response: responseClone,
|
|
6724
|
+
isMockedResponse: false,
|
|
6725
|
+
request: interactiveRequest,
|
|
6726
|
+
requestId
|
|
6727
|
+
});
|
|
6728
|
+
}
|
|
6874
6729
|
return response;
|
|
6875
6730
|
});
|
|
6876
6731
|
};
|
|
@@ -6899,7 +6754,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6899
6754
|
});
|
|
6900
6755
|
}
|
|
6901
6756
|
|
|
6902
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6757
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.29.0/node_modules/@mswjs/interceptors/lib/browser/chunk-732REFPX.mjs
|
|
6903
6758
|
function concatArrayBuffer(left, right) {
|
|
6904
6759
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
6905
6760
|
result.set(left, 0);
|
|
@@ -7550,7 +7405,31 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7550
7405
|
"request listener threw an exception, aborting request...",
|
|
7551
7406
|
resolverResult.error
|
|
7552
7407
|
);
|
|
7553
|
-
|
|
7408
|
+
if (resolverResult.error instanceof Response) {
|
|
7409
|
+
if (isResponseError(resolverResult.error)) {
|
|
7410
|
+
xhrRequestController.errorWith(new TypeError("Network error"));
|
|
7411
|
+
} else {
|
|
7412
|
+
this.respondWith(resolverResult.error);
|
|
7413
|
+
}
|
|
7414
|
+
return;
|
|
7415
|
+
}
|
|
7416
|
+
if (emitter.listenerCount("unhandledException") > 0) {
|
|
7417
|
+
await emitAsync(emitter, "unhandledException", {
|
|
7418
|
+
error: resolverResult.error,
|
|
7419
|
+
request,
|
|
7420
|
+
requestId,
|
|
7421
|
+
controller: {
|
|
7422
|
+
respondWith: xhrRequestController.respondWith.bind(xhrRequestController),
|
|
7423
|
+
errorWith: xhrRequestController.errorWith.bind(xhrRequestController)
|
|
7424
|
+
}
|
|
7425
|
+
});
|
|
7426
|
+
if (originalRequest.readyState > XMLHttpRequest.OPENED) {
|
|
7427
|
+
return;
|
|
7428
|
+
}
|
|
7429
|
+
}
|
|
7430
|
+
xhrRequestController.respondWith(
|
|
7431
|
+
createServerErrorResponse(resolverResult.error)
|
|
7432
|
+
);
|
|
7554
7433
|
return;
|
|
7555
7434
|
}
|
|
7556
7435
|
const mockedResponse = resolverResult.data;
|
|
@@ -7560,7 +7439,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7560
7439
|
mockedResponse.status,
|
|
7561
7440
|
mockedResponse.statusText
|
|
7562
7441
|
);
|
|
7563
|
-
if (mockedResponse
|
|
7442
|
+
if (isResponseError(mockedResponse)) {
|
|
7564
7443
|
this.logger.info(
|
|
7565
7444
|
"received a network error response, rejecting the request promise..."
|
|
7566
7445
|
);
|
|
@@ -7724,795 +7603,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7724
7603
|
}
|
|
7725
7604
|
}
|
|
7726
7605
|
|
|
7727
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.27.1/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
7728
|
-
function bindEvent(target, event) {
|
|
7729
|
-
Object.defineProperties(event, {
|
|
7730
|
-
target: {
|
|
7731
|
-
value: target,
|
|
7732
|
-
enumerable: true,
|
|
7733
|
-
writable: true
|
|
7734
|
-
},
|
|
7735
|
-
currentTarget: {
|
|
7736
|
-
value: target,
|
|
7737
|
-
enumerable: true,
|
|
7738
|
-
writable: true
|
|
7739
|
-
}
|
|
7740
|
-
});
|
|
7741
|
-
return event;
|
|
7742
|
-
}
|
|
7743
|
-
var kCancelable = Symbol("kCancelable");
|
|
7744
|
-
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
7745
|
-
var CancelableMessageEvent = class extends MessageEvent {
|
|
7746
|
-
constructor(type, init) {
|
|
7747
|
-
super(type, init);
|
|
7748
|
-
this[kCancelable] = !!init.cancelable;
|
|
7749
|
-
this[kDefaultPrevented] = false;
|
|
7750
|
-
}
|
|
7751
|
-
get cancelable() {
|
|
7752
|
-
return this[kCancelable];
|
|
7753
|
-
}
|
|
7754
|
-
set cancelable(nextCancelable) {
|
|
7755
|
-
this[kCancelable] = nextCancelable;
|
|
7756
|
-
}
|
|
7757
|
-
get defaultPrevented() {
|
|
7758
|
-
return this[kDefaultPrevented];
|
|
7759
|
-
}
|
|
7760
|
-
set defaultPrevented(nextDefaultPrevented) {
|
|
7761
|
-
this[kDefaultPrevented] = nextDefaultPrevented;
|
|
7762
|
-
}
|
|
7763
|
-
preventDefault() {
|
|
7764
|
-
if (this.cancelable && !this[kDefaultPrevented]) {
|
|
7765
|
-
this[kDefaultPrevented] = true;
|
|
7766
|
-
}
|
|
7767
|
-
}
|
|
7768
|
-
};
|
|
7769
|
-
var CloseEvent = class extends Event {
|
|
7770
|
-
constructor(type, init = {}) {
|
|
7771
|
-
super(type, init);
|
|
7772
|
-
this.code = init.code === void 0 ? 0 : init.code;
|
|
7773
|
-
this.reason = init.reason === void 0 ? "" : init.reason;
|
|
7774
|
-
this.wasClean = init.wasClean === void 0 ? false : init.wasClean;
|
|
7775
|
-
}
|
|
7776
|
-
};
|
|
7777
|
-
var kEmitter2 = Symbol("kEmitter");
|
|
7778
|
-
var WebSocketClientConnection = class {
|
|
7779
|
-
constructor(socket, transport) {
|
|
7780
|
-
this.socket = socket;
|
|
7781
|
-
this.transport = transport;
|
|
7782
|
-
this.id = createRequestId();
|
|
7783
|
-
this.url = new URL(socket.url);
|
|
7784
|
-
this[kEmitter2] = new EventTarget();
|
|
7785
|
-
this.transport.addEventListener("outgoing", (event) => {
|
|
7786
|
-
const message3 = bindEvent(
|
|
7787
|
-
this.socket,
|
|
7788
|
-
new CancelableMessageEvent("message", {
|
|
7789
|
-
data: event.data,
|
|
7790
|
-
origin: event.origin,
|
|
7791
|
-
cancelable: true
|
|
7792
|
-
})
|
|
7793
|
-
);
|
|
7794
|
-
this[kEmitter2].dispatchEvent(message3);
|
|
7795
|
-
if (message3.defaultPrevented) {
|
|
7796
|
-
event.preventDefault();
|
|
7797
|
-
}
|
|
7798
|
-
});
|
|
7799
|
-
this.transport.addEventListener("close", (event) => {
|
|
7800
|
-
this[kEmitter2].dispatchEvent(
|
|
7801
|
-
bindEvent(this.socket, new CloseEvent("close", event))
|
|
7802
|
-
);
|
|
7803
|
-
});
|
|
7804
|
-
}
|
|
7805
|
-
/**
|
|
7806
|
-
* Listen for the outgoing events from the connected WebSocket client.
|
|
7807
|
-
*/
|
|
7808
|
-
addEventListener(type, listener, options) {
|
|
7809
|
-
this[kEmitter2].addEventListener(type, listener, options);
|
|
7810
|
-
}
|
|
7811
|
-
/**
|
|
7812
|
-
* Removes the listener for the given event.
|
|
7813
|
-
*/
|
|
7814
|
-
removeEventListener(event, listener, options) {
|
|
7815
|
-
this[kEmitter2].removeEventListener(
|
|
7816
|
-
event,
|
|
7817
|
-
listener,
|
|
7818
|
-
options
|
|
7819
|
-
);
|
|
7820
|
-
}
|
|
7821
|
-
/**
|
|
7822
|
-
* Send data to the connected client.
|
|
7823
|
-
*/
|
|
7824
|
-
send(data) {
|
|
7825
|
-
this.transport.send(data);
|
|
7826
|
-
}
|
|
7827
|
-
/**
|
|
7828
|
-
* Close the WebSocket connection.
|
|
7829
|
-
* @param {number} code A status code (see https://www.rfc-editor.org/rfc/rfc6455#section-7.4.1).
|
|
7830
|
-
* @param {string} reason A custom connection close reason.
|
|
7831
|
-
*/
|
|
7832
|
-
close(code, reason) {
|
|
7833
|
-
this.transport.close(code, reason);
|
|
7834
|
-
}
|
|
7835
|
-
};
|
|
7836
|
-
var WEBSOCKET_CLOSE_CODE_RANGE_ERROR = "InvalidAccessError: close code out of user configurable range";
|
|
7837
|
-
var kOnSend = Symbol("kOnSend");
|
|
7838
|
-
var kClose = Symbol("kClose");
|
|
7839
|
-
var WebSocketOverride = class extends EventTarget {
|
|
7840
|
-
constructor(url, protocols) {
|
|
7841
|
-
super();
|
|
7842
|
-
this.CONNECTING = 0;
|
|
7843
|
-
this.OPEN = 1;
|
|
7844
|
-
this.CLOSING = 2;
|
|
7845
|
-
this.CLOSED = 3;
|
|
7846
|
-
this._onopen = null;
|
|
7847
|
-
this._onmessage = null;
|
|
7848
|
-
this._onerror = null;
|
|
7849
|
-
this._onclose = null;
|
|
7850
|
-
this.url = url.toString();
|
|
7851
|
-
this.protocol = "";
|
|
7852
|
-
this.extensions = "";
|
|
7853
|
-
this.binaryType = "blob";
|
|
7854
|
-
this.readyState = this.CONNECTING;
|
|
7855
|
-
this.bufferedAmount = 0;
|
|
7856
|
-
Reflect.set(this, "readyState", this.CONNECTING);
|
|
7857
|
-
queueMicrotask(() => {
|
|
7858
|
-
Reflect.set(this, "readyState", this.OPEN);
|
|
7859
|
-
this.protocol = protocols ? protocols[0] : "ws";
|
|
7860
|
-
this.dispatchEvent(bindEvent(this, new Event("open")));
|
|
7861
|
-
});
|
|
7862
|
-
}
|
|
7863
|
-
set onopen(listener) {
|
|
7864
|
-
this.removeEventListener("open", this._onopen);
|
|
7865
|
-
this._onopen = listener;
|
|
7866
|
-
if (listener !== null) {
|
|
7867
|
-
this.addEventListener("open", listener);
|
|
7868
|
-
}
|
|
7869
|
-
}
|
|
7870
|
-
get onopen() {
|
|
7871
|
-
return this._onopen;
|
|
7872
|
-
}
|
|
7873
|
-
set onmessage(listener) {
|
|
7874
|
-
this.removeEventListener(
|
|
7875
|
-
"message",
|
|
7876
|
-
this._onmessage
|
|
7877
|
-
);
|
|
7878
|
-
this._onmessage = listener;
|
|
7879
|
-
if (listener !== null) {
|
|
7880
|
-
this.addEventListener("message", listener);
|
|
7881
|
-
}
|
|
7882
|
-
}
|
|
7883
|
-
get onmessage() {
|
|
7884
|
-
return this._onmessage;
|
|
7885
|
-
}
|
|
7886
|
-
set onerror(listener) {
|
|
7887
|
-
this.removeEventListener("error", this._onerror);
|
|
7888
|
-
this._onerror = listener;
|
|
7889
|
-
if (listener !== null) {
|
|
7890
|
-
this.addEventListener("error", listener);
|
|
7891
|
-
}
|
|
7892
|
-
}
|
|
7893
|
-
get onerror() {
|
|
7894
|
-
return this._onerror;
|
|
7895
|
-
}
|
|
7896
|
-
set onclose(listener) {
|
|
7897
|
-
this.removeEventListener("close", this._onclose);
|
|
7898
|
-
this._onclose = listener;
|
|
7899
|
-
if (listener !== null) {
|
|
7900
|
-
this.addEventListener("close", listener);
|
|
7901
|
-
}
|
|
7902
|
-
}
|
|
7903
|
-
get onclose() {
|
|
7904
|
-
return this._onclose;
|
|
7905
|
-
}
|
|
7906
|
-
/**
|
|
7907
|
-
* @see https://websockets.spec.whatwg.org/#ref-for-dom-websocket-send%E2%91%A0
|
|
7908
|
-
*/
|
|
7909
|
-
send(data) {
|
|
7910
|
-
if (this.readyState === this.CONNECTING) {
|
|
7911
|
-
this.close();
|
|
7912
|
-
throw new DOMException("InvalidStateError");
|
|
7913
|
-
}
|
|
7914
|
-
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) {
|
|
7915
|
-
return;
|
|
7916
|
-
}
|
|
7917
|
-
this.bufferedAmount += getDataSize(data);
|
|
7918
|
-
queueMicrotask(() => {
|
|
7919
|
-
var _a2;
|
|
7920
|
-
this.bufferedAmount = 0;
|
|
7921
|
-
(_a2 = this[kOnSend]) == null ? void 0 : _a2.call(this, data);
|
|
7922
|
-
});
|
|
7923
|
-
}
|
|
7924
|
-
close(code = 1e3, reason) {
|
|
7925
|
-
invariant(code, WEBSOCKET_CLOSE_CODE_RANGE_ERROR);
|
|
7926
|
-
invariant(
|
|
7927
|
-
code === 1e3 || code >= 3e3 && code <= 4999,
|
|
7928
|
-
WEBSOCKET_CLOSE_CODE_RANGE_ERROR
|
|
7929
|
-
);
|
|
7930
|
-
if (this.readyState === this.CLOSING || this.readyState === this.CLOSED) {
|
|
7931
|
-
return;
|
|
7932
|
-
}
|
|
7933
|
-
this[kClose](code, reason);
|
|
7934
|
-
}
|
|
7935
|
-
[(kOnSend, kClose)](code = 1e3, reason) {
|
|
7936
|
-
this.readyState = this.CLOSING;
|
|
7937
|
-
queueMicrotask(() => {
|
|
7938
|
-
this.readyState = this.CLOSED;
|
|
7939
|
-
if (code > 1e3 && code <= 1015) {
|
|
7940
|
-
this.dispatchEvent(bindEvent(this, new Event("error")));
|
|
7941
|
-
}
|
|
7942
|
-
this.dispatchEvent(
|
|
7943
|
-
bindEvent(
|
|
7944
|
-
this,
|
|
7945
|
-
new CloseEvent("close", {
|
|
7946
|
-
code,
|
|
7947
|
-
reason,
|
|
7948
|
-
wasClean: code === 1e3
|
|
7949
|
-
})
|
|
7950
|
-
)
|
|
7951
|
-
);
|
|
7952
|
-
this._onopen = null;
|
|
7953
|
-
this._onmessage = null;
|
|
7954
|
-
this._onerror = null;
|
|
7955
|
-
this._onclose = null;
|
|
7956
|
-
});
|
|
7957
|
-
}
|
|
7958
|
-
addEventListener(type, listener, options) {
|
|
7959
|
-
return super.addEventListener(
|
|
7960
|
-
type,
|
|
7961
|
-
listener,
|
|
7962
|
-
options
|
|
7963
|
-
);
|
|
7964
|
-
}
|
|
7965
|
-
removeEventListener(type, callback, options) {
|
|
7966
|
-
return super.removeEventListener(type, callback, options);
|
|
7967
|
-
}
|
|
7968
|
-
};
|
|
7969
|
-
WebSocketOverride.CONNECTING = 0;
|
|
7970
|
-
WebSocketOverride.OPEN = 1;
|
|
7971
|
-
WebSocketOverride.CLOSING = 2;
|
|
7972
|
-
WebSocketOverride.CLOSED = 3;
|
|
7973
|
-
function getDataSize(data) {
|
|
7974
|
-
if (typeof data === "string") {
|
|
7975
|
-
return data.length;
|
|
7976
|
-
}
|
|
7977
|
-
if (data instanceof Blob) {
|
|
7978
|
-
return data.size;
|
|
7979
|
-
}
|
|
7980
|
-
return data.byteLength;
|
|
7981
|
-
}
|
|
7982
|
-
var kEmitter22 = Symbol("kEmitter");
|
|
7983
|
-
var WebSocketServerConnection = class {
|
|
7984
|
-
constructor(socket, transport, createConnection) {
|
|
7985
|
-
this.socket = socket;
|
|
7986
|
-
this.transport = transport;
|
|
7987
|
-
this.createConnection = createConnection;
|
|
7988
|
-
this[kEmitter22] = new EventTarget();
|
|
7989
|
-
this.mockCloseController = new AbortController();
|
|
7990
|
-
this.transport.addEventListener("outgoing", (event) => {
|
|
7991
|
-
if (this.readyState === -1) {
|
|
7992
|
-
return;
|
|
7993
|
-
}
|
|
7994
|
-
queueMicrotask(() => {
|
|
7995
|
-
if (!event.defaultPrevented) {
|
|
7996
|
-
this.send(event.data);
|
|
7997
|
-
}
|
|
7998
|
-
});
|
|
7999
|
-
});
|
|
8000
|
-
this.transport.addEventListener(
|
|
8001
|
-
"incoming",
|
|
8002
|
-
this.handleIncomingMessage.bind(this)
|
|
8003
|
-
);
|
|
8004
|
-
}
|
|
8005
|
-
/**
|
|
8006
|
-
* Server ready state.
|
|
8007
|
-
* Proxies the ready state of the original WebSocket instance,
|
|
8008
|
-
* if set. If the original connection hasn't been established,
|
|
8009
|
-
* defaults to `-1`.
|
|
8010
|
-
*/
|
|
8011
|
-
get readyState() {
|
|
8012
|
-
if (this.realWebSocket) {
|
|
8013
|
-
return this.realWebSocket.readyState;
|
|
8014
|
-
}
|
|
8015
|
-
return -1;
|
|
8016
|
-
}
|
|
8017
|
-
/**
|
|
8018
|
-
* Open connection to the original WebSocket server.
|
|
8019
|
-
*/
|
|
8020
|
-
connect() {
|
|
8021
|
-
invariant(
|
|
8022
|
-
!this.realWebSocket || this.realWebSocket.readyState !== WebSocket.OPEN,
|
|
8023
|
-
'Failed to call "connect()" on the original WebSocket instance: the connection already open'
|
|
8024
|
-
);
|
|
8025
|
-
const realWebSocket = this.createConnection();
|
|
8026
|
-
realWebSocket.binaryType = this.socket.binaryType;
|
|
8027
|
-
realWebSocket.addEventListener(
|
|
8028
|
-
"open",
|
|
8029
|
-
(event) => {
|
|
8030
|
-
this[kEmitter22].dispatchEvent(
|
|
8031
|
-
bindEvent(this.realWebSocket, new Event("open", event))
|
|
8032
|
-
);
|
|
8033
|
-
},
|
|
8034
|
-
{ once: true }
|
|
8035
|
-
);
|
|
8036
|
-
realWebSocket.addEventListener("message", (event) => {
|
|
8037
|
-
this.transport.dispatchEvent(
|
|
8038
|
-
bindEvent(
|
|
8039
|
-
this.realWebSocket,
|
|
8040
|
-
new MessageEvent("incoming", {
|
|
8041
|
-
data: event.data,
|
|
8042
|
-
origin: event.origin
|
|
8043
|
-
})
|
|
8044
|
-
)
|
|
8045
|
-
);
|
|
8046
|
-
});
|
|
8047
|
-
this.socket.addEventListener("close", this.handleMockClose.bind(this), {
|
|
8048
|
-
signal: this.mockCloseController.signal
|
|
8049
|
-
});
|
|
8050
|
-
realWebSocket.addEventListener("close", this.handleRealClose.bind(this));
|
|
8051
|
-
realWebSocket.addEventListener("error", () => {
|
|
8052
|
-
this.socket.dispatchEvent(bindEvent(this.socket, new Event("error")));
|
|
8053
|
-
});
|
|
8054
|
-
this.realWebSocket = realWebSocket;
|
|
8055
|
-
}
|
|
8056
|
-
/**
|
|
8057
|
-
* Listen for the incoming events from the original WebSocket server.
|
|
8058
|
-
*/
|
|
8059
|
-
addEventListener(event, listener, options) {
|
|
8060
|
-
this[kEmitter22].addEventListener(
|
|
8061
|
-
event,
|
|
8062
|
-
listener.bind(this.realWebSocket),
|
|
8063
|
-
options
|
|
8064
|
-
);
|
|
8065
|
-
}
|
|
8066
|
-
/**
|
|
8067
|
-
* Remove the listener for the given event.
|
|
8068
|
-
*/
|
|
8069
|
-
removeEventListener(event, listener, options) {
|
|
8070
|
-
this[kEmitter22].removeEventListener(
|
|
8071
|
-
event,
|
|
8072
|
-
listener,
|
|
8073
|
-
options
|
|
8074
|
-
);
|
|
8075
|
-
}
|
|
8076
|
-
/**
|
|
8077
|
-
* Send data to the original WebSocket server.
|
|
8078
|
-
* @example
|
|
8079
|
-
* server.send('hello')
|
|
8080
|
-
* server.send(new Blob(['hello']))
|
|
8081
|
-
* server.send(new TextEncoder().encode('hello'))
|
|
8082
|
-
*/
|
|
8083
|
-
send(data) {
|
|
8084
|
-
const { realWebSocket } = this;
|
|
8085
|
-
invariant(
|
|
8086
|
-
realWebSocket,
|
|
8087
|
-
'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
8088
|
-
this.socket.url
|
|
8089
|
-
);
|
|
8090
|
-
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
8091
|
-
return;
|
|
8092
|
-
}
|
|
8093
|
-
if (realWebSocket.readyState === WebSocket.CONNECTING) {
|
|
8094
|
-
realWebSocket.addEventListener(
|
|
8095
|
-
"open",
|
|
8096
|
-
() => {
|
|
8097
|
-
realWebSocket.send(data);
|
|
8098
|
-
},
|
|
8099
|
-
{ once: true }
|
|
8100
|
-
);
|
|
8101
|
-
return;
|
|
8102
|
-
}
|
|
8103
|
-
realWebSocket.send(data);
|
|
8104
|
-
}
|
|
8105
|
-
/**
|
|
8106
|
-
* Close the actual server connection.
|
|
8107
|
-
*/
|
|
8108
|
-
close() {
|
|
8109
|
-
const { realWebSocket } = this;
|
|
8110
|
-
invariant(
|
|
8111
|
-
realWebSocket,
|
|
8112
|
-
'Failed to close server connection for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
8113
|
-
this.socket.url
|
|
8114
|
-
);
|
|
8115
|
-
realWebSocket.removeEventListener("close", this.handleRealClose);
|
|
8116
|
-
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
8117
|
-
return;
|
|
8118
|
-
}
|
|
8119
|
-
realWebSocket.close();
|
|
8120
|
-
queueMicrotask(() => {
|
|
8121
|
-
this[kEmitter22].dispatchEvent(
|
|
8122
|
-
bindEvent(this.realWebSocket, new CloseEvent("close"))
|
|
8123
|
-
);
|
|
8124
|
-
});
|
|
8125
|
-
}
|
|
8126
|
-
handleIncomingMessage(event) {
|
|
8127
|
-
const messageEvent = bindEvent(
|
|
8128
|
-
event.target,
|
|
8129
|
-
new CancelableMessageEvent("message", {
|
|
8130
|
-
data: event.data,
|
|
8131
|
-
origin: event.origin,
|
|
8132
|
-
cancelable: true
|
|
8133
|
-
})
|
|
8134
|
-
);
|
|
8135
|
-
this[kEmitter22].dispatchEvent(messageEvent);
|
|
8136
|
-
if (!messageEvent.defaultPrevented) {
|
|
8137
|
-
this.socket.dispatchEvent(
|
|
8138
|
-
bindEvent(
|
|
8139
|
-
/**
|
|
8140
|
-
* @note Bind the forwarded original server events
|
|
8141
|
-
* to the mock WebSocket instance so it would
|
|
8142
|
-
* dispatch them straight away.
|
|
8143
|
-
*/
|
|
8144
|
-
this.socket,
|
|
8145
|
-
// Clone the message event again to prevent
|
|
8146
|
-
// the "already being dispatched" exception.
|
|
8147
|
-
new MessageEvent("message", {
|
|
8148
|
-
data: event.data,
|
|
8149
|
-
origin: event.origin
|
|
8150
|
-
})
|
|
8151
|
-
)
|
|
8152
|
-
);
|
|
8153
|
-
}
|
|
8154
|
-
}
|
|
8155
|
-
handleMockClose(_event) {
|
|
8156
|
-
if (this.realWebSocket) {
|
|
8157
|
-
this.realWebSocket.close();
|
|
8158
|
-
}
|
|
8159
|
-
}
|
|
8160
|
-
handleRealClose(event) {
|
|
8161
|
-
this.mockCloseController.abort();
|
|
8162
|
-
const closeEvent = bindEvent(
|
|
8163
|
-
this.realWebSocket,
|
|
8164
|
-
new CloseEvent("close", event)
|
|
8165
|
-
);
|
|
8166
|
-
this[kEmitter22].dispatchEvent(closeEvent);
|
|
8167
|
-
if (!closeEvent.defaultPrevented) {
|
|
8168
|
-
this.socket[kClose](event.code, event.reason);
|
|
8169
|
-
}
|
|
8170
|
-
}
|
|
8171
|
-
};
|
|
8172
|
-
var WebSocketClassTransport = class extends EventTarget {
|
|
8173
|
-
constructor(socket) {
|
|
8174
|
-
super();
|
|
8175
|
-
this.socket = socket;
|
|
8176
|
-
this.socket.addEventListener("close", (event) => {
|
|
8177
|
-
this.dispatchEvent(bindEvent(this.socket, new CloseEvent("close", event)));
|
|
8178
|
-
});
|
|
8179
|
-
this.socket[kOnSend] = (data) => {
|
|
8180
|
-
this.dispatchEvent(
|
|
8181
|
-
bindEvent(
|
|
8182
|
-
this.socket,
|
|
8183
|
-
// Dispatch this as cancelable because "client" connection
|
|
8184
|
-
// re-creates this message event (cannot dispatch the same event).
|
|
8185
|
-
new CancelableMessageEvent("outgoing", {
|
|
8186
|
-
data,
|
|
8187
|
-
origin: this.socket.url,
|
|
8188
|
-
cancelable: true
|
|
8189
|
-
})
|
|
8190
|
-
)
|
|
8191
|
-
);
|
|
8192
|
-
};
|
|
8193
|
-
}
|
|
8194
|
-
addEventListener(type, callback, options) {
|
|
8195
|
-
return super.addEventListener(type, callback, options);
|
|
8196
|
-
}
|
|
8197
|
-
dispatchEvent(event) {
|
|
8198
|
-
return super.dispatchEvent(event);
|
|
8199
|
-
}
|
|
8200
|
-
send(data) {
|
|
8201
|
-
queueMicrotask(() => {
|
|
8202
|
-
this.socket.dispatchEvent(
|
|
8203
|
-
bindEvent(
|
|
8204
|
-
/**
|
|
8205
|
-
* @note Setting this event's "target" to the
|
|
8206
|
-
* WebSocket override instance is important.
|
|
8207
|
-
* This way it can tell apart original incoming events
|
|
8208
|
-
* (must be forwarded to the transport) from the
|
|
8209
|
-
* mocked message events like the one below
|
|
8210
|
-
* (must be dispatched on the client instance).
|
|
8211
|
-
*/
|
|
8212
|
-
this.socket,
|
|
8213
|
-
new MessageEvent("message", {
|
|
8214
|
-
data,
|
|
8215
|
-
origin: this.socket.url
|
|
8216
|
-
})
|
|
8217
|
-
)
|
|
8218
|
-
);
|
|
8219
|
-
});
|
|
8220
|
-
}
|
|
8221
|
-
close(code, reason) {
|
|
8222
|
-
this.socket[kClose](code, reason);
|
|
8223
|
-
}
|
|
8224
|
-
};
|
|
8225
|
-
var _WebSocketInterceptor = class extends Interceptor {
|
|
8226
|
-
constructor() {
|
|
8227
|
-
super(_WebSocketInterceptor.symbol);
|
|
8228
|
-
}
|
|
8229
|
-
checkEnvironment() {
|
|
8230
|
-
return typeof globalThis.WebSocket !== "undefined";
|
|
8231
|
-
}
|
|
8232
|
-
setup() {
|
|
8233
|
-
const originalWebSocket = globalThis.WebSocket;
|
|
8234
|
-
const webSocketProxy = new Proxy(globalThis.WebSocket, {
|
|
8235
|
-
construct: (target, args, newTarget) => {
|
|
8236
|
-
const [url, protocols] = args;
|
|
8237
|
-
const createConnection = () => {
|
|
8238
|
-
return Reflect.construct(target, args, newTarget);
|
|
8239
|
-
};
|
|
8240
|
-
const socket = new WebSocketOverride(url, protocols);
|
|
8241
|
-
const transport = new WebSocketClassTransport(socket);
|
|
8242
|
-
queueMicrotask(() => {
|
|
8243
|
-
this.emitter.emit("connection", {
|
|
8244
|
-
client: new WebSocketClientConnection(socket, transport),
|
|
8245
|
-
server: new WebSocketServerConnection(
|
|
8246
|
-
socket,
|
|
8247
|
-
transport,
|
|
8248
|
-
createConnection
|
|
8249
|
-
)
|
|
8250
|
-
});
|
|
8251
|
-
});
|
|
8252
|
-
return socket;
|
|
8253
|
-
}
|
|
8254
|
-
});
|
|
8255
|
-
globalThis.WebSocket = webSocketProxy;
|
|
8256
|
-
this.subscriptions.push(() => {
|
|
8257
|
-
globalThis.WebSocket = originalWebSocket;
|
|
8258
|
-
});
|
|
8259
|
-
}
|
|
8260
|
-
};
|
|
8261
|
-
var WebSocketInterceptor = _WebSocketInterceptor;
|
|
8262
|
-
WebSocketInterceptor.symbol = Symbol("websocket");
|
|
8263
|
-
|
|
8264
|
-
// src/core/ws/webSocketInterceptor.ts
|
|
8265
|
-
var webSocketInterceptor = new WebSocketInterceptor();
|
|
8266
|
-
|
|
8267
|
-
// src/core/ws/handleWebSocketEvent.ts
|
|
8268
|
-
function handleWebSocketEvent(options) {
|
|
8269
|
-
webSocketInterceptor.on("connection", (connection) => {
|
|
8270
|
-
const handlers = options.getHandlers();
|
|
8271
|
-
const connectionEvent = new MessageEvent("connection", {
|
|
8272
|
-
data: connection
|
|
8273
|
-
});
|
|
8274
|
-
const matchingHandlers = handlers.filter(
|
|
8275
|
-
(handler) => {
|
|
8276
|
-
if (handler instanceof WebSocketHandler) {
|
|
8277
|
-
return handler.predicate({
|
|
8278
|
-
event: connectionEvent,
|
|
8279
|
-
parsedResult: handler.parse({
|
|
8280
|
-
event: connectionEvent
|
|
8281
|
-
})
|
|
8282
|
-
});
|
|
8283
|
-
}
|
|
8284
|
-
return false;
|
|
8285
|
-
}
|
|
8286
|
-
);
|
|
8287
|
-
if (matchingHandlers.length > 0) {
|
|
8288
|
-
options?.onMockedConnection(connection);
|
|
8289
|
-
for (const handler of matchingHandlers) {
|
|
8290
|
-
handler[kDispatchEvent](connectionEvent);
|
|
8291
|
-
}
|
|
8292
|
-
} else {
|
|
8293
|
-
options?.onPassthroughConnection(connection);
|
|
8294
|
-
connection.server.connect();
|
|
8295
|
-
}
|
|
8296
|
-
});
|
|
8297
|
-
}
|
|
8298
|
-
|
|
8299
|
-
// src/core/ws/utils/getMessageLength.ts
|
|
8300
|
-
function getMessageLength(data) {
|
|
8301
|
-
if (data instanceof Blob) {
|
|
8302
|
-
return data.size;
|
|
8303
|
-
}
|
|
8304
|
-
if (data instanceof ArrayBuffer) {
|
|
8305
|
-
return data.byteLength;
|
|
8306
|
-
}
|
|
8307
|
-
return new Blob([data]).size;
|
|
8308
|
-
}
|
|
8309
|
-
|
|
8310
|
-
// src/core/ws/utils/truncateMessage.ts
|
|
8311
|
-
var MAX_LENGTH = 24;
|
|
8312
|
-
function truncateMessage(message3) {
|
|
8313
|
-
if (message3.length <= MAX_LENGTH) {
|
|
8314
|
-
return message3;
|
|
8315
|
-
}
|
|
8316
|
-
return `${message3.slice(0, MAX_LENGTH)}\u2026`;
|
|
8317
|
-
}
|
|
8318
|
-
|
|
8319
|
-
// src/core/ws/utils/getPublicData.ts
|
|
8320
|
-
async function getPublicData(data) {
|
|
8321
|
-
if (data instanceof Blob) {
|
|
8322
|
-
const text = await data.text();
|
|
8323
|
-
return `Blob(${truncateMessage(text)})`;
|
|
8324
|
-
}
|
|
8325
|
-
if (typeof data === "object" && "byteLength" in data) {
|
|
8326
|
-
const text = new TextDecoder().decode(data);
|
|
8327
|
-
return `ArrayBuffer(${truncateMessage(text)})`;
|
|
8328
|
-
}
|
|
8329
|
-
return truncateMessage(data);
|
|
8330
|
-
}
|
|
8331
|
-
|
|
8332
|
-
// src/core/ws/utils/attachWebSocketLogger.ts
|
|
8333
|
-
var colors = {
|
|
8334
|
-
blue: "#3b82f6",
|
|
8335
|
-
green: "#22c55e",
|
|
8336
|
-
red: "#ef4444",
|
|
8337
|
-
orange: "#ff6a33"
|
|
8338
|
-
};
|
|
8339
|
-
function attachWebSocketLogger(connection) {
|
|
8340
|
-
const { client, server } = connection;
|
|
8341
|
-
logConnectionOpen(client);
|
|
8342
|
-
client.addEventListener("message", (event) => {
|
|
8343
|
-
logOutgoingClientMessage(event);
|
|
8344
|
-
});
|
|
8345
|
-
client.addEventListener("close", (event) => {
|
|
8346
|
-
logConnectionClose(event);
|
|
8347
|
-
});
|
|
8348
|
-
client.socket.addEventListener("message", (event) => {
|
|
8349
|
-
logIncomingClientMessage(event);
|
|
8350
|
-
});
|
|
8351
|
-
client.socket.addEventListener("error", (event) => {
|
|
8352
|
-
logClientError(event);
|
|
8353
|
-
});
|
|
8354
|
-
client.send = new Proxy(client.send, {
|
|
8355
|
-
apply(target, thisArg, args) {
|
|
8356
|
-
const [data] = args;
|
|
8357
|
-
const messageEvent = new MessageEvent("message", { data });
|
|
8358
|
-
Object.defineProperties(messageEvent, {
|
|
8359
|
-
currentTarget: {
|
|
8360
|
-
enumerable: true,
|
|
8361
|
-
writable: false,
|
|
8362
|
-
value: client.socket
|
|
8363
|
-
},
|
|
8364
|
-
target: {
|
|
8365
|
-
enumerable: true,
|
|
8366
|
-
writable: false,
|
|
8367
|
-
value: client.socket
|
|
8368
|
-
}
|
|
8369
|
-
});
|
|
8370
|
-
logIncomingMockedClientMessage(messageEvent);
|
|
8371
|
-
return Reflect.apply(target, thisArg, args);
|
|
8372
|
-
}
|
|
8373
|
-
});
|
|
8374
|
-
server.addEventListener(
|
|
8375
|
-
"open",
|
|
8376
|
-
() => {
|
|
8377
|
-
server.addEventListener("message", (event) => {
|
|
8378
|
-
logIncomingServerMessage(event);
|
|
8379
|
-
});
|
|
8380
|
-
},
|
|
8381
|
-
{ once: true }
|
|
8382
|
-
);
|
|
8383
|
-
server.send = new Proxy(server.send, {
|
|
8384
|
-
apply(target, thisArg, args) {
|
|
8385
|
-
const [data] = args;
|
|
8386
|
-
const messageEvent = new MessageEvent("message", { data });
|
|
8387
|
-
Object.defineProperties(messageEvent, {
|
|
8388
|
-
currentTarget: {
|
|
8389
|
-
enumerable: true,
|
|
8390
|
-
writable: false,
|
|
8391
|
-
value: server["realWebSocket"]
|
|
8392
|
-
},
|
|
8393
|
-
target: {
|
|
8394
|
-
enumerable: true,
|
|
8395
|
-
writable: false,
|
|
8396
|
-
value: server["realWebSocket"]
|
|
8397
|
-
}
|
|
8398
|
-
});
|
|
8399
|
-
logOutgoingMockedClientMessage(messageEvent);
|
|
8400
|
-
return Reflect.apply(target, thisArg, args);
|
|
8401
|
-
}
|
|
8402
|
-
});
|
|
8403
|
-
}
|
|
8404
|
-
function logConnectionOpen(client) {
|
|
8405
|
-
const publicUrl = toPublicUrl(client.url);
|
|
8406
|
-
console.groupCollapsed(
|
|
8407
|
-
devUtils.formatMessage(`${getTimestamp()} %c\u25B6%c ${publicUrl}`),
|
|
8408
|
-
`color:${colors.blue}`,
|
|
8409
|
-
"color:inherit"
|
|
8410
|
-
);
|
|
8411
|
-
console.log("Client:", client.socket);
|
|
8412
|
-
console.groupEnd();
|
|
8413
|
-
}
|
|
8414
|
-
async function logOutgoingClientMessage(event) {
|
|
8415
|
-
const byteLength = getMessageLength(event.data);
|
|
8416
|
-
const publicData = await getPublicData(event.data);
|
|
8417
|
-
console.groupCollapsed(
|
|
8418
|
-
devUtils.formatMessage(
|
|
8419
|
-
`${getTimestamp({ milliseconds: true })} %c\u2191%c ${publicData} %c${byteLength}%c`
|
|
8420
|
-
),
|
|
8421
|
-
`color:${colors.green}`,
|
|
8422
|
-
"color:inherit",
|
|
8423
|
-
"color:gray;font-weight:normal",
|
|
8424
|
-
"color:inherit;font-weight:inherit"
|
|
8425
|
-
);
|
|
8426
|
-
console.log(event);
|
|
8427
|
-
console.groupEnd();
|
|
8428
|
-
}
|
|
8429
|
-
async function logOutgoingMockedClientMessage(event) {
|
|
8430
|
-
const byteLength = getMessageLength(event.data);
|
|
8431
|
-
const publicData = await getPublicData(event.data);
|
|
8432
|
-
console.groupCollapsed(
|
|
8433
|
-
devUtils.formatMessage(
|
|
8434
|
-
`${getTimestamp({ milliseconds: true })} %c\u21E1%c ${publicData} %c${byteLength}%c`
|
|
8435
|
-
),
|
|
8436
|
-
`color:${colors.orange}`,
|
|
8437
|
-
"color:inherit",
|
|
8438
|
-
"color:gray;font-weight:normal",
|
|
8439
|
-
"color:inherit;font-weight:inherit"
|
|
8440
|
-
);
|
|
8441
|
-
console.log(event);
|
|
8442
|
-
console.groupEnd();
|
|
8443
|
-
}
|
|
8444
|
-
async function logIncomingClientMessage(event) {
|
|
8445
|
-
const byteLength = getMessageLength(event.data);
|
|
8446
|
-
const publicData = await getPublicData(event.data);
|
|
8447
|
-
console.groupCollapsed(
|
|
8448
|
-
devUtils.formatMessage(
|
|
8449
|
-
`${getTimestamp({ milliseconds: true })} %c\u2193%c ${publicData} %c${byteLength}%c`
|
|
8450
|
-
),
|
|
8451
|
-
`color:${colors.red}`,
|
|
8452
|
-
"color:inherit",
|
|
8453
|
-
"color:gray;font-weight:normal",
|
|
8454
|
-
"color:inherit;font-weight:inherit"
|
|
8455
|
-
);
|
|
8456
|
-
console.log(event);
|
|
8457
|
-
console.groupEnd();
|
|
8458
|
-
}
|
|
8459
|
-
async function logIncomingMockedClientMessage(event) {
|
|
8460
|
-
const byteLength = getMessageLength(event.data);
|
|
8461
|
-
const publicData = await getPublicData(event.data);
|
|
8462
|
-
console.groupCollapsed(
|
|
8463
|
-
devUtils.formatMessage(
|
|
8464
|
-
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8465
|
-
),
|
|
8466
|
-
`color:${colors.orange}`,
|
|
8467
|
-
"color:inherit",
|
|
8468
|
-
"color:gray;font-weight:normal",
|
|
8469
|
-
"color:inherit;font-weight:inherit"
|
|
8470
|
-
);
|
|
8471
|
-
console.log(event);
|
|
8472
|
-
console.groupEnd();
|
|
8473
|
-
}
|
|
8474
|
-
function logConnectionClose(event) {
|
|
8475
|
-
const target = event.target;
|
|
8476
|
-
const publicUrl = toPublicUrl(target.url);
|
|
8477
|
-
console.groupCollapsed(
|
|
8478
|
-
devUtils.formatMessage(
|
|
8479
|
-
`${getTimestamp({ milliseconds: true })} %c\u25A0%c ${publicUrl}`
|
|
8480
|
-
),
|
|
8481
|
-
`color:${colors.blue}`,
|
|
8482
|
-
"color:inherit"
|
|
8483
|
-
);
|
|
8484
|
-
console.log(event);
|
|
8485
|
-
console.groupEnd();
|
|
8486
|
-
}
|
|
8487
|
-
async function logIncomingServerMessage(event) {
|
|
8488
|
-
const byteLength = getMessageLength(event.data);
|
|
8489
|
-
const publicData = await getPublicData(event.data);
|
|
8490
|
-
console.groupCollapsed(
|
|
8491
|
-
devUtils.formatMessage(
|
|
8492
|
-
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8493
|
-
),
|
|
8494
|
-
`color:${colors.green}`,
|
|
8495
|
-
"color:inherit",
|
|
8496
|
-
"color:gray;font-weight:normal",
|
|
8497
|
-
"color:inherit;font-weight:inherit"
|
|
8498
|
-
);
|
|
8499
|
-
console.log(event);
|
|
8500
|
-
console.groupEnd();
|
|
8501
|
-
}
|
|
8502
|
-
function logClientError(event) {
|
|
8503
|
-
const socket = event.target;
|
|
8504
|
-
const publicUrl = toPublicUrl(socket.url);
|
|
8505
|
-
console.groupCollapsed(
|
|
8506
|
-
devUtils.formatMessage(
|
|
8507
|
-
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
8508
|
-
),
|
|
8509
|
-
`color:${colors.blue}`,
|
|
8510
|
-
"color:inherit"
|
|
8511
|
-
);
|
|
8512
|
-
console.log(event);
|
|
8513
|
-
console.groupEnd();
|
|
8514
|
-
}
|
|
8515
|
-
|
|
8516
7606
|
// src/browser/setupWorker/setupWorker.ts
|
|
8517
7607
|
var SetupWorkerApi = class extends SetupApi {
|
|
8518
7608
|
context;
|
|
@@ -8629,22 +7719,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8629
7719
|
DEFAULT_START_OPTIONS,
|
|
8630
7720
|
options
|
|
8631
7721
|
);
|
|
8632
|
-
handleWebSocketEvent({
|
|
8633
|
-
getHandlers: () => {
|
|
8634
|
-
return this.handlersController.currentHandlers();
|
|
8635
|
-
},
|
|
8636
|
-
onMockedConnection: (connection) => {
|
|
8637
|
-
if (!this.context.startOptions.quiet) {
|
|
8638
|
-
attachWebSocketLogger(connection);
|
|
8639
|
-
}
|
|
8640
|
-
},
|
|
8641
|
-
onPassthroughConnection() {
|
|
8642
|
-
}
|
|
8643
|
-
});
|
|
8644
|
-
webSocketInterceptor.apply();
|
|
8645
|
-
this.subscriptions.push(() => {
|
|
8646
|
-
webSocketInterceptor.dispose();
|
|
8647
|
-
});
|
|
8648
7722
|
return await this.startHandler(this.context.startOptions, options);
|
|
8649
7723
|
}
|
|
8650
7724
|
stop() {
|