This commit is contained in:
2026-04-10 15:37:02 +08:00
parent 161cd32277
commit f19e482c8f
233 changed files with 43987 additions and 5127 deletions

54
server-node/test.mjs Normal file
View File

@@ -0,0 +1,54 @@
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const scriptPath = fileURLToPath(import.meta.url);
const serverRoot = path.dirname(scriptPath);
const repoRoot = path.resolve(serverRoot, '..');
const bundledNodePath = path.join(
repoRoot,
'.tools',
'node-v22.22.2-win-x64',
process.platform === 'win32' ? 'node.exe' : 'bin/node',
);
const runtimeNodePath = fs.existsSync(bundledNodePath)
? bundledNodePath
: process.execPath;
function collectTestFiles(dirPath) {
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
const testFiles = [];
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name);
if (entry.isDirectory()) {
testFiles.push(...collectTestFiles(fullPath));
continue;
}
if (entry.isFile() && entry.name.endsWith('.test.ts')) {
testFiles.push(path.relative(serverRoot, fullPath));
}
}
return testFiles.sort();
}
const testFiles = collectTestFiles(path.join(serverRoot, 'src'));
if (testFiles.length === 0) {
console.error('No test files found under server-node/src');
process.exit(1);
}
const result = spawnSync(
runtimeNodePath,
['--test', '--test-concurrency=1', '--import', 'tsx', ...testFiles],
{
cwd: serverRoot,
stdio: 'inherit',
},
);
process.exit(result.status ?? 1);