Thanks for the content! Just want to support the channel that is why I left the comment :) Good luck with further videos! (probably i just missed that) It would be nice to mentioned at about approach how to run tests locally and on CI using DynamoDB copy, it would help for less experienced in serverless guys
@CompleteCoding3 жыл бұрын
There is a video I've done on that just here kzfaq.info/get/bejne/q9KPa5iby7OUn6M.html
@konstantin65243 жыл бұрын
Perfect content! I want to leave a comment for supporting chanel!
@CompleteCoding3 жыл бұрын
Much appreciated!
@jc82123 жыл бұрын
Awesome explaination 👍
@CompleteCoding3 жыл бұрын
Glad it was helpful!
@ahmadnabil24412 жыл бұрын
Great explanation! Do u mind sharing vscode extensions names especially the one which checks the code with (x) and (✓) marks and the one that highlights code blocks with different colors?
@CompleteCoding2 жыл бұрын
The ticks and crosses are the "vs code jest" extension. The multi coloured tabs is "Rainbow intent"
@maopuerta34303 жыл бұрын
Excellent video
@CompleteCoding3 жыл бұрын
Thanks!
@cristianecheverria39954 жыл бұрын
Great content!!
@CompleteCoding4 жыл бұрын
Glad you liked it Christian
@EstebanHelgueroCardiff3 жыл бұрын
Hi, when you save data into DynamoDB, then you have to delete it? Or it's just a mock of Dynamo that you are using on this example?
@CompleteCoding3 жыл бұрын
When you run tests it creates a local mock of dynamo so it doesn't polute your real data
@MarzanDaniel Жыл бұрын
Thank you for sharing
@vigneshdev57622 жыл бұрын
Awesome stuff, Just want to know how can mock context parameter of handler function from unit test, can we pass something like contextGenerator()?
@CompleteCoding2 жыл бұрын
Yes, if you need to mock context the that would be the easiest way. Over time you can add parameters to vary the context data you generate
@madhavareddy3488 Жыл бұрын
Hello Sam, does these integration tests leverage emulated API gateway? I want to test the endpoint using it's route (e.g.: GET - /api/players) to test API key authentication. Is this possible?
@CompleteCoding Жыл бұрын
You could do it another way. When you start jest, it starts serverless offline. Your jest tests then call the serverless offline endpoints. You can even then reuse your tests on your deployed resources too which is really cool
@cristianecheverria39954 жыл бұрын
I'm having issues running integration tests after I decided to create multiple environments for my deploys, not sure if that's related but when I run the test using "tableName=user jest" it says "ResourceNotFoundException: Cannot do operations on a non-existent table" when I try to write into Dynamo table. Any suggestion?
@CompleteCoding4 жыл бұрын
Is the table that you are passing in (user) the same as the name of the table you've set in your resources config in serverless?
@cristianecheverria39954 жыл бұрын
@@CompleteCoding I created a Gist file where you can see a resumed version of my serverless.yml file. Not sure if it looks ok, right now it works for my purpose of having multiple environments using --stage in AWS. gist.github.com/crisecheverria/15ea7aa275df344f1d1f647eb0af91d1
@CompleteCoding3 жыл бұрын
as you will be testing locally, you can just run usersTableName=user-dev projectsTableName=projects-dev jest
@mojgandadashi12 жыл бұрын
Sam do you have a video of writing the tests with java? what will be the difference if I want to write the tests in java?
@CompleteCoding2 жыл бұрын
If there is a java test library that can execute a function with an set event then it would be very similar. If you're also testing with a dynamo table you'll have to script a local version of dynamo to start and the configure your dynamo to connect to that. With JS, that is done by the jest dynamo plugin. There might even be a similar plugin for java
@PeteWhelan4 жыл бұрын
Hi Sam Having problems with this one - jest command wont take the env variables - every time I try to add the tableName= (at 20:23 in the tutorial) and get : "not recognized as the name of a cmdlet, function, script file, or operable program...." I have googled / stack overflowed this but can't find an answer that works for me. - any ideas whats wrong? Thanks in advance again
@CompleteCoding4 жыл бұрын
Hey Pete. Are you using Windows, Mac or Linux? Also are you entering it all on a single line
@PeteWhelan4 жыл бұрын
Sam - sorry for the delayed response. I'm using windows and yes I'm entering it on all on one line
@frozenn00b3 жыл бұрын
@8:00 Why not define a default response object, then use the object spread method which has been supported since Node 8.6? ie: eventGenerator(options) { const default = {default event stuff}; return { ...default, ...options }; } -- this is a lot more flexible than the method you use, and requires no editing if later on you need to redefine a variable that you have blank in the default?
@CompleteCoding3 жыл бұрын
spread works brilliantly with flat objects but struggles with deep or nested objects. One thing we're setting it response.requestContext.httpMethod. If we used spread then you would have to pass in the whole requestContext object, not just the method value. You could also make a recursive function that means you can pass in partial objects and it joins them but that would be a lot more work
@frozenn00b3 жыл бұрын
@@CompleteCoding I've been doing spreading for 2 years now, never seen a "struggle". Do you have any references for that as I would be curious what "struggles" exist? As far as the comment about passing the parent objects, yes, but it does also make it more readable, easier to maintain, and far more flexible/future proof.
@privymassage34583 жыл бұрын
Hi Sam, how can I support your channel? Info here is so pricesless just want to show some appreciation.
@CompleteCoding3 жыл бұрын
Right now the best thing I can do is to like and comment on the new videos that come out. It really helps show the video to more people. I'm toying with the KZfaq Membership, Pateron, or having some T-Shirts and merch. Is this the kind of thing you were thinking of?
@wendyliew72542 жыл бұрын
what if the lambda is not exposed to API Gateway nor AppSync? can we still write some integration test against it? It's only called by some other lambda(s) that were exposed via AppSync.
@CompleteCoding2 жыл бұрын
Integration tests are often hard to define with Serverless. In this video I go with "testing a lambda locally without mocking - using local versions instead". In this case you can integration test any Lambda exactly as I do in this video. You may need to change the event that you pass into the handler from your test. The other definition of integration testing is "testing a deployed Lambda that integrates with all of the real services". You can also do this with no-API lambdas. Once everything is deployed, in your tests use the same `lambda.invoke` that you would when calling from another lambda. That will trigger the real lambda and you can see if your tests work.
@jc82123 жыл бұрын
Can you please create one vblog for cognito service to integrate jest test case. It's mean sign in, sign up, post confirmation.
@CompleteCoding3 жыл бұрын
That sounds like you're wanting to test what the user experience would be? Is that right?
@gajendrakumarmangaraja12614 жыл бұрын
ran the command "sls offline start --location ." . showing errors
@CompleteCoding4 жыл бұрын
The first thing is to check your version of serverless-offline. There was a change to v6 that broke the way that it works with the dynamo configuration. You can manually set the version to 5 and it should work
@nemesaenz8793 Жыл бұрын
Why not test actual calls to the api gateway instead of testing the handler function?
@CompleteCoding Жыл бұрын
To test the actual endpoints you'd need to deploy the service first. This is actually what I do a lot more now. I automatically deploy a temporary stack to a 'testing' account when a PR is created. The tests then run and if they fail, that shows up in the PR.