test: npx playwright test erfolgreich
This commit is contained in:
84
scripts/find-missing-playwright-tests.cjs
Normal file
84
scripts/find-missing-playwright-tests.cjs
Normal file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env node
|
||||
/*
|
||||
Scan TSX sources and report missing Playwright tests following the convention:
|
||||
- For file: <root>/(components|pages|...)/path/Foo.tsx
|
||||
- Expect test at: playwright/<same-subtree>/path/fooTest.ts
|
||||
(lowerCamel + 'Test.ts' or same baseName + 'Test.ts').
|
||||
|
||||
You can adjust the mapping rules below to your preference.
|
||||
*/
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const projectRoot = process.cwd();
|
||||
const srcRoots = ["components", "pages", "redux", "services"];
|
||||
const testsRoot = path.join(projectRoot, "playwright");
|
||||
|
||||
/**
|
||||
* Map a TSX file to a desired Playwright test path.
|
||||
* Current rule:
|
||||
* <root>/<subdirs>/<Name>.tsx -> playwright/<root>/<subdirs>/<name>Test.ts
|
||||
* where name = baseName with first letter lowercased.
|
||||
*/
|
||||
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; // ignore non-mapped roots
|
||||
const file = parts.pop();
|
||||
if (!file) return null;
|
||||
const base = file.replace(/\.tsx?$/, "");
|
||||
// lowerCamel for test file base name
|
||||
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}`);
|
||||
}
|
||||
|
||||
// Exit non-zero to make it CI-enforceable
|
||||
process.exitCode = 1;
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user