Skip to content

Commit

Permalink
Add result.signalName
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 18, 2024
1 parent e56bf06 commit 5e3cd62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
21 changes: 7 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,15 @@ import {lineIterator, combineAsyncIterables} from './utilities.js';
export default function nanoSpawn(command, arguments_ = [], {signal, timeout, nativeOptions} = {}) {
const subprocess = spawn(command, arguments_, {...nativeOptions, signal, timeout});

// eslint-disable-next-line no-async-promise-executor
const promise = new Promise(async (resolve, reject) => {
try {
subprocess.on('close', exitCode => {
// TODO: Pass in `stdin` and `stdout` strings here.
resolve({
exitCode,
});
});
const promise = new Promise((resolve, reject) => {
subprocess.on('close', (exitCode, signalName) => {
// TODO: Pass in `stdin` and `stdout` strings here.
resolve({exitCode, signalName});
});

subprocess.on('error', error => {
reject(error);
});
} catch (error) {
subprocess.on('error', error => {
reject(error);
}
});
});

const stdoutLines = lineIterator(subprocess.stdout);
Expand Down
7 changes: 7 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ test('can be awaited', async t => {
// TODO
// t.is(result.stdout, '🦄');
t.is(result.exitCode, 0);
t.is(result.signalName, null);
});

test('stdout produces correct output', async t => {
Expand All @@ -31,6 +32,12 @@ test('stderr produces correct output', async t => {
t.regex(lines[0], /No such file/);
});

test('returns termination signal', async t => {
const {exitCode, signalName} = await nanoSpawn('node', {timeout: 1});
t.is(exitCode, null);
t.is(signalName, 'SIGTERM');
});

test('combines stdout and stderr correctly', async t => {
const result = nanoSpawn('bash', ['-c', 'echo "stdout\nstdout2"; echo "stderr\nstderr2" 1>&2']);

Expand Down

0 comments on commit 5e3cd62

Please sign in to comment.