mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-13 21:33:32 +08:00
fix: harden observer hooks and test discovery (#513)
This commit is contained in:
@@ -10,25 +10,40 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const testsDir = __dirname;
|
||||
const repoRoot = path.resolve(testsDir, '..');
|
||||
const TEST_GLOB = 'tests/**/*.test.js';
|
||||
|
||||
/**
|
||||
* Discover all *.test.js files under testsDir (relative paths for stable output order).
|
||||
*/
|
||||
function discoverTestFiles(dir, baseDir = dir, acc = []) {
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
for (const e of entries) {
|
||||
const full = path.join(dir, e.name);
|
||||
const rel = path.relative(baseDir, full);
|
||||
if (e.isDirectory()) {
|
||||
discoverTestFiles(full, baseDir, acc);
|
||||
} else if (e.isFile() && e.name.endsWith('.test.js')) {
|
||||
acc.push(rel);
|
||||
}
|
||||
function matchesTestGlob(relativePath) {
|
||||
const normalized = relativePath.split(path.sep).join('/');
|
||||
if (typeof path.matchesGlob === 'function') {
|
||||
return path.matchesGlob(normalized, TEST_GLOB);
|
||||
}
|
||||
return acc.sort();
|
||||
|
||||
return /^tests\/(?:.+\/)?[^/]+\.test\.js$/.test(normalized);
|
||||
}
|
||||
|
||||
const testFiles = discoverTestFiles(testsDir);
|
||||
function walkFiles(dir, acc = []) {
|
||||
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
const fullPath = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
walkFiles(fullPath, acc);
|
||||
} else if (entry.isFile()) {
|
||||
acc.push(fullPath);
|
||||
}
|
||||
}
|
||||
return acc;
|
||||
}
|
||||
|
||||
function discoverTestFiles() {
|
||||
return walkFiles(testsDir)
|
||||
.map(fullPath => path.relative(repoRoot, fullPath))
|
||||
.filter(matchesTestGlob)
|
||||
.map(repoRelativePath => path.relative(testsDir, path.join(repoRoot, repoRelativePath)))
|
||||
.sort();
|
||||
}
|
||||
|
||||
const testFiles = discoverTestFiles();
|
||||
|
||||
const BOX_W = 58; // inner width between ║ delimiters
|
||||
const boxLine = s => `║${s.padEnd(BOX_W)}║`;
|
||||
@@ -38,6 +53,11 @@ console.log(boxLine(' Everything Claude Code - Test Suite'));
|
||||
console.log('╚' + '═'.repeat(BOX_W) + '╝');
|
||||
console.log();
|
||||
|
||||
if (testFiles.length === 0) {
|
||||
console.log(`✗ No test files matched ${TEST_GLOB}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
let totalPassed = 0;
|
||||
let totalFailed = 0;
|
||||
let totalTests = 0;
|
||||
|
||||
Reference in New Issue
Block a user