-
-
Notifications
You must be signed in to change notification settings - Fork 794
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Support handlers exported from nested modules (#1348)
- Loading branch information
1 parent
c90b8bf
commit e7c72f4
Showing
10 changed files
with
219 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 0 additions & 145 deletions
145
src/lambda/__tests__/fixtures/lambdaFunction.fixture.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
'use strict' | ||
|
||
exports.fixture = { | ||
contextDoneHandler(event, context) { | ||
context.done(null, 'foo') | ||
}, | ||
|
||
contextDoneHandlerDeferred(event, context) { | ||
setTimeout(() => context.done(null, 'foo'), 100) | ||
}, | ||
|
||
contextSucceedHandler(event, context) { | ||
context.succeed('foo') | ||
}, | ||
|
||
contextSucceedHandlerDeferred(event, context) { | ||
setTimeout(() => context.succeed('foo'), 100) | ||
}, | ||
|
||
callbackHandler(event, context, callback) { | ||
callback(null, 'foo') | ||
}, | ||
|
||
callbackHandlerDeferred(event, context, callback) { | ||
setTimeout(() => callback(null, 'foo'), 100) | ||
}, | ||
|
||
promiseHandler() { | ||
return Promise.resolve('foo') | ||
}, | ||
|
||
promiseHandlerDeferred() { | ||
return new Promise((resolve) => { | ||
setTimeout(() => resolve('foo'), 100) | ||
}) | ||
}, | ||
|
||
async asyncFunctionHandler() { | ||
return 'foo' | ||
}, | ||
|
||
async asyncFunctionHandlerObject() { | ||
return { | ||
foo: 'bar', | ||
} | ||
}, | ||
|
||
// we deliberately test the case where a 'callback' is defined | ||
// in the handler, but a promise is being returned to protect from a | ||
// potential naive implementation, e.g. | ||
// | ||
// const { promisify } = 'utils' | ||
// const promisifiedHandler = handler.length === 3 ? promisify(handler) : handler | ||
// | ||
// if someone would return a promise, but also defines callback, without using it | ||
// the handler would not be returning anything | ||
|
||
promiseWithDefinedCallbackHandler( | ||
event, // eslint-disable-line no-unused-vars | ||
context, // eslint-disable-line no-unused-vars | ||
callback, // eslint-disable-line no-unused-vars | ||
) { | ||
return Promise.resolve('Hello Promise!') | ||
}, | ||
|
||
contextSucceedWithContextDoneHandler(event, context) { | ||
context.succeed('Hello Context.succeed!') | ||
|
||
context.done(null, 'Hello Context.done!') | ||
}, | ||
|
||
callbackWithContextDoneHandler(event, context, callback) { | ||
callback(null, 'Hello Callback!') | ||
|
||
context.done(null, 'Hello Context.done!') | ||
}, | ||
|
||
callbackWithPromiseHandler(event, context, callback) { | ||
callback(null, 'Hello Callback!') | ||
|
||
return Promise.resolve('Hello Promise!') | ||
}, | ||
|
||
callbackInsidePromiseHandler(event, context, callback) { | ||
return new Promise((resolve) => { | ||
callback(null, 'Hello Callback!') | ||
|
||
resolve('Hello Promise!') | ||
}) | ||
}, | ||
|
||
async requestIdHandler(event, context) { | ||
return context.awsRequestId | ||
}, | ||
|
||
async remainingExecutionTimeHandler(event, context) { | ||
const first = context.getRemainingTimeInMillis() | ||
|
||
await new Promise((resolve) => { | ||
setTimeout(resolve, 100) | ||
}) | ||
|
||
const second = context.getRemainingTimeInMillis() | ||
|
||
await new Promise((resolve) => { | ||
setTimeout(resolve, 200) | ||
}) | ||
|
||
const third = context.getRemainingTimeInMillis() | ||
|
||
return [first, second, third] | ||
}, | ||
|
||
async defaultTimeoutHandler(event, context) { | ||
return context.getRemainingTimeInMillis() | ||
}, | ||
|
||
executionTimeInMillisHandler() { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, 100) | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.