msw 2.3.0-ws.rc-3 → 2.3.0-ws.rc-4
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 +7 -7
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index.mjs +7 -7
- package/lib/browser/index.mjs.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.js +0 -3
- package/lib/core/ws/handleWebSocketEvent.js.map +1 -1
- package/lib/core/ws/handleWebSocketEvent.mjs +0 -3
- package/lib/core/ws/handleWebSocketEvent.mjs.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.js +15 -9
- package/lib/core/ws/utils/attachWebSocketLogger.js.map +1 -1
- package/lib/core/ws/utils/attachWebSocketLogger.mjs +15 -9
- package/lib/core/ws/utils/attachWebSocketLogger.mjs.map +1 -1
- package/lib/iife/index.js +128 -82
- package/lib/iife/index.js.map +1 -1
- package/lib/mockServiceWorker.js +1 -1
- package/package.json +2 -2
- package/src/core/ws/handleWebSocketEvent.ts +0 -3
- package/src/core/ws/utils/attachWebSocketLogger.ts +16 -9
- package/src/core/ws.test.ts +1 -1
package/lib/iife/index.js
CHANGED
|
@@ -1129,7 +1129,7 @@ var MockServiceWorker = (() => {
|
|
|
1129
1129
|
return stringToRegexp(path, keys, options);
|
|
1130
1130
|
}
|
|
1131
1131
|
|
|
1132
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1132
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.27.0/node_modules/@mswjs/interceptors/lib/browser/chunk-UJZOJSMP.mjs
|
|
1133
1133
|
var encoder = new TextEncoder();
|
|
1134
1134
|
function encodeBuffer(text) {
|
|
1135
1135
|
return encoder.encode(text);
|
|
@@ -1155,7 +1155,7 @@ var MockServiceWorker = (() => {
|
|
|
1155
1155
|
return RESPONSE_STATUS_CODES_WITHOUT_BODY.has(status);
|
|
1156
1156
|
}
|
|
1157
1157
|
|
|
1158
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1158
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.27.0/node_modules/@mswjs/interceptors/lib/browser/chunk-HAGW22AN.mjs
|
|
1159
1159
|
var IS_PATCHED_MODULE = Symbol("isPatchedModule");
|
|
1160
1160
|
|
|
1161
1161
|
// node_modules/.pnpm/is-node-process@1.2.0/node_modules/is-node-process/lib/index.mjs
|
|
@@ -1445,7 +1445,7 @@ var MockServiceWorker = (() => {
|
|
|
1445
1445
|
return message3.toString();
|
|
1446
1446
|
}
|
|
1447
1447
|
|
|
1448
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1448
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.27.0/node_modules/@mswjs/interceptors/lib/browser/chunk-QED3Q6Z2.mjs
|
|
1449
1449
|
var INTERNAL_REQUEST_ID_HEADER_NAME = "x-interceptors-internal-request-id";
|
|
1450
1450
|
function getGlobalSymbol(symbol) {
|
|
1451
1451
|
return (
|
|
@@ -1593,7 +1593,7 @@ var MockServiceWorker = (() => {
|
|
|
1593
1593
|
return Math.random().toString(16).slice(2);
|
|
1594
1594
|
}
|
|
1595
1595
|
|
|
1596
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
1596
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.27.0/node_modules/@mswjs/interceptors/lib/browser/index.mjs
|
|
1597
1597
|
var BatchInterceptor = class extends Interceptor {
|
|
1598
1598
|
constructor(options) {
|
|
1599
1599
|
BatchInterceptor.symbol = Symbol(options.name);
|
|
@@ -6674,7 +6674,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6674
6674
|
}
|
|
6675
6675
|
};
|
|
6676
6676
|
|
|
6677
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6677
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.27.0/node_modules/@mswjs/interceptors/lib/browser/chunk-OUWBQF3Z.mjs
|
|
6678
6678
|
var RequestController = class {
|
|
6679
6679
|
constructor(request) {
|
|
6680
6680
|
this.request = request;
|
|
@@ -6712,7 +6712,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6712
6712
|
}
|
|
6713
6713
|
}
|
|
6714
6714
|
|
|
6715
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6715
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.27.0/node_modules/@mswjs/interceptors/lib/browser/chunk-3FNUI33J.mjs
|
|
6716
6716
|
function isPropertyAccessible2(obj, key) {
|
|
6717
6717
|
try {
|
|
6718
6718
|
obj[key];
|
|
@@ -6859,7 +6859,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
6859
6859
|
});
|
|
6860
6860
|
}
|
|
6861
6861
|
|
|
6862
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
6862
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.27.0/node_modules/@mswjs/interceptors/lib/browser/chunk-VYFS2IF2.mjs
|
|
6863
6863
|
function concatArrayBuffer(left, right) {
|
|
6864
6864
|
const result = new Uint8Array(left.byteLength + right.byteLength);
|
|
6865
6865
|
result.set(left, 0);
|
|
@@ -7684,7 +7684,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7684
7684
|
}
|
|
7685
7685
|
}
|
|
7686
7686
|
|
|
7687
|
-
// node_modules/.pnpm/@mswjs+interceptors@0.
|
|
7687
|
+
// node_modules/.pnpm/@mswjs+interceptors@0.27.0/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
7688
7688
|
function bindEvent(target, event) {
|
|
7689
7689
|
Object.defineProperties(event, {
|
|
7690
7690
|
target: {
|
|
@@ -7736,16 +7736,25 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7736
7736
|
this.id = createRequestId();
|
|
7737
7737
|
this.url = new URL(socket.url);
|
|
7738
7738
|
this[kEmitter2] = new EventTarget();
|
|
7739
|
-
this.transport.
|
|
7740
|
-
|
|
7741
|
-
|
|
7739
|
+
this.transport.addEventListener("outgoing", (event) => {
|
|
7740
|
+
const message3 = bindEvent(
|
|
7741
|
+
this.socket,
|
|
7742
|
+
new CancelableMessageEvent("message", {
|
|
7743
|
+
data: event.data,
|
|
7744
|
+
origin: event.origin,
|
|
7745
|
+
cancelable: true
|
|
7746
|
+
})
|
|
7742
7747
|
);
|
|
7743
|
-
|
|
7744
|
-
|
|
7748
|
+
this[kEmitter2].dispatchEvent(message3);
|
|
7749
|
+
if (message3.defaultPrevented) {
|
|
7750
|
+
event.preventDefault();
|
|
7751
|
+
}
|
|
7752
|
+
});
|
|
7753
|
+
this.transport.addEventListener("close", (event) => {
|
|
7745
7754
|
this[kEmitter2].dispatchEvent(
|
|
7746
7755
|
bindEvent(this.socket, new CloseEvent("close", event))
|
|
7747
7756
|
);
|
|
7748
|
-
};
|
|
7757
|
+
});
|
|
7749
7758
|
}
|
|
7750
7759
|
/**
|
|
7751
7760
|
* Listen for the outgoing events from the connected WebSocket client.
|
|
@@ -7932,35 +7941,20 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7932
7941
|
this.createConnection = createConnection;
|
|
7933
7942
|
this[kEmitter22] = new EventTarget();
|
|
7934
7943
|
this.mockCloseController = new AbortController();
|
|
7935
|
-
this.transport.
|
|
7936
|
-
|
|
7937
|
-
|
|
7938
|
-
new CancelableMessageEvent("message", {
|
|
7939
|
-
data: event.data,
|
|
7940
|
-
origin: event.origin,
|
|
7941
|
-
cancelable: true
|
|
7942
|
-
})
|
|
7943
|
-
);
|
|
7944
|
-
this[kEmitter22].dispatchEvent(messageEvent);
|
|
7945
|
-
if (!messageEvent.defaultPrevented) {
|
|
7946
|
-
this.socket.dispatchEvent(
|
|
7947
|
-
bindEvent(
|
|
7948
|
-
/**
|
|
7949
|
-
* @note Bind the forwarded original server events
|
|
7950
|
-
* to the mock WebSocket instance so it would
|
|
7951
|
-
* dispatch them straight away.
|
|
7952
|
-
*/
|
|
7953
|
-
this.socket,
|
|
7954
|
-
// Clone the message event again to prevent
|
|
7955
|
-
// the "already being dispatched" exception.
|
|
7956
|
-
new MessageEvent("message", {
|
|
7957
|
-
data: event.data,
|
|
7958
|
-
origin: event.origin
|
|
7959
|
-
})
|
|
7960
|
-
)
|
|
7961
|
-
);
|
|
7944
|
+
this.transport.addEventListener("outgoing", (event) => {
|
|
7945
|
+
if (this.readyState === -1) {
|
|
7946
|
+
return;
|
|
7962
7947
|
}
|
|
7963
|
-
|
|
7948
|
+
queueMicrotask(() => {
|
|
7949
|
+
if (!event.defaultPrevented) {
|
|
7950
|
+
this.send(event.data);
|
|
7951
|
+
}
|
|
7952
|
+
});
|
|
7953
|
+
});
|
|
7954
|
+
this.transport.addEventListener(
|
|
7955
|
+
"incoming",
|
|
7956
|
+
this.handleIncomingMessage.bind(this)
|
|
7957
|
+
);
|
|
7964
7958
|
}
|
|
7965
7959
|
/**
|
|
7966
7960
|
* Server ready state.
|
|
@@ -7994,7 +7988,15 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7994
7988
|
{ once: true }
|
|
7995
7989
|
);
|
|
7996
7990
|
realWebSocket.addEventListener("message", (event) => {
|
|
7997
|
-
this.transport.
|
|
7991
|
+
this.transport.dispatchEvent(
|
|
7992
|
+
bindEvent(
|
|
7993
|
+
this.realWebSocket,
|
|
7994
|
+
new MessageEvent("incoming", {
|
|
7995
|
+
data: event.data,
|
|
7996
|
+
origin: event.origin
|
|
7997
|
+
})
|
|
7998
|
+
)
|
|
7999
|
+
);
|
|
7998
8000
|
});
|
|
7999
8001
|
this.socket.addEventListener("close", this.handleMockClose.bind(this), {
|
|
8000
8002
|
signal: this.mockCloseController.signal
|
|
@@ -8075,6 +8077,35 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8075
8077
|
);
|
|
8076
8078
|
});
|
|
8077
8079
|
}
|
|
8080
|
+
handleIncomingMessage(event) {
|
|
8081
|
+
const messageEvent = bindEvent(
|
|
8082
|
+
event.target,
|
|
8083
|
+
new CancelableMessageEvent("message", {
|
|
8084
|
+
data: event.data,
|
|
8085
|
+
origin: event.origin,
|
|
8086
|
+
cancelable: true
|
|
8087
|
+
})
|
|
8088
|
+
);
|
|
8089
|
+
this[kEmitter22].dispatchEvent(messageEvent);
|
|
8090
|
+
if (!messageEvent.defaultPrevented) {
|
|
8091
|
+
this.socket.dispatchEvent(
|
|
8092
|
+
bindEvent(
|
|
8093
|
+
/**
|
|
8094
|
+
* @note Bind the forwarded original server events
|
|
8095
|
+
* to the mock WebSocket instance so it would
|
|
8096
|
+
* dispatch them straight away.
|
|
8097
|
+
*/
|
|
8098
|
+
this.socket,
|
|
8099
|
+
// Clone the message event again to prevent
|
|
8100
|
+
// the "already being dispatched" exception.
|
|
8101
|
+
new MessageEvent("message", {
|
|
8102
|
+
data: event.data,
|
|
8103
|
+
origin: event.origin
|
|
8104
|
+
})
|
|
8105
|
+
)
|
|
8106
|
+
);
|
|
8107
|
+
}
|
|
8108
|
+
}
|
|
8078
8109
|
handleMockClose(_event) {
|
|
8079
8110
|
if (this.realWebSocket) {
|
|
8080
8111
|
this.realWebSocket.close();
|
|
@@ -8092,41 +8123,53 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8092
8123
|
}
|
|
8093
8124
|
}
|
|
8094
8125
|
};
|
|
8095
|
-
var
|
|
8096
|
-
};
|
|
8097
|
-
var WebSocketClassTransport = class extends WebSocketTransport {
|
|
8126
|
+
var WebSocketClassTransport = class extends EventTarget {
|
|
8098
8127
|
constructor(socket) {
|
|
8099
8128
|
super();
|
|
8100
8129
|
this.socket = socket;
|
|
8101
|
-
this.
|
|
8102
|
-
|
|
8103
|
-
this.onIncoming = () => {
|
|
8104
|
-
};
|
|
8105
|
-
this.onClose = () => {
|
|
8106
|
-
};
|
|
8107
|
-
this.socket.addEventListener("close", (event) => this.onClose(event), {
|
|
8108
|
-
once: true
|
|
8130
|
+
this.socket.addEventListener("close", (event) => {
|
|
8131
|
+
this.dispatchEvent(bindEvent(this.socket, new CloseEvent("close", event)));
|
|
8109
8132
|
});
|
|
8110
|
-
this.socket[kOnSend] = (
|
|
8133
|
+
this.socket[kOnSend] = (data) => {
|
|
8134
|
+
this.dispatchEvent(
|
|
8135
|
+
bindEvent(
|
|
8136
|
+
this.socket,
|
|
8137
|
+
// Dispatch this as cancelable because "client" connection
|
|
8138
|
+
// re-creates this message event (cannot dispatch the same event).
|
|
8139
|
+
new CancelableMessageEvent("outgoing", {
|
|
8140
|
+
data,
|
|
8141
|
+
origin: this.socket.url,
|
|
8142
|
+
cancelable: true
|
|
8143
|
+
})
|
|
8144
|
+
)
|
|
8145
|
+
);
|
|
8146
|
+
};
|
|
8147
|
+
}
|
|
8148
|
+
addEventListener(type, callback, options) {
|
|
8149
|
+
return super.addEventListener(type, callback, options);
|
|
8150
|
+
}
|
|
8151
|
+
dispatchEvent(event) {
|
|
8152
|
+
return super.dispatchEvent(event);
|
|
8111
8153
|
}
|
|
8112
8154
|
send(data) {
|
|
8113
8155
|
queueMicrotask(() => {
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8156
|
+
this.socket.dispatchEvent(
|
|
8157
|
+
bindEvent(
|
|
8158
|
+
/**
|
|
8159
|
+
* @note Setting this event's "target" to the
|
|
8160
|
+
* WebSocket override instance is important.
|
|
8161
|
+
* This way it can tell apart original incoming events
|
|
8162
|
+
* (must be forwarded to the transport) from the
|
|
8163
|
+
* mocked message events like the one below
|
|
8164
|
+
* (must be dispatched on the client instance).
|
|
8165
|
+
*/
|
|
8166
|
+
this.socket,
|
|
8167
|
+
new MessageEvent("message", {
|
|
8168
|
+
data,
|
|
8169
|
+
origin: this.socket.url
|
|
8170
|
+
})
|
|
8171
|
+
)
|
|
8128
8172
|
);
|
|
8129
|
-
this.socket.dispatchEvent(message3);
|
|
8130
8173
|
});
|
|
8131
8174
|
}
|
|
8132
8175
|
close(code, reason) {
|
|
@@ -8203,9 +8246,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8203
8246
|
} else {
|
|
8204
8247
|
options?.onPassthroughConnection(connection);
|
|
8205
8248
|
connection.server.connect();
|
|
8206
|
-
connection.client.addEventListener("message", (event) => {
|
|
8207
|
-
connection.server.send(event.data);
|
|
8208
|
-
});
|
|
8209
8249
|
}
|
|
8210
8250
|
});
|
|
8211
8251
|
}
|
|
@@ -8244,6 +8284,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8244
8284
|
}
|
|
8245
8285
|
|
|
8246
8286
|
// src/core/ws/utils/attachWebSocketLogger.ts
|
|
8287
|
+
var colors = {
|
|
8288
|
+
blue: "#3b82f6",
|
|
8289
|
+
green: "#22c55e",
|
|
8290
|
+
red: "#ef4444",
|
|
8291
|
+
orange: "#ff6a33"
|
|
8292
|
+
};
|
|
8247
8293
|
function attachWebSocketLogger(connection) {
|
|
8248
8294
|
const { client, server } = connection;
|
|
8249
8295
|
logConnectionOpen(client);
|
|
@@ -8312,8 +8358,8 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8312
8358
|
function logConnectionOpen(client) {
|
|
8313
8359
|
const publicUrl = toPublicUrl(client.url);
|
|
8314
8360
|
console.groupCollapsed(
|
|
8315
|
-
devUtils.formatMessage(`${getTimestamp()} %c\
|
|
8316
|
-
|
|
8361
|
+
devUtils.formatMessage(`${getTimestamp()} %c\u25B6%c ${publicUrl}`),
|
|
8362
|
+
`color:${colors.blue}`,
|
|
8317
8363
|
"color:inherit"
|
|
8318
8364
|
);
|
|
8319
8365
|
console.log("Client:", client.socket);
|
|
@@ -8326,7 +8372,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8326
8372
|
devUtils.formatMessage(
|
|
8327
8373
|
`${getTimestamp({ milliseconds: true })} %c\u2191%c ${publicData} %c${byteLength}%c`
|
|
8328
8374
|
),
|
|
8329
|
-
|
|
8375
|
+
`color:${colors.green}`,
|
|
8330
8376
|
"color:inherit",
|
|
8331
8377
|
"color:gray;font-weight:normal",
|
|
8332
8378
|
"color:inherit;font-weight:inherit"
|
|
@@ -8341,7 +8387,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8341
8387
|
devUtils.formatMessage(
|
|
8342
8388
|
`${getTimestamp({ milliseconds: true })} %c\u21E1%c ${publicData} %c${byteLength}%c`
|
|
8343
8389
|
),
|
|
8344
|
-
|
|
8390
|
+
`color:${colors.orange}`,
|
|
8345
8391
|
"color:inherit",
|
|
8346
8392
|
"color:gray;font-weight:normal",
|
|
8347
8393
|
"color:inherit;font-weight:inherit"
|
|
@@ -8356,7 +8402,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8356
8402
|
devUtils.formatMessage(
|
|
8357
8403
|
`${getTimestamp({ milliseconds: true })} %c\u2193%c ${publicData} %c${byteLength}%c`
|
|
8358
8404
|
),
|
|
8359
|
-
|
|
8405
|
+
`color:${colors.red}`,
|
|
8360
8406
|
"color:inherit",
|
|
8361
8407
|
"color:gray;font-weight:normal",
|
|
8362
8408
|
"color:inherit;font-weight:inherit"
|
|
@@ -8371,7 +8417,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8371
8417
|
devUtils.formatMessage(
|
|
8372
8418
|
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8373
8419
|
),
|
|
8374
|
-
|
|
8420
|
+
`color:${colors.orange}`,
|
|
8375
8421
|
"color:inherit",
|
|
8376
8422
|
"color:gray;font-weight:normal",
|
|
8377
8423
|
"color:inherit;font-weight:inherit"
|
|
@@ -8386,7 +8432,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8386
8432
|
devUtils.formatMessage(
|
|
8387
8433
|
`${getTimestamp({ milliseconds: true })} %c\u25A0%c ${publicUrl}`
|
|
8388
8434
|
),
|
|
8389
|
-
|
|
8435
|
+
`color:${colors.blue}`,
|
|
8390
8436
|
"color:inherit"
|
|
8391
8437
|
);
|
|
8392
8438
|
console.log(event);
|
|
@@ -8399,7 +8445,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8399
8445
|
devUtils.formatMessage(
|
|
8400
8446
|
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8401
8447
|
),
|
|
8402
|
-
|
|
8448
|
+
`color:${colors.green}`,
|
|
8403
8449
|
"color:inherit",
|
|
8404
8450
|
"color:gray;font-weight:normal",
|
|
8405
8451
|
"color:inherit;font-weight:inherit"
|
|
@@ -8414,7 +8460,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8414
8460
|
devUtils.formatMessage(
|
|
8415
8461
|
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
8416
8462
|
),
|
|
8417
|
-
|
|
8463
|
+
`color:${colors.blue}`,
|
|
8418
8464
|
"color:inherit"
|
|
8419
8465
|
);
|
|
8420
8466
|
console.log(event);
|