mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
fix: Fix handler resolution (multi . case) for local invocation (#7398)
This commit is contained in:
parent
0ed52f61de
commit
d84e9e7d1e
@ -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,
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user