summaryrefslogtreecommitdiff
path: root/tests/unit/websocket_test.ts
diff options
context:
space:
mode:
authorLuca Casonato <hello@lcas.dev>2024-06-08 18:36:43 +0200
committerGitHub <noreply@github.com>2024-06-08 18:36:43 +0200
commit585ba28d479ea1db20e80c318055c448cb13391b (patch)
treea65db7e12f287c1fcb350aec8f4b093c12700818 /tests/unit/websocket_test.ts
parentc1f23c578881b85ae79b524a60160d8f4fb7151b (diff)
fix(ext/websocket): correctly order messages when sending blobs (#24133)
Previously the asynchronous read of the blob would not block sends that are started later. We now do this, but in such a way as to not regress performance in the common case of not using `Blob`.
Diffstat (limited to 'tests/unit/websocket_test.ts')
-rw-r--r--tests/unit/websocket_test.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/unit/websocket_test.ts b/tests/unit/websocket_test.ts
index 223b13404..74e85052e 100644
--- a/tests/unit/websocket_test.ts
+++ b/tests/unit/websocket_test.ts
@@ -706,6 +706,31 @@ Deno.test("echo arraybuffer with binaryType arraybuffer", async () => {
await promise;
});
+Deno.test("echo blob mixed with string", async () => {
+ const { promise, resolve } = Promise.withResolvers<void>();
+ const ws = new WebSocket("ws://localhost:4242");
+ ws.binaryType = "arraybuffer";
+ const blob = new Blob(["foo"]);
+ ws.onerror = () => fail();
+ ws.onopen = () => {
+ ws.send(blob);
+ ws.send("bar");
+ };
+ const messages: (ArrayBuffer | string)[] = [];
+ ws.onmessage = (e) => {
+ messages.push(e.data);
+ if (messages.length === 2) {
+ assertEquals(messages[0], new Uint8Array([102, 111, 111]).buffer);
+ assertEquals(messages[1], "bar");
+ ws.close();
+ }
+ };
+ ws.onclose = () => {
+ resolve();
+ };
+ await promise;
+});
+
Deno.test("Event Handlers order", async () => {
const { promise, resolve } = Promise.withResolvers<void>();
const ws = new WebSocket("ws://localhost:4242");