msw 2.3.0-ws.rc-9 → 2.3.0-ws.rc-11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/index.js +15 -8
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +15 -8
- package/lib/browser/index.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/ws/WebSocketClientManager.d.mts +1 -3
- package/lib/core/ws/WebSocketClientManager.d.ts +1 -3
- package/lib/core/ws/WebSocketClientManager.js +1 -2
- package/lib/core/ws/WebSocketClientManager.js.map +1 -1
- package/lib/core/ws/WebSocketClientManager.mjs +1 -2
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientStore.d.mts +2 -2
- package/lib/core/ws/WebSocketClientStore.d.ts +2 -2
- package/lib/core/ws/WebSocketClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketClientStore.mjs.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.js +27 -6
- package/lib/core/ws/WebSocketIndexedDBClientStore.js.map +1 -1
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs +27 -6
- package/lib/core/ws/WebSocketIndexedDBClientStore.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.d.mts +2 -0
- package/lib/core/ws/handleWebSocketEvent.d.ts +2 -0
- package/lib/core/ws/handleWebSocketEvent.js +30 -13
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +32 -13
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.d.mts +2 -24
- package/lib/core/ws/utils/attachWebSocketLogger.d.ts +2 -24
- package/lib/core/ws/utils/attachWebSocketLogger.js +41 -60
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +41 -60
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -1
- package/lib/core/ws.js +1 -1
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs +1 -1
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +170 -110
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +10 -5
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +10 -5
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +10 -5
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +10 -5
- package/lib/node/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/browser/setupWorker/setupWorker.ts +5 -7
- package/src/browser/setupWorker/start/createRequestListener.ts +7 -1
- package/src/core/utils/handleRequest.ts +2 -1
- package/src/core/ws/WebSocketClientManager.ts +1 -5
- package/src/core/ws/WebSocketClientStore.ts +1 -1
- package/src/core/ws/WebSocketIndexedDBClientStore.ts +39 -6
- package/src/core/ws/handleWebSocketEvent.ts +40 -14
- package/src/core/ws/utils/attachWebSocketLogger.ts +45 -79
- package/src/core/ws.ts +1 -1
- package/src/node/SetupServerCommonApi.ts +17 -6
package/lib/iife/index.js
CHANGED
|
@@ -14412,7 +14412,7 @@ ${operationTypes.join("\n")}
|
|
|
14412
14412
|
return stringToRegexp(path, keys, options);
|
|
14413
14413
|
}
|
|
14414
14414
|
|
|
14415
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14415
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.1/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
|
|
14416
14416
|
var encoder = new TextEncoder();
|
|
14417
14417
|
function encodeBuffer(text) {
|
|
14418
14418
|
return encoder.encode(text);
|
|
@@ -14428,7 +14428,7 @@ ${operationTypes.join("\n")}
|
|
|
14428
14428
|
);
|
|
14429
14429
|
}
|
|
14430
14430
|
|
|
14431
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14431
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.1/node_modules/@mswjs/interceptors/lib/browser/chunk-XVPRNJO7.mjs
|
|
14432
14432
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
14433
14433
|
function isPropertyAccessible(obj, key) {
|
|
14434
14434
|
try {
|
|
@@ -14848,7 +14848,7 @@ ${operationTypes.join("\n")}
|
|
|
14848
14848
|
return message3.toString();
|
|
14849
14849
|
}
|
|
14850
14850
|
|
|
14851
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14851
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.1/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
14852
14852
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
14853
14853
|
function getGlobalSymbol(symbol) {
|
|
14854
14854
|
return (
|
|
@@ -14996,7 +14996,7 @@ ${operationTypes.join("\n")}
|
|
|
14996
14996
|
return Math.random().toString(16).slice(2);
|
|
14997
14997
|
}
|
|
14998
14998
|
|
|
14999
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
14999
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.1/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
15000
15000
|
var BatchInterceptor = class extends Interceptor {
|
|
15001
15001
|
constructor(options) {
|
|
15002
15002
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -28366,7 +28366,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28366
28366
|
async add(client) {
|
|
28367
28367
|
const promise = new DeferredPromise();
|
|
28368
28368
|
const store2 = await this.getStore();
|
|
28369
|
-
const request = store2.
|
|
28369
|
+
const request = store2.put({
|
|
28370
28370
|
id: client.id,
|
|
28371
28371
|
url: client.url.href
|
|
28372
28372
|
});
|
|
@@ -28374,7 +28374,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28374
28374
|
promise.resolve();
|
|
28375
28375
|
};
|
|
28376
28376
|
request.onerror = () => {
|
|
28377
|
-
|
|
28377
|
+
console.error(request.error);
|
|
28378
|
+
promise.reject(
|
|
28379
|
+
new Error(
|
|
28380
|
+
`Failed to add WebSocket client "${client.id}". There is likely an additional output above.`
|
|
28381
|
+
)
|
|
28382
|
+
);
|
|
28378
28383
|
};
|
|
28379
28384
|
return promise;
|
|
28380
28385
|
}
|
|
@@ -28386,7 +28391,12 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28386
28391
|
promise.resolve(request.result);
|
|
28387
28392
|
};
|
|
28388
28393
|
request.onerror = () => {
|
|
28389
|
-
|
|
28394
|
+
console.log(request.error);
|
|
28395
|
+
promise.reject(
|
|
28396
|
+
new Error(
|
|
28397
|
+
`Failed to get all WebSocket clients. There is likely an additional output above.`
|
|
28398
|
+
)
|
|
28399
|
+
);
|
|
28390
28400
|
};
|
|
28391
28401
|
return promise;
|
|
28392
28402
|
}
|
|
@@ -28400,9 +28410,10 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28400
28410
|
promise.resolve();
|
|
28401
28411
|
};
|
|
28402
28412
|
store2.transaction.onerror = () => {
|
|
28413
|
+
console.error(store2.transaction.error);
|
|
28403
28414
|
promise.reject(
|
|
28404
28415
|
new Error(
|
|
28405
|
-
`Failed to delete WebSocket clients [${clientIds.join(", ")}]
|
|
28416
|
+
`Failed to delete WebSocket clients [${clientIds.join(", ")}]. There is likely an additional output above.`
|
|
28406
28417
|
)
|
|
28407
28418
|
);
|
|
28408
28419
|
};
|
|
@@ -28427,11 +28438,21 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28427
28438
|
promise.resolve(db);
|
|
28428
28439
|
};
|
|
28429
28440
|
store2.transaction.onerror = () => {
|
|
28430
|
-
|
|
28441
|
+
console.error(store2.transaction.error);
|
|
28442
|
+
promise.reject(
|
|
28443
|
+
new Error(
|
|
28444
|
+
"Failed to create WebSocket client store. There is likely an additional output above."
|
|
28445
|
+
)
|
|
28446
|
+
);
|
|
28431
28447
|
};
|
|
28432
28448
|
};
|
|
28433
28449
|
request.onerror = () => {
|
|
28434
|
-
|
|
28450
|
+
console.error(request.error);
|
|
28451
|
+
promise.reject(
|
|
28452
|
+
new Error(
|
|
28453
|
+
"Failed to open an IndexedDB database. There is likely an additional output above."
|
|
28454
|
+
)
|
|
28455
|
+
);
|
|
28435
28456
|
};
|
|
28436
28457
|
return promise;
|
|
28437
28458
|
}
|
|
@@ -28443,9 +28464,8 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28443
28464
|
|
|
28444
28465
|
// src/core/ws/WebSocketClientManager.ts
|
|
28445
28466
|
var WebSocketClientManager = class {
|
|
28446
|
-
constructor(channel
|
|
28467
|
+
constructor(channel) {
|
|
28447
28468
|
this.channel = channel;
|
|
28448
|
-
this.url = url;
|
|
28449
28469
|
this.store = typeof indexedDB !== "undefined" ? new WebSocketIndexedDBClientStore() : new WebSocketMemoryClientStore();
|
|
28450
28470
|
this.runtimeClients = /* @__PURE__ */ new Map();
|
|
28451
28471
|
this.allClients = /* @__PURE__ */ new Set();
|
|
@@ -28581,7 +28601,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
28581
28601
|
"Expected a WebSocket server URL to be a valid path but got %s",
|
|
28582
28602
|
typeof url
|
|
28583
28603
|
);
|
|
28584
|
-
const clientManager = new WebSocketClientManager(webSocketChannel
|
|
28604
|
+
const clientManager = new WebSocketClientManager(webSocketChannel);
|
|
28585
28605
|
return {
|
|
28586
28606
|
get clients() {
|
|
28587
28607
|
return clientManager.clients;
|
|
@@ -29171,7 +29191,9 @@ Learn more about creating the Service Worker script: https://mswjs.io/docs/cli/i
|
|
|
29171
29191
|
await handleRequest(
|
|
29172
29192
|
request,
|
|
29173
29193
|
requestId,
|
|
29174
|
-
context.getRequestHandlers()
|
|
29194
|
+
context.getRequestHandlers().filter((handler) => {
|
|
29195
|
+
return handler instanceof HttpHandler || handler instanceof GraphQLHandler;
|
|
29196
|
+
}),
|
|
29175
29197
|
options,
|
|
29176
29198
|
context.emitter,
|
|
29177
29199
|
{
|
|
@@ -29453,7 +29475,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29453
29475
|
}
|
|
29454
29476
|
};
|
|
29455
29477
|
|
|
29456
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29478
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.1/node_modules/@mswjs/interceptors/lib/browser/chunk-THPGBWJQ.mjs
|
|
29457
29479
|
var InterceptorError = class extends Error {
|
|
29458
29480
|
constructor(message3) {
|
|
29459
29481
|
super(message3);
|
|
@@ -29621,7 +29643,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29621
29643
|
return false;
|
|
29622
29644
|
}
|
|
29623
29645
|
|
|
29624
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29646
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.1/node_modules/@mswjs/interceptors/lib/browser/chunk-G5SOR3ND.mjs
|
|
29625
29647
|
function canParseUrl(url) {
|
|
29626
29648
|
try {
|
|
29627
29649
|
new URL(url);
|
|
@@ -29818,7 +29840,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
29818
29840
|
var FetchInterceptor = _FetchInterceptor;
|
|
29819
29841
|
FetchInterceptor.symbol = Symbol("fetch");
|
|
29820
29842
|
|
|
29821
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
29843
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.1/node_modules/@mswjs/interceptors/lib/browser/chunk-SUQ32ZQK.mjs
|
|
29822
29844
|
function concatArrayBuffer(left, right) {
|
|
29823
29845
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
29824
29846
|
result.set(left, 0);
|
|
@@ -30689,7 +30711,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30689
30711
|
}
|
|
30690
30712
|
}
|
|
30691
30713
|
|
|
30692
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
30714
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.36.1/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
30693
30715
|
function bindEvent(target, event) {
|
|
30694
30716
|
Object.defineProperties(event, {
|
|
30695
30717
|
target: {
|
|
@@ -30739,6 +30761,30 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30739
30761
|
this.wasClean = init.wasClean === void 0 ? false : init.wasClean;
|
|
30740
30762
|
}
|
|
30741
30763
|
};
|
|
30764
|
+
var CancelableCloseEvent = class extends CloseEvent {
|
|
30765
|
+
constructor(type, init = {}) {
|
|
30766
|
+
super(type, init);
|
|
30767
|
+
this[kCancelable] = !!init.cancelable;
|
|
30768
|
+
this[kDefaultPrevented] = false;
|
|
30769
|
+
}
|
|
30770
|
+
get cancelable() {
|
|
30771
|
+
return this[kCancelable];
|
|
30772
|
+
}
|
|
30773
|
+
set cancelable(nextCancelable) {
|
|
30774
|
+
this[kCancelable] = nextCancelable;
|
|
30775
|
+
}
|
|
30776
|
+
get defaultPrevented() {
|
|
30777
|
+
return this[kDefaultPrevented];
|
|
30778
|
+
}
|
|
30779
|
+
set defaultPrevented(nextDefaultPrevented) {
|
|
30780
|
+
this[kDefaultPrevented] = nextDefaultPrevented;
|
|
30781
|
+
}
|
|
30782
|
+
preventDefault() {
|
|
30783
|
+
if (this.cancelable && !this[kDefaultPrevented]) {
|
|
30784
|
+
this[kDefaultPrevented] = true;
|
|
30785
|
+
}
|
|
30786
|
+
}
|
|
30787
|
+
};
|
|
30742
30788
|
var kEmitter2 = Symbol("kEmitter");
|
|
30743
30789
|
var kBoundListener = Symbol("kBoundListener");
|
|
30744
30790
|
var WebSocketClientConnection = class {
|
|
@@ -30957,21 +31003,22 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30957
31003
|
}
|
|
30958
31004
|
var kEmitter22 = Symbol("kEmitter");
|
|
30959
31005
|
var kBoundListener2 = Symbol("kBoundListener");
|
|
31006
|
+
var kSend = Symbol("kSend");
|
|
30960
31007
|
var WebSocketServerConnection = class {
|
|
30961
|
-
constructor(
|
|
30962
|
-
this.
|
|
31008
|
+
constructor(client, transport, createConnection) {
|
|
31009
|
+
this.client = client;
|
|
30963
31010
|
this.transport = transport;
|
|
30964
31011
|
this.createConnection = createConnection;
|
|
30965
31012
|
this[kEmitter22] = new EventTarget();
|
|
30966
31013
|
this.mockCloseController = new AbortController();
|
|
30967
31014
|
this.realCloseController = new AbortController();
|
|
30968
31015
|
this.transport.addEventListener("outgoing", (event) => {
|
|
30969
|
-
if (this.
|
|
31016
|
+
if (typeof this.realWebSocket === "undefined") {
|
|
30970
31017
|
return;
|
|
30971
31018
|
}
|
|
30972
31019
|
queueMicrotask(() => {
|
|
30973
31020
|
if (!event.defaultPrevented) {
|
|
30974
|
-
this
|
|
31021
|
+
this[kSend](event.data);
|
|
30975
31022
|
}
|
|
30976
31023
|
});
|
|
30977
31024
|
});
|
|
@@ -30981,16 +31028,15 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30981
31028
|
);
|
|
30982
31029
|
}
|
|
30983
31030
|
/**
|
|
30984
|
-
*
|
|
30985
|
-
*
|
|
30986
|
-
* if set. If the original connection hasn't been established,
|
|
30987
|
-
* defaults to `-1`.
|
|
31031
|
+
* The `WebSocket` instance connected to the original server.
|
|
31032
|
+
* Accessing this before calling `server.connect()` will throw.
|
|
30988
31033
|
*/
|
|
30989
|
-
get
|
|
30990
|
-
|
|
30991
|
-
|
|
30992
|
-
|
|
30993
|
-
|
|
31034
|
+
get socket() {
|
|
31035
|
+
invariant2(
|
|
31036
|
+
this.realWebSocket,
|
|
31037
|
+
'Cannot access "socket" on the original WebSocket server object: the connection is not open. Did you forget to call `server.connect()`?'
|
|
31038
|
+
);
|
|
31039
|
+
return this.realWebSocket;
|
|
30994
31040
|
}
|
|
30995
31041
|
/**
|
|
30996
31042
|
* Open connection to the original WebSocket server.
|
|
@@ -31001,7 +31047,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31001
31047
|
'Failed to call "connect()" on the original WebSocket instance: the connection already open'
|
|
31002
31048
|
);
|
|
31003
31049
|
const realWebSocket = this.createConnection();
|
|
31004
|
-
realWebSocket.binaryType = this.
|
|
31050
|
+
realWebSocket.binaryType = this.client.binaryType;
|
|
31005
31051
|
realWebSocket.addEventListener(
|
|
31006
31052
|
"open",
|
|
31007
31053
|
(event) => {
|
|
@@ -31022,7 +31068,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31022
31068
|
)
|
|
31023
31069
|
);
|
|
31024
31070
|
});
|
|
31025
|
-
this.
|
|
31071
|
+
this.client.addEventListener("close", this.handleMockClose.bind(this), {
|
|
31026
31072
|
signal: this.mockCloseController.signal
|
|
31027
31073
|
});
|
|
31028
31074
|
realWebSocket.addEventListener("close", this.handleRealClose.bind(this), {
|
|
@@ -31030,7 +31076,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31030
31076
|
});
|
|
31031
31077
|
realWebSocket.addEventListener("error", () => {
|
|
31032
31078
|
this[kEmitter22].dispatchEvent(bindEvent(realWebSocket, new Event("error")));
|
|
31033
|
-
this.
|
|
31079
|
+
this.client.dispatchEvent(bindEvent(this.client, new Event("error")));
|
|
31034
31080
|
});
|
|
31035
31081
|
this.realWebSocket = realWebSocket;
|
|
31036
31082
|
}
|
|
@@ -31038,7 +31084,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31038
31084
|
* Listen for the incoming events from the original WebSocket server.
|
|
31039
31085
|
*/
|
|
31040
31086
|
addEventListener(event, listener, options) {
|
|
31041
|
-
const boundListener = listener.bind(this.
|
|
31087
|
+
const boundListener = listener.bind(this.client);
|
|
31042
31088
|
Object.defineProperty(listener, kBoundListener2, {
|
|
31043
31089
|
value: boundListener,
|
|
31044
31090
|
enumerable: false
|
|
@@ -31067,11 +31113,14 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31067
31113
|
* server.send(new TextEncoder().encode('hello'))
|
|
31068
31114
|
*/
|
|
31069
31115
|
send(data) {
|
|
31116
|
+
this[kSend](data);
|
|
31117
|
+
}
|
|
31118
|
+
[(kEmitter22, kSend)](data) {
|
|
31070
31119
|
const { realWebSocket } = this;
|
|
31071
31120
|
invariant2(
|
|
31072
31121
|
realWebSocket,
|
|
31073
31122
|
'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
31074
|
-
this.
|
|
31123
|
+
this.client.url
|
|
31075
31124
|
);
|
|
31076
31125
|
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
31077
31126
|
return;
|
|
@@ -31096,7 +31145,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31096
31145
|
invariant2(
|
|
31097
31146
|
realWebSocket,
|
|
31098
31147
|
'Failed to close server connection for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
31099
|
-
this.
|
|
31148
|
+
this.client.url
|
|
31100
31149
|
);
|
|
31101
31150
|
this.realCloseController.abort();
|
|
31102
31151
|
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
@@ -31107,12 +31156,13 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31107
31156
|
this[kEmitter22].dispatchEvent(
|
|
31108
31157
|
bindEvent(
|
|
31109
31158
|
this.realWebSocket,
|
|
31110
|
-
new
|
|
31159
|
+
new CancelableCloseEvent("close", {
|
|
31111
31160
|
/**
|
|
31112
31161
|
* @note `server.close()` in the interceptor
|
|
31113
31162
|
* always results in clean closures.
|
|
31114
31163
|
*/
|
|
31115
|
-
code: 1e3
|
|
31164
|
+
code: 1e3,
|
|
31165
|
+
cancelable: true
|
|
31116
31166
|
})
|
|
31117
31167
|
)
|
|
31118
31168
|
);
|
|
@@ -31129,14 +31179,14 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31129
31179
|
);
|
|
31130
31180
|
this[kEmitter22].dispatchEvent(messageEvent);
|
|
31131
31181
|
if (!messageEvent.defaultPrevented) {
|
|
31132
|
-
this.
|
|
31182
|
+
this.client.dispatchEvent(
|
|
31133
31183
|
bindEvent(
|
|
31134
31184
|
/**
|
|
31135
31185
|
* @note Bind the forwarded original server events
|
|
31136
31186
|
* to the mock WebSocket instance so it would
|
|
31137
31187
|
* dispatch them straight away.
|
|
31138
31188
|
*/
|
|
31139
|
-
this.
|
|
31189
|
+
this.client,
|
|
31140
31190
|
// Clone the message event again to prevent
|
|
31141
31191
|
// the "already being dispatched" exception.
|
|
31142
31192
|
new MessageEvent("message", {
|
|
@@ -31156,11 +31206,16 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31156
31206
|
this.mockCloseController.abort();
|
|
31157
31207
|
const closeEvent = bindEvent(
|
|
31158
31208
|
this.realWebSocket,
|
|
31159
|
-
new
|
|
31209
|
+
new CancelableCloseEvent("close", {
|
|
31210
|
+
code: event.code,
|
|
31211
|
+
reason: event.reason,
|
|
31212
|
+
wasClean: event.wasClean,
|
|
31213
|
+
cancelable: true
|
|
31214
|
+
})
|
|
31160
31215
|
);
|
|
31161
31216
|
this[kEmitter22].dispatchEvent(closeEvent);
|
|
31162
31217
|
if (!closeEvent.defaultPrevented) {
|
|
31163
|
-
this.
|
|
31218
|
+
this.client[kClose](event.code, event.reason);
|
|
31164
31219
|
}
|
|
31165
31220
|
}
|
|
31166
31221
|
};
|
|
@@ -31287,30 +31342,46 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31287
31342
|
|
|
31288
31343
|
// src/core/ws/handleWebSocketEvent.ts
|
|
31289
31344
|
function handleWebSocketEvent(options) {
|
|
31290
|
-
webSocketInterceptor.on("connection", (connection) => {
|
|
31345
|
+
webSocketInterceptor.on("connection", async (connection) => {
|
|
31291
31346
|
const handlers = options.getHandlers();
|
|
31292
31347
|
const connectionEvent = new MessageEvent("connection", {
|
|
31293
31348
|
data: connection
|
|
31294
31349
|
});
|
|
31295
|
-
const matchingHandlers =
|
|
31296
|
-
|
|
31297
|
-
|
|
31298
|
-
|
|
31299
|
-
|
|
31300
|
-
|
|
31301
|
-
|
|
31302
|
-
|
|
31303
|
-
|
|
31304
|
-
}
|
|
31305
|
-
return false;
|
|
31350
|
+
const matchingHandlers = [];
|
|
31351
|
+
for (const handler of handlers) {
|
|
31352
|
+
if (handler instanceof WebSocketHandler && handler.predicate({
|
|
31353
|
+
event: connectionEvent,
|
|
31354
|
+
parsedResult: handler.parse({
|
|
31355
|
+
event: connectionEvent
|
|
31356
|
+
})
|
|
31357
|
+
})) {
|
|
31358
|
+
matchingHandlers.push(handler);
|
|
31306
31359
|
}
|
|
31307
|
-
|
|
31360
|
+
}
|
|
31308
31361
|
if (matchingHandlers.length > 0) {
|
|
31309
31362
|
options?.onMockedConnection(connection);
|
|
31310
31363
|
for (const handler of matchingHandlers) {
|
|
31311
31364
|
handler[kDispatchEvent](connectionEvent);
|
|
31312
31365
|
}
|
|
31313
31366
|
} else {
|
|
31367
|
+
const request = new Request(connection.client.url, {
|
|
31368
|
+
headers: {
|
|
31369
|
+
upgrade: "websocket",
|
|
31370
|
+
connection: "upgrade"
|
|
31371
|
+
}
|
|
31372
|
+
});
|
|
31373
|
+
await onUnhandledRequest(
|
|
31374
|
+
request,
|
|
31375
|
+
options.getUnhandledRequestStrategy()
|
|
31376
|
+
).catch((error3) => {
|
|
31377
|
+
const errorEvent = new Event("error");
|
|
31378
|
+
Object.defineProperty(errorEvent, "cause", {
|
|
31379
|
+
enumerable: true,
|
|
31380
|
+
configurable: false,
|
|
31381
|
+
value: error3
|
|
31382
|
+
});
|
|
31383
|
+
connection.client.socket.dispatchEvent(errorEvent);
|
|
31384
|
+
});
|
|
31314
31385
|
options?.onPassthroughConnection(connection);
|
|
31315
31386
|
connection.server.connect();
|
|
31316
31387
|
}
|
|
@@ -31352,10 +31423,10 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31352
31423
|
|
|
31353
31424
|
// src/core/ws/utils/attachWebSocketLogger.ts
|
|
31354
31425
|
var colors = {
|
|
31355
|
-
|
|
31356
|
-
|
|
31357
|
-
|
|
31358
|
-
|
|
31426
|
+
system: "#3b82f6",
|
|
31427
|
+
outgoing: "#22c55e",
|
|
31428
|
+
incoming: "#ef4444",
|
|
31429
|
+
mocked: "#ff6a33"
|
|
31359
31430
|
};
|
|
31360
31431
|
function attachWebSocketLogger(connection) {
|
|
31361
31432
|
const { client, server } = connection;
|
|
@@ -31366,9 +31437,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31366
31437
|
client.addEventListener("close", (event) => {
|
|
31367
31438
|
logConnectionClose(event);
|
|
31368
31439
|
});
|
|
31369
|
-
client.socket.addEventListener("message", (event) => {
|
|
31370
|
-
logIncomingClientMessage(event);
|
|
31371
|
-
});
|
|
31372
31440
|
client.socket.addEventListener("error", (event) => {
|
|
31373
31441
|
logClientError(event);
|
|
31374
31442
|
});
|
|
@@ -31388,7 +31456,9 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31388
31456
|
value: client.socket
|
|
31389
31457
|
}
|
|
31390
31458
|
});
|
|
31391
|
-
|
|
31459
|
+
queueMicrotask(() => {
|
|
31460
|
+
logIncomingMockedClientMessage(messageEvent);
|
|
31461
|
+
});
|
|
31392
31462
|
return Reflect.apply(target, thisArg, args);
|
|
31393
31463
|
}
|
|
31394
31464
|
});
|
|
@@ -31409,12 +31479,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31409
31479
|
currentTarget: {
|
|
31410
31480
|
enumerable: true,
|
|
31411
31481
|
writable: false,
|
|
31412
|
-
value: server
|
|
31482
|
+
value: server.socket
|
|
31413
31483
|
},
|
|
31414
31484
|
target: {
|
|
31415
31485
|
enumerable: true,
|
|
31416
31486
|
writable: false,
|
|
31417
|
-
value: server
|
|
31487
|
+
value: server.socket
|
|
31418
31488
|
}
|
|
31419
31489
|
});
|
|
31420
31490
|
logOutgoingMockedClientMessage(messageEvent);
|
|
@@ -31426,50 +31496,47 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31426
31496
|
const publicUrl = toPublicUrl(client.url);
|
|
31427
31497
|
console.groupCollapsed(
|
|
31428
31498
|
devUtils.formatMessage(`${getTimestamp()} %c\u25B6%c ${publicUrl}`),
|
|
31429
|
-
`color:${colors.
|
|
31499
|
+
`color:${colors.system}`,
|
|
31430
31500
|
"color:inherit"
|
|
31431
31501
|
);
|
|
31432
31502
|
console.log("Client:", client.socket);
|
|
31433
31503
|
console.groupEnd();
|
|
31434
31504
|
}
|
|
31435
|
-
|
|
31436
|
-
const
|
|
31437
|
-
const
|
|
31505
|
+
function logConnectionClose(event) {
|
|
31506
|
+
const target = event.target;
|
|
31507
|
+
const publicUrl = toPublicUrl(target.url);
|
|
31438
31508
|
console.groupCollapsed(
|
|
31439
31509
|
devUtils.formatMessage(
|
|
31440
|
-
`${getTimestamp({ milliseconds: true })} %c\
|
|
31510
|
+
`${getTimestamp({ milliseconds: true })} %c\u25A0%c ${publicUrl}`
|
|
31441
31511
|
),
|
|
31442
|
-
`color:${colors.
|
|
31443
|
-
"color:inherit"
|
|
31444
|
-
"color:gray;font-weight:normal",
|
|
31445
|
-
"color:inherit;font-weight:inherit"
|
|
31512
|
+
`color:${colors.system}`,
|
|
31513
|
+
"color:inherit"
|
|
31446
31514
|
);
|
|
31447
31515
|
console.log(event);
|
|
31448
31516
|
console.groupEnd();
|
|
31449
31517
|
}
|
|
31450
|
-
|
|
31451
|
-
const
|
|
31452
|
-
const
|
|
31518
|
+
function logClientError(event) {
|
|
31519
|
+
const socket = event.target;
|
|
31520
|
+
const publicUrl = toPublicUrl(socket.url);
|
|
31453
31521
|
console.groupCollapsed(
|
|
31454
31522
|
devUtils.formatMessage(
|
|
31455
|
-
`${getTimestamp({ milliseconds: true })} %c\
|
|
31523
|
+
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
31456
31524
|
),
|
|
31457
|
-
`color:${colors.
|
|
31458
|
-
"color:inherit"
|
|
31459
|
-
"color:gray;font-weight:normal",
|
|
31460
|
-
"color:inherit;font-weight:inherit"
|
|
31525
|
+
`color:${colors.system}`,
|
|
31526
|
+
"color:inherit"
|
|
31461
31527
|
);
|
|
31462
31528
|
console.log(event);
|
|
31463
31529
|
console.groupEnd();
|
|
31464
31530
|
}
|
|
31465
|
-
async function
|
|
31531
|
+
async function logOutgoingClientMessage(event) {
|
|
31466
31532
|
const byteLength = getMessageLength(event.data);
|
|
31467
31533
|
const publicData = await getPublicData(event.data);
|
|
31534
|
+
const arrow = event.defaultPrevented ? "\u21E1" : "\u2B06";
|
|
31468
31535
|
console.groupCollapsed(
|
|
31469
31536
|
devUtils.formatMessage(
|
|
31470
|
-
`${getTimestamp({ milliseconds: true })} %c
|
|
31537
|
+
`${getTimestamp({ milliseconds: true })} %c${arrow}%c ${publicData} %c${byteLength}%c`
|
|
31471
31538
|
),
|
|
31472
|
-
`color:${colors.
|
|
31539
|
+
`color:${colors.outgoing}`,
|
|
31473
31540
|
"color:inherit",
|
|
31474
31541
|
"color:gray;font-weight:normal",
|
|
31475
31542
|
"color:inherit;font-weight:inherit"
|
|
@@ -31477,14 +31544,14 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31477
31544
|
console.log(event);
|
|
31478
31545
|
console.groupEnd();
|
|
31479
31546
|
}
|
|
31480
|
-
async function
|
|
31547
|
+
async function logOutgoingMockedClientMessage(event) {
|
|
31481
31548
|
const byteLength = getMessageLength(event.data);
|
|
31482
31549
|
const publicData = await getPublicData(event.data);
|
|
31483
31550
|
console.groupCollapsed(
|
|
31484
31551
|
devUtils.formatMessage(
|
|
31485
|
-
`${getTimestamp({ milliseconds: true })} %c\
|
|
31552
|
+
`${getTimestamp({ milliseconds: true })} %c\u2B06%c ${publicData} %c${byteLength}%c`
|
|
31486
31553
|
),
|
|
31487
|
-
`color:${colors.
|
|
31554
|
+
`color:${colors.mocked}`,
|
|
31488
31555
|
"color:inherit",
|
|
31489
31556
|
"color:gray;font-weight:normal",
|
|
31490
31557
|
"color:inherit;font-weight:inherit"
|
|
@@ -31492,15 +31559,17 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31492
31559
|
console.log(event);
|
|
31493
31560
|
console.groupEnd();
|
|
31494
31561
|
}
|
|
31495
|
-
function
|
|
31496
|
-
const
|
|
31497
|
-
const
|
|
31562
|
+
async function logIncomingMockedClientMessage(event) {
|
|
31563
|
+
const byteLength = getMessageLength(event.data);
|
|
31564
|
+
const publicData = await getPublicData(event.data);
|
|
31498
31565
|
console.groupCollapsed(
|
|
31499
31566
|
devUtils.formatMessage(
|
|
31500
|
-
`${getTimestamp({ milliseconds: true })} %c\
|
|
31567
|
+
`${getTimestamp({ milliseconds: true })} %c\u2B07%c ${publicData} %c${byteLength}%c`
|
|
31501
31568
|
),
|
|
31502
|
-
`color:${colors.
|
|
31503
|
-
"color:inherit"
|
|
31569
|
+
`color:${colors.mocked}`,
|
|
31570
|
+
"color:inherit",
|
|
31571
|
+
"color:gray;font-weight:normal",
|
|
31572
|
+
"color:inherit;font-weight:inherit"
|
|
31504
31573
|
);
|
|
31505
31574
|
console.log(event);
|
|
31506
31575
|
console.groupEnd();
|
|
@@ -31508,11 +31577,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31508
31577
|
async function logIncomingServerMessage(event) {
|
|
31509
31578
|
const byteLength = getMessageLength(event.data);
|
|
31510
31579
|
const publicData = await getPublicData(event.data);
|
|
31580
|
+
const arrow = event.defaultPrevented ? "\u21E3" : "\u2B07";
|
|
31511
31581
|
console.groupCollapsed(
|
|
31512
31582
|
devUtils.formatMessage(
|
|
31513
|
-
`${getTimestamp({ milliseconds: true })} %c
|
|
31583
|
+
`${getTimestamp({ milliseconds: true })} %c${arrow}%c ${publicData} %c${byteLength}%c`
|
|
31514
31584
|
),
|
|
31515
|
-
`color:${colors.
|
|
31585
|
+
`color:${colors.incoming}`,
|
|
31516
31586
|
"color:inherit",
|
|
31517
31587
|
"color:gray;font-weight:normal",
|
|
31518
31588
|
"color:inherit;font-weight:inherit"
|
|
@@ -31520,19 +31590,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31520
31590
|
console.log(event);
|
|
31521
31591
|
console.groupEnd();
|
|
31522
31592
|
}
|
|
31523
|
-
function logClientError(event) {
|
|
31524
|
-
const socket = event.target;
|
|
31525
|
-
const publicUrl = toPublicUrl(socket.url);
|
|
31526
|
-
console.groupCollapsed(
|
|
31527
|
-
devUtils.formatMessage(
|
|
31528
|
-
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
31529
|
-
),
|
|
31530
|
-
`color:${colors.blue}`,
|
|
31531
|
-
"color:inherit"
|
|
31532
|
-
);
|
|
31533
|
-
console.log(event);
|
|
31534
|
-
console.groupEnd();
|
|
31535
|
-
}
|
|
31536
31593
|
|
|
31537
31594
|
// src/browser/setupWorker/setupWorker.ts
|
|
31538
31595
|
var SetupWorkerApi = class extends SetupApi {
|
|
@@ -31651,6 +31708,9 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31651
31708
|
options
|
|
31652
31709
|
);
|
|
31653
31710
|
handleWebSocketEvent({
|
|
31711
|
+
getUnhandledRequestStrategy: () => {
|
|
31712
|
+
return this.context.startOptions.onUnhandledRequest;
|
|
31713
|
+
},
|
|
31654
31714
|
getHandlers: () => {
|
|
31655
31715
|
return this.handlersController.currentHandlers();
|
|
31656
31716
|
},
|