import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { runInNewContext } from "node:vm"; import { normalizeLayout, validate } from "./src/layout.ts"; const fixtures = JSON.parse(readFileSync(new URL("../docs/layout-cases.json", import.meta.url), "utf8")); const offline = readFileSync(new URL("./canvas.html", import.meta.url), "utf8"); const offlineFunction = name => { const start = offline.indexOf("function " + name + "("); const end = offline.indexOf("\n}", start) + 2; assert.ok(start >= 0 && end > start, name); return offline.slice(start, end); }; for (const { name, accepted, layout } of fixtures) { let editorAccepted; try { editorAccepted = !validate(normalizeLayout(layout)).some(issue => issue.level === "error"); } catch { editorAccepted = false; } assert.equal(editorAccepted, accepted, "Vue editor: " + name); const offlineAccepted = runInNewContext(` let state, activePage, selectedId; function pushHistory() {} function syncControls() {} function fitCanvas() {} function render() {} ${offlineFunction("importLayout")} ${offlineFunction("validate")} try { importLayout(layout); validate().errors === 0; } catch { false; } `, { layout }); assert.equal(offlineAccepted, accepted, "Offline editor: " + name); } console.log(`${fixtures.length} shared cases passed in both editors`);