msw 2.3.0-ws.rc-3 → 2.3.0-ws.rc-5
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 +134 -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.1/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.1/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.1/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.1/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.1/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.1/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.1/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.1/node_modules/@mswjs/interceptors/lib/browser/interceptors/WebSocket/index.mjs
|
|
7688
7688
|
function bindEvent(target, event) {
|
|
7689
7689
|
Object.defineProperties(event, {
|
|
7690
7690
|
target: {
|
|
@@ -7711,9 +7711,15 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7711
7711
|
get cancelable() {
|
|
7712
7712
|
return this[kCancelable];
|
|
7713
7713
|
}
|
|
7714
|
+
set cancelable(nextCancelable) {
|
|
7715
|
+
this[kCancelable] = nextCancelable;
|
|
7716
|
+
}
|
|
7714
7717
|
get defaultPrevented() {
|
|
7715
7718
|
return this[kDefaultPrevented];
|
|
7716
7719
|
}
|
|
7720
|
+
set defaultPrevented(nextDefaultPrevented) {
|
|
7721
|
+
this[kDefaultPrevented] = nextDefaultPrevented;
|
|
7722
|
+
}
|
|
7717
7723
|
preventDefault() {
|
|
7718
7724
|
if (this.cancelable && !this[kDefaultPrevented]) {
|
|
7719
7725
|
this[kDefaultPrevented] = true;
|
|
@@ -7736,16 +7742,25 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7736
7742
|
this.id = createRequestId();
|
|
7737
7743
|
this.url = new URL(socket.url);
|
|
7738
7744
|
this[kEmitter2] = new EventTarget();
|
|
7739
|
-
this.transport.
|
|
7740
|
-
|
|
7741
|
-
|
|
7745
|
+
this.transport.addEventListener("outgoing", (event) => {
|
|
7746
|
+
const message3 = bindEvent(
|
|
7747
|
+
this.socket,
|
|
7748
|
+
new CancelableMessageEvent("message", {
|
|
7749
|
+
data: event.data,
|
|
7750
|
+
origin: event.origin,
|
|
7751
|
+
cancelable: true
|
|
7752
|
+
})
|
|
7742
7753
|
);
|
|
7743
|
-
|
|
7744
|
-
|
|
7754
|
+
this[kEmitter2].dispatchEvent(message3);
|
|
7755
|
+
if (message3.defaultPrevented) {
|
|
7756
|
+
event.preventDefault();
|
|
7757
|
+
}
|
|
7758
|
+
});
|
|
7759
|
+
this.transport.addEventListener("close", (event) => {
|
|
7745
7760
|
this[kEmitter2].dispatchEvent(
|
|
7746
7761
|
bindEvent(this.socket, new CloseEvent("close", event))
|
|
7747
7762
|
);
|
|
7748
|
-
};
|
|
7763
|
+
});
|
|
7749
7764
|
}
|
|
7750
7765
|
/**
|
|
7751
7766
|
* Listen for the outgoing events from the connected WebSocket client.
|
|
@@ -7932,35 +7947,20 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7932
7947
|
this.createConnection = createConnection;
|
|
7933
7948
|
this[kEmitter22] = new EventTarget();
|
|
7934
7949
|
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
|
-
);
|
|
7950
|
+
this.transport.addEventListener("outgoing", (event) => {
|
|
7951
|
+
if (this.readyState === -1) {
|
|
7952
|
+
return;
|
|
7962
7953
|
}
|
|
7963
|
-
|
|
7954
|
+
queueMicrotask(() => {
|
|
7955
|
+
if (!event.defaultPrevented) {
|
|
7956
|
+
this.send(event.data);
|
|
7957
|
+
}
|
|
7958
|
+
});
|
|
7959
|
+
});
|
|
7960
|
+
this.transport.addEventListener(
|
|
7961
|
+
"incoming",
|
|
7962
|
+
this.handleIncomingMessage.bind(this)
|
|
7963
|
+
);
|
|
7964
7964
|
}
|
|
7965
7965
|
/**
|
|
7966
7966
|
* Server ready state.
|
|
@@ -7994,7 +7994,15 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
7994
7994
|
{ once: true }
|
|
7995
7995
|
);
|
|
7996
7996
|
realWebSocket.addEventListener("message", (event) => {
|
|
7997
|
-
this.transport.
|
|
7997
|
+
this.transport.dispatchEvent(
|
|
7998
|
+
bindEvent(
|
|
7999
|
+
this.realWebSocket,
|
|
8000
|
+
new MessageEvent("incoming", {
|
|
8001
|
+
data: event.data,
|
|
8002
|
+
origin: event.origin
|
|
8003
|
+
})
|
|
8004
|
+
)
|
|
8005
|
+
);
|
|
7998
8006
|
});
|
|
7999
8007
|
this.socket.addEventListener("close", this.handleMockClose.bind(this), {
|
|
8000
8008
|
signal: this.mockCloseController.signal
|
|
@@ -8075,6 +8083,35 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8075
8083
|
);
|
|
8076
8084
|
});
|
|
8077
8085
|
}
|
|
8086
|
+
handleIncomingMessage(event) {
|
|
8087
|
+
const messageEvent = bindEvent(
|
|
8088
|
+
event.target,
|
|
8089
|
+
new CancelableMessageEvent("message", {
|
|
8090
|
+
data: event.data,
|
|
8091
|
+
origin: event.origin,
|
|
8092
|
+
cancelable: true
|
|
8093
|
+
})
|
|
8094
|
+
);
|
|
8095
|
+
this[kEmitter22].dispatchEvent(messageEvent);
|
|
8096
|
+
if (!messageEvent.defaultPrevented) {
|
|
8097
|
+
this.socket.dispatchEvent(
|
|
8098
|
+
bindEvent(
|
|
8099
|
+
/**
|
|
8100
|
+
* @note Bind the forwarded original server events
|
|
8101
|
+
* to the mock WebSocket instance so it would
|
|
8102
|
+
* dispatch them straight away.
|
|
8103
|
+
*/
|
|
8104
|
+
this.socket,
|
|
8105
|
+
// Clone the message event again to prevent
|
|
8106
|
+
// the "already being dispatched" exception.
|
|
8107
|
+
new MessageEvent("message", {
|
|
8108
|
+
data: event.data,
|
|
8109
|
+
origin: event.origin
|
|
8110
|
+
})
|
|
8111
|
+
)
|
|
8112
|
+
);
|
|
8113
|
+
}
|
|
8114
|
+
}
|
|
8078
8115
|
handleMockClose(_event) {
|
|
8079
8116
|
if (this.realWebSocket) {
|
|
8080
8117
|
this.realWebSocket.close();
|
|
@@ -8092,41 +8129,53 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8092
8129
|
}
|
|
8093
8130
|
}
|
|
8094
8131
|
};
|
|
8095
|
-
var
|
|
8096
|
-
};
|
|
8097
|
-
var WebSocketClassTransport = class extends WebSocketTransport {
|
|
8132
|
+
var WebSocketClassTransport = class extends EventTarget {
|
|
8098
8133
|
constructor(socket) {
|
|
8099
8134
|
super();
|
|
8100
8135
|
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
|
|
8136
|
+
this.socket.addEventListener("close", (event) => {
|
|
8137
|
+
this.dispatchEvent(bindEvent(this.socket, new CloseEvent("close", event)));
|
|
8109
8138
|
});
|
|
8110
|
-
this.socket[kOnSend] = (
|
|
8139
|
+
this.socket[kOnSend] = (data) => {
|
|
8140
|
+
this.dispatchEvent(
|
|
8141
|
+
bindEvent(
|
|
8142
|
+
this.socket,
|
|
8143
|
+
// Dispatch this as cancelable because "client" connection
|
|
8144
|
+
// re-creates this message event (cannot dispatch the same event).
|
|
8145
|
+
new CancelableMessageEvent("outgoing", {
|
|
8146
|
+
data,
|
|
8147
|
+
origin: this.socket.url,
|
|
8148
|
+
cancelable: true
|
|
8149
|
+
})
|
|
8150
|
+
)
|
|
8151
|
+
);
|
|
8152
|
+
};
|
|
8153
|
+
}
|
|
8154
|
+
addEventListener(type, callback, options) {
|
|
8155
|
+
return super.addEventListener(type, callback, options);
|
|
8156
|
+
}
|
|
8157
|
+
dispatchEvent(event) {
|
|
8158
|
+
return super.dispatchEvent(event);
|
|
8111
8159
|
}
|
|
8112
8160
|
send(data) {
|
|
8113
8161
|
queueMicrotask(() => {
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
|
|
8122
|
-
|
|
8123
|
-
|
|
8124
|
-
|
|
8125
|
-
|
|
8126
|
-
|
|
8127
|
-
|
|
8162
|
+
this.socket.dispatchEvent(
|
|
8163
|
+
bindEvent(
|
|
8164
|
+
/**
|
|
8165
|
+
* @note Setting this event's "target" to the
|
|
8166
|
+
* WebSocket override instance is important.
|
|
8167
|
+
* This way it can tell apart original incoming events
|
|
8168
|
+
* (must be forwarded to the transport) from the
|
|
8169
|
+
* mocked message events like the one below
|
|
8170
|
+
* (must be dispatched on the client instance).
|
|
8171
|
+
*/
|
|
8172
|
+
this.socket,
|
|
8173
|
+
new MessageEvent("message", {
|
|
8174
|
+
data,
|
|
8175
|
+
origin: this.socket.url
|
|
8176
|
+
})
|
|
8177
|
+
)
|
|
8128
8178
|
);
|
|
8129
|
-
this.socket.dispatchEvent(message3);
|
|
8130
8179
|
});
|
|
8131
8180
|
}
|
|
8132
8181
|
close(code, reason) {
|
|
@@ -8203,9 +8252,6 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8203
8252
|
} else {
|
|
8204
8253
|
options?.onPassthroughConnection(connection);
|
|
8205
8254
|
connection.server.connect();
|
|
8206
|
-
connection.client.addEventListener("message", (event) => {
|
|
8207
|
-
connection.server.send(event.data);
|
|
8208
|
-
});
|
|
8209
8255
|
}
|
|
8210
8256
|
});
|
|
8211
8257
|
}
|
|
@@ -8244,6 +8290,12 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8244
8290
|
}
|
|
8245
8291
|
|
|
8246
8292
|
// src/core/ws/utils/attachWebSocketLogger.ts
|
|
8293
|
+
var colors = {
|
|
8294
|
+
blue: "#3b82f6",
|
|
8295
|
+
green: "#22c55e",
|
|
8296
|
+
red: "#ef4444",
|
|
8297
|
+
orange: "#ff6a33"
|
|
8298
|
+
};
|
|
8247
8299
|
function attachWebSocketLogger(connection) {
|
|
8248
8300
|
const { client, server } = connection;
|
|
8249
8301
|
logConnectionOpen(client);
|
|
@@ -8312,8 +8364,8 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8312
8364
|
function logConnectionOpen(client) {
|
|
8313
8365
|
const publicUrl = toPublicUrl(client.url);
|
|
8314
8366
|
console.groupCollapsed(
|
|
8315
|
-
devUtils.formatMessage(`${getTimestamp()} %c\
|
|
8316
|
-
|
|
8367
|
+
devUtils.formatMessage(`${getTimestamp()} %c\u25B6%c ${publicUrl}`),
|
|
8368
|
+
`color:${colors.blue}`,
|
|
8317
8369
|
"color:inherit"
|
|
8318
8370
|
);
|
|
8319
8371
|
console.log("Client:", client.socket);
|
|
@@ -8326,7 +8378,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8326
8378
|
devUtils.formatMessage(
|
|
8327
8379
|
`${getTimestamp({ milliseconds: true })} %c\u2191%c ${publicData} %c${byteLength}%c`
|
|
8328
8380
|
),
|
|
8329
|
-
|
|
8381
|
+
`color:${colors.green}`,
|
|
8330
8382
|
"color:inherit",
|
|
8331
8383
|
"color:gray;font-weight:normal",
|
|
8332
8384
|
"color:inherit;font-weight:inherit"
|
|
@@ -8341,7 +8393,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8341
8393
|
devUtils.formatMessage(
|
|
8342
8394
|
`${getTimestamp({ milliseconds: true })} %c\u21E1%c ${publicData} %c${byteLength}%c`
|
|
8343
8395
|
),
|
|
8344
|
-
|
|
8396
|
+
`color:${colors.orange}`,
|
|
8345
8397
|
"color:inherit",
|
|
8346
8398
|
"color:gray;font-weight:normal",
|
|
8347
8399
|
"color:inherit;font-weight:inherit"
|
|
@@ -8356,7 +8408,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8356
8408
|
devUtils.formatMessage(
|
|
8357
8409
|
`${getTimestamp({ milliseconds: true })} %c\u2193%c ${publicData} %c${byteLength}%c`
|
|
8358
8410
|
),
|
|
8359
|
-
|
|
8411
|
+
`color:${colors.red}`,
|
|
8360
8412
|
"color:inherit",
|
|
8361
8413
|
"color:gray;font-weight:normal",
|
|
8362
8414
|
"color:inherit;font-weight:inherit"
|
|
@@ -8371,7 +8423,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8371
8423
|
devUtils.formatMessage(
|
|
8372
8424
|
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8373
8425
|
),
|
|
8374
|
-
|
|
8426
|
+
`color:${colors.orange}`,
|
|
8375
8427
|
"color:inherit",
|
|
8376
8428
|
"color:gray;font-weight:normal",
|
|
8377
8429
|
"color:inherit;font-weight:inherit"
|
|
@@ -8386,7 +8438,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8386
8438
|
devUtils.formatMessage(
|
|
8387
8439
|
`${getTimestamp({ milliseconds: true })} %c\u25A0%c ${publicUrl}`
|
|
8388
8440
|
),
|
|
8389
|
-
|
|
8441
|
+
`color:${colors.blue}`,
|
|
8390
8442
|
"color:inherit"
|
|
8391
8443
|
);
|
|
8392
8444
|
console.log(event);
|
|
@@ -8399,7 +8451,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8399
8451
|
devUtils.formatMessage(
|
|
8400
8452
|
`${getTimestamp({ milliseconds: true })} %c\u21E3%c ${publicData} %c${byteLength}%c`
|
|
8401
8453
|
),
|
|
8402
|
-
|
|
8454
|
+
`color:${colors.green}`,
|
|
8403
8455
|
"color:inherit",
|
|
8404
8456
|
"color:gray;font-weight:normal",
|
|
8405
8457
|
"color:inherit;font-weight:inherit"
|
|
@@ -8414,7 +8466,7 @@ Please consider using a custom "serviceWorker.url" option to point to the actual
|
|
|
8414
8466
|
devUtils.formatMessage(
|
|
8415
8467
|
`${getTimestamp({ milliseconds: true })} %c\xD7%c ${publicUrl}`
|
|
8416
8468
|
),
|
|
8417
|
-
|
|
8469
|
+
`color:${colors.blue}`,
|
|
8418
8470
|
"color:inherit"
|
|
8419
8471
|
);
|
|
8420
8472
|
console.log(event);
|