75 lines
2.1 KiB
JavaScript
75 lines
2.1 KiB
JavaScript
#!/usr/bin/env node
|
|
/*
|
|
Scan TSX sources and report missing Playwright tests following the convention:
|
|
- For file: <root>/(components|pages|redux|services)/path/Foo.tsx
|
|
- Expect test at: playwright/<root>/path/fooTest.ts
|
|
|
|
Adjust srcRoots to your needs.
|
|
*/
|
|
import fs from "fs";
|
|
import path from "path";
|
|
|
|
const projectRoot = process.cwd();
|
|
const srcRoots = ["components", "pages", "redux", "services"];
|
|
|
|
function mapToTest(tsxAbs) {
|
|
const rel = path.relative(projectRoot, tsxAbs).replace(/\\/g, "/");
|
|
const parts = rel.split("/");
|
|
const top = parts.shift();
|
|
if (!srcRoots.includes(top)) return null;
|
|
const file = parts.pop();
|
|
if (!file) return null;
|
|
const base = file.replace(/\.tsx?$/, "");
|
|
const lowerCamel = base.charAt(0).toLowerCase() + base.slice(1);
|
|
const testRel = path
|
|
.join("playwright", top, ...parts, `${lowerCamel}Test.ts`)
|
|
.replace(/\\/g, "/");
|
|
return path.join(projectRoot, testRel);
|
|
}
|
|
|
|
function walk(dir, files = []) {
|
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
if (entry.name.startsWith(".") || entry.name === "node_modules") continue;
|
|
const p = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) walk(p, files);
|
|
else files.push(p);
|
|
}
|
|
return files;
|
|
}
|
|
|
|
function main() {
|
|
const tsxFiles = [];
|
|
for (const root of srcRoots) {
|
|
const abs = path.join(projectRoot, root);
|
|
if (!fs.existsSync(abs)) continue;
|
|
tsxFiles.push(...walk(abs).filter((f) => /\.tsx$/.test(f)));
|
|
}
|
|
|
|
const results = [];
|
|
for (const tsx of tsxFiles) {
|
|
const testPath = mapToTest(tsx);
|
|
if (!testPath) continue;
|
|
if (!fs.existsSync(testPath)) {
|
|
results.push({ tsx, testPath });
|
|
}
|
|
}
|
|
|
|
if (results.length === 0) {
|
|
console.log(
|
|
"✅ Alle TSX-Dateien haben entsprechende Playwright-Tests nach der Konvention."
|
|
);
|
|
return;
|
|
}
|
|
|
|
console.log("❌ Fehlende Playwright-Tests gefunden (Vorschlagspfade):");
|
|
for (const r of results) {
|
|
const relSrc = path.relative(projectRoot, r.tsx).replace(/\\/g, "/");
|
|
const relTest = path.relative(projectRoot, r.testPath).replace(/\\/g, "/");
|
|
console.log(`- ${relSrc} -> ${relTest}`);
|
|
}
|
|
|
|
process.exitCode = 1;
|
|
}
|
|
|
|
main();
|