#!/usr/bin/env node /** * Scans all test files and regenerates .github/tests.md from their test() names. * Run via: node scripts/generate-tests-md.js */ const fs = require("fs"); const path = require("path"); const TEST_DIR = path.join(__dirname, "../tests"); const OUT_FILE = path.join(__dirname, "../.github/tests.md"); const testFiles = fs.readdirSync(TEST_DIR) .filter(f => f.endsWith(".test.js")) .sort(); const lines = [ "# Test Index", "", "> Auto-generated by `scripts/generate-tests-md.js`. Do not edit by hand.", "> Run `node scripts/generate-tests-md.js` to regenerate.", "", "---", "", ]; for (const file of testFiles) { const src = fs.readFileSync(path.join(TEST_DIR, file), "utf8"); // Match test("name", ...) — handles single and double quotes, multiline names const re = /^describe\(["'`]([\s\S]*?)["'`]\s*,/gm; const names = []; let m; while ((m = re.exec(src)) !== null) names.push(m[1].replace(/\s+/g, " ").trim()); if (names.length === 0) continue; lines.push(`## \`test/${file}\``); for (const name of names) lines.push(`- \`${name}\``); lines.push(""); lines.push("---"); lines.push(""); } fs.writeFileSync(OUT_FILE, lines.join("\n")); console.log(`Written ${OUT_FILE} (${lines.length} lines, ${testFiles.length} files)`);