import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; const hydrateRoot = vi.fn(); vi.mock("react-dom/client", () => ({ hydrateRoot, })); describe("Sites entry bootstrap", () => { beforeEach(() => { document.body.innerHTML = ""; hydrateRoot.mockReset(); vi.resetModules(); }); afterEach(() => { document.body.innerHTML = ""; vi.restoreAllMocks(); }); it("hydrates each known island host", async () => { document.body.innerHTML = `
`; const { bootstrapIslands } = await import("@/client/sites/hydrate"); await bootstrapIslands(); expect(hydrateRoot).toHaveBeenCalledTimes(3); for (const host of document.querySelectorAll("[data-island]")) { expect(host.dataset.islandHydrated).toBe("true"); } }); it("skips hosts already marked as hydrated", async () => { document.body.innerHTML = `
`; const { bootstrapIslands } = await import("@/client/sites/hydrate"); await bootstrapIslands(); expect(hydrateRoot).not.toHaveBeenCalled(); }); it("ignores unknown island names and malformed props without throwing", async () => { document.body.innerHTML = `
`; const { bootstrapIslands } = await import("@/client/sites/hydrate"); await expect(bootstrapIslands()).resolves.toBeUndefined(); expect(hydrateRoot).not.toHaveBeenCalled(); }); });