msw 2.3.0-ws.rc-1 → 2.3.0-ws.rc-2
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/README.md +8 -3
- package/cli/init.js +1 -1
- package/lib/browser/index.d.mts +4 -4
- package/lib/browser/index.js +64 -59
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +64 -59
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/{GraphQLHandler-Cbu12sb0.d.ts → GraphQLHandler-3gvpA65n.d.ts} +3 -3
- package/lib/core/{GraphQLHandler-QGQY_9Rc.d.mts → GraphQLHandler-4DPdxG0R.d.mts} +3 -3
- package/lib/core/{HttpResponse-BWB1yDNM.d.mts → HttpResponse-aJY-D0oG.d.ts} +3 -3
- package/lib/core/{HttpResponse-DeJBWGN5.d.ts → HttpResponse-xuSipbNt.d.mts} +3 -3
- package/lib/core/HttpResponse.d.mts +1 -1
- package/lib/core/HttpResponse.d.ts +1 -1
- package/lib/core/HttpResponse.js.map +1 -1
- package/lib/core/HttpResponse.mjs.map +1 -1
- package/lib/core/SetupApi.d.mts +1 -1
- package/lib/core/SetupApi.d.ts +1 -1
- package/lib/core/bypass.js +6 -1
- package/lib/core/bypass.js.map +1 -1
- package/lib/core/bypass.mjs +6 -1
- package/lib/core/bypass.mjs.map +1 -1
- package/lib/core/getResponse.d.mts +1 -1
- package/lib/core/getResponse.d.ts +1 -1
- package/lib/core/getResponse.js +2 -2
- package/lib/core/getResponse.js.map +1 -1
- package/lib/core/getResponse.mjs +2 -2
- package/lib/core/getResponse.mjs.map +1 -1
- package/lib/core/graphql.d.mts +8 -6
- package/lib/core/graphql.d.ts +8 -6
- package/lib/core/graphql.js.map +1 -1
- package/lib/core/graphql.mjs.map +1 -1
- package/lib/core/handlers/GraphQLHandler.d.mts +2 -2
- package/lib/core/handlers/GraphQLHandler.d.ts +2 -2
- package/lib/core/handlers/GraphQLHandler.js.map +1 -1
- package/lib/core/handlers/GraphQLHandler.mjs.map +1 -1
- package/lib/core/handlers/HttpHandler.d.mts +1 -1
- package/lib/core/handlers/HttpHandler.d.ts +1 -1
- package/lib/core/handlers/HttpHandler.js +1 -1
- package/lib/core/handlers/HttpHandler.js.map +1 -1
- package/lib/core/handlers/HttpHandler.mjs +1 -1
- package/lib/core/handlers/HttpHandler.mjs.map +1 -1
- package/lib/core/handlers/RequestHandler.d.mts +1 -1
- package/lib/core/handlers/RequestHandler.d.ts +1 -1
- package/lib/core/handlers/WebSocketHandler.d.mts +11 -17
- package/lib/core/handlers/WebSocketHandler.d.ts +11 -17
- package/lib/core/handlers/WebSocketHandler.js +9 -12
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +9 -12
- 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 +4 -4
- package/lib/core/index.d.ts +4 -4
- package/lib/core/index.js +2 -0
- package/lib/core/index.js.map +1 -1
- package/lib/core/index.mjs +4 -0
- 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/typeUtils.d.mts +6 -1
- package/lib/core/typeUtils.d.ts +6 -1
- package/lib/core/typeUtils.js.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/HttpResponse/decorators.js +4 -1
- package/lib/core/utils/HttpResponse/decorators.js.map +1 -1
- package/lib/core/utils/HttpResponse/decorators.mjs +4 -1
- package/lib/core/utils/HttpResponse/decorators.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 +1 -1
- package/lib/core/utils/handleRequest.d.ts +1 -1
- package/lib/core/utils/handleRequest.js.map +1 -1
- package/lib/core/utils/handleRequest.mjs.map +1 -1
- package/lib/core/utils/handleWebSocketEvent.d.mts +8 -2
- package/lib/core/utils/handleWebSocketEvent.d.ts +8 -2
- package/lib/core/utils/handleWebSocketEvent.js +20 -17
- package/lib/core/utils/handleWebSocketEvent.js.map +1 -1
- package/lib/core/utils/handleWebSocketEvent.mjs +21 -22
- package/lib/core/utils/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/utils/internal/mergeRight.js +15 -12
- package/lib/core/utils/internal/mergeRight.js.map +1 -1
- package/lib/core/utils/internal/mergeRight.mjs +15 -12
- package/lib/core/utils/internal/mergeRight.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 +4 -1
- package/lib/core/utils/logging/getTimestamp.d.ts +4 -1
- package/lib/core/utils/logging/getTimestamp.js +6 -2
- package/lib/core/utils/logging/getTimestamp.js.map +1 -1
- package/lib/core/utils/logging/getTimestamp.mjs +6 -2
- package/lib/core/utils/logging/getTimestamp.mjs.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +34 -0
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +34 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js +211 -0
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +191 -0
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -0
- package/lib/core/ws/utils/getMessageLength.d.mts +11 -0
- package/lib/core/ws/utils/getMessageLength.d.ts +11 -0
- package/lib/core/ws/utils/getMessageLength.js +33 -0
- package/lib/core/ws/utils/getMessageLength.js.map +1 -0
- package/lib/core/ws/utils/getMessageLength.mjs +13 -0
- package/lib/core/ws/utils/getMessageLength.mjs.map +1 -0
- package/lib/core/ws/utils/getPublicData.d.mts +5 -0
- package/lib/core/ws/utils/getPublicData.d.ts +5 -0
- package/lib/core/ws/utils/getPublicData.js +36 -0
- package/lib/core/ws/utils/getPublicData.js.map +1 -0
- package/lib/core/ws/utils/getPublicData.mjs +16 -0
- package/lib/core/ws/utils/getPublicData.mjs.map +1 -0
- package/lib/core/ws/utils/truncateMessage.d.mts +3 -0
- package/lib/core/ws/utils/truncateMessage.d.ts +3 -0
- package/lib/core/{utils/internal/randomId.js → ws/utils/truncateMessage.js} +11 -7
- package/lib/core/ws/utils/truncateMessage.js.map +1 -0
- package/lib/core/ws/utils/truncateMessage.mjs +11 -0
- package/lib/core/ws/utils/truncateMessage.mjs.map +1 -0
- package/lib/iife/index.js +508 -231
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +8 -11
- package/lib/native/index.d.mts +4 -4
- package/lib/native/index.js +8 -2
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +8 -2
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.d.mts +6 -6
- package/lib/node/index.d.ts +2 -2
- package/lib/node/index.js +8 -2
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +8 -2
- package/lib/node/index.mjs.map +1 -1
- package/package.json +8 -11
- package/src/browser/setupWorker/glossary.ts +4 -1
- package/src/browser/setupWorker/setupWorker.ts +19 -2
- package/src/browser/setupWorker/start/createRequestListener.ts +1 -1
- package/src/browser/setupWorker/start/createStartHandler.ts +9 -19
- package/src/browser/setupWorker/start/utils/createMessageChannel.ts +1 -1
- package/src/browser/utils/checkWorkerIntegrity.ts +34 -0
- package/src/core/HttpResponse.ts +3 -2
- package/src/core/bypass.test.ts +22 -0
- package/src/core/bypass.ts +9 -1
- package/src/core/getResponse.ts +2 -2
- package/src/core/graphql.ts +6 -3
- package/src/core/handlers/GraphQLHandler.test.ts +4 -5
- package/src/core/handlers/GraphQLHandler.ts +7 -4
- package/src/core/handlers/HttpHandler.test.ts +5 -5
- package/src/core/handlers/HttpHandler.ts +1 -1
- package/src/core/handlers/WebSocketHandler.ts +21 -39
- package/src/core/index.ts +6 -2
- package/src/core/typeUtils.ts +16 -10
- package/src/core/utils/HttpResponse/decorators.ts +8 -4
- package/src/core/utils/handleRequest.test.ts +14 -14
- package/src/core/utils/handleRequest.ts +1 -1
- package/src/core/utils/handleWebSocketEvent.ts +39 -29
- package/src/core/utils/internal/mergeRight.ts +16 -13
- package/src/core/utils/logging/getTimestamp.test.ts +20 -6
- package/src/core/utils/logging/getTimestamp.ts +11 -6
- package/src/core/ws/utils/attachWebSocketLogger.ts +262 -0
- package/src/core/ws/utils/getMessageLength.test.ts +16 -0
- package/src/core/ws/utils/getMessageLength.ts +19 -0
- package/src/core/ws/utils/getPublicData.test.ts +38 -0
- package/src/core/ws/utils/getPublicData.ts +17 -0
- package/src/core/ws/utils/truncateMessage.test.ts +12 -0
- package/src/core/ws/utils/truncateMessage.ts +9 -0
- package/src/mockServiceWorker.js +7 -10
- package/src/node/SetupServerApi.ts +4 -4
- package/src/node/SetupServerCommonApi.ts +6 -2
- package/src/node/glossary.ts +3 -3
- package/lib/core/utils/internal/randomId.d.mts +0 -3
- package/lib/core/utils/internal/randomId.d.ts +0 -3
- package/lib/core/utils/internal/randomId.js.map +0 -1
- package/lib/core/utils/internal/randomId.mjs +0 -7
- package/lib/core/utils/internal/randomId.mjs.map +0 -1
- package/src/browser/utils/requestIntegrityCheck.ts +0 -23
- package/src/core/utils/internal/randomId.ts +0 -3
package/lib/iife/index.js
CHANGED
|
@@ -32,6 +32,7 @@ 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,
|
|
35
36
|
bypass: () => bypass,
|
|
36
37
|
cleanUrl: () => cleanUrl,
|
|
37
38
|
delay: () => delay,
|
|
@@ -626,9 +627,13 @@ var MockServiceWorker = (() => {
|
|
|
626
627
|
}
|
|
627
628
|
|
|
628
629
|
// src/core/utils/logging/getTimestamp.ts
|
|
629
|
-
function getTimestamp() {
|
|
630
|
+
function getTimestamp(options) {
|
|
630
631
|
const now = /* @__PURE__ */ new Date();
|
|
631
|
-
|
|
632
|
+
const timestamp = `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}:${now.getSeconds().toString().padStart(2, "0")}`;
|
|
633
|
+
if (options?.milliseconds) {
|
|
634
|
+
return `${timestamp}.${now.getMilliseconds().toString().padStart(3, "0")}`;
|
|
635
|
+
}
|
|
636
|
+
return timestamp;
|
|
632
637
|
}
|
|
633
638
|
|
|
634
639
|
// src/core/utils/logging/serializeRequest.ts
|
|
@@ -1124,7 +1129,7 @@ var MockServiceWorker = (() => {
|
|
|
1124
1129
|
return stringToRegexp(path, keys, options);
|
|
1125
1130
|
}
|
|
1126
1131
|
|
|
1127
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
1132
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
|
|
1128
1133
|
var encoder = new TextEncoder();
|
|
1129
1134
|
function encodeBuffer(text) {
|
|
1130
1135
|
return encoder.encode(text);
|
|
@@ -1150,7 +1155,7 @@ var MockServiceWorker = (() => {
|
|
|
1150
1155
|
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
1151
1156
|
}
|
|
1152
1157
|
|
|
1153
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
1158
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-HAGW22AN.mjs
|
|
1154
1159
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1155
1160
|
|
|
1156
1161
|
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
@@ -1440,7 +1445,8 @@ var MockServiceWorker = (() => {
|
|
|
1440
1445
|
return message3.toString();
|
|
1441
1446
|
}
|
|
1442
1447
|
|
|
1443
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
1448
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
1449
|
+
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
1444
1450
|
function getGlobalSymbol(symbol) {
|
|
1445
1451
|
return (
|
|
1446
1452
|
// @ts-ignore https://github.com/Microsoft/TypeScript/issues/24587
|
|
@@ -1583,8 +1589,11 @@ var MockServiceWorker = (() => {
|
|
|
1583
1589
|
this.logger.info("cleared global instance!", this.symbol.description);
|
|
1584
1590
|
}
|
|
1585
1591
|
};
|
|
1592
|
+
function createRequestId() {
|
|
1593
|
+
return Math.random().toString(16).slice(2);
|
|
1594
|
+
}
|
|
1586
1595
|
|
|
1587
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
1596
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1588
1597
|
var BatchInterceptor = class extends Interceptor {
|
|
1589
1598
|
constructor(options) {
|
|
1590
1599
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -2291,7 +2300,7 @@ Invalid value has been removed from localStorage to prevent subsequent failed pa
|
|
|
2291
2300
|
queryParams.push(paramName);
|
|
2292
2301
|
});
|
|
2293
2302
|
devUtils.warn(
|
|
2294
|
-
`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters
|
|
2303
|
+
`Found a redundant usage of query parameters in the request handler URL for "${method} ${path}". Please match against a path instead and access query parameters using "new URL(request.url).searchParams" instead. Learn more: https://mswjs.io/docs/recipes/query-parameters`
|
|
2295
2304
|
);
|
|
2296
2305
|
}
|
|
2297
2306
|
async parse(args) {
|
|
@@ -5618,12 +5627,14 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5618
5627
|
// src/core/handlers/WebSocketHandler.ts
|
|
5619
5628
|
var kEmitter = Symbol("kEmitter");
|
|
5620
5629
|
var kDispatchEvent = Symbol("kDispatchEvent");
|
|
5621
|
-
var
|
|
5630
|
+
var kSender = Symbol("kSender");
|
|
5622
5631
|
var WebSocketHandler = class {
|
|
5623
5632
|
constructor(url) {
|
|
5624
5633
|
this.url = url;
|
|
5625
5634
|
this[kEmitter] = new Emitter();
|
|
5635
|
+
this.callFrame = getCallFrame(new Error());
|
|
5626
5636
|
}
|
|
5637
|
+
callFrame;
|
|
5627
5638
|
[kEmitter];
|
|
5628
5639
|
parse(args) {
|
|
5629
5640
|
const connection = args.event.data;
|
|
@@ -5637,19 +5648,13 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5637
5648
|
}
|
|
5638
5649
|
async [kDispatchEvent](event) {
|
|
5639
5650
|
const parsedResult = this.parse({ event });
|
|
5640
|
-
const shouldIntercept = this.predicate({ event, parsedResult });
|
|
5641
|
-
if (!shouldIntercept) {
|
|
5642
|
-
return;
|
|
5643
|
-
}
|
|
5644
|
-
if (!Reflect.get(event, kDefaultPrevented)) {
|
|
5645
|
-
Reflect.set(event, kDefaultPrevented, true);
|
|
5646
|
-
}
|
|
5647
5651
|
const connection = event.data;
|
|
5648
|
-
|
|
5652
|
+
const resolvedConnection = {
|
|
5649
5653
|
client: connection.client,
|
|
5650
5654
|
server: connection.server,
|
|
5651
5655
|
params: parsedResult.match.params || {}
|
|
5652
|
-
}
|
|
5656
|
+
};
|
|
5657
|
+
this[kEmitter].emit("connection", resolvedConnection);
|
|
5653
5658
|
}
|
|
5654
5659
|
};
|
|
5655
5660
|
|
|
@@ -5959,16 +5964,11 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
5959
5964
|
return transformedResponse;
|
|
5960
5965
|
}
|
|
5961
5966
|
|
|
5962
|
-
// src/core/utils/internal/randomId.ts
|
|
5963
|
-
function randomId() {
|
|
5964
|
-
return Math.random().toString(16).slice(2);
|
|
5965
|
-
}
|
|
5966
|
-
|
|
5967
5967
|
// src/core/getResponse.ts
|
|
5968
5968
|
var getResponse = async (handlers, request) => {
|
|
5969
5969
|
const result = await executeHandlers({
|
|
5970
5970
|
request,
|
|
5971
|
-
requestId:
|
|
5971
|
+
requestId: createRequestId(),
|
|
5972
5972
|
handlers
|
|
5973
5973
|
});
|
|
5974
5974
|
return result?.response;
|
|
@@ -5996,7 +5996,9 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
5996
5996
|
});
|
|
5997
5997
|
}
|
|
5998
5998
|
if (typeof document !== "undefined") {
|
|
5999
|
-
const responseCookies =
|
|
5999
|
+
const responseCookies = Headers2.prototype.getSetCookie.call(
|
|
6000
|
+
init.headers
|
|
6001
|
+
);
|
|
6000
6002
|
for (const cookieString of responseCookies) {
|
|
6001
6003
|
document.cookie = cookieString;
|
|
6002
6004
|
}
|
|
@@ -6141,7 +6143,12 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
6141
6143
|
|
|
6142
6144
|
// src/core/bypass.ts
|
|
6143
6145
|
function bypass(input, init) {
|
|
6144
|
-
const request =
|
|
6146
|
+
const request = new Request(
|
|
6147
|
+
// If given a Request instance, clone it not to exhaust
|
|
6148
|
+
// the original request's body.
|
|
6149
|
+
input instanceof Request ? input.clone() : input,
|
|
6150
|
+
init
|
|
6151
|
+
);
|
|
6145
6152
|
invariant(
|
|
6146
6153
|
!request.bodyUsed,
|
|
6147
6154
|
'Failed to create a bypassed request to "%s %s": given request instance already has its body read. Make sure to clone the intercepted request if you wish to read its body before bypassing it.',
|
|
@@ -6343,7 +6350,7 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
6343
6350
|
context.emitter,
|
|
6344
6351
|
{
|
|
6345
6352
|
onPassthroughResponse() {
|
|
6346
|
-
messageChannel.postMessage("
|
|
6353
|
+
messageChannel.postMessage("PASSTHROUGH");
|
|
6347
6354
|
},
|
|
6348
6355
|
async onMockedResponse(response, { handler, parsedResult }) {
|
|
6349
6356
|
const responseClone = response.clone();
|
|
@@ -6407,18 +6414,21 @@ This exception has been gracefully handled as a 500 response, however, it's stro
|
|
|
6407
6414
|
};
|
|
6408
6415
|
};
|
|
6409
6416
|
|
|
6410
|
-
// src/browser/utils/
|
|
6411
|
-
async function
|
|
6417
|
+
// src/browser/utils/checkWorkerIntegrity.ts
|
|
6418
|
+
async function checkWorkerIntegrity(context) {
|
|
6412
6419
|
context.workerChannel.send("INTEGRITY_CHECK_REQUEST");
|
|
6413
|
-
const { payload
|
|
6414
|
-
|
|
6415
|
-
|
|
6416
|
-
|
|
6417
|
-
|
|
6418
|
-
|
|
6420
|
+
const { payload } = await context.events.once("INTEGRITY_CHECK_RESPONSE");
|
|
6421
|
+
if (payload.checksum !== "26357c79639bfa20d64c0efca2a87423") {
|
|
6422
|
+
devUtils.warn(
|
|
6423
|
+
`The currently registered Service Worker has been generated by a different version of MSW (${payload.packageVersion}) and may not be fully compatible with the installed version.
|
|
6424
|
+
|
|
6425
|
+
It's recommended you update your worker script by running this command:
|
|
6426
|
+
|
|
6427
|
+
\u2022 npx msw init <PUBLIC_DIR>
|
|
6428
|
+
|
|
6429
|
+
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.`
|
|
6419
6430
|
);
|
|
6420
6431
|
}
|
|
6421
|
-
return serviceWorker;
|
|
6422
6432
|
}
|
|
6423
6433
|
|
|
6424
6434
|
// src/browser/setupWorker/start/createResponseListener.ts
|
|
@@ -6514,19 +6524,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6514
6524
|
}
|
|
6515
6525
|
window.clearInterval(context.keepAliveInterval);
|
|
6516
6526
|
});
|
|
6517
|
-
|
|
6518
|
-
(
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6522
|
-
|
|
6523
|
-
The mocking is still enabled, but it's highly recommended that you update your Service Worker by running:
|
|
6524
|
-
|
|
6525
|
-
$ npx msw init <PUBLIC_DIR>
|
|
6526
|
-
|
|
6527
|
-
This is necessary to ensure that the Service Worker is in sync with the library to guarantee its stability.
|
|
6528
|
-
If this message still persists after updating, please report an issue: https://github.com/open-draft/msw/issues `);
|
|
6529
|
-
}
|
|
6527
|
+
await checkWorkerIntegrity(context).catch((error3) => {
|
|
6528
|
+
devUtils.error(
|
|
6529
|
+
"Error while checking the worker script integrity. Please report this on GitHub (https://github.com/mswjs/msw/issues), including the original error below."
|
|
6530
|
+
);
|
|
6531
|
+
console.error(error3);
|
|
6532
|
+
});
|
|
6530
6533
|
context.keepAliveInterval = window.setInterval(
|
|
6531
6534
|
() => context.workerChannel.send("KEEPALIVE_REQUEST"),
|
|
6532
6535
|
5e3
|
|
@@ -6590,19 +6593,22 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6590
6593
|
|
|
6591
6594
|
// src/core/utils/internal/mergeRight.ts
|
|
6592
6595
|
function mergeRight(left, right) {
|
|
6593
|
-
return Object.entries(right).reduce(
|
|
6594
|
-
|
|
6595
|
-
|
|
6596
|
-
|
|
6596
|
+
return Object.entries(right).reduce(
|
|
6597
|
+
(result, [key, rightValue]) => {
|
|
6598
|
+
const leftValue = result[key];
|
|
6599
|
+
if (Array.isArray(leftValue) && Array.isArray(rightValue)) {
|
|
6600
|
+
result[key] = leftValue.concat(rightValue);
|
|
6601
|
+
return result;
|
|
6602
|
+
}
|
|
6603
|
+
if (isObject(leftValue) && isObject(rightValue)) {
|
|
6604
|
+
result[key] = mergeRight(leftValue, rightValue);
|
|
6605
|
+
return result;
|
|
6606
|
+
}
|
|
6607
|
+
result[key] = rightValue;
|
|
6597
6608
|
return result;
|
|
6598
|
-
}
|
|
6599
|
-
|
|
6600
|
-
|
|
6601
|
-
return result;
|
|
6602
|
-
}
|
|
6603
|
-
result[key] = rightValue;
|
|
6604
|
-
return result;
|
|
6605
|
-
}, Object.assign({}, left));
|
|
6609
|
+
},
|
|
6610
|
+
Object.assign({}, left)
|
|
6611
|
+
);
|
|
6606
6612
|
}
|
|
6607
6613
|
|
|
6608
6614
|
// src/browser/setupWorker/start/utils/prepareStartHandler.ts
|
|
@@ -6685,7 +6691,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6685
6691
|
}
|
|
6686
6692
|
};
|
|
6687
6693
|
|
|
6688
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
6694
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-OUWBQF3Z.mjs
|
|
6689
6695
|
var RequestController = class {
|
|
6690
6696
|
constructor(request) {
|
|
6691
6697
|
this.request = request;
|
|
@@ -6723,16 +6729,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6723
6729
|
}
|
|
6724
6730
|
}
|
|
6725
6731
|
|
|
6726
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
6727
|
-
function uuidv4() {
|
|
6728
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
6729
|
-
const r = Math.random() * 16 | 0;
|
|
6730
|
-
const v = c == "x" ? r : r & 3 | 8;
|
|
6731
|
-
return v.toString(16);
|
|
6732
|
-
});
|
|
6733
|
-
}
|
|
6734
|
-
|
|
6735
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.8/node_modules/@mswjs/interceptors/lib/browser/chunk-65OQZE6W.mjs
|
|
6732
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-3FNUI33J.mjs
|
|
6736
6733
|
function isPropertyAccessible2(obj, key) {
|
|
6737
6734
|
try {
|
|
6738
6735
|
obj[key];
|
|
@@ -6756,7 +6753,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6756
6753
|
checkEnvironment() {
|
|
6757
6754
|
return typeof globalThis !== "undefined" && typeof globalThis.fetch !== "undefined";
|
|
6758
6755
|
}
|
|
6759
|
-
setup() {
|
|
6756
|
+
async setup() {
|
|
6760
6757
|
const pureFetch = globalThis.fetch;
|
|
6761
6758
|
invariant(
|
|
6762
6759
|
!pureFetch[IS_PATCHED_MODULE],
|
|
@@ -6764,7 +6761,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6764
6761
|
);
|
|
6765
6762
|
globalThis.fetch = async (input, init) => {
|
|
6766
6763
|
var _a2;
|
|
6767
|
-
const requestId =
|
|
6764
|
+
const requestId = createRequestId();
|
|
6768
6765
|
const resolvedInput = typeof input === "string" && typeof location !== "undefined" && !canParseUrl(input) ? new URL(input, location.origin) : input;
|
|
6769
6766
|
const request = new Request(resolvedInput, init);
|
|
6770
6767
|
this.logger.info("[%s] %s", request.method, request.url);
|
|
@@ -6879,7 +6876,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
6879
6876
|
});
|
|
6880
6877
|
}
|
|
6881
6878
|
|
|
6882
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
6879
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/chunk-VYFS2IF2.mjs
|
|
6883
6880
|
function concatArrayBuffer(left, right) {
|
|
6884
6881
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
6885
6882
|
result.set(left, 0);
|
|
@@ -7073,7 +7070,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7073
7070
|
this.method = "GET";
|
|
7074
7071
|
this.url = null;
|
|
7075
7072
|
this.events = /* @__PURE__ */ new Map();
|
|
7076
|
-
this.requestId =
|
|
7073
|
+
this.requestId = createRequestId();
|
|
7077
7074
|
this.requestHeaders = new Headers();
|
|
7078
7075
|
this.responseBuffer = new Uint8Array();
|
|
7079
7076
|
this.request = createProxy(initialRequest, {
|
|
@@ -7155,7 +7152,10 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7155
7152
|
this.request.readyState
|
|
7156
7153
|
);
|
|
7157
7154
|
if (IS_NODE2) {
|
|
7158
|
-
this.request.setRequestHeader(
|
|
7155
|
+
this.request.setRequestHeader(
|
|
7156
|
+
INTERNAL_REQUEST_ID_HEADER_NAME,
|
|
7157
|
+
this.requestId
|
|
7158
|
+
);
|
|
7159
7159
|
}
|
|
7160
7160
|
return invoke();
|
|
7161
7161
|
}
|
|
@@ -7701,32 +7701,39 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7701
7701
|
}
|
|
7702
7702
|
}
|
|
7703
7703
|
|
|
7704
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.26.
|
|
7704
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.26.15/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
7705
7705
|
function bindEvent(target, event) {
|
|
7706
|
-
Object.
|
|
7707
|
-
|
|
7708
|
-
|
|
7709
|
-
|
|
7706
|
+
Object.defineProperties(event, {
|
|
7707
|
+
target: {
|
|
7708
|
+
value: target,
|
|
7709
|
+
enumerable: true,
|
|
7710
|
+
writable: true
|
|
7711
|
+
},
|
|
7712
|
+
currentTarget: {
|
|
7713
|
+
value: target,
|
|
7714
|
+
enumerable: true,
|
|
7715
|
+
writable: true
|
|
7716
|
+
}
|
|
7710
7717
|
});
|
|
7711
7718
|
return event;
|
|
7712
7719
|
}
|
|
7713
7720
|
var kCancelable = Symbol("kCancelable");
|
|
7714
|
-
var
|
|
7721
|
+
var kDefaultPrevented = Symbol("kDefaultPrevented");
|
|
7715
7722
|
var CancelableMessageEvent = class extends MessageEvent {
|
|
7716
7723
|
constructor(type, init) {
|
|
7717
7724
|
super(type, init);
|
|
7718
7725
|
this[kCancelable] = !!init.cancelable;
|
|
7719
|
-
this[
|
|
7726
|
+
this[kDefaultPrevented] = false;
|
|
7720
7727
|
}
|
|
7721
7728
|
get cancelable() {
|
|
7722
7729
|
return this[kCancelable];
|
|
7723
7730
|
}
|
|
7724
7731
|
get defaultPrevented() {
|
|
7725
|
-
return this[
|
|
7732
|
+
return this[kDefaultPrevented];
|
|
7726
7733
|
}
|
|
7727
7734
|
preventDefault() {
|
|
7728
|
-
if (this.cancelable && !this[
|
|
7729
|
-
this[
|
|
7735
|
+
if (this.cancelable && !this[kDefaultPrevented]) {
|
|
7736
|
+
this[kDefaultPrevented] = true;
|
|
7730
7737
|
}
|
|
7731
7738
|
}
|
|
7732
7739
|
};
|
|
@@ -7743,7 +7750,7 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7743
7750
|
constructor(socket, transport) {
|
|
7744
7751
|
this.socket = socket;
|
|
7745
7752
|
this.transport = transport;
|
|
7746
|
-
this.id =
|
|
7753
|
+
this.id = createRequestId();
|
|
7747
7754
|
this.url = new URL(socket.url);
|
|
7748
7755
|
this[kEmitter2] = new EventTarget();
|
|
7749
7756
|
this.transport.onOutgoing = (data) => {
|
|
@@ -7760,8 +7767,8 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7760
7767
|
/**
|
|
7761
7768
|
* Listen for the outgoing events from the connected WebSocket client.
|
|
7762
7769
|
*/
|
|
7763
|
-
addEventListener(
|
|
7764
|
-
this[kEmitter2].addEventListener(
|
|
7770
|
+
addEventListener(type, listener, options) {
|
|
7771
|
+
this[kEmitter2].addEventListener(type, listener, options);
|
|
7765
7772
|
}
|
|
7766
7773
|
/**
|
|
7767
7774
|
* Removes the listener for the given event.
|
|
@@ -7788,129 +7795,6 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
7788
7795
|
this.transport.close(code, reason);
|
|
7789
7796
|
}
|
|
7790
7797
|
};
|
|
7791
|
-
var kEmitter22 = Symbol("kEmitter");
|
|
7792
|
-
var WebSocketServerConnection = class {
|
|
7793
|
-
constructor(socket, transport, createConnection) {
|
|
7794
|
-
this.socket = socket;
|
|
7795
|
-
this.transport = transport;
|
|
7796
|
-
this.createConnection = createConnection;
|
|
7797
|
-
this[kEmitter22] = new EventTarget();
|
|
7798
|
-
this.transport.onIncoming = (event) => {
|
|
7799
|
-
const messageEvent = bindEvent(
|
|
7800
|
-
this.realWebSocket,
|
|
7801
|
-
new CancelableMessageEvent("message", {
|
|
7802
|
-
data: event.data,
|
|
7803
|
-
origin: event.origin,
|
|
7804
|
-
cancelable: true
|
|
7805
|
-
})
|
|
7806
|
-
);
|
|
7807
|
-
this[kEmitter22].dispatchEvent(messageEvent);
|
|
7808
|
-
if (!messageEvent.defaultPrevented) {
|
|
7809
|
-
this.socket.dispatchEvent(
|
|
7810
|
-
bindEvent(
|
|
7811
|
-
/**
|
|
7812
|
-
* @note Bind the forwarded original server events
|
|
7813
|
-
* to the mock WebSocket instance so it would
|
|
7814
|
-
* dispatch them straight away.
|
|
7815
|
-
*/
|
|
7816
|
-
this.socket,
|
|
7817
|
-
// Clone the message event again to prevent
|
|
7818
|
-
// the "already being dispatched" exception.
|
|
7819
|
-
new MessageEvent("message", {
|
|
7820
|
-
data: event.data,
|
|
7821
|
-
origin: event.origin
|
|
7822
|
-
})
|
|
7823
|
-
)
|
|
7824
|
-
);
|
|
7825
|
-
}
|
|
7826
|
-
};
|
|
7827
|
-
}
|
|
7828
|
-
/**
|
|
7829
|
-
* Server ready state.
|
|
7830
|
-
* Proxies the ready state of the original WebSocket instance,
|
|
7831
|
-
* if set. If the original connection hasn't been established,
|
|
7832
|
-
* defaults to `-1`.
|
|
7833
|
-
*/
|
|
7834
|
-
get readyState() {
|
|
7835
|
-
if (this.realWebSocket) {
|
|
7836
|
-
return this.realWebSocket.readyState;
|
|
7837
|
-
}
|
|
7838
|
-
return -1;
|
|
7839
|
-
}
|
|
7840
|
-
/**
|
|
7841
|
-
* Open connection to the original WebSocket server.
|
|
7842
|
-
*/
|
|
7843
|
-
connect() {
|
|
7844
|
-
invariant(
|
|
7845
|
-
this.readyState === -1,
|
|
7846
|
-
'Failed to call "connect()" on the original WebSocket instance: the connection already open'
|
|
7847
|
-
);
|
|
7848
|
-
const ws2 = this.createConnection();
|
|
7849
|
-
ws2.binaryType = this.socket.binaryType;
|
|
7850
|
-
this.socket.addEventListener(
|
|
7851
|
-
"close",
|
|
7852
|
-
(event) => {
|
|
7853
|
-
ws2.close(event.code, event.reason);
|
|
7854
|
-
},
|
|
7855
|
-
{ once: true }
|
|
7856
|
-
);
|
|
7857
|
-
ws2.addEventListener("message", (event) => {
|
|
7858
|
-
this.transport.onIncoming(event);
|
|
7859
|
-
});
|
|
7860
|
-
ws2.addEventListener("error", () => {
|
|
7861
|
-
this.socket.dispatchEvent(bindEvent(this.socket, new Event("error")));
|
|
7862
|
-
});
|
|
7863
|
-
this.realWebSocket = ws2;
|
|
7864
|
-
}
|
|
7865
|
-
/**
|
|
7866
|
-
* Listen for the incoming events from the original WebSocket server.
|
|
7867
|
-
*/
|
|
7868
|
-
addEventListener(event, listener, options) {
|
|
7869
|
-
this[kEmitter22].addEventListener(
|
|
7870
|
-
event,
|
|
7871
|
-
listener.bind(this.realWebSocket),
|
|
7872
|
-
options
|
|
7873
|
-
);
|
|
7874
|
-
}
|
|
7875
|
-
/**
|
|
7876
|
-
* Removes the listener for the given event.
|
|
7877
|
-
*/
|
|
7878
|
-
removeEventListener(event, listener, options) {
|
|
7879
|
-
this[kEmitter22].removeEventListener(
|
|
7880
|
-
event,
|
|
7881
|
-
listener,
|
|
7882
|
-
options
|
|
7883
|
-
);
|
|
7884
|
-
}
|
|
7885
|
-
/**
|
|
7886
|
-
* Send data to the original WebSocket server.
|
|
7887
|
-
* @example
|
|
7888
|
-
* server.send('hello')
|
|
7889
|
-
* server.send(new Blob(['hello']))
|
|
7890
|
-
* server.send(new TextEncoder().encode('hello'))
|
|
7891
|
-
*/
|
|
7892
|
-
send(data) {
|
|
7893
|
-
const { realWebSocket } = this;
|
|
7894
|
-
invariant(
|
|
7895
|
-
realWebSocket,
|
|
7896
|
-
'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "await server.connect()"?',
|
|
7897
|
-
this.socket.url
|
|
7898
|
-
);
|
|
7899
|
-
if (realWebSocket.readyState === realWebSocket.CONNECTING) {
|
|
7900
|
-
realWebSocket.addEventListener(
|
|
7901
|
-
"open",
|
|
7902
|
-
() => {
|
|
7903
|
-
realWebSocket.send(data);
|
|
7904
|
-
},
|
|
7905
|
-
{ once: true }
|
|
7906
|
-
);
|
|
7907
|
-
return;
|
|
7908
|
-
}
|
|
7909
|
-
realWebSocket.send(data);
|
|
7910
|
-
}
|
|
7911
|
-
};
|
|
7912
|
-
var WebSocketTransport = class {
|
|
7913
|
-
};
|
|
7914
7798
|
var WEBSOCKET_CLOSE_CODE_RANGE_ERROR = "InvalidAccessError: close code out of user configurable range";
|
|
7915
7799
|
var kOnSend = Symbol("kOnSend");
|
|
7916
7800
|
var kClose = Symbol("kClose");
|
|
@@ -8057,6 +7941,176 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
8057
7941
|
}
|
|
8058
7942
|
return data.byteLength;
|
|
8059
7943
|
}
|
|
7944
|
+
var kEmitter22 = Symbol("kEmitter");
|
|
7945
|
+
var WebSocketServerConnection = class {
|
|
7946
|
+
constructor(socket, transport, createConnection) {
|
|
7947
|
+
this.socket = socket;
|
|
7948
|
+
this.transport = transport;
|
|
7949
|
+
this.createConnection = createConnection;
|
|
7950
|
+
this[kEmitter22] = new EventTarget();
|
|
7951
|
+
this.mockCloseController = new AbortController();
|
|
7952
|
+
this.transport.onIncoming = (event) => {
|
|
7953
|
+
const messageEvent = bindEvent(
|
|
7954
|
+
this.realWebSocket,
|
|
7955
|
+
new CancelableMessageEvent("message", {
|
|
7956
|
+
data: event.data,
|
|
7957
|
+
origin: event.origin,
|
|
7958
|
+
cancelable: true
|
|
7959
|
+
})
|
|
7960
|
+
);
|
|
7961
|
+
this[kEmitter22].dispatchEvent(messageEvent);
|
|
7962
|
+
if (!messageEvent.defaultPrevented) {
|
|
7963
|
+
this.socket.dispatchEvent(
|
|
7964
|
+
bindEvent(
|
|
7965
|
+
/**
|
|
7966
|
+
* @note Bind the forwarded original server events
|
|
7967
|
+
* to the mock WebSocket instance so it would
|
|
7968
|
+
* dispatch them straight away.
|
|
7969
|
+
*/
|
|
7970
|
+
this.socket,
|
|
7971
|
+
// Clone the message event again to prevent
|
|
7972
|
+
// the "already being dispatched" exception.
|
|
7973
|
+
new MessageEvent("message", {
|
|
7974
|
+
data: event.data,
|
|
7975
|
+
origin: event.origin
|
|
7976
|
+
})
|
|
7977
|
+
)
|
|
7978
|
+
);
|
|
7979
|
+
}
|
|
7980
|
+
};
|
|
7981
|
+
}
|
|
7982
|
+
/**
|
|
7983
|
+
* Server ready state.
|
|
7984
|
+
* Proxies the ready state of the original WebSocket instance,
|
|
7985
|
+
* if set. If the original connection hasn't been established,
|
|
7986
|
+
* defaults to `-1`.
|
|
7987
|
+
*/
|
|
7988
|
+
get readyState() {
|
|
7989
|
+
if (this.realWebSocket) {
|
|
7990
|
+
return this.realWebSocket.readyState;
|
|
7991
|
+
}
|
|
7992
|
+
return -1;
|
|
7993
|
+
}
|
|
7994
|
+
/**
|
|
7995
|
+
* Open connection to the original WebSocket server.
|
|
7996
|
+
*/
|
|
7997
|
+
connect() {
|
|
7998
|
+
invariant(
|
|
7999
|
+
!this.realWebSocket || this.realWebSocket.readyState !== WebSocket.OPEN,
|
|
8000
|
+
'Failed to call "connect()" on the original WebSocket instance: the connection already open'
|
|
8001
|
+
);
|
|
8002
|
+
const realWebSocket = this.createConnection();
|
|
8003
|
+
realWebSocket.binaryType = this.socket.binaryType;
|
|
8004
|
+
realWebSocket.addEventListener(
|
|
8005
|
+
"open",
|
|
8006
|
+
(event) => {
|
|
8007
|
+
this[kEmitter22].dispatchEvent(
|
|
8008
|
+
bindEvent(this.realWebSocket, new Event("open", event))
|
|
8009
|
+
);
|
|
8010
|
+
},
|
|
8011
|
+
{ once: true }
|
|
8012
|
+
);
|
|
8013
|
+
realWebSocket.addEventListener("message", (event) => {
|
|
8014
|
+
this.transport.onIncoming(event);
|
|
8015
|
+
});
|
|
8016
|
+
this.socket.addEventListener("close", this.handleMockClose.bind(this), {
|
|
8017
|
+
signal: this.mockCloseController.signal
|
|
8018
|
+
});
|
|
8019
|
+
realWebSocket.addEventListener("close", this.handleRealClose.bind(this));
|
|
8020
|
+
realWebSocket.addEventListener("error", () => {
|
|
8021
|
+
this.socket.dispatchEvent(bindEvent(this.socket, new Event("error")));
|
|
8022
|
+
});
|
|
8023
|
+
this.realWebSocket = realWebSocket;
|
|
8024
|
+
}
|
|
8025
|
+
/**
|
|
8026
|
+
* Listen for the incoming events from the original WebSocket server.
|
|
8027
|
+
*/
|
|
8028
|
+
addEventListener(event, listener, options) {
|
|
8029
|
+
this[kEmitter22].addEventListener(
|
|
8030
|
+
event,
|
|
8031
|
+
listener.bind(this.realWebSocket),
|
|
8032
|
+
options
|
|
8033
|
+
);
|
|
8034
|
+
}
|
|
8035
|
+
/**
|
|
8036
|
+
* Remove the listener for the given event.
|
|
8037
|
+
*/
|
|
8038
|
+
removeEventListener(event, listener, options) {
|
|
8039
|
+
this[kEmitter22].removeEventListener(
|
|
8040
|
+
event,
|
|
8041
|
+
listener,
|
|
8042
|
+
options
|
|
8043
|
+
);
|
|
8044
|
+
}
|
|
8045
|
+
/**
|
|
8046
|
+
* Send data to the original WebSocket server.
|
|
8047
|
+
* @example
|
|
8048
|
+
* server.send('hello')
|
|
8049
|
+
* server.send(new Blob(['hello']))
|
|
8050
|
+
* server.send(new TextEncoder().encode('hello'))
|
|
8051
|
+
*/
|
|
8052
|
+
send(data) {
|
|
8053
|
+
const { realWebSocket } = this;
|
|
8054
|
+
invariant(
|
|
8055
|
+
realWebSocket,
|
|
8056
|
+
'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
8057
|
+
this.socket.url
|
|
8058
|
+
);
|
|
8059
|
+
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
8060
|
+
return;
|
|
8061
|
+
}
|
|
8062
|
+
if (realWebSocket.readyState === WebSocket.CONNECTING) {
|
|
8063
|
+
realWebSocket.addEventListener(
|
|
8064
|
+
"open",
|
|
8065
|
+
() => {
|
|
8066
|
+
realWebSocket.send(data);
|
|
8067
|
+
},
|
|
8068
|
+
{ once: true }
|
|
8069
|
+
);
|
|
8070
|
+
return;
|
|
8071
|
+
}
|
|
8072
|
+
realWebSocket.send(data);
|
|
8073
|
+
}
|
|
8074
|
+
/**
|
|
8075
|
+
* Close the actual server connection.
|
|
8076
|
+
*/
|
|
8077
|
+
close() {
|
|
8078
|
+
const { realWebSocket } = this;
|
|
8079
|
+
invariant(
|
|
8080
|
+
realWebSocket,
|
|
8081
|
+
'Failed to close server connection for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
8082
|
+
this.socket.url
|
|
8083
|
+
);
|
|
8084
|
+
realWebSocket.removeEventListener("close", this.handleRealClose);
|
|
8085
|
+
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
8086
|
+
return;
|
|
8087
|
+
}
|
|
8088
|
+
realWebSocket.close();
|
|
8089
|
+
queueMicrotask(() => {
|
|
8090
|
+
this[kEmitter22].dispatchEvent(
|
|
8091
|
+
bindEvent(this.realWebSocket, new CloseEvent("close"))
|
|
8092
|
+
);
|
|
8093
|
+
});
|
|
8094
|
+
}
|
|
8095
|
+
handleMockClose(_event) {
|
|
8096
|
+
if (this.realWebSocket) {
|
|
8097
|
+
this.realWebSocket.close();
|
|
8098
|
+
}
|
|
8099
|
+
}
|
|
8100
|
+
handleRealClose(event) {
|
|
8101
|
+
this.mockCloseController.abort();
|
|
8102
|
+
const closeEvent = bindEvent(
|
|
8103
|
+
this.realWebSocket,
|
|
8104
|
+
new CloseEvent("close", event)
|
|
8105
|
+
);
|
|
8106
|
+
this[kEmitter22].dispatchEvent(closeEvent);
|
|
8107
|
+
if (!closeEvent.defaultPrevented) {
|
|
8108
|
+
this.socket[kClose](event.code, event.reason);
|
|
8109
|
+
}
|
|
8110
|
+
}
|
|
8111
|
+
};
|
|
8112
|
+
var WebSocketTransport = class {
|
|
8113
|
+
};
|
|
8060
8114
|
var WebSocketClassTransport = class extends WebSocketTransport {
|
|
8061
8115
|
constructor(socket) {
|
|
8062
8116
|
super();
|
|
@@ -8139,29 +8193,32 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
8139
8193
|
var webSocketInterceptor = new WebSocketInterceptor();
|
|
8140
8194
|
|
|
8141
8195
|
// src/core/utils/handleWebSocketEvent.ts
|
|
8142
|
-
function handleWebSocketEvent(
|
|
8196
|
+
function handleWebSocketEvent(options) {
|
|
8143
8197
|
webSocketInterceptor.on("connection", (connection) => {
|
|
8144
|
-
const handlers =
|
|
8198
|
+
const handlers = options.getHandlers();
|
|
8145
8199
|
const connectionEvent = new MessageEvent("connection", {
|
|
8146
8200
|
data: connection
|
|
8147
|
-
/**
|
|
8148
|
-
* @note This message event should be marked as "cancelable"
|
|
8149
|
-
* to have its default prevented using "event.preventDefault()".
|
|
8150
|
-
* There's a bug in Node.js that breaks the "cancelable" flag.
|
|
8151
|
-
* @see https://github.com/nodejs/node/issues/51767
|
|
8152
|
-
*/
|
|
8153
|
-
});
|
|
8154
|
-
Object.defineProperty(connectionEvent, kDefaultPrevented, {
|
|
8155
|
-
enumerable: false,
|
|
8156
|
-
writable: true,
|
|
8157
|
-
value: false
|
|
8158
8201
|
});
|
|
8159
|
-
|
|
8160
|
-
|
|
8202
|
+
const matchingHandlers = handlers.filter(
|
|
8203
|
+
(handler) => {
|
|
8204
|
+
if (handler instanceof WebSocketHandler) {
|
|
8205
|
+
return handler.predicate({
|
|
8206
|
+
event: connectionEvent,
|
|
8207
|
+
parsedResult: handler.parse({
|
|
8208
|
+
event: connectionEvent
|
|
8209
|
+
})
|
|
8210
|
+
});
|
|
8211
|
+
}
|
|
8212
|
+
return false;
|
|
8213
|
+
}
|
|
8214
|
+
);
|
|
8215
|
+
if (matchingHandlers.length > 0) {
|
|
8216
|
+
options?.onMockedConnection(connection);
|
|
8217
|
+
for (const handler of matchingHandlers) {
|
|
8161
8218
|
handler[kDispatchEvent](connectionEvent);
|
|
8162
8219
|
}
|
|
8163
|
-
}
|
|
8164
|
-
|
|
8220
|
+
} else {
|
|
8221
|
+
options?.onPassthroughConnection(connection);
|
|
8165
8222
|
connection.server.connect();
|
|
8166
8223
|
connection.client.addEventListener("message", (event) => {
|
|
8167
8224
|
connection.server.send(event.data);
|
|
@@ -8170,6 +8227,217 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
8170
8227
|
});
|
|
8171
8228
|
}
|
|
8172
8229
|
|
|
8230
|
+
// src/core/ws/utils/getMessageLength.ts
|
|
8231
|
+
function getMessageLength(data) {
|
|
8232
|
+
if (data instanceof Blob) {
|
|
8233
|
+
return data.size;
|
|
8234
|
+
}
|
|
8235
|
+
if (data instanceof ArrayBuffer) {
|
|
8236
|
+
return data.byteLength;
|
|
8237
|
+
}
|
|
8238
|
+
return new Blob([data]).size;
|
|
8239
|
+
}
|
|
8240
|
+
|
|
8241
|
+
// src/core/ws/utils/truncateMessage.ts
|
|
8242
|
+
var MAX_LENGTH = 24;
|
|
8243
|
+
function truncateMessage(message3) {
|
|
8244
|
+
if (message3.length <= MAX_LENGTH) {
|
|
8245
|
+
return message3;
|
|
8246
|
+
}
|
|
8247
|
+
return `${message3.slice(0, MAX_LENGTH)}\u2026`;
|
|
8248
|
+
}
|
|
8249
|
+
|
|
8250
|
+
// src/core/ws/utils/getPublicData.ts
|
|
8251
|
+
async function getPublicData(data) {
|
|
8252
|
+
if (data instanceof Blob) {
|
|
8253
|
+
const text = await data.text();
|
|
8254
|
+
return `Blob(${truncateMessage(text)})`;
|
|
8255
|
+
}
|
|
8256
|
+
if (typeof data === "object" && "byteLength" in data) {
|
|
8257
|
+
const text = new TextDecoder().decode(data);
|
|
8258
|
+
return `ArrayBuffer(${truncateMessage(text)})`;
|
|
8259
|
+
}
|
|
8260
|
+
return truncateMessage(data);
|
|
8261
|
+
}
|
|
8262
|
+
|
|
8263
|
+
// src/core/ws/utils/attachWebSocketLogger.ts
|
|
8264
|
+
function attachWebSocketLogger(connection) {
|
|
8265
|
+
const { client, server } = connection;
|
|
8266
|
+
logConnectionOpen(client);
|
|
8267
|
+
client.addEventListener("message", (event) => {
|
|
8268
|
+
logOutgoingClientMessage(event);
|
|
8269
|
+
});
|
|
8270
|
+
client.addEventListener("close", (event) => {
|
|
8271
|
+
logConnectionClose(event);
|
|
8272
|
+
});
|
|
8273
|
+
client.socket.addEventListener("message", (event) => {
|
|
8274
|
+
logIncomingClientMessage(event);
|
|
8275
|
+
});
|
|
8276
|
+
client.socket.addEventListener("error", (event) => {
|
|
8277
|
+
logClientError(event);
|
|
8278
|
+
});
|
|
8279
|
+
client.send = new Proxy(client.send, {
|
|
8280
|
+
apply(target, thisArg, args) {
|
|
8281
|
+
const [data] = args;
|
|
8282
|
+
const messageEvent = new MessageEvent("message", { data });
|
|
8283
|
+
Object.defineProperties(messageEvent, {
|
|
8284
|
+
currentTarget: {
|
|
8285
|
+
enumerable: true,
|
|
8286
|
+
writable: false,
|
|
8287
|
+
value: client.socket
|
|
8288
|
+
},
|
|
8289
|
+
target: {
|
|
8290
|
+
enumerable: true,
|
|
8291
|
+
writable: false,
|
|
8292
|
+
value: client.socket
|
|
8293
|
+
}
|
|
8294
|
+
});
|
|
8295
|
+
logIncomingMockedClientMessage(messageEvent);
|
|
8296
|
+
return Reflect.apply(target, thisArg, args);
|
|
8297
|
+
}
|
|
8298
|
+
});
|
|
8299
|
+
server.addEventListener(
|
|
8300
|
+
"open",
|
|
8301
|
+
() => {
|
|
8302
|
+
server.addEventListener("message", (event) => {
|
|
8303
|
+
logIncomingServerMessage(event);
|
|
8304
|
+
});
|
|
8305
|
+
},
|
|
8306
|
+
{ once: true }
|
|
8307
|
+
);
|
|
8308
|
+
server.send = new Proxy(server.send, {
|
|
8309
|
+
apply(target, thisArg, args) {
|
|
8310
|
+
const [data] = args;
|
|
8311
|
+
const messageEvent = new MessageEvent("message", { data });
|
|
8312
|
+
Object.defineProperties(messageEvent, {
|
|
8313
|
+
currentTarget: {
|
|
8314
|
+
enumerable: true,
|
|
8315
|
+
writable: false,
|
|
8316
|
+
value: server["realWebSocket"]
|
|
8317
|
+
},
|
|
8318
|
+
target: {
|
|
8319
|
+
enumerable: true,
|
|
8320
|
+
writable: false,
|
|
8321
|
+
value: server["realWebSocket"]
|
|
8322
|
+
}
|
|
8323
|
+
});
|
|
8324
|
+
logOutgoingMockedClientMessage(messageEvent);
|
|
8325
|
+
return Reflect.apply(target, thisArg, args);
|
|
8326
|
+
}
|
|
8327
|
+
});
|
|
8328
|
+
}
|
|
8329
|
+
function logConnectionOpen(client) {
|
|
8330
|
+
const publicUrl = toPublicUrl(client.url);
|
|
8331
|
+
console.groupCollapsed(
|
|
8332
|
+
devUtils.formatMessage(`${getTimestamp()} %c\u25B8%c ${publicUrl}`),
|
|
8333
|
+
"color:blue",
|
|
8334
|
+
"color:inherit"
|
|
8335
|
+
);
|
|
8336
|
+
console.log("Client:", client.socket);
|
|
8337
|
+
console.groupEnd();
|
|
8338
|
+
}
|
|
8339
|
+
async function logOutgoingClientMessage(event) {
|
|
8340
|
+
const byteLength = getMessageLength(event.data);
|
|
8341
|
+
const publicData = await getPublicData(event.data);
|
|
8342
|
+
console.groupCollapsed(
|
|
8343
|
+
devUtils.formatMessage(
|
|
8344
|
+
`${getTimestamp({ milliseconds: true })} %c\u2191%c ${publicData} %c${byteLength}%c`
|
|
8345
|
+
),
|
|
8346
|
+
"color:green",
|
|
8347
|
+
"color:inherit",
|
|
8348
|
+
"color:gray;font-weight:normal",
|
|
8349
|
+
"color:inherit;font-weight:inherit"
|
|
8350
|
+
);
|
|
8351
|
+
console.log(event);
|
|
8352
|
+
console.groupEnd();
|
|
8353
|
+
}
|
|
8354
|
+
async function logOutgoingMockedClientMessage(event) {
|
|
8355
|
+
const byteLength = getMessageLength(event.data);
|
|
8356
|
+
const publicData = await getPublicData(event.data);
|
|
8357
|
+
console.groupCollapsed(
|
|
8358
|
+
devUtils.formatMessage(
|
|
8359
|
+
`${getTimestamp({ milliseconds: true })} %c\u21E1%c ${publicData} %c${byteLength}%c`
|
|
8360
|
+
),
|
|
8361
|
+
"color:orangered",
|
|
8362
|
+
"color:inherit",
|
|
8363
|
+
"color:gray;font-weight:normal",
|
|
8364
|
+
"color:inherit;font-weight:inherit"
|
|
8365
|
+
);
|
|
8366
|
+
console.log(event);
|
|
8367
|
+
console.groupEnd();
|
|
8368
|
+
}
|
|
8369
|
+
async function logIncomingClientMessage(event) {
|
|
8370
|
+
const byteLength = getMessageLength(event.data);
|
|
8371
|
+
const publicData = await getPublicData(event.data);
|
|
8372
|
+
console.groupCollapsed(
|
|
8373
|
+
devUtils.formatMessage(
|
|
8374
|
+
`${getTimestamp({ milliseconds: true })} %c\u2193%c ${publicData} %c${byteLength}%c`
|
|
8375
|
+
),
|
|
8376
|
+
"color:red",
|
|
8377
|
+
"color:inherit",
|
|
8378
|
+
"color:gray;font-weight:normal",
|
|
8379
|
+
"color:inherit;font-weight:inherit"
|
|
8380
|
+
);
|
|
8381
|
+
console.log(event);
|
|
8382
|
+
console.groupEnd();
|
|
8383
|
+
}
|
|
8384
|
+
async function logIncomingMockedClientMessage(event) {
|
|
8385
|
+
const byteLength = getMessageLength(event.data);
|
|
8386
|
+
const publicData = await getPublicData(event.data);
|
|
8387
|
+
console.groupCollapsed(
|
|
8388
|
+
devUtils.formatMessage(
|
|
8389
|
+
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8390
|
+
),
|
|
8391
|
+
"color:orangered",
|
|
8392
|
+
"color:inherit",
|
|
8393
|
+
"color:gray;font-weight:normal",
|
|
8394
|
+
"color:inherit;font-weight:inherit"
|
|
8395
|
+
);
|
|
8396
|
+
console.log(event);
|
|
8397
|
+
console.groupEnd();
|
|
8398
|
+
}
|
|
8399
|
+
function logConnectionClose(event) {
|
|
8400
|
+
const target = event.target;
|
|
8401
|
+
const publicUrl = toPublicUrl(target.url);
|
|
8402
|
+
console.groupCollapsed(
|
|
8403
|
+
devUtils.formatMessage(
|
|
8404
|
+
`${getTimestamp({ milliseconds: true })} %c\u25A0%c ${publicUrl}`
|
|
8405
|
+
),
|
|
8406
|
+
"color:blue",
|
|
8407
|
+
"color:inherit"
|
|
8408
|
+
);
|
|
8409
|
+
console.log(event);
|
|
8410
|
+
console.groupEnd();
|
|
8411
|
+
}
|
|
8412
|
+
async function logIncomingServerMessage(event) {
|
|
8413
|
+
const byteLength = getMessageLength(event.data);
|
|
8414
|
+
const publicData = await getPublicData(event.data);
|
|
8415
|
+
console.groupCollapsed(
|
|
8416
|
+
devUtils.formatMessage(
|
|
8417
|
+
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8418
|
+
),
|
|
8419
|
+
"color:orangered",
|
|
8420
|
+
"color:inherit",
|
|
8421
|
+
"color:gray;font-weight:normal",
|
|
8422
|
+
"color:inherit;font-weight:inherit"
|
|
8423
|
+
);
|
|
8424
|
+
console.log(event);
|
|
8425
|
+
console.groupEnd();
|
|
8426
|
+
}
|
|
8427
|
+
function logClientError(event) {
|
|
8428
|
+
const socket = event.target;
|
|
8429
|
+
const publicUrl = toPublicUrl(socket.url);
|
|
8430
|
+
console.groupCollapsed(
|
|
8431
|
+
devUtils.formatMessage(
|
|
8432
|
+
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
8433
|
+
),
|
|
8434
|
+
"color:red",
|
|
8435
|
+
"color:inherit"
|
|
8436
|
+
);
|
|
8437
|
+
console.log(event);
|
|
8438
|
+
console.groupEnd();
|
|
8439
|
+
}
|
|
8440
|
+
|
|
8173
8441
|
// src/browser/setupWorker/setupWorker.ts
|
|
8174
8442
|
var SetupWorkerApi = class extends SetupApi {
|
|
8175
8443
|
context;
|
|
@@ -8286,8 +8554,17 @@ If this message still persists after updating, please report an issue: https://g
|
|
|
8286
8554
|
DEFAULT_START_OPTIONS,
|
|
8287
8555
|
options
|
|
8288
8556
|
);
|
|
8289
|
-
handleWebSocketEvent(
|
|
8290
|
-
|
|
8557
|
+
handleWebSocketEvent({
|
|
8558
|
+
getHandlers: () => {
|
|
8559
|
+
return this.handlersController.currentHandlers();
|
|
8560
|
+
},
|
|
8561
|
+
onMockedConnection: (connection) => {
|
|
8562
|
+
if (!this.context.startOptions.quiet) {
|
|
8563
|
+
attachWebSocketLogger(connection);
|
|
8564
|
+
}
|
|
8565
|
+
},
|
|
8566
|
+
onPassthroughConnection() {
|
|
8567
|
+
}
|
|
8291
8568
|
});
|
|
8292
8569
|
webSocketInterceptor.apply();
|
|
8293
8570
|
this.subscriptions.push(() => {
|