2.1.0 • Published 4 years ago

@lyvly/mock-mongo v2.1.0

Weekly downloads
14
License
MIT
Repository
github
Last release
4 years ago

mock-mongo

Mocks a Mongo Replica Set, using mongodb-memory-server.

Motivation

There are many motivations in life for building packages, this one was simple. We use the mock DB everywhere, and we needed to prove that we could publish libraries in a nice simple concise manner. So here we are.

Usage

In your test file, import MockMongo:

import { MockMongo } from '@lyvly/mock-mongo

To start the db:

await MockMongo.start([options])

By default, we use the following mongodb-memory-server options:

  debug: false,
  replSet: {
    storageEngine: 'wiredTiger',
  },

You can override this by passing your own options to start.

start returns the mongo memory server instance.

To get the connection uri:

await MockMongo.getUri()

To stop the DB:

await MockMongo.stop()

To get a native mongo collection to test against:

await MockMongo.getCollection(databaseName, collectionName)

To get the mongo memory server instance

MockMongo.get()

To set a new mongo memory server instance

MockMongo.set(mongoInstance)
2.1.0

4 years ago

2.0.0

4 years ago

1.0.2

4 years ago

1.0.4

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago