diff options
Diffstat (limited to 'cli/tests')
-rw-r--r-- | cli/tests/testdata/run/websocket_test.ts | 2 | ||||
-rw-r--r-- | cli/tests/unit/websocket_test.ts | 54 |
2 files changed, 51 insertions, 5 deletions
diff --git a/cli/tests/testdata/run/websocket_test.ts b/cli/tests/testdata/run/websocket_test.ts index 43db15cce..b759d042d 100644 --- a/cli/tests/testdata/run/websocket_test.ts +++ b/cli/tests/testdata/run/websocket_test.ts @@ -163,7 +163,7 @@ Deno.test("websocket error", async () => { // Error message got changed because we don't use warp in test_util assertEquals( err.message, - "InvalidData: invalid data", + "NetworkError: failed to connect to WebSocket: invalid data", ); promise1.resolve(); }; diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts index 8ae729d42..697f524d0 100644 --- a/cli/tests/unit/websocket_test.ts +++ b/cli/tests/unit/websocket_test.ts @@ -29,6 +29,50 @@ Deno.test(async function websocketConstructorTakeURLObjectAsParameter() { await promise; }); +Deno.test(async function websocketH2SendSmallPacket() { + const promise = deferred(); + const ws = new WebSocket(new URL("wss://localhost:4248/")); + assertEquals(ws.url, "wss://localhost:4248/"); + let messageCount = 0; + ws.onerror = (e) => promise.reject(e); + ws.onopen = () => { + ws.send("a".repeat(16)); + ws.send("a".repeat(16)); + ws.send("a".repeat(16)); + }; + ws.onmessage = () => { + if (++messageCount == 3) { + ws.close(); + } + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + +Deno.test(async function websocketH2SendLargePacket() { + const promise = deferred(); + const ws = new WebSocket(new URL("wss://localhost:4248/")); + assertEquals(ws.url, "wss://localhost:4248/"); + let messageCount = 0; + ws.onerror = (e) => promise.reject(e); + ws.onopen = () => { + ws.send("a".repeat(65000)); + ws.send("a".repeat(65000)); + ws.send("a".repeat(65000)); + }; + ws.onmessage = () => { + if (++messageCount == 3) { + ws.close(); + } + }; + ws.onclose = () => { + promise.resolve(); + }; + await promise; +}); + Deno.test(async function websocketSendLargePacket() { const promise = deferred(); const ws = new WebSocket(new URL("wss://localhost:4243/")); @@ -49,13 +93,14 @@ Deno.test(async function websocketSendLargePacket() { Deno.test(async function websocketSendLargeBinaryPacket() { const promise = deferred(); const ws = new WebSocket(new URL("wss://localhost:4243/")); + ws.binaryType = "arraybuffer"; assertEquals(ws.url, "wss://localhost:4243/"); ws.onerror = (e) => promise.reject(e); ws.onopen = () => { ws.send(new Uint8Array(65000)); }; - ws.onmessage = (msg) => { - console.log(msg); + ws.onmessage = (msg: MessageEvent) => { + assertEquals(msg.data.byteLength, 65000); ws.close(); }; ws.onclose = () => { @@ -67,13 +112,14 @@ Deno.test(async function websocketSendLargeBinaryPacket() { Deno.test(async function websocketSendLargeBlobPacket() { const promise = deferred(); const ws = new WebSocket(new URL("wss://localhost:4243/")); + ws.binaryType = "arraybuffer"; assertEquals(ws.url, "wss://localhost:4243/"); ws.onerror = (e) => promise.reject(e); ws.onopen = () => { ws.send(new Blob(["a".repeat(65000)])); }; - ws.onmessage = (msg) => { - console.log(msg); + ws.onmessage = (msg: MessageEvent) => { + assertEquals(msg.data.byteLength, 65000); ws.close(); }; ws.onclose = () => { |