This commit is contained in:
2026-09-28 16:15:50 +02:00
parent a0ae396b33
commit 34b7dc977a
25 changed files with 1595 additions and 8 deletions
+34
View File
@@ -0,0 +1,34 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { run, ProcessError, ProcessTimeoutError } from '../src/exec.js';
test('resolves with stdout on success', async () => {
const { stdout } = await run('node', ['-e', 'process.stdout.write("hi")']);
assert.equal(stdout, 'hi');
});
test('rejects with ProcessError on non-zero exit, capturing stderr', async () => {
await assert.rejects(
run('node', ['-e', 'process.stderr.write("bad"); process.exit(2)']),
(err) => {
assert.ok(err instanceof ProcessError);
assert.equal(err.code, 2);
assert.equal(err.stderr, 'bad');
return true;
},
);
});
test('rejects with ProcessTimeoutError when the process exceeds the timeout', async () => {
await assert.rejects(
run('node', ['-e', 'setTimeout(() => {}, 5000)'], { timeoutMs: 100 }),
ProcessTimeoutError,
);
});
test('passes cwd and env through to the child process', async () => {
const { stdout } = await run('node', ['-e', 'process.stdout.write(process.env.FOO || "")'], {
env: { ...process.env, FOO: 'bar' },
});
assert.equal(stdout, 'bar');
});