Generator-emitted scaffold (pnpm turbo gen core-package realtime) plus the story-00-precedent coverage repairs (coverage provider devDep, symbols.ts exclude + tested allowlist mirror) and three minimal tests covering generator-emitted realtime code the template suite misses. Squash of 31d85e0 + review-fix cf11b38. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016j8z4VHjedXDTjEDNg7qHK
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { z } from "zod";
|
|
import { InMemoryRealtimeBroadcaster } from "@/in-memory-realtime-broadcaster";
|
|
import { defineRealtimeChannel } from "@/realtime-channel";
|
|
|
|
const ch = defineRealtimeChannel("a.b", z.object({ x: z.number() }).strict(), {
|
|
scope: "public",
|
|
});
|
|
|
|
describe("InMemoryRealtimeBroadcaster", () => {
|
|
it("validates payload via the descriptor schema", async () => {
|
|
const b = new InMemoryRealtimeBroadcaster();
|
|
await expect(
|
|
b.broadcast(ch, { x: "not a number" } as never),
|
|
).rejects.toThrow();
|
|
});
|
|
|
|
it("delivers to subscribers in order", async () => {
|
|
const b = new InMemoryRealtimeBroadcaster();
|
|
const got: number[] = [];
|
|
b.subscribe(ch, async (p) => {
|
|
got.push(p.x);
|
|
});
|
|
await b.broadcast(ch, { x: 1 });
|
|
await b.broadcast(ch, { x: 2 });
|
|
expect(got).toEqual([1, 2]);
|
|
});
|
|
|
|
it("does nothing when no subscribers", async () => {
|
|
const b = new InMemoryRealtimeBroadcaster();
|
|
await b.broadcast(ch, { x: 1 });
|
|
// does not throw
|
|
});
|
|
});
|