| 1 | #!/usr/bin/env node |
| 2 | /** |
| 3 | * Scans all test files and regenerates .github/tests.md from their test() names. |
| 4 | * Run via: node scripts/generate-tests-md.js |
| 5 | */ |
| 6 | |
| 7 | const fs = require("fs"); |
| 8 | const path = require("path"); |
| 9 | |
| 10 | const TEST_DIR = path.join(__dirname, "../tests"); |
| 11 | const OUT_FILE = path.join(__dirname, "../.github/tests.md"); |
| 12 | |
| 13 | const testFiles = fs.readdirSync(TEST_DIR) |
| 14 | .filter(f => f.endsWith(".test.js")) |
| 15 | .sort(); |
| 16 | |
| 17 | const lines = [ |
| 18 | "# Test Index", |
| 19 | "", |
| 20 | "> Auto-generated by `scripts/generate-tests-md.js`. Do not edit by hand.", |
| 21 | "> Run `node scripts/generate-tests-md.js` to regenerate.", |
| 22 | "", |
| 23 | "---", |
| 24 | "", |
| 25 | ]; |
| 26 | |
| 27 | for (const file of testFiles) |
| 28 | { |
| 29 | const src = fs.readFileSync(path.join(TEST_DIR, file), "utf8"); |
| 30 | |
| 31 | // Match test("name", ...) — handles single and double quotes, multiline names |
| 32 | const re = /^describe\(["'`]([\s\S]*?)["'`]\s*,/gm; |
| 33 | const names = []; |
| 34 | let m; |
| 35 | while ((m = re.exec(src)) !== null) |
| 36 | names.push(m[1].replace(/\s+/g, " ").trim()); |
| 37 | |
| 38 | if (names.length === 0) continue; |
| 39 | |
| 40 | lines.push(`## \`test/${file}\``); |
| 41 | for (const name of names) |
| 42 | lines.push(`- \`${name}\``); |
| 43 | lines.push(""); |
| 44 | lines.push("---"); |
| 45 | lines.push(""); |
| 46 | } |
| 47 | |
| 48 | fs.writeFileSync(OUT_FILE, lines.join("\n")); |
| 49 | console.log(`Written ${OUT_FILE} (${lines.length} lines, ${testFiles.length} files)`); |