diff --git a/test/cli.js b/test/cli.js index 0e7015be..060d86ad 100644 --- a/test/cli.js +++ b/test/cli.js @@ -1,7 +1,6 @@ const pathModule = require('path'); -const expect = require('unexpected').clone(); - const childProcess = require('child_process'); +const expect = require('unexpected').clone(); function consumeStream(stream) { return new Promise((resolve, reject) => { @@ -13,48 +12,6 @@ function consumeStream(stream) { }); } -async function run(commandAndArgs, stdin) { - if (typeof commandAndArgs !== 'undefined' && !Array.isArray(commandAndArgs)) { - commandAndArgs = [commandAndArgs]; - } - - const proc = childProcess.spawn(commandAndArgs[0], commandAndArgs.slice(1)); - - const promises = { - exit: new Promise((resolve, reject) => { - proc.on('error', reject).on('exit', exitCode => { - if (exitCode === 0) { - resolve(); - } else { - const err = new Error(`Child process exited with ${exitCode}`); - err.exitCode = exitCode; - reject(err); - } - }); - }), - stdin: new Promise((resolve, reject) => { - proc.stdin.on('error', reject).on('close', resolve); - }), - stdout: consumeStream(proc.stdout), - stderr: consumeStream(proc.stderr) - }; - - if (typeof stdin === 'undefined') { - proc.stdin.end(); - } else { - proc.stdin.end(stdin); - } - - try { - await Promise.all(Object.values(promises)); - return [await promises.stdout, await promises.stderr]; - } catch (err) { - err.stdout = await promises.stdout; - err.stderr = await promises.stderr; - throw err; - } -} - async function runSubfont(...args) { const proc = childProcess.spawn( pathModule.resolve(__dirname, '..', 'lib', 'cli.js'),