Files
WRNexusJS/packages/compiler/test/island-resolution.test.ts
T
ClintchizandClaude Opus 5 b405025f37 feat(compiler): resolve .tsx imports and tag them as islands
.wrn keeps resolution priority so existing components are unaffected
when a .tsx file shares their name.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-18 15:15:08 +05:30

65 lines
2.1 KiB
TypeScript

import { expect, test } from "bun:test";
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { resolveWrnImport } from "../src/import-resolver.ts";
function appWith(files: Record<string, string>) {
const root = mkdtempSync(join(tmpdir(), "wrnexus-island-"));
mkdirSync(join(root, "app"), { recursive: true });
for (const [name, contents] of Object.entries(files)) {
writeFileSync(join(root, "app", name), contents);
}
return root;
}
test("resolves a .tsx import and tags it as an island", () => {
const root = appWith({ "Chart.tsx": "export default function Chart() { return null; }" });
const result = resolveWrnImport(
{ source: "./Chart", specifiers: [] } as any,
join(root, "app", "page.wrn"),
{ appRoot: root },
);
expect(result.resolved).toContain("Chart.tsx");
expect(result.kind).toBe("island");
});
test("does not tag a .ts import as an island", () => {
const root = appWith({ "helper.ts": "export const value = 1;" });
const result = resolveWrnImport(
{ source: "./helper", specifiers: [] } as any,
join(root, "app", "page.wrn"),
{ appRoot: root },
);
expect(result.resolved).toContain("helper.ts");
expect(result.kind).toBeUndefined();
});
test("prefers .wrn over .tsx when both exist", () => {
const root = appWith({
"Widget.wrn": "<template></template>",
"Widget.tsx": "export default function Widget() { return null; }",
});
const result = resolveWrnImport(
{ source: "./Widget", specifiers: [] } as any,
join(root, "app", "page.wrn"),
{ appRoot: root },
);
expect(result.resolved).toContain("Widget.wrn");
expect(result.kind).toBeUndefined();
});
test("resolves an explicit .tsx extension as an island", () => {
const root = appWith({ "Chart.tsx": "export default function Chart() { return null; }" });
const result = resolveWrnImport(
{ source: "./Chart.tsx", specifiers: [] } as any,
join(root, "app", "page.wrn"),
{ appRoot: root },
);
expect(result.kind).toBe("island");
});