// SPDX-License-Identifier: GPL-3.0-or-later import { test } from "node:test"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; const root = join(dirname(fileURLToPath(import.meta.url)), ".."); const html = readFileSync(join(root, "src-gui", "index.html"), "utf8"); // Pull a top-level `function name(...) { ... }` out of the inline script by // counting braces, so we can unit-test the pure chart builders without a DOM. function extractFn(src, name) { const start = src.indexOf("function " + name + "("); assert.ok(start >= 0, `function ${name} should exist in the dashboard script`); const braceStart = src.indexOf("{", start); let depth = 0; for (let i = braceStart; i < src.length; i += 1) { if (src[i] === "{") depth += 1; else if (src[i] === "}") { depth -= 1; if (depth === 0) return src.slice(start, i + 1); } } throw new Error(`unbalanced braces extracting ${name}`); } // Compile the three pure chart helpers together so scoreChart/severityChart // can resolve fmtWhen. `new Function` only compiles — it does not run, so no // DOM is touched; we then invoke the returned functions with sample data. const script = html.match(/