🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

mongodb-memory-server

Package Overview
Dependencies
Maintainers
1
Versions
352
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-memory-server - npm Package Compare versions

Comparing version

to
1.3.1

48

lib/MongoMemoryServer.js

@@ -58,2 +58,6 @@ 'use strict';

var _debug = require('debug');
var _debug2 = _interopRequireDefault(_debug);
var _MongoInstance = require('./util/MongoInstance');

@@ -73,2 +77,4 @@

function MongoMemoryServer() {
var _this = this;
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

@@ -84,7 +90,11 @@

this.debug = function (msg) {
if (_this.opts.debug) {
console.log(msg);
}
};
// autoStart by default
if (!opts.hasOwnProperty('autoStart') || opts.autoStart) {
if (opts.debug) {
console.log('Autostarting MongoDB instance...');
}
this.debug('Autostarting MongoDB instance...');
this.start();

@@ -95,13 +105,6 @@ }

_createClass(MongoMemoryServer, [{
key: 'debug',
value: function debug(msg) {
if (this.opts.debug) {
console.log(msg);
}
}
}, {
key: 'start',
value: function () {
var _ref2 = _asyncToGenerator(regeneratorRuntime.mark(function _callee2() {
var _this = this;
var _this2 = this;

@@ -123,9 +126,9 @@ return regeneratorRuntime.wrap(function _callee2$(_context2) {

if (err.message === 'Mongod shutting down' || err === 'Mongod shutting down') {
_this.debug(`Mongodb does not started. Trying to start on another port one more time...`);
_this.opts.instance.port = null;
return _this._startUpInstance();
_this2.debug(`Mongodb does not started. Trying to start on another port one more time...`);
_this2.opts.instance.port = null;
return _this2._startUpInstance();
}
throw err;
}).catch(function (err) {
if (!_this.opts.debug) {
if (!_this2.opts.debug) {
throw new Error(`${err.message}\n\nUse debug option for more info: new MongoMemoryServer({ debug: true })`);

@@ -171,6 +174,9 @@ }

data.port = _context3.sent;
_context3.next = 8;
this.debug = (0, _debug2.default)(`Mongo[${data.port}]`);
this.debug.enabled = !!this.opts.debug;
_context3.next = 10;
return generateConnectionString(data.port);
case 8:
case 10:
data.uri = _context3.sent;

@@ -190,3 +196,3 @@

// After that startup MongoDB instance
_context3.next = 14;
_context3.next = 16;
return _MongoInstance2.default.run({

@@ -201,6 +207,6 @@ instance: {

spawn: this.opts.spawn,
debug: this.opts.debug
debug: this.debug
});
case 14:
case 16:
childProcess = _context3.sent;

@@ -213,3 +219,3 @@

case 18:
case 20:
case 'end':

@@ -216,0 +222,0 @@ return _context3.stop();

@@ -50,3 +50,3 @@ 'use strict';

var _opts$downloadDir, downloadDir, _opts$platform, platform, _opts$arch, arch, _opts$version, version, _opts$http, http;
var _opts$downloadDir, downloadDir, _opts$platform, platform, _opts$arch, arch, _opts$version, version, _opts$http, http, debug;

@@ -58,9 +58,25 @@ return regeneratorRuntime.wrap(function _callee$(_context) {

_opts$downloadDir = opts.downloadDir, downloadDir = _opts$downloadDir === undefined ? _path2.default.resolve(_os2.default.homedir(), '.mongodb-binaries') : _opts$downloadDir, _opts$platform = opts.platform, platform = _opts$platform === undefined ? _os2.default.platform() : _opts$platform, _opts$arch = opts.arch, arch = _opts$arch === undefined ? _os2.default.arch() : _opts$arch, _opts$version = opts.version, version = _opts$version === undefined ? '3.4.4' : _opts$version, _opts$http = opts.http, http = _opts$http === undefined ? {} : _opts$http;
debug = void 0;
if (this.cache[version]) {
_context.next = 5;
if (opts.debug) {
if (opts.debug.call && typeof opts.debug === 'function' && opts.debug.apply) {
debug = opts.debug;
} else {
debug = console.log.bind(null);
}
} else {
debug = function debug(msg) {}; // eslint-disable-line
}
if (!this.cache[version]) {
_context.next = 7;
break;
}
_context.next = 4;
debug(`MongoBinary: found cached binary path for ${version}`);
_context.next = 10;
break;
case 7:
_context.next = 9;
return new Promise(function (resolve, reject) {

@@ -72,3 +88,3 @@ (0, _mkdirp2.default)(downloadDir, function (err) {

case 4:
case 9:
this.cache[version] = new Promise(function (resolve, reject) {

@@ -80,2 +96,4 @@ _properLockfile2.default.lock(downloadDir, {

}, function (err, releaseLock) {
debug('MongoBinary: Download lock created');
if (err) {

@@ -94,11 +112,14 @@ reject(err);

if (opts.debug) {
downloader.debug = console.log.bind(null);
}
downloader.debug = debug;
downloader.downloadAndExtract().then(function (releaseDir) {
releaseLock();
resolve(_this.findBinPath(releaseDir));
releaseLock(function (e) {
debug(e ? `MongoBinary: Error when removing download lock ${e}` : `MongoBinary: Download lock removed`);
});
return _this.findBinPath(releaseDir);
}).then(function (binPath) {
resolve(binPath);
}).catch(function (e) {
return reject(e);
debug(`MongoBinary: Error with mongod binary path: ${e}`);
reject(e);
});

@@ -108,6 +129,9 @@ });

case 5:
return _context.abrupt('return', this.cache[version]);
case 10:
return _context.abrupt('return', this.cache[version].then(function (binPath) {
debug(`MongoBinary: Mongod binary path: ${binPath}`);
return binPath;
}));
case 6:
case 11:
case 'end':

@@ -114,0 +138,0 @@ return _context.stop();

@@ -47,3 +47,11 @@ 'use strict';

this.debug = this.opts.instance && this.opts.instance.debug ? console.log.bind(null) : function () {};
if (this.opts.instance && this.opts.instance.debug) {
if (this.opts.instance.debug.call && typeof this.opts.instance.debug === 'function' && this.opts.instance.debug.apply) {
this.debug = this.opts.instance.debug;
} else {
this.debug = console.log.bind(null);
}
} else {
this.debug = function () {};
}
}

@@ -80,4 +88,8 @@

launch = new Promise(function (resolve, reject) {
_this.instanceReady = resolve;
_this.instanceReady = function () {
_this.debug('MongodbInstance: is ready!');
resolve(_this.childProcess);
};
_this.instanceFailed = function (err) {
_this.debug(`MongodbInstance: is failed: ${err.toString()}`);
if (_this.killerProcess) _this.killerProcess.kill();

@@ -161,3 +173,3 @@ reject(err);

if (/waiting for connections on port/i.test(log)) {
this.instanceReady(true);
this.instanceReady();
} else if (/addr already in use/i.test(log)) {

@@ -164,0 +176,0 @@ this.instanceFailed(`Port ${this.opts.instance.port} already in use`);

{
"name": "mongodb-memory-server",
"version": "1.3.0",
"version": "1.3.1",
"description": "In-memory MongoDB Server. Designed with testing in mind, the server will allow you to connect your favourite ODM or client library to the MongoDB Server and run integration tests isolated from each other.",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet