fix: Fix handler resolution (multi . case) for local invocation (#7398)

This commit is contained in:
Arben Bakiu 2020-02-27 23:19:09 +01:00 committed by GitHub
parent 0ed52f61de
commit d84e9e7d1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 9 deletions

View File

@ -178,8 +178,9 @@ class AwsInvokeLocal {
}
if (runtime.startsWith('nodejs')) {
const handlerPath = handler.split('.')[0];
const handlerName = handler.split('.')[1];
const handlerSeparatorIndex = handler.lastIndexOf('.');
const handlerPath = handler.slice(0, handlerSeparatorIndex);
const handlerName = handler.slice(handlerSeparatorIndex + 1);
return this.invokeLocalNodeJs(
handlerPath,
handlerName,

View File

@ -501,13 +501,22 @@ describe('AwsInvokeLocal', () => {
).to.be.equal(true);
}));
it('should call invokeLocalNodeJs for any node.js runtime version', () => {
awsInvokeLocal.options.functionObj.runtime = 'nodejs12.x';
return awsInvokeLocal.invokeLocal().then(() => {
expect(invokeLocalNodeJsStub.calledOnce).to.be.equal(true);
expect(
invokeLocalNodeJsStub.calledWithExactly('handler', 'hello', {}, undefined)
).to.be.equal(true);
describe('for different handler paths', () => {
[
{ path: 'handler.hello', expected: 'handler' },
{ path: '.build/handler.hello', expected: '.build/handler' },
].forEach(item => {
it(`should call invokeLocalNodeJs for any node.js runtime version for ${item.path}`, () => {
awsInvokeLocal.options.functionObj.handler = item.path;
awsInvokeLocal.options.functionObj.runtime = 'nodejs12.x';
return awsInvokeLocal.invokeLocal().then(() => {
expect(invokeLocalNodeJsStub.calledOnce).to.be.equal(true);
expect(
invokeLocalNodeJsStub.calledWithExactly(item.expected, 'hello', {}, undefined)
).to.be.equal(true);
});
});
});
});