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'); });