50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
import fs from "node:fs";
|
|
import path from "node:path";
|
|
|
|
const repoRoot = process.cwd();
|
|
const packagesDir = path.join(repoRoot, "packages");
|
|
const failures = [];
|
|
|
|
function walk(dir) {
|
|
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
const files = [];
|
|
for (const entry of entries) {
|
|
if (entry.name === "node_modules" || entry.name === "dist" || entry.name === ".vitest") {
|
|
continue;
|
|
}
|
|
const absolutePath = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) {
|
|
files.push(...walk(absolutePath));
|
|
} else {
|
|
files.push(absolutePath);
|
|
}
|
|
}
|
|
return files;
|
|
}
|
|
|
|
for (const packageName of fs.readdirSync(packagesDir).sort()) {
|
|
const packageDir = path.join(packagesDir, packageName);
|
|
const packageJsonPath = path.join(packageDir, "package.json");
|
|
if (!fs.existsSync(packageJsonPath)) {
|
|
continue;
|
|
}
|
|
|
|
const hasTests = walk(packageDir).some((filePath) => /\.(?:test|spec)\.[cm]?[tj]sx?$/.test(filePath));
|
|
if (!hasTests) {
|
|
continue;
|
|
}
|
|
|
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
if (typeof packageJson.scripts?.test !== "string" || packageJson.scripts.test.trim().length === 0) {
|
|
failures.push(`${path.relative(repoRoot, packageJsonPath)} has test files but no scripts.test`);
|
|
}
|
|
}
|
|
|
|
if (failures.length > 0) {
|
|
process.stderr.write(`FAIL package test script verification\n${failures.map((failure) => `- ${failure}`).join("\n")}\n`);
|
|
process.exit(1);
|
|
}
|
|
|
|
process.stdout.write("PASS package test script verification\n");
|