httpapi-pty-websocket.test.ts 731 B

12345678910111213141516171819
  1. import { describe, expect } from "bun:test"
  2. import { Effect } from "effect"
  3. import { handlePtyInput } from "../../src/pty/input"
  4. import { it } from "../lib/effect"
  5. describe("pty HttpApi websocket input", () => {
  6. it.effect("does not forward invalid binary frames to the PTY handler", () =>
  7. Effect.gen(function* () {
  8. const messages: Array<string | ArrayBuffer> = []
  9. const handler = { onMessage: (message: string | ArrayBuffer) => messages.push(message) }
  10. yield* handlePtyInput(handler, "ready")
  11. yield* handlePtyInput(handler, new Uint8Array([0xff, 0xfe, 0xfd]))
  12. yield* handlePtyInput(handler, new TextEncoder().encode("hello"))
  13. expect(messages).toEqual(["ready", "hello"])
  14. }),
  15. )
  16. })