Unit Testing in Serverless - tutorial including DynamoDB
HTML-код
- Опубликовано: 28 фев 2020
- In this video we'll learn about unit testing in Serverless and how we can also unit test interactions with AWS services such as DynamoDB
Code for starting this video:
github.com/SamWSoftware/Serve...
Code for completed Lesson
github.com/SamWSoftware/Serve... Наука
Great video, thanks again Sam! Enjoyed this tutorial.
My pleasure!
Love your channel. Thank you for the lessons.
Glad you like them!
Thanks for this video Sam!! Was great! :) help me a lot!
Glad it helped you out
That is another great video!
Thanks! The next one on integration testing serverless Lambdas will be coming out shortly
Thanks for good video again!
My pleasure!
basically all your vids 👍
Thanks David. Glad they're helpful
Testing for S3 is missing !
With S3 there isn't a library that I've found that works as well as this one does for dynamo. Since these are meant to be unit testing I would mock the s3 service to create the tests.
Note to anyone using this tutorial having problems running Jest:
Install Jest Globally AS WELL AS npm install --save-dev jest.
Nice spot Pete
Or instead of adding JEST Globally, you can add a script to package.json like "test": "jest"
And then just run "npm run test"
Hi! Quick question, using this same code or a similar one, If I wanted to use jest testing WITHOUT mocking the Database, using the real DynamoDB, does the configuration change or any additional changes to perform? I'm currently trying to make a change in the project, from having the DynamoDB configuration in Handler to a proper Dynamo.js file, but I seem to get the error: UnrecognizedClientException: The security token included in the request is invalid.
I'm not sure if this stems from handler reading the dynamo configuration from serverless.yml, and the Dynamo.js file does not read it
Any answer is appreciated.
You would have to change the configuration in Dynamo.js so that it uses the correct AWS credentials to access the real database when running a test. Add something like this to the top of the Dynamo.js file in the (isTest) block. This uses the credentials for the profile when running the lambda.
var credentials = new AWS.SharedIniFileCredentials({profile: 'work-account'});
AWS.config.credentials = credentials;
Why Skipped the S3 unit tests???
With S3 there isn't a library that I've found that works as well as this one does for dynamo. Since these are meant to be unit testing I would mock the s3 service to create the tests.
I am getting error while executing jest with @shelf/jest-dynamodb added in jest.config.js file.
Try following the previous video on serverless offline first. There may be some steps in that that are needed to get jest to work.
@@CompleteCoding java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
You can use jest-dynalite which is a fork of jest-dynamodb as replacement because it doesn't require Java.
@@rendelllasola66 Thanks for point that out
Hi, Sir i want to contact you .
My details are in the 'about' section of the channel page
First view
thanks Dhanwa
java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException
This sounds like you haven't got the Java processor required. If you follow this video on setting up serverless-offline it will show you how to install this. Then it should all work.
ruclips.net/video/ul_85jfM0oo/видео.html
Dynamo intialisation file is written in TS. To compile ts file in jest, I read you need to include 'ts-jest' as preset. But to use dynamo
local, we need to use "@shelf/jest-dynamodb" as preset. How can I add two presets in one jest config file? Please help me out.
Great video btw!