msw 2.3.0-ws.rc-8 → 2.3.0-ws.rc-10
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/index.d.mts +2 -2
- package/lib/core/index.d.ts +2 -2
- package/lib/core/index.js.map +1 -1
- package/lib/core/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.js +2 -2
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +2 -2
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -1
- package/lib/core/ws.d.mts +8 -6
- package/lib/core/ws.d.ts +8 -6
- package/lib/core/ws.js +2 -2
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs +2 -2
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +128 -58
- 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/index.ts +2 -0
- 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 +2 -2
- package/src/core/ws.ts +15 -9
- 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.0/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.0/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.0/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.0/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,12 +28601,12 @@ 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;
|
|
28588
28608
|
},
|
|
28589
|
-
|
|
28609
|
+
addEventListener(event, listener) {
|
|
28590
28610
|
const handler = new WebSocketHandler(url);
|
|
28591
28611
|
handler[kEmitter].on("connection", async ({ client }) => {
|
|
28592
28612
|
await clientManager.addConnection(client);
|
|
@@ -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.0/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.0/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.0/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.0/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 {
|
|
@@ -30958,15 +31004,15 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30958
31004
|
var kEmitter22 = Symbol("kEmitter");
|
|
30959
31005
|
var kBoundListener2 = Symbol("kBoundListener");
|
|
30960
31006
|
var WebSocketServerConnection = class {
|
|
30961
|
-
constructor(
|
|
30962
|
-
this.
|
|
31007
|
+
constructor(client, transport, createConnection) {
|
|
31008
|
+
this.client = client;
|
|
30963
31009
|
this.transport = transport;
|
|
30964
31010
|
this.createConnection = createConnection;
|
|
30965
31011
|
this[kEmitter22] = new EventTarget();
|
|
30966
31012
|
this.mockCloseController = new AbortController();
|
|
30967
31013
|
this.realCloseController = new AbortController();
|
|
30968
31014
|
this.transport.addEventListener("outgoing", (event) => {
|
|
30969
|
-
if (this.
|
|
31015
|
+
if (typeof this.realWebSocket === "undefined") {
|
|
30970
31016
|
return;
|
|
30971
31017
|
}
|
|
30972
31018
|
queueMicrotask(() => {
|
|
@@ -30981,16 +31027,15 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
30981
31027
|
);
|
|
30982
31028
|
}
|
|
30983
31029
|
/**
|
|
30984
|
-
*
|
|
30985
|
-
*
|
|
30986
|
-
* if set. If the original connection hasn't been established,
|
|
30987
|
-
* defaults to `-1`.
|
|
31030
|
+
* The `WebSocket` instance connected to the original server.
|
|
31031
|
+
* Accessing this before calling `server.connect()` will throw.
|
|
30988
31032
|
*/
|
|
30989
|
-
get
|
|
30990
|
-
|
|
30991
|
-
|
|
30992
|
-
|
|
30993
|
-
|
|
31033
|
+
get socket() {
|
|
31034
|
+
invariant2(
|
|
31035
|
+
this.realWebSocket,
|
|
31036
|
+
'Cannot access "socket" on the original WebSocket server object: the connection is not open. Did you forget to call `server.connect()`?'
|
|
31037
|
+
);
|
|
31038
|
+
return this.realWebSocket;
|
|
30994
31039
|
}
|
|
30995
31040
|
/**
|
|
30996
31041
|
* Open connection to the original WebSocket server.
|
|
@@ -31001,7 +31046,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31001
31046
|
'Failed to call "connect()" on the original WebSocket instance: the connection already open'
|
|
31002
31047
|
);
|
|
31003
31048
|
const realWebSocket = this.createConnection();
|
|
31004
|
-
realWebSocket.binaryType = this.
|
|
31049
|
+
realWebSocket.binaryType = this.client.binaryType;
|
|
31005
31050
|
realWebSocket.addEventListener(
|
|
31006
31051
|
"open",
|
|
31007
31052
|
(event) => {
|
|
@@ -31022,7 +31067,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31022
31067
|
)
|
|
31023
31068
|
);
|
|
31024
31069
|
});
|
|
31025
|
-
this.
|
|
31070
|
+
this.client.addEventListener("close", this.handleMockClose.bind(this), {
|
|
31026
31071
|
signal: this.mockCloseController.signal
|
|
31027
31072
|
});
|
|
31028
31073
|
realWebSocket.addEventListener("close", this.handleRealClose.bind(this), {
|
|
@@ -31030,7 +31075,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31030
31075
|
});
|
|
31031
31076
|
realWebSocket.addEventListener("error", () => {
|
|
31032
31077
|
this[kEmitter22].dispatchEvent(bindEvent(realWebSocket, new Event("error")));
|
|
31033
|
-
this.
|
|
31078
|
+
this.client.dispatchEvent(bindEvent(this.client, new Event("error")));
|
|
31034
31079
|
});
|
|
31035
31080
|
this.realWebSocket = realWebSocket;
|
|
31036
31081
|
}
|
|
@@ -31038,7 +31083,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31038
31083
|
* Listen for the incoming events from the original WebSocket server.
|
|
31039
31084
|
*/
|
|
31040
31085
|
addEventListener(event, listener, options) {
|
|
31041
|
-
const boundListener = listener.bind(this.
|
|
31086
|
+
const boundListener = listener.bind(this.client);
|
|
31042
31087
|
Object.defineProperty(listener, kBoundListener2, {
|
|
31043
31088
|
value: boundListener,
|
|
31044
31089
|
enumerable: false
|
|
@@ -31071,7 +31116,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31071
31116
|
invariant2(
|
|
31072
31117
|
realWebSocket,
|
|
31073
31118
|
'Failed to call "server.send()" for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
31074
|
-
this.
|
|
31119
|
+
this.client.url
|
|
31075
31120
|
);
|
|
31076
31121
|
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
31077
31122
|
return;
|
|
@@ -31096,7 +31141,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31096
31141
|
invariant2(
|
|
31097
31142
|
realWebSocket,
|
|
31098
31143
|
'Failed to close server connection for "%s": the connection is not open. Did you forget to call "server.connect()"?',
|
|
31099
|
-
this.
|
|
31144
|
+
this.client.url
|
|
31100
31145
|
);
|
|
31101
31146
|
this.realCloseController.abort();
|
|
31102
31147
|
if (realWebSocket.readyState === WebSocket.CLOSING || realWebSocket.readyState === WebSocket.CLOSED) {
|
|
@@ -31107,12 +31152,13 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31107
31152
|
this[kEmitter22].dispatchEvent(
|
|
31108
31153
|
bindEvent(
|
|
31109
31154
|
this.realWebSocket,
|
|
31110
|
-
new
|
|
31155
|
+
new CancelableCloseEvent("close", {
|
|
31111
31156
|
/**
|
|
31112
31157
|
* @note `server.close()` in the interceptor
|
|
31113
31158
|
* always results in clean closures.
|
|
31114
31159
|
*/
|
|
31115
|
-
code: 1e3
|
|
31160
|
+
code: 1e3,
|
|
31161
|
+
cancelable: true
|
|
31116
31162
|
})
|
|
31117
31163
|
)
|
|
31118
31164
|
);
|
|
@@ -31129,14 +31175,14 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31129
31175
|
);
|
|
31130
31176
|
this[kEmitter22].dispatchEvent(messageEvent);
|
|
31131
31177
|
if (!messageEvent.defaultPrevented) {
|
|
31132
|
-
this.
|
|
31178
|
+
this.client.dispatchEvent(
|
|
31133
31179
|
bindEvent(
|
|
31134
31180
|
/**
|
|
31135
31181
|
* @note Bind the forwarded original server events
|
|
31136
31182
|
* to the mock WebSocket instance so it would
|
|
31137
31183
|
* dispatch them straight away.
|
|
31138
31184
|
*/
|
|
31139
|
-
this.
|
|
31185
|
+
this.client,
|
|
31140
31186
|
// Clone the message event again to prevent
|
|
31141
31187
|
// the "already being dispatched" exception.
|
|
31142
31188
|
new MessageEvent("message", {
|
|
@@ -31156,11 +31202,16 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31156
31202
|
this.mockCloseController.abort();
|
|
31157
31203
|
const closeEvent = bindEvent(
|
|
31158
31204
|
this.realWebSocket,
|
|
31159
|
-
new
|
|
31205
|
+
new CancelableCloseEvent("close", {
|
|
31206
|
+
code: event.code,
|
|
31207
|
+
reason: event.reason,
|
|
31208
|
+
wasClean: event.wasClean,
|
|
31209
|
+
cancelable: true
|
|
31210
|
+
})
|
|
31160
31211
|
);
|
|
31161
31212
|
this[kEmitter22].dispatchEvent(closeEvent);
|
|
31162
31213
|
if (!closeEvent.defaultPrevented) {
|
|
31163
|
-
this.
|
|
31214
|
+
this.client[kClose](event.code, event.reason);
|
|
31164
31215
|
}
|
|
31165
31216
|
}
|
|
31166
31217
|
};
|
|
@@ -31287,30 +31338,46 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31287
31338
|
|
|
31288
31339
|
// src/core/ws/handleWebSocketEvent.ts
|
|
31289
31340
|
function handleWebSocketEvent(options) {
|
|
31290
|
-
webSocketInterceptor.on("connection", (connection) => {
|
|
31341
|
+
webSocketInterceptor.on("connection", async (connection) => {
|
|
31291
31342
|
const handlers = options.getHandlers();
|
|
31292
31343
|
const connectionEvent = new MessageEvent("connection", {
|
|
31293
31344
|
data: connection
|
|
31294
31345
|
});
|
|
31295
|
-
const matchingHandlers =
|
|
31296
|
-
|
|
31297
|
-
|
|
31298
|
-
|
|
31299
|
-
|
|
31300
|
-
|
|
31301
|
-
|
|
31302
|
-
|
|
31303
|
-
|
|
31304
|
-
}
|
|
31305
|
-
return false;
|
|
31346
|
+
const matchingHandlers = [];
|
|
31347
|
+
for (const handler of handlers) {
|
|
31348
|
+
if (handler instanceof WebSocketHandler && handler.predicate({
|
|
31349
|
+
event: connectionEvent,
|
|
31350
|
+
parsedResult: handler.parse({
|
|
31351
|
+
event: connectionEvent
|
|
31352
|
+
})
|
|
31353
|
+
})) {
|
|
31354
|
+
matchingHandlers.push(handler);
|
|
31306
31355
|
}
|
|
31307
|
-
|
|
31356
|
+
}
|
|
31308
31357
|
if (matchingHandlers.length > 0) {
|
|
31309
31358
|
options?.onMockedConnection(connection);
|
|
31310
31359
|
for (const handler of matchingHandlers) {
|
|
31311
31360
|
handler[kDispatchEvent](connectionEvent);
|
|
31312
31361
|
}
|
|
31313
31362
|
} else {
|
|
31363
|
+
const request = new Request(connection.client.url, {
|
|
31364
|
+
headers: {
|
|
31365
|
+
upgrade: "websocket",
|
|
31366
|
+
connection: "upgrade"
|
|
31367
|
+
}
|
|
31368
|
+
});
|
|
31369
|
+
await onUnhandledRequest(
|
|
31370
|
+
request,
|
|
31371
|
+
options.getUnhandledRequestStrategy()
|
|
31372
|
+
).catch((error3) => {
|
|
31373
|
+
const errorEvent = new Event("error");
|
|
31374
|
+
Object.defineProperty(errorEvent, "cause", {
|
|
31375
|
+
enumerable: true,
|
|
31376
|
+
configurable: false,
|
|
31377
|
+
value: error3
|
|
31378
|
+
});
|
|
31379
|
+
connection.client.socket.dispatchEvent(errorEvent);
|
|
31380
|
+
});
|
|
31314
31381
|
options?.onPassthroughConnection(connection);
|
|
31315
31382
|
connection.server.connect();
|
|
31316
31383
|
}
|
|
@@ -31409,12 +31476,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31409
31476
|
currentTarget: {
|
|
31410
31477
|
enumerable: true,
|
|
31411
31478
|
writable: false,
|
|
31412
|
-
value: server
|
|
31479
|
+
value: server.socket
|
|
31413
31480
|
},
|
|
31414
31481
|
target: {
|
|
31415
31482
|
enumerable: true,
|
|
31416
31483
|
writable: false,
|
|
31417
|
-
value: server
|
|
31484
|
+
value: server.socket
|
|
31418
31485
|
}
|
|
31419
31486
|
});
|
|
31420
31487
|
logOutgoingMockedClientMessage(messageEvent);
|
|
@@ -31651,6 +31718,9 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
31651
31718
|
options
|
|
31652
31719
|
);
|
|
31653
31720
|
handleWebSocketEvent({
|
|
31721
|
+
getUnhandledRequestStrategy: () => {
|
|
31722
|
+
return this.context.startOptions.onUnhandledRequest;
|
|
31723
|
+
},
|
|
31654
31724
|
getHandlers: () => {
|
|
31655
31725
|
return this.handlersController.currentHandlers();
|
|
31656
31726
|
},
|