Skip to content

Commit 1f591f5

Browse files
bjohansebasclaude
andcommitted
test: prove SSE broadcast with two real pages and a mid-connection publish
Two browser pages connected to the same server both apply a single edit — broadcast proven end to end. The unit variant also stops passing vacuously: it now publishes while both SSE clients are attached instead of only observing the per-client connect-time sync. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 3e86c54 commit 1f591f5

2 files changed

Lines changed: 39 additions & 6 deletions

File tree

test/e2e/client.test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import collectConsole, { normalizeConsole } from "../helpers/console-collector";
22
import createHotApp from "../helpers/hot-app";
3-
import runBrowser from "../helpers/run-browser";
3+
import runBrowser, { runPage } from "../helpers/run-browser";
44

55
jest.setTimeout(120000);
66

@@ -102,6 +102,26 @@ describe("hot client (browser)", () => {
102102
expect(await readReloadMarker(page)).toBe(true);
103103
});
104104

105+
it("broadcasts one build to every connected page", async () => {
106+
app = await createHotApp({ code: acceptedApp("v1") });
107+
({ page, browser } = await runBrowser());
108+
const pageTwo = await runPage(browser);
109+
110+
await page.goto(app.url);
111+
await pageTwo.goto(app.url);
112+
await waitForAppText(page, "v1");
113+
await waitForAppText(pageTwo, "v1");
114+
115+
// One edit, one publish ed build — every connected page applies it.
116+
app.edit(acceptedApp("v2"));
117+
await waitForAppText(page, "v2");
118+
await waitForAppText(pageTwo, "v2");
119+
120+
expect(
121+
await pageTwo.evaluate(() => document.getElementById("app").textContent),
122+
).toBe("v2");
123+
});
124+
105125
it("falls back to a full reload when the update is not accepted", async () => {
106126
app = await createHotApp({ code: unacceptedApp("v1") });
107127
({ page, browser } = await runBrowser());

test/middleware.test.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7299,13 +7299,26 @@ describe.each([
72997299

73007300
await waitUntilValid(instance);
73017301

7302-
const [first, second] = await Promise.all([
7303-
readSseEvents(server, "/__webpack_hmr"),
7304-
readSseEvents(server, "/__webpack_hmr"),
7302+
const events = Promise.all([
7303+
readSseEvents(server, "/__webpack_hmr", 1500),
7304+
readSseEvents(server, "/__webpack_hmr", 1500),
73057305
]);
73067306

7307-
expect(first.some((event) => event.action === "sync")).toBe(true);
7308-
expect(second.some((event) => event.action === "sync")).toBe(true);
7307+
// Broadcast while both clients are attached — the connect-time sync
7308+
// alone is written per client and would make this pass vacuously.
7309+
await new Promise((resolve) => {
7310+
setTimeout(resolve, 300);
7311+
});
7312+
instance.context.hot.publish({ action: "broadcast-check" });
7313+
7314+
const [first, second] = await events;
7315+
7316+
expect(first.some((event) => event.action === "broadcast-check")).toBe(
7317+
true,
7318+
);
7319+
expect(second.some((event) => event.action === "broadcast-check")).toBe(
7320+
true,
7321+
);
73097322
});
73107323
});
73117324
});

0 commit comments

Comments
 (0)