// CI check: loads the inlined demo in jsdom with ALL network blocked and fails if the page // tries to fetch or load any script (e.g. a lazy chunk or an RSC .txt payload), or throws. // Usage: node tools/artifact-check.mjs dist/demo.html import { JSDOM, VirtualConsole } from 'jsdom'; import fs from 'fs'; const file = process.argv[2] || 'dist/demo.html'; const errors = [], network = []; const vc = new VirtualConsole(); vc.on('jsdomError', (e) => errors.push(String(e.message))); const dom = new JSDOM(fs.readFileSync(file, 'utf8'), { runScripts: 'dangerously', url: 'https://artifact.local/', virtualConsole: vc, pretendToBeVisual: true, beforeParse(w) { Object.assign(w, { TextEncoder, TextDecoder, MessageChannel, ReadableStream, structuredClone }); w.fetch = (u) => { network.push(`fetch ${u}`); return Promise.reject(new Error('blocked')); }; const create = w.document.createElement.bind(w.document); w.document.createElement = (tag, ...rest) => { const el = create(tag, ...rest); if (tag === 'script') { const d = Object.getOwnPropertyDescriptor(w.HTMLScriptElement.prototype, 'src'); Object.defineProperty(el, 'src', { set(v) { network.push(`script ${v}`); d.set.call(el, v); }, get() { return d.get.call(el); } }); } return el; }; }, }); const w = dom.window; await new Promise((r) => setTimeout(r, 2000)); for (const route of ['#/am', '#/am/courses', '#/admin']) { w.location.hash = route; await new Promise((r) => setTimeout(r, 300)); } // React can re-insert hoisted /