diff --git a/index.js b/index.js index 4e5e75e..99e13f2 100644 --- a/index.js +++ b/index.js @@ -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); diff --git a/test.js b/test.js index 2b4235f..82c46d6 100644 --- a/test.js +++ b/test.js @@ -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 => { @@ -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']);