// Every function named in an inline on*="..." handler (in magazine.js markup or the section HTML) // must be exported on `root` in magazine.js -- an unexported one fails silently in the browser // (e.g. the region-type picker never opening). import { test } from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; const js = readFileSync(new URL('../static/js/magazine.js', import.meta.url), 'utf8'); const html = readFileSync(new URL('../static/sections/s-magazine.html', import.meta.url), 'utf8'); const exported = new Set([...js.matchAll(/^root\.(\w+)\s*=/gm)].map((m) => m[1])); const handlerCalls = (text) => [...text.matchAll(/\son(?:click|change|input|focus|blur|keydown|keyup|mousedown|submit)=\\?["']([^"']*)/g)] .flatMap((m) => [...m[1].matchAll(/\b(mag\w+)\s*\(/g)].map((c) => c[1])); test('every mag* inline handler is exported on window', () => { const used = new Set([...handlerCalls(js), ...handlerCalls(html)]); const missing = [...used].filter((name) => !exported.has(name)).sort(); assert.deepEqual(missing, []); });