BlueGit

timfa filemanager

Files

filemanager / scripts / generate-tests-md.js

generate-tests-md.js

fixes and updates
timfa Tim Falken · pushed by timfa · 6 months ago
0ae63c84 History
generate-tests-md.js 1.3 KiB Download Raw
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
7const fs = require("fs");
8const path = require("path");
9
10const TEST_DIR = path.join(__dirname, "../tests");
11const OUT_FILE = path.join(__dirname, "../.github/tests.md");
12
13const testFiles = fs.readdirSync(TEST_DIR)
14 .filter(f => f.endsWith(".test.js"))
15 .sort();
16
17const 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
27for (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
48fs.writeFileSync(OUT_FILE, lines.join("\n"));
49console.log(`Written ${OUT_FILE} (${lines.length} lines, ${testFiles.length} files)`);