How to use the mongodb-memory-server.default function in mongodb-memory-server

To help you get started, we’ve selected a few mongodb-memory-server examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github entria / graphql-dataloader-boilerplate / test / environment / mongodb.js View on Github external
constructor(config) {
    // console.error('\n# MongoDB Environment Constructor #\n');
    super(config);
    this.mongod = new MongodbMemoryServer.default({
      instance: {
        // settings here
        // dbName is null, so it's random
        // dbName: MONGO_DB_NAME,
      },
      binary: {
        version: '4.0.0',
      },
      // debug: true,
      autoStart: false,
    });
  }
github keystonejs / keystone / packages / test-utils / lib / test-utils.js View on Github external
async function getMongoMemoryServerConfig() {
  mongoServer = mongoServer || new MongoDBMemoryServer();
  mongoServerReferences++;
  // Passing `true` here generates a new, random DB name for us
  const mongoUri = await mongoServer.getConnectionString(true);
  // In theory the dbName can contain query params so lets parse it then extract the db name
  const dbName = url
    .parse(mongoUri)
    .pathname.split('/')
    .pop();

  return { mongoUri, dbName };
}
github deliciousinsights / mongoose-pii / markFieldsAsPII.spec.js View on Github external
beforeAll(async () => {
    // DEV NOTE: do NOT resetModules() here, as it'll impact Mongoose’s
    // internal driver initialization, leading to weird "Decimal128 of null"
    // errors -- this one was tough to hunt down…
    jest.dontMock('./util/ciphers')

    server = new MongoDBMemoryServer()
    const url = await server.getConnectionString()
    connection = await mongoose.createConnection(url, {
      autoReconnect: true,
      connectTimeoutMS: 1000,
      reconnectInterval: 100,
      reconnectTries: Number.MAX_VALUE,
      useNewUrlParser: true,
    })
  })
github keystonejs / keystone / packages / mongo-join-builder / examples / database.js View on Github external
module.exports = async () => {
  const mongoServer = new MongoDBMemoryServer();
  const mongoUri = await mongoServer.getConnectionString();
  const mongoConnection = await MongoClient.connect(mongoUri, { useNewUrlParser: true });
  const mongoDb = mongoConnection.db(await mongoServer.getDbName());

  // Only item 2 & 3 have stock. Item 2 only has stock in warehouse A.Item 3 used
  // to have stock in warehouse B, but now only has stock in warehouse A.
  const { insertedIds: insertedStock } = await mongoDb
    .collection('warehouses')
    .insertMany([
      { warehouse: 'A', instock: 0 },
      { warehouse: 'A', instock: 80 },
      { warehouse: 'B', instock: 0 },
      { warehouse: 'B', instock: 0 },
      { warehouse: 'A', instock: 40 },
    ]);
github shelfio / jest-mongodb / setup.js View on Github external
const fs = require('fs');
const {resolve, join} = require('path');
const cwd = require('cwd');
const MongodbMemoryServer = require('mongodb-memory-server');
const globalConfigPath = join(__dirname, 'globalConfig.json');

const debug = require('debug')('jest-mongodb:setup');
const mongod = new MongodbMemoryServer.default(getMongodbMemoryOptions());

module.exports = async () => {
  if (!mongod.isRunning) {
    await mongod.start();
  }

  const mongoConfig = {
    mongoDBName: getMongodbMemoryOptions().instance.dbName,
    mongoUri: await mongod.getConnectionString()
  };

  // Write global config to disk because all tests run in different contexts.
  fs.writeFileSync(globalConfigPath, JSON.stringify(mongoConfig));
  debug('Config is written');

  // Set reference to mongod in order to close the server during teardown.
github qhacks / qhacks-dashboard / packages / server / __tests__ / config / mongo-environment.js View on Github external
constructor(config) {
    super(config);

    this.mongod = new MongodbMemoryServer.default({
      instance: {
        dbName: this.global.dbName
      },
      binary: {
        version: "3.4.4"
      }
    });
  }
github OpenNeuroOrg / openneuro / server / mongo-environment.js View on Github external
const MongodbMemoryServer = require('mongodb-memory-server').default
const NodeEnvironment = require('jest-environment-node')

const mongod = new MongodbMemoryServer()

class MongoEnvironment extends NodeEnvironment {
  constructor(config) {
    super(config)
  }

  async setup() {
    console.log('Setup MongoDB Test Environment')

    this.global.__MONGO_URI__ = `mongodb://localhost:${await mongod.getPort()}/`

    await super.setup()
  }

  async teardown() {
    console.log('Teardown MongoDB Test Environment')
github OpenNeuroOrg / openneuro / server / jest-setup.js View on Github external
const MongodbMemoryServer = require('mongodb-memory-server').default
const mongod = new MongodbMemoryServer()

module.exports = () => {
  global.__MONGOD__ = mongod
}
github RodolfoSilva / graphql-typescript-server-boilerplate / scripts / jest-globalSetup.js View on Github external
const { default: MongoMemoryServer } = require('mongodb-memory-server');
const mongod = new MongoMemoryServer({ autoStart: false });

const globalSetup = async () => {
  await mongod.start();

  process.env.MONGO_URI = await mongod.getConnectionString();

  global.__MONGOD__ = mongod;
};

module.exports = globalSetup;
github OpenNeuroOrg / openneuro / packages / openneuro-server / mongo-environment.js View on Github external
constructor(config) {
    super(config)
    this.mongod = new MongodbMemoryServer()
  }

mongodb-memory-server

MongoDB Server for testing (auto-download latest version). The server will allow you to connect your favourite ODM or client library to the MongoDB Server and run parallel integration tests isolated from each other.

MIT
Latest version published 13 days ago

Package Health Score

98 / 100
Full package analysis