Fix npm test glob on CI

This commit is contained in:
2026-06-26 18:41:12 -05:00
parent 266a92fedb
commit dd49e42290
2 changed files with 43 additions and 1 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
"private": true,
"scripts": {
"start": "node scripts/start-electron.js",
"test": "node --test \"tests/unit/*.test.js\"",
"test": "node scripts/run-unit-tests.js",
"sample": "node scripts/make-sample-guide.js",
"package:windows": "node scripts/package-windows.js",
"build": "bash scripts/build-release.sh",
+42
View File
@@ -0,0 +1,42 @@
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
function collectTestFiles(rootDir) {
const files = [];
if (!fs.existsSync(rootDir)) return files;
const walk = (dir) => {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory()) {
walk(full);
continue;
}
if (/\.(test|spec)\.(js|mjs|cjs)$/.test(entry.name)) files.push(full);
}
};
walk(rootDir);
files.sort((a, b) => a.localeCompare(b));
return files;
}
const root = path.join(process.cwd(), 'tests', 'unit');
const tests = collectTestFiles(root);
if (!tests.length) {
console.log('No unit test files found under tests/unit, skipping unit tests.');
process.exit(0);
}
const result = spawnSync(process.execPath, ['--test', ...tests], { stdio: 'inherit' });
if (result.error) {
console.error(result.error.message);
process.exit(result.status ?? 1);
}
process.exit(result.status ?? 0);