From 6fb932d703d17f483d298c21b636ad6fa5708450 Mon Sep 17 00:00:00 2001 From: Alexander Lichter Date: Tue, 7 Apr 2026 16:23:47 +0200 Subject: [PATCH 1/3] test: add failing island tests for layouts containing islands --- .../react/test/unit/plugin-islands.test.ts | 118 +++++++++++++ .../solid/test/unit/plugin-islands.test.ts | 118 +++++++++++++ .../svelte/test/unit/plugin-islands.test.ts | 130 ++++++++++++++ packages/vue/test/unit/plugin-islands.test.ts | 160 ++++++++++++++++++ 4 files changed, 526 insertions(+) create mode 100644 packages/react/test/unit/plugin-islands.test.ts create mode 100644 packages/solid/test/unit/plugin-islands.test.ts create mode 100644 packages/svelte/test/unit/plugin-islands.test.ts create mode 100644 packages/vue/test/unit/plugin-islands.test.ts diff --git a/packages/react/test/unit/plugin-islands.test.ts b/packages/react/test/unit/plugin-islands.test.ts new file mode 100644 index 0000000000..28eced3a49 --- /dev/null +++ b/packages/react/test/unit/plugin-islands.test.ts @@ -0,0 +1,118 @@ +import { describe, expect, it, beforeEach, afterEach } from "vitest"; +import { mkdirSync, writeFileSync, rmSync } from "node:fs"; +import { join } from "node:path"; +import { islandsPlugin } from "../../src/plugin-islands"; + +const TMP = join(import.meta.dirname, "__tmp_islands_plugin__"); +const PAGES_DIR = join(TMP, "pages"); + +function writeFile(relativePath: string, content: string): void { + const full = join(PAGES_DIR, relativePath); + mkdirSync(join(full, ".."), { recursive: true }); + writeFileSync(full, content); +} + +function setupPlugin() { + const plugins = islandsPlugin(PAGES_DIR); + const plugin = plugins[0]; + + const config = { root: TMP, command: "build" as const, plugins: [] }; + (plugin as any).configResolved(config); + + return { + async buildStart() { + await (plugin as any).buildStart.call({}); + }, + loadClientEntry(): string | undefined { + return (plugin as any).load.handler("\0virtual:void-islands-client"); + }, + }; +} + +describe("islandsPlugin — layout island import scanning", () => { + beforeEach(() => { + mkdirSync(PAGES_DIR, { recursive: true }); + }); + + afterEach(() => { + rmSync(TMP, { recursive: true, force: true }); + }); + + it("pre-scans island imports from island layouts into the manifest", async () => { + writeFile( + "blog/layout.island.tsx", + `import Counter from "../_components/Counter" with { island: "load" } +export default function Layout({ children }) { return
{children}
; }`, + ); + writeFile( + "blog/index.island.tsx", + `export default function Blog() { return
Blog
; }`, + ); + writeFile( + "_components/Counter.tsx", + `export default function Counter() { return ; }`, + ); + + const { buildStart, loadClientEntry } = setupPlugin(); + await buildStart(); + const clientEntry = loadClientEntry(); + + expect(clientEntry).toBeDefined(); + expect(clientEntry).toContain("pages/_components/Counter"); + }); + + it("pre-scans island imports from island pages into the manifest", async () => { + writeFile( + "index.island.tsx", + `import Toggle from "./Toggle" with { island: "idle" } +export default function Home() { return ; }`, + ); + writeFile("Toggle.tsx", `export default function Toggle() { return ; }`); + + const { buildStart, loadClientEntry } = setupPlugin(); + await buildStart(); + const clientEntry = loadClientEntry(); + + expect(clientEntry).toBeDefined(); + expect(clientEntry).toContain("pages/Toggle"); + }); + + it("includes island imports from both pages and layouts", async () => { + writeFile( + "app/layout.island.tsx", + `import Nav from "../_components/Nav" with { island: "load" } +export default function Layout({ children }) { return
; }`, + ); + writeFile( + "app/index.island.tsx", + `import Widget from "../_components/Widget" with { island: "idle" } +export default function Index() { return ; }`, + ); + writeFile("_components/Nav.tsx", `export default function Nav() { return