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
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 RU-vid Membership, Pateron, or having some T-Shirts and merch. Is this the kind of thing you were thinking of?
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?
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
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.
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.
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?
@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?
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
@@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.
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
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.
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
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?
@@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
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