Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderReplayGate.testkit.test.ts

35 lines1.1 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { makeProviderReplayGate } from "./ProviderReplayGate.testkit.ts";
4​
5describe("ProviderReplayGate", () => {
6 it("signals arrival before the held frame is released", async () => {
7 const label = "held-frame";
8 const gate = makeProviderReplayGate([label]);
9 const reached = gate.waitForReached(label);
10 let emitted = false;
11 const emission = gate.beforeEmit(label).then(() => {
12 emitted = true;
13 });
14​
15 expect(await reached).toBe(true);
16 expect(emitted).toBe(false);
17 gate.release(label);
18 await emission;
19 expect(emitted).toBe(true);
20 expect(await gate.waitForReached(label)).toBe(true);
21 expect(await gate.waitForReached("unknown-frame")).toBe(false);
22 });
23​
24 it("stops waiting when the replay consumer is interrupted", async () => {
25 const label = "held-frame";
26 const gate = makeProviderReplayGate([label]);
27 const controller = new AbortController();
28 const waiting = gate.beforeEmit(label, controller.signal);
29​
30 expect(gate.hasReached(label)).toBe(true);
31 controller.abort();
32 await waiting;
33 expect(gate.release(label)).toBe(true);
34 });
35});