mongo-ci
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

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.

Dependencies (2)

Dev Dependencies (5)

Package Sidebar

Install

npm i mongo-ci

Weekly Downloads

17

Version

1.3.2

License

MIT

Unpacked Size

20.7 kB

Total Files

9

Last publish

Collaborators

  • aerabi