Week 3 | Testing and Deploying
June 15, 2020This week involved setting up unit tests and deployment. For testing, I used Mocha and Chai as they seemed to be the most popular. Creating the tests was a tedious task, but in the end it was satisfying. Seeing tests pass on each change was nice that I did not have to test certain endpoints myself.
Once I set up the tests, I wanted a way to automatically run the tests. I had my mind set on Github Actions for this tasks since I’ve used it before, it’s free, and easy. There was already a lot of examples on how to test a Node.js application with Github Actions. One example used multiple Nodejs and MongoDB versions which is something I did not think about before. What was nice about the workflow is that it setup a test database for me that is removed on completion so I did not have to worry about deleting records for each test. Using this workflow, I was able to ensure that my endpoints still worked on each Github push.
Next week, I plan on deploying this application and have a way to automatically update. I plan on have a shell script that is able to pull the updated code, stop the docker containers and rebuild them. I can have Github Actions make an SSH command to the server to run the script.