Member-only story
Integration Tests in Node.js
Discussing a basic setup for Mocha to run integration tests

In the previous piece, I wrote about the importance of unit tests and how it improved our codebase.
But, what if you want to have more security and also write integration tests in a Node.js application? In this piece, I will discuss a basic setup for Mocha to run integration tests.
While creating examples for this piece, I focused on issues I had in one of my projects. In this project, we had a big REST API application which had hardly any tests at all.
However, there was one important interface and one of the previous developers decided it was important to test it, because it was crucial for the client’s company not to go out of business.
If anything else crashed, we did not worry too much about it but this one was pretty much the end of the world.
The test setup we had was far from perfect. The issue was that the test ran on a real database and created real items on it. These items needed to be removed with a cleanup process.
The cleanup was failing quite regularly and then this product crashed the next test runs because of constraint violations. We needed to manually remove this product.