Files
prompt-optimizer/scripts/run-many.test.mjs
linshen 520ae2be99 build(deps): align toolchain peers and replace npm-run-all
- align TypeScript with the current eslint peer range across packages
- replace npm-run-all with a local run-many script and test coverage
- tighten remaining mcp-server typing so the package lint stays clean
- update the lockfile after removing redundant root-level tooling deps
2026-03-27 22:18:57 +08:00

61 lines
1.7 KiB
JavaScript

import test from 'node:test';
import assert from 'node:assert/strict';
import { getRunnerSpec, parseArgs, runSequential, runParallel } from './run-many.js';
test('parseArgs supports sequential mode by default', () => {
assert.deepEqual(parseArgs(['build:core', 'build:ui']), {
parallel: false,
scripts: ['build:core', 'build:ui'],
});
});
test('parseArgs supports parallel aliases', () => {
assert.deepEqual(parseArgs(['--parallel', 'build:web', 'build:ext']), {
parallel: true,
scripts: ['build:web', 'build:ext'],
});
assert.deepEqual(parseArgs(['-p', 'build:web', 'build:ext']), {
parallel: true,
scripts: ['build:web', 'build:ext'],
});
});
test('getRunnerSpec uses shell mode for Windows pnpm invocation', () => {
assert.deepEqual(getRunnerSpec('win32'), {
command: 'pnpm',
shell: true,
});
assert.deepEqual(getRunnerSpec('linux'), {
command: 'pnpm',
shell: false,
});
});
test('runSequential executes scripts in order and stops on failure', async () => {
const executed = [];
const runner = async (script) => {
executed.push(script);
if (script === 'build:ui') {
throw new Error('boom');
}
};
await assert.rejects(
runSequential(['build:core', 'build:ui', 'build:web'], runner),
/boom/
);
assert.deepEqual(executed, ['build:core', 'build:ui']);
});
test('runParallel waits for all scripts to finish when all succeed', async () => {
const executed = [];
const runner = async (script) => {
await new Promise((resolve) => setTimeout(resolve, script === 'build:web' ? 10 : 1));
executed.push(script);
};
await runParallel(['build:web', 'build:ext'], runner);
assert.deepEqual(new Set(executed), new Set(['build:web', 'build:ext']));
});