Files
nage/server/ref/deno.test.ts
T
2026-09-18 11:41:18 +02:00

65 lines
1.3 KiB
TypeScript

/// <reference lib="deno.ns" />
import { assertEquals } from "jsr:@std/assert";
import { close, connect, flush, href, setup } from "../testSetup.ts";
import { getHandler } from "./deno.ts";
Deno.test(
"Welcome all clients on connect.",
setup(async () => {
const [s1, m1] = await connect(href);
const [s2, m2] = await connect(href);
await flush();
assertEquals(m1, ["Welcome 1, type /join <room>."]);
assertEquals(m2, ["Welcome 2, type /join <room>."]);
await close(s2);
await close(s1);
}, getHandler()),
);
Deno.test(
"Messages all clients in a room on joining.",
setup(async () => {
const [s1, m1] = await connect(href);
const [s2, m2] = await connect(href);
await flush();
m1.length = 0;
m2.length = 0;
s1.send("/join meh");
s2.send("/join meh");
await flush();
assertEquals(m1, ["1 has joined!", "2 has joined!"]);
assertEquals(m2, ["2 has joined!"]);
await close(s2);
await close(s1);
}, getHandler()),
);
Deno.test(
"Messages remaining members if one left the room.",
setup(async () => {
const [s1, m1] = await connect(href);
const [s2, m2] = await connect(href);
s1.send("/join meh");
s2.send("/join meh");
await flush();
m1.length = 0;
m2.length = 0;
await close(s2);
await flush();
assertEquals(m1, ["2 has left!"]);
assertEquals(m2, []);
await close(s1);
}, getHandler()),
);