Open nelsonic opened 8 years ago
I would be keen to research this!
Please go for it! :+1:
@nikhilaravi are you using the gulpfile.js
from https://medium.com/@AdamRNeary/a-gulp-workflow-for-amazon-lambda-61c2afd723b6 ?
@nelsonic I read through it yesterday but haven't used it yet.
@nelsonic what do you think about extending the mock-context-object npm module to generate more accurate responses from the context methods.
It doesn't yet account for different invocation types i.e. Event or Request/Response. From the AWS docs about the context.sucess
function:
If the Lambda function is invoked using the Event invocation type (asynchronous invocation), the method will return "HTTP status 202, request accepted" response. If the Lambda function is invoked using the RequestResponse invocation type (synchronous invocation), the method will return HTTP status 200 (OK) and set the response > body to the string representation of the result.
@nikhilaravi submit this as a question on the project repo and see if you get a response before investing the time in a PR... but if you get a quick response, feel free to extend. We need to check tomorrow if they already have a plan for mocking their Lambda functions...
in light of the chat with P today we might end up using simple-mock
in which case we will create a [simple-mock-lambda
] which uses the module...
@nelsonic okay i'll do that now and I was just thinking about how to mock the function invocation similar to the invoke api but a simple-mock-lambda module sounds great.
@nelsonic found another example of testing on this repo but the context methods only seem to be for synchronous invocation.
Yeah, I haven't yet seen anything that looks elegant for testing Lambda functions ... we might be forced to come up with something better. :stuck_out_tongue_winking_eye:
All the repos using the mock-context module https://github.com/search?p=3&q=aws-lambda-mock-context&type=Code&utf8=%E2%9C%93
@nelsonic If we're using promises should we also use an async test runner like ava?
If you return a promise in the test you don't need to explicitly end the test as it will end when the promise resolves.
Can we simplify it...?
@nelsonic I had a look at the book you sent us and got a few ideas so will have a go at implementing them on Monday :)
Sweet! :lollipop: Meanwhile hope you have a RESTful remainder of your weekend! :+1:
haha! @nelsonic I found another module that mocks the context https://github.com/motdotla/node-lambda/blob/master/lib/main.js#L51-L67
However the values passed into the 'context.succeed', 'context.fail' methods are not passed back to the invoker. I think the only way to do this at the moment seems to be using the mock-context module (which uses promises) or using callbacks. I have included examples of both in the PR #45
Hi @nikhilaravi / @nelsonic , How do I test a lamba when implemented with callbacks and not context? (Node 6.10.0)
Thank you Sarmistha
How are we going to Unit Test the Lambda
handler
to ensure it works as expected? https://aws.amazon.com/blogs/compute/serverless-testing-with-aws-lambda/ ? https://medium.com/@AdamRNeary/developing-and-testing-amazon-lambda-functions-e590fac85df4