Skip to content

Commit

Permalink
Handle non-zero exit from commands run in a way needed by execa
Browse files Browse the repository at this point in the history
Fixes #197
  • Loading branch information
kategengler committed Aug 29, 2018
1 parent 39ede7d commit 33c6152
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/utils/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};
15 changes: 15 additions & 0 deletions test/utils/run-test.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
});

0 comments on commit 33c6152

Please sign in to comment.