diff options
Diffstat (limited to 'test/js/first_party/ws/ws.test.ts')
-rw-r--r-- | test/js/first_party/ws/ws.test.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/test/js/first_party/ws/ws.test.ts b/test/js/first_party/ws/ws.test.ts index fc8e63f5f..58d06c710 100644 --- a/test/js/first_party/ws/ws.test.ts +++ b/test/js/first_party/ws/ws.test.ts @@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterEach } from "bun:test"; import type { Subprocess } from "bun"; import { spawn } from "bun"; import { bunEnv, bunExe, nodeExe } from "harness"; -import { WebSocket } from "ws"; +import { WebSocket, WebSocketServer } from "ws"; const strings = [ { @@ -239,6 +239,30 @@ describe("WebSocket", () => { }); }); +it("isBinary", done => { + const wss = new WebSocketServer({ port: 0 }); + let isDone = false; + wss.on("connection", ws => { + ws.on("message", (data, isBinary) => { + if (isDone) { + expect(isBinary).toBeTrue(); + wss.close(); + ws.close(); + done(); + return; + } + expect(isBinary).toBeFalse(); + isDone = true; + }); + }); + + const ws = new WebSocket("ws://localhost:" + wss.address().port); + ws.on("open", function open() { + ws.send("hello"); + ws.send(Buffer.from([1, 2, 3])); + }); +}); + function test(label: string, fn: (ws: WebSocket, done: (err?: unknown) => void) => void, timeout?: number) { it( label, |