summaryrefslogtreecommitdiff
path: root/cli/tests/unit/websocket_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit/websocket_test.ts')
-rw-r--r--cli/tests/unit/websocket_test.ts61
1 files changed, 58 insertions, 3 deletions
diff --git a/cli/tests/unit/websocket_test.ts b/cli/tests/unit/websocket_test.ts
index 11f0fd7dc..b761cd118 100644
--- a/cli/tests/unit/websocket_test.ts
+++ b/cli/tests/unit/websocket_test.ts
@@ -21,7 +21,7 @@ Deno.test(async function websocketConstructorTakeURLObjectAsParameter() {
const promise = deferred();
const ws = new WebSocket(new URL("ws://localhost:4242/"));
assertEquals(ws.url, "ws://localhost:4242/");
- ws.onerror = () => fail();
+ ws.onerror = (e) => promise.reject(e);
ws.onopen = () => ws.close();
ws.onclose = () => {
promise.resolve();
@@ -29,13 +29,66 @@ Deno.test(async function websocketConstructorTakeURLObjectAsParameter() {
await promise;
});
+Deno.test(async function websocketSendLargePacket() {
+ const promise = deferred();
+ const ws = new WebSocket(new URL("wss://localhost:4243/"));
+ assertEquals(ws.url, "wss://localhost:4243/");
+ ws.onerror = (e) => promise.reject(e);
+ ws.onopen = () => {
+ ws.send("a".repeat(65000));
+ };
+ ws.onmessage = () => {
+ ws.close();
+ };
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await promise;
+});
+
+Deno.test(async function websocketSendLargeBinaryPacket() {
+ const promise = deferred();
+ const ws = new WebSocket(new URL("wss://localhost:4243/"));
+ 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.close();
+ };
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await promise;
+});
+
+Deno.test(async function websocketSendLargeBlobPacket() {
+ const promise = deferred();
+ const ws = new WebSocket(new URL("wss://localhost:4243/"));
+ 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.close();
+ };
+ ws.onclose = () => {
+ promise.resolve();
+ };
+ await promise;
+});
+
// https://github.com/denoland/deno/pull/17762
// https://github.com/denoland/deno/issues/17761
Deno.test(async function websocketPingPong() {
const promise = deferred();
const ws = new WebSocket("ws://localhost:4245/");
assertEquals(ws.url, "ws://localhost:4245/");
- ws.onerror = () => fail();
+ ws.onerror = (e) => promise.reject(e);
ws.onmessage = (e) => {
ws.send(e.data);
};
@@ -144,7 +197,9 @@ Deno.test({
const ws = new WebSocket(serveUrl);
assertEquals(ws.url, serveUrl);
ws.onerror = () => fail();
- ws.onmessage = () => ws.send("bye");
+ ws.onmessage = (m: MessageEvent) => {
+ if (m.data == "Hello") ws.send("bye");
+ };
ws.onclose = () => {
promise.resolve();
};