lambda-tester | Helper for unit testing AWS Lambda functions | Runtime Evironment library
kandi X-RAY | lambda-tester Summary
kandi X-RAY | lambda-tester Summary
Helper for unit testing AWS Lambda functions
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- create a proxy server
- Resolve handler for tester .
- Create a log stream
- Run a callback
- Adds the cleanup function to the given promise
- Create a function that will create a lambda context
- Stop the server
- Wait until the xray has been settled
- Waits for an xRay .
- Process a message
lambda-tester Key Features
lambda-tester Examples and Code Snippets
Community Discussions
Trending Discussions on lambda-tester
QUESTION
I am new to Node.js. I was trying to write a jest unit test cases for AWS lambda function(for node environment). I used a node module called "lambda-tester" to test it. But the problem with "lambda-tester" is, it will hit the actual service and return the data. I don't want to do that. I need to mock the service call.
So, I wanted to go with the plain old way. But, I have issues with mocking it. Can you help me to write basic unit test case for the below lambda ith mocking the function "serviceFunction" ?
...ANSWER
Answered 2019-Oct-31 at 11:50You can use jest.spyOn(object, methodName, accessType?) method to mock dataService.retrieveData
method. And, your serviceFunction
function only has one statement, so you can test lambdaService
function with it together.
E.g.
index.js
:
QUESTION
I'm trying to figure out a way to mock redis in this module:
...ANSWER
Answered 2017-Jun-13 at 09:07Your problem is not whether Sinon supports this or that, but rather a missing understanding of how "classes" work in Ecmascript, as shown by the attempt at stubbing constructor
property in the test code. That will never work, as that property has nothing to do with how any resulting objects turn out. It is simply a reference to the function that was used to create the object. I have covered a very similar topic on the Sinon tracker that you might have interest in reading to gain some core JS foo :-) Basically, it is not possible to stub a constructor, but you can probably coerce your code to use another constructor function in its place through either DI or link seams.
As a matter of fact, a few answers down in the same thread, you will see me covering an example of how I myself designed a Redis using class to be easily testable by supporting dependency injection. You might want to check it out, as it is more or less directly applicable to your example module above.
Another technique, which you already has tried getting to work, is using link seams (using rewire
). The Sinon homepage has a nice article on doing this. Both rewire
and proxyquire
will do the job just fine here: I think you have just complicated the matter a bit by wrapping the require statement with a mock.
Even though I am on the Sinon maintainer team, I never use the mock
functionality, so I cannot tell you how to use that, as I think it obscures the testing, but to get the basic link seams working using rewire
I would basically remove all the Sinon code first and get the basic case going (removing redis
for a stubbed module you have created).
Only then, add Sinon code as required.
QUESTION
I have a deploy script I only want to run if my test is successful but believe there is an issue with my conditional statement if [ "$VALID" ]
ANSWER
Answered 2019-Feb-28 at 03:51You could do something along the lines of:
QUESTION
Background
I was thrown on this project to help alleviate some stress. The trouble is no one else has done this either so I'm pioneering the cause.
What I know
I can get lambda function output locally with:
...ANSWER
Answered 2017-Nov-10 at 16:33Use lamba-tester, there are examples on the github page.
I wrote a simple lambda test function and then tested the output with jasmine
+ lambda-tester
As for my code, I'll need to refactor the handler someone else wrote before it will work. My simple test looks like:
Serverless yml
QUESTION
There are many posts online about how to test AWS lambdas, and how to mock certain dependencies etc. Maybe I am over simplifying, but I don't need any of that. For a while, I have been using mocha/chai and lambda-tester. This worked just fine for running tests with simple npm test
.
My problem now is, as I am being ushered towards using Jest instead of mocha/chai, I have since updated all of my tests to match Jest syntax(fairly similar as most are). Now however, my tests sometimes pass and sometimes fail. While this makes me think my tests are not handling async correctly, I do not see how I can make use of the Jest docs and use done in my code, as I believe lambda-tester returns the result I am expecting.
To keep things simple, one of my Lambdas simply returns an image url. My test should verify that has a statusCode:200
and that headers has a content-type property.
Here is my test as it was in mocha/chai format, when it consistently passed (verified not false positives):
...ANSWER
Answered 2017-Sep-22 at 00:00There seems to be nothing wrong with your code.
One of the biggest difference between mocha
and jest
is that jest
runs tests concurrently and therefore it can detect issues like race conditions and mutations outside your handler on your Lambda that mocha
may miss.
Here's I would troubleshoot it:
- Try to run that single test multiple times (that single file and that single test using
test.only
). - Try running the entire suite serially using
jest --runInBand
.
If we get consistent failures with those, then you probably have race condition issues and/or maybe a bug in your code where you store state outside of your handler and it is being shared by different invocations.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install lambda-tester
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page