import { expect, test } from "bun:test" import { existsSync, readFileSync, readdirSync } from "node:fs" import { join } from "node:path" const dir = import.meta.dir const page = join(dir, "page") const read = (f) => readFileSync(join(page, f), "utf8") const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")) // view.js is a classic script, as the page loads it const scope = {} new Function("globalThis", read("view.js"))(scope) const V = scope.LayerfsView test("the package declares the page magpie shows", () => { const p = pkg.magpie.page expect(p.title).toBe("LayerFS trajectory") expect(p.titles.zh).toBe("LayerFS 轨迹") expect(p.file).toBe("page/index.html") expect(p.icon).toBe("page/icon.svg") expect(pkg.files).toContain("page") for (const f of ["index.html", "app.js", "view.js", "style.css", "icon.svg"]) expect(existsSync(join(page, f))).toBe(true) const html = read("index.html") expect(html).toContain("_magpie/bridge.js") // the host serves the bridge beside every page expect(html).toContain('src="trajectory.js"') // the page sandbox forbids inline scripts and any fetch; the only // data script is the bundled sample trajectory shipped with the page expect(html).not.toMatch(/