forked from EvoMap/evolver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-suite.js
More file actions
63 lines (57 loc) · 2.04 KB
/
Copy pathvalidate-suite.js
File metadata and controls
63 lines (57 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Usage: node scripts/validate-suite.js [test-glob-pattern]
// Runs the evolver test suite -- repo root is derived from script location, no shell glob needed.
const { execSync } = require('child_process');
const path = require('path');
const fs = require('fs');
const EVOLVER_REPO_ROOT = path.join(__dirname, '..');
const pattern = process.argv[2] || 'test/*.test.js';
function expandTestGlob(repoRoot, pat) {
const dir = pat.replace(/\/\*\.test\.js$/, '');
const fullDir = path.isAbsolute(dir) ? dir : path.join(repoRoot, dir);
return fs.readdirSync(fullDir)
.filter(f => f.endsWith('.test.js'))
.map(f => path.join(fullDir, f))
.sort();
}
const files = expandTestGlob(EVOLVER_REPO_ROOT, pattern);
if (files.length === 0) {
console.error('FAIL: no tests found matching pattern: ' + pattern);
process.exit(1);
}
const cmd = 'node --test ' + files.join(' ');
const env = Object.assign({}, process.env, {
NODE_ENV: 'test',
EVOLVER_REPO_ROOT,
GEP_ASSETS_DIR: path.join(EVOLVER_REPO_ROOT, 'assets', 'gep'),
});
delete env.EVOLVE_BRIDGE;
delete env.OPENCLAW_WORKSPACE;
try {
const output = execSync(cmd, {
cwd: EVOLVER_REPO_ROOT,
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 180000,
env,
});
const out = output.toString('utf8');
const passMatch = out.match(/pass (\d+)/);
const failMatch = out.match(/fail (\d+)/);
const passCount = passMatch ? Number(passMatch[1]) : 0;
const failCount = failMatch ? Number(failMatch[1]) : 0;
if (failCount > 0) {
console.error('FAIL: ' + failCount + ' test(s) failed');
process.exit(1);
}
if (passCount === 0) {
console.error('FAIL: no tests found');
process.exit(1);
}
console.log('ok: ' + passCount + ' test(s) passed, 0 failed');
} catch (e) {
const stderr = e.stderr ? e.stderr.toString('utf8').slice(-500) : '';
const stdout = e.stdout ? e.stdout.toString('utf8').slice(-500) : '';
console.error('FAIL: test suite exited with code ' + (e.status || 'unknown'));
if (stderr) console.error(stderr);
if (stdout) console.error(stdout);
process.exit(1);
}