Start all mongodb deployment types for testing
Switch branches/tags
INT-602b SSL SSL2 fix-stop-on-windows greenkeeper-eslint-config-mongodb-js-2.1.0 greenkeeper-eslint-config-mongodb-js-2.1.1 greenkeeper-fs-extra-1.0.0 greenkeeper-gulp-3.9.1 greenkeeper-istanbul-0.4.2 greenkeeper-mocha-3.1.0 greenkeeper-mongodb-2.2.2 greenkeeper-mongodb-2.2.3 greenkeeper-mongodb-2.2.4 greenkeeper-mongodb-2.2.8 greenkeeper-mongodb-js-precommit-0.2.9 greenkeeper-mongodb-version-manager-0.7.2 greenkeeper-mongodb-version-manager-0.8.1 greenkeeper-mongodb-version-manager-0.8.2 greenkeeper-mongodb-version-manager-0.8.3 greenkeeper-mongodb-version-manager-0.8.4 greenkeeper-mongodb-version-manager-0.8.5 greenkeeper-mongodb-version-manager-0.8.6 greenkeeper-which-1.2.5 greenkeeper/async-2.1.4 greenkeeper/async-2.1.5 greenkeeper/async-2.2.0 greenkeeper/async-2.3.0 greenkeeper/async-pin-2.1.2 greenkeeper/async-pin-2.1.4 greenkeeper/debug-2.3.3 greenkeeper/debug-2.4.0 greenkeeper/debug-2.4.1 greenkeeper/debug-2.4.2 greenkeeper/debug-2.4.3 greenkeeper/debug-2.4.4 greenkeeper/debug-2.4.5 greenkeeper/debug-2.5.0 greenkeeper/debug-2.5.1 greenkeeper/debug-2.5.2 greenkeeper/debug-2.6.0 greenkeeper/debug-2.6.1 greenkeeper/debug-2.6.2 greenkeeper/debug-2.6.3 greenkeeper/debug-2.6.4 greenkeeper/debug-pin-2.3.2 greenkeeper/debug-pin-2.4.3 greenkeeper/fs-extra-2.0.0 greenkeeper/fs-extra-2.1.0 greenkeeper/fs-extra-2.1.1 greenkeeper/fs-extra-2.1.2 greenkeeper/kill-mongodb-1.0.0 greenkeeper/lodash.defaults-4.2.0 greenkeeper/lodash.defaults-pin-4.1.0 greenkeeper/lone-0.5.0 greenkeeper/mocha-3.2.0 greenkeeper/mocha-pin-3.1.2 greenkeeper/mongodb-2.2.12 greenkeeper/mongodb-2.2.13 greenkeeper/mongodb-2.2.14 greenkeeper/mongodb-2.2.15 greenkeeper/mongodb-2.2.16 greenkeeper/mongodb-2.2.17 greenkeeper/mongodb-2.2.18 greenkeeper/mongodb-2.2.19 greenkeeper/mongodb-2.2.20 greenkeeper/mongodb-2.2.21 greenkeeper/mongodb-2.2.22 greenkeeper/mongodb-2.2.23 greenkeeper/mongodb-2.2.24 greenkeeper/mongodb-2.2.25 greenkeeper/mongodb-2.2.26 greenkeeper/mongodb-pin-2.2.11 greenkeeper/mongodb-version-manager-1.0.7 greenkeeper/mongodb-version-manager-pin-1.0.6 greenkeeper/pre-commit-1.1.3 greenkeeper/pre-commit-1.2.0 greenkeeper/pre-commit-1.2.1 greenkeeper/pre-commit-1.2.2 greenkeeper/pre-commit-pin-1.1.2 greenkeeper/pre-commit-pin-1.1.3 greenkeeper/untildify-3.0.2 greenkeeper/untildify-pin-3.0.1 greenkeeper/which-1.2.12 greenkeeper/which-1.2.13 greenkeeper/which-1.2.14 greenkeeper/which-pin-1.2.11 greenkeeper/which-pin-1.2.12 kerberos-travis-electron master
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
lib
mocha
test
.eslintrc
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
appveyor.yml
gulpfile.js :shirt" fix eslint indent errors Apr 28, 2016
index.js
package.json
usage.txt

README.md

mongodb-runner

Easily install and run MongoDB to test your code against it.

Examples

Mocha

Mocha before/after hooks make writing tests for code that depends on MongoDB insanely simple:

describe('my app', function() {
  before(require('mongodb-runner/mocha/before'));
  after(require('mongodb-runner/mocha/after'));
  it('should connect', function(done) {
    require('mongodb').connect('mongodb://localhost:27017/', done);
  });
});

Global hooks are also supported. Add the following to a new file called test/mongodb.js:

before(require('mongodb-runner/mocha/before'));
after(require('mongodb-runner/mocha/after'));

And then just require it:

mocha --require test/mongodb.js test/*.test.js

TravisCI

Modify your package.json to start and stop MongoDB before and after your tests automatically when you run npm test:

{
  "scripts": {
    "pretest": "mongodb-runner start",
    "test": "mocha",
    "posttest": "mongodb-runner stop"
  }
}

Update your .travis.yml to run your tests against the full version + topology matrix:

language: node_js
cache:
  directories:
    - node_modules
env:
  - MONGODB_VERSION=2.6.x MONGODB_TOPOLOGY=standalone
  - MONGODB_VERSION=3.0.x MONGODB_TOPOLOGY=standalone
  - MONGODB_VERSION=unstable MONGODB_TOPOLOGY=standalone
  - MONGODB_VERSION=2.6.x MONGODB_TOPOLOGY=replicaset
  - MONGODB_VERSION=3.0.x MONGODB_TOPOLOGY=replicaset
  - MONGODB_VERSION=unstable MONGODB_TOPOLOGY=replicaset
  - MONGODB_VERSION=2.6.x MONGODB_TOPOLOGY=cluster
  - MONGODB_VERSION=3.0.x MONGODB_TOPOLOGY=cluster
  - MONGODB_VERSION=unstable MONGODB_TOPOLOGY=cluster

And 🎉 Now you're fully covered for all of those all of those edge cases the full version + topology matrix can present!

Usage

Usage: mongodb-runner <start|stop> [options]

Start/stop mongodb for testing.

Options:
  --topology=<topology>         One of standalone, replicaset, or cluster [Default: `standalone`].
  --pidpath=<pidpath>           Where to put pid files [Default: `~/mongodb/pids`].
  --bin=<path>                  Path to mongod|mongos binary [Default: `which mongod|mongos`].

Options depending on `--topology`:
  --topology=standalone
    --name=<name>                 The replSet name [Default: `my-standalone`].
    --port=<port>                 Port to start mongod on [Default: `27017`].
    --dbpath=<dbpath>             Where to put the data [Default: `~/.mongodb/data/#{name}`]
    --logpath=<logpath>           [Default: `~/.mongodb/#{name}.log`]

  --topology=replicaset
    --name=<name>                 The replSet name [Default: `my-replicaset`].
    --port=<port>                 The starting port to use for mongod instances [Default: `31000`].
    --dbpath=<dbpath>             [Default: `~/.mongodb/data/#{name}-#{instance_id}`]
    --logpath=<logpath>           [Default: `~/.mongodb/#{name}.log/#{instance_id}.log`]
    --arbiters=<n>                How many arbiters to start [Default: `0`].
    --passives=<n>                How many passive instances to start [Default: `1`].
    --secondaries=<n>             How many secondary instances to start [Default: `2`]. Maps to `secondaries` option.

  --topology=cluster
    --shards=<n>                  Number of shards in the cluster [Default: `2`].
    --routers=<n>                 Number of router instances [Default: `2`].
    --configs=<n>                 Number of config servers [Default: `1`].
    --routerPort=<port>           Port number to start incrementing from when starting routers [Default `50000`].
    --port=<port>                 Port number to start incrementing from when starting shard members [Default `31000`].
    --configPort=<port>           Port number to start incrementing from when starting shard members [Default `35000`].

Environment Variables:
  MONGODB_VERSION      What version of MongoDB should be installed and available [Default: `stable`]
  MONGODB_TOPOLOGY     See `--topology`
  MONGODB_PORT         See `--port`
  MONGODB_TOPOLOGY     See `topology`
  MONGODB_ARBITERS     See `arbiters`
  MONGODB_SECONDARIES  See `secondaries`
  MONGODB_PASSIVES     See `passives`
  MONGODB_SHARDS       See `--shards`
  MONGODB_ROUTERS      See `--routers`
  MONGODB_CONFIGS      See `--configs`
  MONGODB_SHARDS_PORT  See `--shardPort`
  MONGODB_CONFIGS_PORT See `--configPort`
  MONGODB_ARBITERS     See `--arbiters`
  MONGODB_SECONDARIES  See `--secondaries`
  MONGODB_PASSIVES     See `--passives`

As mongodb-runner uses mongodb-version-manager to actually handle resolving versions and downloading MongoDB, it follows the same storage conventions.

When installed globally, npm install -g mongodb-runner, each version of MongoDB you've installed are stored under ~/.mongodb/versions:

├── mongodb-3.0.7-osx-64
├── mongodb-3.2.0-osx-64
├── mongodb-3.3.8-osx-64-enterprise
├── mongodb-3.4.0-rc2-osx-64
├── mongodb-3.4.4-osx-64
├── mongodb-3.4.5-osx-64-enterprise
├── mongodb-3.5.1-osx-64
├── mongodb-3.6.3-osx-64
├── mongodb-3.6.4-osx-64
├── mongodb-3.7.3-osx-64
└── mongodb-current -> ~/.mongodb/versions/mongodb-3.6.4-osx-64

The contents of each directory under ~/.mongodb/versions/mongodb-* are:

├── GNU-AGPL-3.0
├── MPL-2
├── README
├── THIRD-PARTY-NOTICES
└── bin
    ├── bsondump
    ├── install_compass
    ├── mongo
    ├── mongod
    ├── mongodump
    ├── mongoexport
    ├── mongofiles
    ├── mongoimport
    ├── mongoperf
    ├── mongoreplay
    ├── mongorestore
    ├── mongos
    ├── mongostat
    └── mongotop

When installed locally, npm install mongodb-runner --save-dev, each version of MongoDB you've installed are stored under /node_modules/mongodb-version-manager/.mongodb/versions with the same directory layout as above. This helps to speed up CI builds by caching downloads in a directory you're most likely to already have setup for CI. For more information, see the mongodb-version-manager README.md.

License

Apache 2.0