Fix npm test glob on CI
This commit is contained in:
+1
-1
@@ -8,7 +8,7 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node scripts/start-electron.js",
|
"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",
|
"sample": "node scripts/make-sample-guide.js",
|
||||||
"package:windows": "node scripts/package-windows.js",
|
"package:windows": "node scripts/package-windows.js",
|
||||||
"build": "bash scripts/build-release.sh",
|
"build": "bash scripts/build-release.sh",
|
||||||
|
|||||||
@@ -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);
|
||||||
Reference in New Issue
Block a user