import { describe, expect, it } from "vitest"; import { loadFactory } from "../src/loader.ts"; import type { MountContext } from "../src/types.ts"; describe("native runtime source loading", () => { it("loads TypeScript with native TUI imports without generated files or reload", async () => { const factory = await loadFactory( 'import { Text } from "@earendil-works/pi-tui"; export default function mount(_ctx: unknown) { return new Text("native", 0, 0); }', ); const component = await factory({} as MountContext); expect(component.render(20).map((line) => line.trimEnd())).toEqual([ "native", ]); }); it("evaluates successive revisions without stale module cache", async () => { const first = await loadFactory( 'export default () => ({render: () => ["one"], invalidate() {}})', ); const second = await loadFactory( 'export default () => ({render: () => ["two"], invalidate() {}})', ); expect((await first({} as MountContext)).render(20)).toEqual(["one"]); expect((await second({} as MountContext)).render(20)).toEqual(["two"]); }); it("rejects malformed source and missing factory", async () => { await expect(loadFactory("export default function (")).rejects.toThrow(); await expect(loadFactory("export const other = 1")).rejects.toThrow( "default component factory", ); }); });