diff --git a/lib/plugins/aws/invokeLocal/index.js b/lib/plugins/aws/invokeLocal/index.js index 701a61b12..13112d9c6 100644 --- a/lib/plugins/aws/invokeLocal/index.js +++ b/lib/plugins/aws/invokeLocal/index.js @@ -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, diff --git a/lib/plugins/aws/invokeLocal/index.test.js b/lib/plugins/aws/invokeLocal/index.test.js index c0981729d..0e0440daf 100644 --- a/lib/plugins/aws/invokeLocal/index.test.js +++ b/lib/plugins/aws/invokeLocal/index.test.js @@ -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); + }); + }); }); });