Reject promise and handle exit code in the wrapper

This commit is contained in:
Joe Stanton 2016-12-02 09:46:28 +00:00 committed by Maciej Winnicki
parent fb1b4ef14a
commit b5284df55f
No known key found for this signature in database
GPG Key ID: 950BD3CA7EDF6008
3 changed files with 11 additions and 6 deletions

View File

@ -17,4 +17,7 @@ process.noDeprecation = true;
});
return serverless.init().then(() => serverless.run());
}).catch(e => logError(e)))();
}).catch(e => {
process.exitCode = 1;
logError(e);
}))();

View File

@ -120,7 +120,7 @@ class AwsInvoke {
}
if (invocationReply.FunctionError) {
process.exit(1);
return BbPromise.reject(new Error("Invoked function errored"));
}
return BbPromise.resolve();

View File

@ -260,8 +260,7 @@ describe('AwsInvoke', () => {
return awsInvoke.log(invocationReplyMock);
});
it('should exit on error', () => {
const exit = sinon.stub(process, 'exit');
it('rejects the promise for failed invocations', (done) => {
const invocationReplyMock = {
Payload: `
{
@ -272,8 +271,11 @@ describe('AwsInvoke', () => {
FunctionError: true,
};
awsInvoke.log(invocationReplyMock);
expect(exit.calledWithExactly(1)).to.be.equal(true);
awsInvoke.log(invocationReplyMock).then(p => {
done(new Error("Promise resolved"));
}, (e) => {
done()
});
});
});
});