import { expect, test } from "bun:test"; import { HMR_CLIENT_JS } from "../src/runtime.ts"; test("HMR client syncs fresh HTML over the websocket", () => { expect(HMR_CLIENT_JS).toContain('send({ type: "sync"'); expect(HMR_CLIENT_JS).toContain('msg.type === "html"'); expect(HMR_CLIENT_JS).toContain("applyHtml(msg.html)"); expect(HMR_CLIENT_JS).not.toContain("fetch(location.href"); expect(HMR_CLIENT_JS).not.toContain("location.reload()"); }); test("HMR replaces hydrated components when their server signature changes", () => { expect(HMR_CLIENT_JS).toContain('from.getAttribute("data-wrn-hydration")'); expect(HMR_CLIENT_JS).toContain('from.getAttribute("data-wrn-behavior")'); expect(HMR_CLIENT_JS).toContain('from.getAttribute("data-scope")'); expect(HMR_CLIENT_JS).toContain("window.__wrnexusDisposeBehaviors(from)"); // Cloned nodes are re-stamped with the live document nonce before insertion. expect(HMR_CLIENT_JS).toContain("from.replaceWith(adoptNonce(to.cloneNode(true)))"); });