feat: hub de sortie WebSocket avec buffer rejouable
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// 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([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user