msw 2.3.0-ws.rc-5 → 2.3.0-ws.rc-7
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 +3 -9
- package/lib/browser/index.js +160 -62
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +160 -62
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/handlers/WebSocketHandler.js +1 -2
- package/lib/core/handlers/WebSocketHandler.js.map +1 -1
- package/lib/core/handlers/WebSocketHandler.mjs +1 -2
- package/lib/core/handlers/WebSocketHandler.mjs.map +1 -1
- package/lib/core/utils/internal/Disposable.d.mts +2 -2
- package/lib/core/utils/internal/Disposable.d.ts +2 -2
- package/lib/core/utils/internal/Disposable.js +5 -2
- package/lib/core/utils/internal/Disposable.js.map +1 -1
- package/lib/core/utils/internal/Disposable.mjs +5 -2
- package/lib/core/utils/internal/Disposable.mjs.map +1 -1
- package/lib/core/utils/internal/devUtils.d.mts +10 -1
- package/lib/core/utils/internal/devUtils.d.ts +10 -1
- package/lib/core/utils/internal/devUtils.js +7 -0
- package/lib/core/utils/internal/devUtils.js.map +1 -1
- package/lib/core/utils/internal/devUtils.mjs +7 -0
- package/lib/core/utils/internal/devUtils.mjs.map +1 -1
- package/lib/core/utils/matching/normalizePath.d.mts +1 -0
- package/lib/core/utils/matching/normalizePath.d.ts +1 -0
- package/lib/core/utils/matching/normalizePath.js.map +1 -1
- package/lib/core/utils/matching/normalizePath.mjs.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.js +3 -3
- package/lib/core/utils/request/onUnhandledRequest.js.map +1 -1
- package/lib/core/utils/request/onUnhandledRequest.mjs +4 -4
- package/lib/core/utils/request/onUnhandledRequest.mjs.map +1 -1
- package/lib/core/utils/url/cleanUrl.d.mts +2 -1
- package/lib/core/utils/url/cleanUrl.d.ts +2 -1
- package/lib/core/utils/url/cleanUrl.js +3 -0
- package/lib/core/utils/url/cleanUrl.js.map +1 -1
- package/lib/core/utils/url/cleanUrl.mjs +3 -0
- package/lib/core/utils/url/cleanUrl.mjs.map +1 -1
- package/lib/core/ws/WebSocketClientManager.d.mts +9 -15
- package/lib/core/ws/WebSocketClientManager.d.ts +9 -15
- package/lib/core/ws/WebSocketClientManager.js +73 -34
- package/lib/core/ws/WebSocketClientManager.js.map +1 -1
- package/lib/core/ws/WebSocketClientManager.mjs +73 -34
- package/lib/core/ws/WebSocketClientManager.mjs.map +1 -1
- package/lib/core/ws.js +4 -2
- package/lib/core/ws.js.map +1 -1
- package/lib/core/ws.mjs +4 -2
- package/lib/core/ws.mjs.map +1 -1
- package/lib/iife/index.js +278 -113
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/lib/native/index.js +5 -0
- package/lib/native/index.js.map +1 -1
- package/lib/native/index.mjs +6 -1
- package/lib/native/index.mjs.map +1 -1
- package/lib/node/index.js +5 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/index.mjs +6 -1
- package/lib/node/index.mjs.map +1 -1
- package/package.json +17 -5
- package/src/browser/setupWorker/start/createStartHandler.ts +6 -0
- package/src/browser/setupWorker/stop/createStop.ts +4 -0
- package/src/core/handlers/WebSocketHandler.ts +1 -2
- package/src/core/utils/internal/Disposable.ts +6 -3
- package/src/core/utils/internal/devUtils.test.ts +21 -0
- package/src/core/utils/internal/devUtils.ts +13 -0
- package/src/core/utils/matching/matchRequestUrl.test.ts +11 -0
- package/src/core/utils/matching/normalizePath.test.ts +7 -1
- package/src/core/utils/matching/normalizePath.ts +1 -0
- package/src/core/utils/request/onUnhandledRequest.test.ts +30 -4
- package/src/core/utils/request/onUnhandledRequest.ts +4 -4
- package/src/core/utils/url/cleanUrl.test.ts +8 -3
- package/src/core/utils/url/cleanUrl.ts +9 -1
- package/src/core/utils/url/getAbsoluteUrl.node.test.ts +3 -3
- package/src/core/utils/url/getAbsoluteUrl.test.ts +5 -5
- package/src/core/utils/url/isAbsoluteUrl.test.ts +7 -7
- package/src/core/ws/WebSocketClientManager.test.ts +43 -45
- package/src/core/ws/WebSocketClientManager.ts +107 -44
- package/src/core/ws.ts +4 -2
- package/src/node/SetupServerCommonApi.ts +7 -1
package/lib/iife/index.js
CHANGED
|
@@ -145,6 +145,12 @@ var MockServiceWorker = (() => {
|
|
|
145
145
|
warn,
|
|
146
146
|
error
|
|
147
147
|
};
|
|
148
|
+
var InternalError = class extends Error {
|
|
149
|
+
constructor(message3) {
|
|
150
|
+
super(message3);
|
|
151
|
+
this.name = "InternalError";
|
|
152
|
+
}
|
|
153
|
+
};
|
|
148
154
|
|
|
149
155
|
// src/core/utils/internal/checkGlobals.ts
|
|
150
156
|
function checkGlobals() {
|
|
@@ -345,8 +351,11 @@ var MockServiceWorker = (() => {
|
|
|
345
351
|
// src/core/utils/internal/Disposable.ts
|
|
346
352
|
var Disposable = class {
|
|
347
353
|
subscriptions = [];
|
|
348
|
-
|
|
349
|
-
|
|
354
|
+
dispose() {
|
|
355
|
+
let subscription;
|
|
356
|
+
while (subscription = this.subscriptions.shift()) {
|
|
357
|
+
subscription();
|
|
358
|
+
}
|
|
350
359
|
}
|
|
351
360
|
};
|
|
352
361
|
|
|
@@ -1129,7 +1138,7 @@ var MockServiceWorker = (() => {
|
|
|
1129
1138
|
return stringToRegexp(path, keys, options);
|
|
1130
1139
|
}
|
|
1131
1140
|
|
|
1132
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1141
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.30.0/node_modules/@mswjs/interceptors/lib/browser/chunk-6HYIRFX2.mjs
|
|
1133
1142
|
var encoder = new TextEncoder();
|
|
1134
1143
|
function encodeBuffer(text) {
|
|
1135
1144
|
return encoder.encode(text);
|
|
@@ -1144,6 +1153,17 @@ var MockServiceWorker = (() => {
|
|
|
1144
1153
|
array.byteOffset + array.byteLength
|
|
1145
1154
|
);
|
|
1146
1155
|
}
|
|
1156
|
+
|
|
1157
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.30.0/node_modules/@mswjs/interceptors/lib/browser/chunk-OMISYKWR.mjs
|
|
1158
|
+
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1159
|
+
function isPropertyAccessible(obj, key) {
|
|
1160
|
+
try {
|
|
1161
|
+
obj[key];
|
|
1162
|
+
return true;
|
|
1163
|
+
} catch (e) {
|
|
1164
|
+
return false;
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1147
1167
|
var RESPONSE_STATUS_CODES_WITHOUT_BODY = /* @__PURE__ */ new Set([
|
|
1148
1168
|
101,
|
|
1149
1169
|
103,
|
|
@@ -1154,9 +1174,27 @@ var MockServiceWorker = (() => {
|
|
|
1154
1174
|
function isResponseWithoutBody(status) {
|
|
1155
1175
|
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
1156
1176
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1177
|
+
function createServerErrorResponse(body) {
|
|
1178
|
+
return new Response(
|
|
1179
|
+
JSON.stringify(
|
|
1180
|
+
body instanceof Error ? {
|
|
1181
|
+
name: body.name,
|
|
1182
|
+
message: body.message,
|
|
1183
|
+
stack: body.stack
|
|
1184
|
+
} : body
|
|
1185
|
+
),
|
|
1186
|
+
{
|
|
1187
|
+
status: 500,
|
|
1188
|
+
statusText: "Unhandled Exception",
|
|
1189
|
+
headers: {
|
|
1190
|
+
"Content-Type": "application/json"
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
);
|
|
1194
|
+
}
|
|
1195
|
+
function isResponseError(response) {
|
|
1196
|
+
return isPropertyAccessible(response, "type") && response.type === "error";
|
|
1197
|
+
}
|
|
1160
1198
|
|
|
1161
1199
|
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
1162
1200
|
function isNodeProcess() {
|
|
@@ -1445,7 +1483,7 @@ var MockServiceWorker = (() => {
|
|
|
1445
1483
|
return message3.toString();
|
|
1446
1484
|
}
|
|
1447
1485
|
|
|
1448
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1486
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.30.0/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
1449
1487
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
1450
1488
|
function getGlobalSymbol(symbol) {
|
|
1451
1489
|
return (
|
|
@@ -1593,7 +1631,7 @@ var MockServiceWorker = (() => {
|
|
|
1593
1631
|
return Math.random().toString(16).slice(2);
|
|
1594
1632
|
}
|
|
1595
1633
|
|
|
1596
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1634
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.30.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1597
1635
|
var BatchInterceptor = class extends Interceptor {
|
|
1598
1636
|
constructor(options) {
|
|
1599
1637
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -1645,6 +1683,9 @@ var MockServiceWorker = (() => {
|
|
|
1645
1683
|
return new URL(`/${path}`, "http://localhost").searchParams;
|
|
1646
1684
|
}
|
|
1647
1685
|
function cleanUrl(path) {
|
|
1686
|
+
if (path.endsWith("?")) {
|
|
1687
|
+
return path;
|
|
1688
|
+
}
|
|
1648
1689
|
return path.replace(REDUNDANT_CHARACTERS_EXP, "");
|
|
1649
1690
|
}
|
|
1650
1691
|
|
|
@@ -2087,7 +2128,7 @@ var MockServiceWorker = (() => {
|
|
|
2087
2128
|
return false;
|
|
2088
2129
|
}
|
|
2089
2130
|
}
|
|
2090
|
-
function
|
|
2131
|
+
function isPropertyAccessible2(object, method) {
|
|
2091
2132
|
try {
|
|
2092
2133
|
object[method];
|
|
2093
2134
|
return true;
|
|
@@ -2100,7 +2141,7 @@ var MockServiceWorker = (() => {
|
|
|
2100
2141
|
this.store = /* @__PURE__ */ new Map();
|
|
2101
2142
|
}
|
|
2102
2143
|
add(request, response) {
|
|
2103
|
-
if (
|
|
2144
|
+
if (isPropertyAccessible2(request, "credentials") && request.credentials === "omit") {
|
|
2104
2145
|
return;
|
|
2105
2146
|
}
|
|
2106
2147
|
const requestUrl = new URL(request.url);
|
|
@@ -2125,7 +2166,7 @@ var MockServiceWorker = (() => {
|
|
|
2125
2166
|
this.deleteExpiredCookies();
|
|
2126
2167
|
const requestUrl = new URL(request.url);
|
|
2127
2168
|
const originCookies = this.store.get(requestUrl.origin) || /* @__PURE__ */ new Map();
|
|
2128
|
-
if (!
|
|
2169
|
+
if (!isPropertyAccessible2(request, "credentials")) {
|
|
2129
2170
|
return originCookies;
|
|
2130
2171
|
}
|
|
2131
2172
|
switch (request.credentials) {
|
|
@@ -5652,8 +5693,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5652
5693
|
const parsedResult = this.parse({ event });
|
|
5653
5694
|
const connection = event.data;
|
|
5654
5695
|
const resolvedConnection = {
|
|
5655
|
-
|
|
5656
|
-
server: connection.server,
|
|
5696
|
+
...connection,
|
|
5657
5697
|
params: parsedResult.match.params || {}
|
|
5658
5698
|
};
|
|
5659
5699
|
this[kEmitter].emit("connection", resolvedConnection);
|
|
@@ -5661,25 +5701,81 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5661
5701
|
};
|
|
5662
5702
|
|
|
5663
5703
|
// src/core/ws/WebSocketClientManager.ts
|
|
5664
|
-
var
|
|
5704
|
+
var MSW_WEBSOCKET_CLIENTS_KEY = "msw:ws:clients";
|
|
5665
5705
|
var WebSocketClientManager = class {
|
|
5666
|
-
constructor(channel) {
|
|
5706
|
+
constructor(channel, url) {
|
|
5667
5707
|
this.channel = channel;
|
|
5668
|
-
this.
|
|
5669
|
-
this.
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5708
|
+
this.url = url;
|
|
5709
|
+
this.inMemoryClients = /* @__PURE__ */ new Set();
|
|
5710
|
+
if (typeof localStorage !== "undefined") {
|
|
5711
|
+
localStorage.removeItem = new Proxy(localStorage.removeItem, {
|
|
5712
|
+
apply: (target, thisArg, args) => {
|
|
5713
|
+
const [key] = args;
|
|
5714
|
+
if (key === MSW_WEBSOCKET_CLIENTS_KEY) {
|
|
5715
|
+
this.inMemoryClients.clear();
|
|
5716
|
+
}
|
|
5717
|
+
return Reflect.apply(target, thisArg, args);
|
|
5675
5718
|
}
|
|
5676
|
-
}
|
|
5677
|
-
}
|
|
5719
|
+
});
|
|
5720
|
+
}
|
|
5678
5721
|
}
|
|
5722
|
+
inMemoryClients;
|
|
5679
5723
|
/**
|
|
5680
5724
|
* All active WebSocket client connections.
|
|
5681
5725
|
*/
|
|
5682
|
-
clients
|
|
5726
|
+
get clients() {
|
|
5727
|
+
if (typeof localStorage !== "undefined") {
|
|
5728
|
+
const inMemoryClients = Array.from(this.inMemoryClients);
|
|
5729
|
+
console.log("get clients()", inMemoryClients, this.getSerializedClients());
|
|
5730
|
+
return new Set(
|
|
5731
|
+
inMemoryClients.concat(
|
|
5732
|
+
this.getSerializedClients().filter((serializedClient) => {
|
|
5733
|
+
if (inMemoryClients.every(
|
|
5734
|
+
(client) => client.id !== serializedClient.clientId
|
|
5735
|
+
)) {
|
|
5736
|
+
return serializedClient;
|
|
5737
|
+
}
|
|
5738
|
+
}).map((serializedClient) => {
|
|
5739
|
+
return new WebSocketRemoteClientConnection(
|
|
5740
|
+
serializedClient.clientId,
|
|
5741
|
+
new URL(serializedClient.url),
|
|
5742
|
+
this.channel
|
|
5743
|
+
);
|
|
5744
|
+
})
|
|
5745
|
+
)
|
|
5746
|
+
);
|
|
5747
|
+
}
|
|
5748
|
+
return this.inMemoryClients;
|
|
5749
|
+
}
|
|
5750
|
+
getSerializedClients() {
|
|
5751
|
+
invariant(
|
|
5752
|
+
typeof localStorage !== "undefined",
|
|
5753
|
+
"Failed to call WebSocketClientManager#getSerializedClients() in a non-browser environment. This is likely a bug in MSW. Please, report it on GitHub: https://github.com/mswjs/msw"
|
|
5754
|
+
);
|
|
5755
|
+
const clientsJson = localStorage.getItem(MSW_WEBSOCKET_CLIENTS_KEY);
|
|
5756
|
+
if (!clientsJson) {
|
|
5757
|
+
return [];
|
|
5758
|
+
}
|
|
5759
|
+
const allClients = JSON.parse(clientsJson);
|
|
5760
|
+
const matchingClients = allClients.filter((client) => {
|
|
5761
|
+
return matchRequestUrl(new URL(client.url), this.url).matches;
|
|
5762
|
+
});
|
|
5763
|
+
return matchingClients;
|
|
5764
|
+
}
|
|
5765
|
+
addClient(client) {
|
|
5766
|
+
this.inMemoryClients.add(client);
|
|
5767
|
+
if (typeof localStorage !== "undefined") {
|
|
5768
|
+
const serializedClients = this.getSerializedClients();
|
|
5769
|
+
const nextSerializedClients = serializedClients.concat({
|
|
5770
|
+
clientId: client.id,
|
|
5771
|
+
url: client.url.href
|
|
5772
|
+
});
|
|
5773
|
+
localStorage.setItem(
|
|
5774
|
+
MSW_WEBSOCKET_CLIENTS_KEY,
|
|
5775
|
+
JSON.stringify(nextSerializedClients)
|
|
5776
|
+
);
|
|
5777
|
+
}
|
|
5778
|
+
}
|
|
5683
5779
|
/**
|
|
5684
5780
|
* Adds the given `WebSocket` client connection to the set
|
|
5685
5781
|
* of all connections. The given connection is always the complete
|
|
@@ -5687,14 +5783,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5687
5783
|
* for the opened connections in the same runtime.
|
|
5688
5784
|
*/
|
|
5689
5785
|
addConnection(client) {
|
|
5690
|
-
this.
|
|
5691
|
-
this.channel.postMessage({
|
|
5692
|
-
type: "connection:open",
|
|
5693
|
-
payload: {
|
|
5694
|
-
clientId: client.id,
|
|
5695
|
-
url: client.url.toString()
|
|
5696
|
-
}
|
|
5697
|
-
});
|
|
5786
|
+
this.addClient(client);
|
|
5698
5787
|
const handleExtraneousMessage = (message3) => {
|
|
5699
5788
|
const { type, payload } = message3.data;
|
|
5700
5789
|
if (typeof payload === "object" && "clientId" in payload && payload.clientId !== client.id) {
|
|
@@ -5719,18 +5808,6 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5719
5808
|
once: true
|
|
5720
5809
|
});
|
|
5721
5810
|
}
|
|
5722
|
-
/**
|
|
5723
|
-
* Adds a client connection wrapper to operate with
|
|
5724
|
-
* WebSocket client connections in other runtimes.
|
|
5725
|
-
*/
|
|
5726
|
-
onRemoteConnection(id, url) {
|
|
5727
|
-
this.clients.add(
|
|
5728
|
-
// Create a connection-compatible instance that can
|
|
5729
|
-
// operate with this client from a different runtime
|
|
5730
|
-
// using the BroadcastChannel messages.
|
|
5731
|
-
new WebSocketRemoteClientConnection(id, url, this.channel)
|
|
5732
|
-
);
|
|
5733
|
-
}
|
|
5734
5811
|
};
|
|
5735
5812
|
var WebSocketRemoteClientConnection = class {
|
|
5736
5813
|
constructor(id, url, channel) {
|
|
@@ -5768,9 +5845,11 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5768
5845
|
"Expected a WebSocket server URL to be a valid path but got %s",
|
|
5769
5846
|
typeof url
|
|
5770
5847
|
);
|
|
5771
|
-
const clientManager = new WebSocketClientManager(wsBroadcastChannel);
|
|
5848
|
+
const clientManager = new WebSocketClientManager(wsBroadcastChannel, url);
|
|
5772
5849
|
return {
|
|
5773
|
-
clients
|
|
5850
|
+
get clients() {
|
|
5851
|
+
return clientManager.clients;
|
|
5852
|
+
},
|
|
5774
5853
|
on(event, listener) {
|
|
5775
5854
|
const handler = new WebSocketHandler(url);
|
|
5776
5855
|
handler[kEmitter].on("connection", ({ client }) => {
|
|
@@ -5842,7 +5921,7 @@ Consider naming this operation or using "graphql.operation()" request handler to
|
|
|
5842
5921
|
// src/core/utils/request/onUnhandledRequest.ts
|
|
5843
5922
|
async function onUnhandledRequest(request, strategy = "warn") {
|
|
5844
5923
|
const url = new URL(request.url);
|
|
5845
|
-
const publicUrl = toPublicUrl(url);
|
|
5924
|
+
const publicUrl = toPublicUrl(url) + url.search;
|
|
5846
5925
|
const unhandledRequestMessage = `intercepted a request without a matching request handler:
|
|
5847
5926
|
|
|
5848
5927
|
\u2022 ${request.method} ${publicUrl}
|
|
@@ -5853,7 +5932,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
5853
5932
|
switch (strategy2) {
|
|
5854
5933
|
case "error": {
|
|
5855
5934
|
devUtils.error("Error: %s", unhandledRequestMessage);
|
|
5856
|
-
throw new
|
|
5935
|
+
throw new InternalError(
|
|
5857
5936
|
devUtils.formatMessage(
|
|
5858
5937
|
'Cannot bypass a request when using the "error" strategy for the "onUnhandledRequest" option.'
|
|
5859
5938
|
)
|
|
@@ -5866,7 +5945,7 @@ Read more: https://mswjs.io/docs/getting-started/mocks`;
|
|
|
5866
5945
|
case "bypass":
|
|
5867
5946
|
break;
|
|
5868
5947
|
default:
|
|
5869
|
-
throw new
|
|
5948
|
+
throw new InternalError(
|
|
5870
5949
|
devUtils.formatMessage(
|
|
5871
5950
|
'Failed to react to an unhandled request: unknown strategy "%s". Please provide one of the supported strategies ("bypass", "warn", "error") or a custom callback function as the value of the "onUnhandledRequest" option.',
|
|
5872
5951
|
strategy2
|
|
@@ -6506,6 +6585,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6506
6585
|
context.workerChannel.send("CLIENT_CLOSED");
|
|
6507
6586
|
}
|
|
6508
6587
|
window.clearInterval(context.keepAliveInterval);
|
|
6588
|
+
localStorage.removeItem(MSW_WEBSOCKET_CLIENTS_KEY);
|
|
6509
6589
|
});
|
|
6510
6590
|
await checkWorkerIntegrity(context).catch((error3) => {
|
|
6511
6591
|
devUtils.error(
|
|
@@ -6565,6 +6645,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6565
6645
|
context.workerChannel.send("MOCK_DEACTIVATE");
|
|
6566
6646
|
context.isMockingEnabled = false;
|
|
6567
6647
|
window.clearInterval(context.keepAliveInterval);
|
|
6648
|
+
localStorage.removeItem(MSW_WEBSOCKET_CLIENTS_KEY);
|
|
6568
6649
|
printStopMessage({ quiet: context.startOptions?.quiet });
|
|
6569
6650
|
};
|
|
6570
6651
|
};
|
|
@@ -6674,7 +6755,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6674
6755
|
}
|
|
6675
6756
|
};
|
|
6676
6757
|
|
|
6677
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6758
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.30.0/node_modules/@mswjs/interceptors/lib/browser/chunk-OUWBQF3Z.mjs
|
|
6678
6759
|
var RequestController = class {
|
|
6679
6760
|
constructor(request) {
|
|
6680
6761
|
this.request = request;
|
|
@@ -6712,15 +6793,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6712
6793
|
}
|
|
6713
6794
|
}
|
|
6714
6795
|
|
|
6715
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6716
|
-
function isPropertyAccessible2(obj, key) {
|
|
6717
|
-
try {
|
|
6718
|
-
obj[key];
|
|
6719
|
-
return true;
|
|
6720
|
-
} catch (e) {
|
|
6721
|
-
return false;
|
|
6722
|
-
}
|
|
6723
|
-
}
|
|
6796
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.30.0/node_modules/@mswjs/interceptors/lib/browser/chunk-MAEPOYB6.mjs
|
|
6724
6797
|
function canParseUrl(url) {
|
|
6725
6798
|
try {
|
|
6726
6799
|
new URL(url);
|
|
@@ -6773,64 +6846,113 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6773
6846
|
{ once: true }
|
|
6774
6847
|
);
|
|
6775
6848
|
}
|
|
6776
|
-
const
|
|
6777
|
-
|
|
6778
|
-
|
|
6779
|
-
|
|
6849
|
+
const responsePromise = new DeferredPromise();
|
|
6850
|
+
const respondWith = (response) => {
|
|
6851
|
+
this.logger.info("responding with a mock response:", response);
|
|
6852
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
6853
|
+
this.logger.info('emitting the "response" event...');
|
|
6854
|
+
const responseClone = response.clone();
|
|
6855
|
+
this.emitter.emit("response", {
|
|
6856
|
+
response: responseClone,
|
|
6857
|
+
isMockedResponse: true,
|
|
6858
|
+
request: interactiveRequest,
|
|
6859
|
+
requestId
|
|
6860
|
+
});
|
|
6861
|
+
}
|
|
6862
|
+
Object.defineProperty(response, "url", {
|
|
6863
|
+
writable: false,
|
|
6864
|
+
enumerable: true,
|
|
6865
|
+
configurable: false,
|
|
6866
|
+
value: request.url
|
|
6780
6867
|
});
|
|
6781
|
-
|
|
6782
|
-
|
|
6783
|
-
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6868
|
+
responsePromise.resolve(response);
|
|
6869
|
+
};
|
|
6870
|
+
const errorWith = (reason) => {
|
|
6871
|
+
responsePromise.reject(reason);
|
|
6872
|
+
};
|
|
6873
|
+
const resolverResult = await until(
|
|
6874
|
+
async () => {
|
|
6875
|
+
const listenersFinished = emitAsync(this.emitter, "request", {
|
|
6876
|
+
request: interactiveRequest,
|
|
6877
|
+
requestId
|
|
6878
|
+
});
|
|
6879
|
+
await Promise.race([
|
|
6880
|
+
requestAborted,
|
|
6881
|
+
// Put the listeners invocation Promise in the same race condition
|
|
6882
|
+
// with the request abort Promise because otherwise awaiting the listeners
|
|
6883
|
+
// would always yield some response (or undefined).
|
|
6884
|
+
listenersFinished,
|
|
6885
|
+
requestController.responsePromise
|
|
6886
|
+
]);
|
|
6887
|
+
this.logger.info("all request listeners have been resolved!");
|
|
6888
|
+
const mockedResponse2 = await requestController.responsePromise;
|
|
6889
|
+
this.logger.info("event.respondWith called with:", mockedResponse2);
|
|
6890
|
+
return mockedResponse2;
|
|
6891
|
+
}
|
|
6892
|
+
);
|
|
6794
6893
|
if (requestAborted.state === "rejected") {
|
|
6795
|
-
|
|
6894
|
+
this.logger.info(
|
|
6895
|
+
"request has been aborted:",
|
|
6896
|
+
requestAborted.rejectionReason
|
|
6897
|
+
);
|
|
6898
|
+
responsePromise.reject(requestAborted.rejectionReason);
|
|
6899
|
+
return responsePromise;
|
|
6796
6900
|
}
|
|
6797
6901
|
if (resolverResult.error) {
|
|
6798
|
-
|
|
6902
|
+
this.logger.info(
|
|
6903
|
+
"request listerner threw an error:",
|
|
6904
|
+
resolverResult.error
|
|
6905
|
+
);
|
|
6906
|
+
if (resolverResult.error instanceof Response) {
|
|
6907
|
+
if (isResponseError(resolverResult.error)) {
|
|
6908
|
+
errorWith(createNetworkError(resolverResult.error));
|
|
6909
|
+
} else {
|
|
6910
|
+
respondWith(resolverResult.error);
|
|
6911
|
+
}
|
|
6912
|
+
}
|
|
6913
|
+
if (this.emitter.listenerCount("unhandledException") > 0) {
|
|
6914
|
+
await emitAsync(this.emitter, "unhandledException", {
|
|
6915
|
+
error: resolverResult.error,
|
|
6916
|
+
request,
|
|
6917
|
+
requestId,
|
|
6918
|
+
controller: {
|
|
6919
|
+
respondWith,
|
|
6920
|
+
errorWith
|
|
6921
|
+
}
|
|
6922
|
+
});
|
|
6923
|
+
if (responsePromise.state !== "pending") {
|
|
6924
|
+
return responsePromise;
|
|
6925
|
+
}
|
|
6926
|
+
}
|
|
6927
|
+
respondWith(createServerErrorResponse(resolverResult.error));
|
|
6928
|
+
return responsePromise;
|
|
6799
6929
|
}
|
|
6800
6930
|
const mockedResponse = resolverResult.data;
|
|
6801
6931
|
if (mockedResponse && !((_a2 = request.signal) == null ? void 0 : _a2.aborted)) {
|
|
6802
6932
|
this.logger.info("received mocked response:", mockedResponse);
|
|
6803
|
-
if (
|
|
6933
|
+
if (isResponseError(mockedResponse)) {
|
|
6804
6934
|
this.logger.info(
|
|
6805
6935
|
"received a network error response, rejecting the request promise..."
|
|
6806
6936
|
);
|
|
6807
|
-
|
|
6937
|
+
errorWith(createNetworkError(mockedResponse));
|
|
6938
|
+
} else {
|
|
6939
|
+
respondWith(mockedResponse);
|
|
6808
6940
|
}
|
|
6809
|
-
|
|
6810
|
-
this.emitter.emit("response", {
|
|
6811
|
-
response: responseClone,
|
|
6812
|
-
isMockedResponse: true,
|
|
6813
|
-
request: interactiveRequest,
|
|
6814
|
-
requestId
|
|
6815
|
-
});
|
|
6816
|
-
Object.defineProperty(mockedResponse, "url", {
|
|
6817
|
-
writable: false,
|
|
6818
|
-
enumerable: true,
|
|
6819
|
-
configurable: false,
|
|
6820
|
-
value: request.url
|
|
6821
|
-
});
|
|
6822
|
-
return mockedResponse;
|
|
6941
|
+
return responsePromise;
|
|
6823
6942
|
}
|
|
6824
6943
|
this.logger.info("no mocked response received!");
|
|
6825
6944
|
return pureFetch(request).then((response) => {
|
|
6826
|
-
|
|
6827
|
-
this.
|
|
6828
|
-
|
|
6829
|
-
|
|
6830
|
-
|
|
6831
|
-
|
|
6832
|
-
|
|
6833
|
-
|
|
6945
|
+
this.logger.info("original fetch performed", response);
|
|
6946
|
+
if (this.emitter.listenerCount("response") > 0) {
|
|
6947
|
+
this.logger.info('emitting the "response" event...');
|
|
6948
|
+
const responseClone = response.clone();
|
|
6949
|
+
this.emitter.emit("response", {
|
|
6950
|
+
response: responseClone,
|
|
6951
|
+
isMockedResponse: false,
|
|
6952
|
+
request: interactiveRequest,
|
|
6953
|
+
requestId
|
|
6954
|
+
});
|
|
6955
|
+
}
|
|
6834
6956
|
return response;
|
|
6835
6957
|
});
|
|
6836
6958
|
};
|
|
@@ -6859,7 +6981,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6859
6981
|
});
|
|
6860
6982
|
}
|
|
6861
6983
|
|
|
6862
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6984
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.30.0/node_modules/@mswjs/interceptors/lib/browser/chunk-732REFPX.mjs
|
|
6863
6985
|
function concatArrayBuffer(left, right) {
|
|
6864
6986
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
6865
6987
|
result.set(left, 0);
|
|
@@ -7510,7 +7632,31 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7510
7632
|
"request listener threw an exception, aborting request...",
|
|
7511
7633
|
resolverResult.error
|
|
7512
7634
|
);
|
|
7513
|
-
|
|
7635
|
+
if (resolverResult.error instanceof Response) {
|
|
7636
|
+
if (isResponseError(resolverResult.error)) {
|
|
7637
|
+
xhrRequestController.errorWith(new TypeError("Network error"));
|
|
7638
|
+
} else {
|
|
7639
|
+
this.respondWith(resolverResult.error);
|
|
7640
|
+
}
|
|
7641
|
+
return;
|
|
7642
|
+
}
|
|
7643
|
+
if (emitter.listenerCount("unhandledException") > 0) {
|
|
7644
|
+
await emitAsync(emitter, "unhandledException", {
|
|
7645
|
+
error: resolverResult.error,
|
|
7646
|
+
request,
|
|
7647
|
+
requestId,
|
|
7648
|
+
controller: {
|
|
7649
|
+
respondWith: xhrRequestController.respondWith.bind(xhrRequestController),
|
|
7650
|
+
errorWith: xhrRequestController.errorWith.bind(xhrRequestController)
|
|
7651
|
+
}
|
|
7652
|
+
});
|
|
7653
|
+
if (originalRequest.readyState > XMLHttpRequest.OPENED) {
|
|
7654
|
+
return;
|
|
7655
|
+
}
|
|
7656
|
+
}
|
|
7657
|
+
xhrRequestController.respondWith(
|
|
7658
|
+
createServerErrorResponse(resolverResult.error)
|
|
7659
|
+
);
|
|
7514
7660
|
return;
|
|
7515
7661
|
}
|
|
7516
7662
|
const mockedResponse = resolverResult.data;
|
|
@@ -7520,7 +7666,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7520
7666
|
mockedResponse.status,
|
|
7521
7667
|
mockedResponse.statusText
|
|
7522
7668
|
);
|
|
7523
|
-
if (mockedResponse
|
|
7669
|
+
if (isResponseError(mockedResponse)) {
|
|
7524
7670
|
this.logger.info(
|
|
7525
7671
|
"received a network error response, rejecting the request promise..."
|
|
7526
7672
|
);
|
|
@@ -7684,7 +7830,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7684
7830
|
}
|
|
7685
7831
|
}
|
|
7686
7832
|
|
|
7687
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
7833
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.30.0/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
7688
7834
|
function bindEvent(target, event) {
|
|
7689
7835
|
Object.defineProperties(event, {
|
|
7690
7836
|
target: {
|
|
@@ -7735,6 +7881,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7735
7881
|
}
|
|
7736
7882
|
};
|
|
7737
7883
|
var kEmitter2 = Symbol("kEmitter");
|
|
7884
|
+
var kBoundListener = Symbol("kBoundListener");
|
|
7738
7885
|
var WebSocketClientConnection = class {
|
|
7739
7886
|
constructor(socket, transport) {
|
|
7740
7887
|
this.socket = socket;
|
|
@@ -7766,7 +7913,16 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7766
7913
|
* Listen for the outgoing events from the connected WebSocket client.
|
|
7767
7914
|
*/
|
|
7768
7915
|
addEventListener(type, listener, options) {
|
|
7769
|
-
this
|
|
7916
|
+
const boundListener = listener.bind(this.socket);
|
|
7917
|
+
Object.defineProperty(listener, kBoundListener, {
|
|
7918
|
+
value: boundListener,
|
|
7919
|
+
enumerable: false
|
|
7920
|
+
});
|
|
7921
|
+
this[kEmitter2].addEventListener(
|
|
7922
|
+
type,
|
|
7923
|
+
boundListener,
|
|
7924
|
+
options
|
|
7925
|
+
);
|
|
7770
7926
|
}
|
|
7771
7927
|
/**
|
|
7772
7928
|
* Removes the listener for the given event.
|
|
@@ -7774,7 +7930,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7774
7930
|
removeEventListener(event, listener, options) {
|
|
7775
7931
|
this[kEmitter2].removeEventListener(
|
|
7776
7932
|
event,
|
|
7777
|
-
listener,
|
|
7933
|
+
Reflect.get(listener, kBoundListener),
|
|
7778
7934
|
options
|
|
7779
7935
|
);
|
|
7780
7936
|
}
|
|
@@ -7816,7 +7972,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7816
7972
|
Reflect.set(this, "readyState", this.CONNECTING);
|
|
7817
7973
|
queueMicrotask(() => {
|
|
7818
7974
|
Reflect.set(this, "readyState", this.OPEN);
|
|
7819
|
-
this.protocol = protocols ? protocols[0] : "
|
|
7975
|
+
this.protocol = typeof protocols === "string" ? protocols : Array.isArray(protocols) && protocols.length > 0 ? protocols[0] : "";
|
|
7820
7976
|
this.dispatchEvent(bindEvent(this, new Event("open")));
|
|
7821
7977
|
});
|
|
7822
7978
|
}
|
|
@@ -7940,6 +8096,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7940
8096
|
return data.byteLength;
|
|
7941
8097
|
}
|
|
7942
8098
|
var kEmitter22 = Symbol("kEmitter");
|
|
8099
|
+
var kBoundListener2 = Symbol("kBoundListener");
|
|
7943
8100
|
var WebSocketServerConnection = class {
|
|
7944
8101
|
constructor(socket, transport, createConnection) {
|
|
7945
8102
|
this.socket = socket;
|
|
@@ -8017,9 +8174,14 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8017
8174
|
* Listen for the incoming events from the original WebSocket server.
|
|
8018
8175
|
*/
|
|
8019
8176
|
addEventListener(event, listener, options) {
|
|
8177
|
+
const boundListener = listener.bind(this.socket);
|
|
8178
|
+
Object.defineProperty(listener, kBoundListener2, {
|
|
8179
|
+
value: boundListener,
|
|
8180
|
+
enumerable: false
|
|
8181
|
+
});
|
|
8020
8182
|
this[kEmitter22].addEventListener(
|
|
8021
8183
|
event,
|
|
8022
|
-
|
|
8184
|
+
boundListener,
|
|
8023
8185
|
options
|
|
8024
8186
|
);
|
|
8025
8187
|
}
|
|
@@ -8029,7 +8191,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8029
8191
|
removeEventListener(event, listener, options) {
|
|
8030
8192
|
this[kEmitter22].removeEventListener(
|
|
8031
8193
|
event,
|
|
8032
|
-
listener,
|
|
8194
|
+
Reflect.get(listener, kBoundListener2),
|
|
8033
8195
|
options
|
|
8034
8196
|
);
|
|
8035
8197
|
}
|
|
@@ -8206,7 +8368,10 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8206
8368
|
socket,
|
|
8207
8369
|
transport,
|
|
8208
8370
|
createConnection
|
|
8209
|
-
)
|
|
8371
|
+
),
|
|
8372
|
+
info: {
|
|
8373
|
+
protocols
|
|
8374
|
+
}
|
|
8210
8375
|
});
|
|
8211
8376
|
});
|
|
8212
8377
|
return socket;
|