Integration tests with Mongo
Launching a MongoDB service container
In this example, we will see a NodeJS project that uses MongoDB for data storage. For the integration test phase we will launch an instance of MongoDB in order to run a set of Mocha tests.
The Mocha tests are looking for a MongoDB connection at
The example NodeJS project
You can see the example project at https://github.com/codefreshdemo/example_nodejs_mongo. The repository contains the NodeJS source code and the Mocha tests.
You can play with it locally by using Docker compose to launch both the application and the MongoDB datastore.
Create a pipeline with MongoDB integration tests
Here is the whole pipeline:
This pipeline does the following:
- Clones the source code through a Git clone step.
- Builds a Docker image with the application source code as well as the Mocha tests through a build step.
- Runs Mocha tests while launching a service container for an active MongoDB instance
Notice that we also use the
readiness property in the testing phase so that we can verify MongoDB is ready and listening, before running the tests.