diff --git a/lib/utils/run.js b/lib/utils/run.js index dbb2fab2..a4e8c254 100644 --- a/lib/utils/run.js +++ b/lib/utils/run.js @@ -17,9 +17,8 @@ module.exports = function run(command, args, opts) { debug('spawned with execa.shell', cmdArgs, opts); - return child.then((child) => { - if (child.code !== 0) { - return Promise.reject(child.code); - } + return child.catch((error) => { + debug('error', error); + return Promise.reject(error.code); }); }; diff --git a/test/utils/run-test.js b/test/utils/run-test.js new file mode 100644 index 00000000..aeda1f51 --- /dev/null +++ b/test/utils/run-test.js @@ -0,0 +1,15 @@ +'use strict'; + +const expect = require('chai').expect; + +describe('utils/run', () => { + it('rejects if command exits non-zero', () => { + let run = require('../../lib/utils/run'); + + return run('exit 1', [], {}).then(() => { + expect(true).to.equal(false, 'Should not succeed'); + }).catch((res) => { + expect(res).to.equal(1, 'Should reject with exit code'); + }); + }); +});