| 1234567891011121314151617181920212223242526272829 |
- import fs from 'node:fs';
- import path from 'node:path';
- import { spawnSync } from 'node:child_process';
- const root = path.resolve(import.meta.dirname, '..');
- const workspaceRoot = path.resolve(root, '..');
- function workspaceTemps() {
- return new Set(fs.readdirSync(workspaceRoot, { withFileTypes: true })
- .filter(entry => entry.name.startsWith('.tmp-'))
- .map(entry => entry.name));
- }
- function collect(directory, found = []) {
- for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
- const file = path.join(directory, entry.name);
- if (entry.isDirectory()) collect(file, found);
- else if (entry.name.endsWith('.test.mjs')) found.push(file);
- }
- return found;
- }
- const tests = collect(path.join(root, 'mcp', 'src')).sort();
- if (!tests.length) throw new Error('No tests found.');
- const before = workspaceTemps();
- const result = spawnSync(process.execPath, ['--test', ...tests], { cwd: root, stdio: 'inherit' });
- const created = [...workspaceTemps()].filter(name => !before.has(name));
- if (created.length) {
- console.error(`Tests polluted the workspace root: ${created.join(', ')}`);
- process.exit(1);
- }
- process.exit(result.status || 0);
|