Socket
Socket
Sign inDemoInstall

@shelf/jest-mongodb

Package Overview
Dependencies
3
Maintainers
43
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.1.1 to 2.2.0

jest-mongodb-config-repl.js

8

environment.js

@@ -5,3 +5,3 @@ const NodeEnvironment = require('jest-environment-node');

const uuid = require('uuid');
const {MongoMemoryServer} = require('mongodb-memory-server');
const {MongoMemoryServer, MongoMemoryReplSet} = require('mongodb-memory-server');
const {getMongodbMemoryOptions} = require('./helpers');

@@ -14,5 +14,9 @@

const globalConfigPath = path.join(cwd, 'globalConfig.json');
const options = getMongodbMemoryOptions();
const isReplSet = Boolean(options.replSet);
let mongo = new MongoMemoryServer(getMongodbMemoryOptions());
debug(`isReplSet`, isReplSet);
let mongo = isReplSet ? new MongoMemoryReplSet(options) : new MongoMemoryServer(options);
module.exports = class MongoEnvironment extends NodeEnvironment {

@@ -19,0 +23,0 @@ constructor(config, context) {

const {resolve} = require('path');
const cwd = process.cwd();
const configFile = process.env.MONGO_MEMORY_SERVER_FILE || 'jest-mongodb-config.js';
module.exports.getMongodbMemoryOptions = function () {
try {
const {mongodbMemoryServerOptions} = require(resolve(cwd, 'jest-mongodb-config.js'));
const {mongodbMemoryServerOptions} = require(resolve(cwd, configFile));

@@ -23,3 +24,3 @@ return mongodbMemoryServerOptions;

try {
const {mongoURLEnvName} = require(resolve(cwd, 'jest-mongodb-config.js'));
const {mongoURLEnvName} = require(resolve(cwd, configFile));

@@ -34,3 +35,3 @@ return mongoURLEnvName || 'MONGO_URL';

try {
const {useSharedDBForAllJestWorkers} = require(resolve(cwd, 'jest-mongodb-config.js'));
const {useSharedDBForAllJestWorkers} = require(resolve(cwd, configFile));

@@ -37,0 +38,0 @@ if (typeof useSharedDBForAllJestWorkers === 'undefined') {

@@ -8,3 +8,2 @@ const {MongoClient} = require('mongodb');

beforeAll(async () => {

@@ -11,0 +10,0 @@ connection = await MongoClient.connect(uri, {

{
"name": "@shelf/jest-mongodb",
"version": "2.1.1",
"version": "2.2.0",
"private": false,

@@ -22,3 +22,4 @@ "description": "Run your tests using Jest & MongoDB in Memory server",

"lint": "eslint . --fix --ext .js,.json,.ts --quiet",
"test": "jest"
"test": "jest",
"test:repl": "MONGO_MEMORY_SERVER_FILE=jest-mongodb-config-repl.js jest"
},

@@ -55,5 +56,5 @@ "husky": {

"husky": "4.3.8",
"jest": "27.4.3",
"lint-staged": "12.1.2",
"mongodb": "4.1.0",
"jest": "27.4.5",
"lint-staged": "12.1.4",
"mongodb": "4.2.2",
"prettier": "2.5.1"

@@ -60,0 +61,0 @@ },

@@ -106,2 +106,21 @@ # jest-mongodb [![CircleCI](https://circleci.com/gh/shelfio/jest-mongodb/tree/master.svg?style=svg)](https://circleci.com/gh/shelfio/jest-mongodb/tree/master) ![](https://img.shields.io/badge/code_style-prettier-ff69b4.svg) [![npm (scoped)](https://img.shields.io/npm/v/@shelf/jest-mongodb.svg)](https://www.npmjs.com/package/@shelf/jest-mongodb)

To use mongo as a replica set you must add the `replSet` config object and set
`count` and `storageEngine` fields:
```js
module.exports = {
mongodbMemoryServerOptions: {
binary: {
skipMD5: true,
},
autoStart: false,
instance: {},
replSet: {
count: 3,
storageEngine: 'wiredTiger',
},
},
};
```
### 3. Configure MongoDB client

@@ -108,0 +127,0 @@

const fs = require('fs');
const {join} = require('path');
const {MongoMemoryServer} = require('mongodb-memory-server');
const {MongoMemoryServer, MongoMemoryReplSet} = require('mongodb-memory-server');
const {

@@ -11,4 +11,11 @@ getMongodbMemoryOptions,

const debug = require('debug')('jest-mongodb:setup');
const mongod = new MongoMemoryServer(getMongodbMemoryOptions());
const mongoMemoryServerOptions = getMongodbMemoryOptions();
const isReplSet = Boolean(mongoMemoryServerOptions.replSet);
debug(`isReplSet ${isReplSet}`);
const mongo = isReplSet
? new MongoMemoryReplSet(mongoMemoryServerOptions)
: new MongoMemoryServer(mongoMemoryServerOptions);
const cwd = process.cwd();

@@ -25,4 +32,4 @@ const globalConfigPath = join(cwd, 'globalConfig.json');

if (shouldUseSharedDBForAllJestWorkers()) {
if (!mongod.isRunning) {
await mongod.start();
if (!mongo.isRunning) {
await mongo.start();
}

@@ -32,3 +39,3 @@

mongoConfig.mongoUri = await mongod.getUri();
mongoConfig.mongoUri = await mongo.getUri();

@@ -38,3 +45,3 @@ process.env[mongoURLEnvName] = mongoConfig.mongoUri;

// Set reference to mongod in order to close the server during teardown.
global.__MONGOD__ = mongod;
global.__MONGOD__ = mongo;
}

@@ -41,0 +48,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc