0e8d5a9bcf
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
32 lines
932 B
TypeScript
32 lines
932 B
TypeScript
// server/ws/outputHub.test.ts
|
|
import { describe, it, expect, vi } from "vitest";
|
|
import { OutputHub } from "./outputHub.js";
|
|
|
|
describe("OutputHub", () => {
|
|
it("rejoue le buffer aux nouveaux abonnés", () => {
|
|
const hub = new OutputHub();
|
|
hub.publish("m1", "ligne1");
|
|
hub.publish("m1", "ligne2");
|
|
const received: string[] = [];
|
|
hub.subscribe("m1", (c) => received.push(c));
|
|
expect(received).toEqual(["ligne1", "ligne2"]);
|
|
});
|
|
|
|
it("diffuse les nouveaux chunks aux abonnés", () => {
|
|
const hub = new OutputHub();
|
|
const fn = vi.fn();
|
|
hub.subscribe("m1", fn);
|
|
hub.publish("m1", "x");
|
|
expect(fn).toHaveBeenCalledWith("x");
|
|
});
|
|
|
|
it("vide le buffer avec clear()", () => {
|
|
const hub = new OutputHub();
|
|
hub.publish("m1", "old");
|
|
hub.clear("m1");
|
|
const received: string[] = [];
|
|
hub.subscribe("m1", (c) => received.push(c));
|
|
expect(received).toEqual([]);
|
|
});
|
|
});
|