Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including mongo-ci with all npm packages installed. Try it out:

var mongoCi = require("mongo-ci")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

mongo-ci v1.3.2

Node.js MongoDB testing package

mongo-ci

This library is created to prepare environment for testing with MongoDB, especially designed to work well with CI.

Installation

$ npm install -D mongo-ci

Usage

import * as mongoCI from 'mongo-ci';

describte('Repository Test', () => {
  beforeAll(async (done) => mongoCI.init(process.env.MONGO_HOST || 'localhost').then(done));
  beforeEach(async (done) => mongoCI.load(mockData).then(done));
  afterEach(async (done) => mongoCI.deleteAll().then(done));
  afterAll(async (done) => mongoCI.drop().then(done));
});

The mock data:

import { ObjectId } from 'mongodb';

export const mockData = {
  'device-groups':
    [
      {
        '_id': new ObjectId('0123456789abcdef01234560'),
        'devices': [],
        'lastModified': '1572945305311',
      },
      {
        '_id': new ObjectId('0123456789abcdef01234561'),
        'parent': '0123456789abcdef01234560',
        'devices': [],
        'lastModified': '1572945305311',
      },
    ],
  };

In the GitLab-CI configuration, i.e. .gitlab-ci.yml:

variables:
  NODE_VERSION: 12.0.0

test:jasmine:
  stage: test
  image: node:${NODE_VERSION}
  allow_failure: false
  services:
    - mongo
  variables:
    MONGO_HOST: 'mongo'
    Host: 'mongo'
    Database: 'test'
  script:
    - npm test

Travis-CI configuration is similar. For further details please refer to this document.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free