From d84e9e7d1e440b5bfaae39b4cfefd83f8ac2e8b9 Mon Sep 17 00:00:00 2001 From: Arben Bakiu <47607244+arbbakbenny@users.noreply.github.com> Date: Thu, 27 Feb 2020 23:19:09 +0100 Subject: [PATCH] fix: Fix handler resolution (multi . case) for local invocation (#7398) --- lib/plugins/aws/invokeLocal/index.js | 5 +++-- lib/plugins/aws/invokeLocal/index.test.js | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) 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); + }); + }); }); });