I like RethinkDB for its simplicity, API and local admin tool. Recently I wanted to unit test NodeJS code that interfaces with a RethinkDB on a continuous build server. I love using TravisCI, Codeship and CircleCI and consider well tested code a prerequisite to a solid application. Here is how to install and run the database while executing BDD tests (in my case using Mocha).
To install RethinkDB on CircleCI instance I added the following config file
This will install the latest available 1.16 version of the database. If you want to install the 2.x version
sudo apt-get install rethinkdb=2.\* command.
To start RethinkDB process I wrote the following helper js code
var spawn = require('child_process').spawn;
The above function returns another function that can kill the started database process.
To start the DB before running the unit tests I call
startRethinkDB inside the
var startRethinkDb = require('./start-rethinkdb');
There is a short timeout to let db to come up, then another short delay after the tests are finished to close all open DB connections.
The CI is now happy and runs the tests against the database. Just remember that any local DB data persists unless you delete the saved database folder.