Files
ManagerAccount/backend/run-tests.js
2026-11-02 15:09:59 +07:00

19 lines
968 B
JavaScript

const fs = require('node:fs');
const path = require('node:path');
const { spawnSync } = require('node:child_process');
// Restrict discovery to source tests. Browser profiles in tmp/ can contain
// third-party extension *.test.js files and must never enter the project suite.
function discover(directory) {
if (!fs.existsSync(directory)) return [];
return fs.readdirSync(directory, { withFileTypes: true }).flatMap(entry => {
const target = path.join(directory, entry.name);
if (entry.isDirectory() && entry.name !== 'node_modules') return discover(target);
return entry.isFile() && /\.test\.[cm]?js$/.test(entry.name) ? [target] : [];
});
}
const files = [__dirname, path.resolve(__dirname, '../test')].flatMap(discover);
const result = spawnSync(process.execPath, ['--test', ...process.argv.slice(2), ...files], { stdio: 'inherit' });
if (result.error) console.error(result.error.message);
process.exitCode = result.status ?? 1;