// Sanity checks for the VS Code extension assets. Run with `node test/validate.mjs`. // Verifies the JSON contribution files parse and that the bundled compiler both // accepts valid .wrn and reports an offset for invalid .wrn (what diagnostics need). import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; import { createRequire } from "node:module"; const here = dirname(fileURLToPath(import.meta.url)); const root = join(here, ".."); const require = createRequire(import.meta.url); let failures = 0; const ok = (name) => console.log(` ok ${name}`); const bad = (name, detail) => { failures++; console.error(` FAIL ${name}${detail ? " — " + detail : ""}`); }; // 1. All JSON contribution files parse. for (const rel of [ "package.json", "language-configuration.json", "syntaxes/wrn.tmLanguage.json", "snippets/wrn.json", ]) { try { JSON.parse(readFileSync(join(root, rel), "utf8")); ok(`json parses: ${rel}`); } catch (e) { bad(`json parses: ${rel}`, e.message); } } // 2. Grammar wires up the right scope + embedded languages. const grammar = JSON.parse(readFileSync(join(root, "syntaxes/wrn.tmLanguage.json"), "utf8")); grammar.scopeName === "source.wrn" ? ok("grammar scopeName") : bad("grammar scopeName"); // 3. Bundled compiler: valid source compiles, invalid source throws with an offset. try { const compiler = require(join(root, "src/compiler.cjs")); const good = `page Home {\n view {

Hi

}\n}`; compiler.compileWireFile(good); ok("compiler accepts valid .wrn"); const badSrc = `page Home {\n view {

Hi

}\n}`; let threw = false; try { compiler.compileWireFile(badSrc); } catch (e) { threw = true; /offset\s+\d+|end of input/.test(e.message) ? ok("compiler reports a locatable error") : bad("compiler reports a locatable error", e.message); } if (!threw) bad("compiler rejects invalid .wrn"); } catch (e) { bad("compiler bundle loads", e.message); } console.log(failures === 0 ? "\nAll extension checks passed." : `\n${failures} check(s) failed.`); process.exit(failures === 0 ? 0 : 1);