Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shelf/jest-mongodb

Package Overview
Dependencies
Maintainers
58
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shelf/jest-mongodb - npm Package Compare versions

Comparing version 4.2.0 to 4.3.0

14

lib/environment.js

@@ -11,6 +11,2 @@ "use strict";

const debug = require('debug')('jest-mongodb:environment');
const options = (0, _helpers.getMongodbMemoryOptions)();
const isReplSet = Boolean(options.replSet);
debug(`isReplSet`, isReplSet);
const mongo = isReplSet ? new _mongodbMemoryServer.MongoMemoryReplSet(options) : new _mongodbMemoryServer.MongoMemoryServer(options);
module.exports = class MongoEnvironment extends _jestEnvironmentNode.TestEnvironment {

@@ -20,2 +16,6 @@ constructor(config, context) {

this.globalConfigPath = (0, _path.join)(config.globalConfig.rootDir, 'globalConfig.json');
const options = (0, _helpers.getMongodbMemoryOptions)(config.globalConfig.rootDir);
const isReplSet = Boolean(options.replSet);
debug(`isReplSet`, isReplSet);
this.mongo = isReplSet ? new _mongodbMemoryServer.MongoMemoryReplSet(options) : new _mongodbMemoryServer.MongoMemoryServer(options);
}

@@ -28,4 +28,4 @@ async setup() {

} else {
await mongo.start();
this.global.__MONGO_URI__ = mongo.getUri();
await this.mongo.start();
this.global.__MONGO_URI__ = this.mongo.getUri();
}

@@ -37,3 +37,3 @@ this.global.__MONGO_DB_NAME__ = globalConfig.mongoDBName || (0, _crypto.randomUUID)();

debug('Teardown MongoDB Test Environment');
await mongo.stop();
await this.mongo.stop();
await super.teardown();

@@ -40,0 +40,0 @@ }

@@ -1,3 +0,3 @@

export declare function getMongodbMemoryOptions(): any;
export declare function getMongoURLEnvName(): any;
export declare function shouldUseSharedDBForAllJestWorkers(): any;
export declare function getMongodbMemoryOptions(cwd: string): any;
export declare function getMongoURLEnvName(cwd: string): any;
export declare function shouldUseSharedDBForAllJestWorkers(cwd: string): any;

@@ -10,5 +10,4 @@ "use strict";

var _path = require("path");
const cwd = process.cwd();
const configFile = process.env.MONGO_MEMORY_SERVER_FILE || 'jest-mongodb-config.js';
function getMongodbMemoryOptions() {
function getMongodbMemoryOptions(cwd) {
try {

@@ -29,3 +28,3 @@ const {

}
function getMongoURLEnvName() {
function getMongoURLEnvName(cwd) {
try {

@@ -40,3 +39,3 @@ const {

}
function shouldUseSharedDBForAllJestWorkers() {
function shouldUseSharedDBForAllJestWorkers(cwd) {
try {

@@ -43,0 +42,0 @@ const {

@@ -10,20 +10,20 @@ "use strict";

const debug = require('debug')('jest-mongodb:setup');
const mongoMemoryServerOptions = (0, _helpers.getMongodbMemoryOptions)();
const isReplSet = Boolean(mongoMemoryServerOptions.replSet);
debug(`isReplSet ${isReplSet}`);
// @ts-ignore
const mongo = isReplSet ? new _mongodbMemoryServer.MongoMemoryReplSet(mongoMemoryServerOptions) : new _mongodbMemoryServer.MongoMemoryServer(mongoMemoryServerOptions);
module.exports = async config => {
const globalConfigPath = (0, _path.join)(config.rootDir, 'globalConfig.json');
const options = (0, _helpers.getMongodbMemoryOptions)();
const mongoMemoryServerOptions = (0, _helpers.getMongodbMemoryOptions)(config.rootDir);
const isReplSet = Boolean(mongoMemoryServerOptions.replSet);
debug(`isReplSet ${isReplSet}`);
// @ts-ignore
const mongo = isReplSet ? new _mongodbMemoryServer.MongoMemoryReplSet(mongoMemoryServerOptions) : new _mongodbMemoryServer.MongoMemoryServer(mongoMemoryServerOptions);
const options = (0, _helpers.getMongodbMemoryOptions)(config.rootDir);
const mongoConfig = {};
debug(`shouldUseSharedDBForAllJestWorkers: ${(0, _helpers.shouldUseSharedDBForAllJestWorkers)()}`);
debug(`shouldUseSharedDBForAllJestWorkers: ${(0, _helpers.shouldUseSharedDBForAllJestWorkers)(config.rootDir)}`);
// if we run one mongodb instance for all tests
if ((0, _helpers.shouldUseSharedDBForAllJestWorkers)()) {
if ((0, _helpers.shouldUseSharedDBForAllJestWorkers)(config.rootDir)) {
if (!mongo.isRunning) {
await mongo.start();
}
const mongoURLEnvName = (0, _helpers.getMongoURLEnvName)();
const mongoURLEnvName = (0, _helpers.getMongoURLEnvName)(config.rootDir);
mongoConfig.mongoUri = await mongo.getUri();

@@ -30,0 +30,0 @@ process.env[mongoURLEnvName] = mongoConfig.mongoUri;

{
"name": "@shelf/jest-mongodb",
"version": "4.2.0",
"private": false,
"version": "4.3.0",
"description": "Run your tests using Jest & MongoDB in Memory server",

@@ -60,4 +59,4 @@ "keywords": [

"@shelf/prettier-config": "1.0.0",
"@shelf/tsconfig": "0.0.11",
"@types/jest": "29.5.8",
"@shelf/tsconfig": "0.1.0",
"@types/jest": "29.5.11",
"@types/node": "16",

@@ -67,2 +66,3 @@ "eslint": "8.53.0",

"jest": "29.7.0",
"jest-environment-node": "29.6.4",
"lint-staged": "13.3.0",

@@ -69,0 +69,0 @@ "mongodb": "6.3.0",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc