diff options
author | Luca Casonato <lucacasonato@yahoo.com> | 2020-09-09 21:33:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-09 21:33:38 +0200 |
commit | a3bcdb2b69bdaa9b616df6db07f1c88c8b578fb2 (patch) | |
tree | 6a7732bdcf683e25dc4b4af4946ff4f58b432e3b /std/examples | |
parent | 0d126930cab8167f42ad8607faa202b30b42c680 (diff) |
chore(std): remove std/ws connect method (#7403)
Diffstat (limited to 'std/examples')
-rw-r--r-- | std/examples/chat/server_test.ts | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts index 8a5bf5471..336b188e9 100644 --- a/std/examples/chat/server_test.ts +++ b/std/examples/chat/server_test.ts @@ -2,7 +2,6 @@ import { assert, assertEquals } from "../../testing/asserts.ts"; import { TextProtoReader } from "../../textproto/mod.ts"; import { BufReader } from "../../io/bufio.ts"; -import { connectWebSocket, WebSocket } from "../../ws/mod.ts"; import { delay } from "../../async/delay.ts"; import { resolve, dirname, fromFileUrl } from "../../path/mod.ts"; @@ -57,18 +56,25 @@ Deno.test({ name: "[examples/chat] GET /ws should upgrade conn to ws", async fn() { const server = await startServer(); - let ws: WebSocket | undefined; + let ws: WebSocket; try { - ws = await connectWebSocket("http://127.0.0.1:8080/ws"); - const it = ws[Symbol.asyncIterator](); - - assertEquals((await it.next()).value, "Connected: [1]"); - ws.send("Hello"); - assertEquals((await it.next()).value, "[1]: Hello"); + ws = new WebSocket("ws://127.0.0.1:8080/ws"); + await new Promise((resolve) => { + ws.onmessage = ((message) => { + assertEquals(message.data, "Connected: [1]"); + ws.onmessage = ((message) => { + assertEquals(message.data, "[1]: Hello"); + ws.close(); + resolve(); + }); + ws.send("Hello"); + }); + }); + } catch (err) { + console.log(err); } finally { server.close(); server.stdout.close(); - ws!.conn.close(); } }, }); |