65 lines
2.1 KiB
JavaScript
65 lines
2.1 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
import { readdir } from 'node:fs/promises';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { spawn } from 'node:child_process';
|
|
|
|
export async function findUnitTests(root) {
|
|
const files = [];
|
|
async function visit(directory) {
|
|
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
const filename = path.join(directory, entry.name);
|
|
if (entry.isDirectory()) await visit(filename);
|
|
else if (entry.isFile() && /\.test\.[cm]?[jt]sx?$/.test(entry.name))
|
|
files.push(filename);
|
|
}
|
|
}
|
|
// Reports contain local browser capture tools and historical snapshots, not unit suites.
|
|
for (const directory of ['src', 'tests', 'test/unit'])
|
|
await visit(path.join(root, directory));
|
|
return files.sort();
|
|
}
|
|
|
|
if (
|
|
process.argv[1] &&
|
|
path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)
|
|
) {
|
|
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
const files = await findUnitTests(root);
|
|
if (!files.length)
|
|
throw new Error('No unit tests found in src/, tests/, or test/unit/.');
|
|
const child = spawn(
|
|
process.execPath,
|
|
['--test', ...process.argv.slice(2), ...files],
|
|
{
|
|
cwd: root,
|
|
stdio: 'inherit',
|
|
},
|
|
);
|
|
child.on('error', (error) => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|
|
child.on('exit', (code) => {
|
|
process.exitCode = code ?? 1;
|
|
});
|
|
}
|