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

mongo-unit

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-unit - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

.mongo-unit/diagnostic.data/metrics.2017-09-23T06-57-51Z-00000

75

index.js
'use strict';
//process.env.DEBUG= '*'
const Debug = require('debug')
const portfinder = require('portfinder')
const {MongodHelper} = require('mongodb-prebuilt')
const client = require('mongodb').MongoClient
const fs = require('fs')
const ps = require('ps-node');
const ps = require('ps-node')
const debug = Debug('mongo-unit')

@@ -14,8 +14,4 @@ const dataFolder = '/.mongo-unit'

dbName:'test',
auto_shutdown: true,
args: {
storageEngine: "ephemeralForTest",
dbpath: defaultTempDir,
port: 27017
}
dbpath: defaultTempDir,
port: 27017,
}

@@ -25,19 +21,27 @@

function runMogo(opts, port){
const MongodHelper = require('mongodb-prebuilt').MongodHelper
opts.port = port
const mongodHelper = new MongodHelper(['--port', port, '--dbpath', opts.dbpath,'--storageEngine', 'ephemeralForTest']);
return mongodHelper.run()
.then(()=>{
dbUrl = 'mongodb://localhost:' + port+'/'+opts.dbName
debug(`mongo is started on ${dbUrl}`)
return dbUrl
})
}
function start(opts) {
const mongo_opts = Object.assign(defaultMongoOpts, (opts || {}))
Debug.enable('mongo-unit')
if(mongo_opts.verbose){
Debug.enable('*')
}
if (dbUrl) {
return Promise.resolve(dbUrl)
} else {
const mongo_opts = Object.assign(defaultMongoOpts, (opts || {}))
makeSureTempDirExist(mongo_opts.args.dbpath)
return makeSureOtherMongoProcessesKilled(mongo_opts.args.dbpath)
.then(()=>getFreePort(mongo_opts.args.port))
.then(port => {
mongo_opts.args.port = port
const mongodHelper = new MongodHelper(['--port', port, '--dbpath', mongo_opts.args.dbpath,'--storageEngine', 'ephemeralForTest']);
return mongodHelper.run()
.then(()=>{
dbUrl = 'mongodb://localhost:' + port+'/'+mongo_opts.dbName
return dbUrl
})
})
makeSureTempDirExist(mongo_opts.dbpath)
return makeSureOtherMongoProcessesKilled(mongo_opts.dbpath)
.then(()=>getFreePort(mongo_opts.port))
.then(port => runMogo(mongo_opts, port))
}

@@ -65,3 +69,2 @@ }

function clean(data) {

@@ -87,3 +90,3 @@ return client.connect(getUrl())

if (err) {
console.log('cannot get free port', err)
debug(`cannot get free port: ${err}`)
reject(err)

@@ -130,2 +133,22 @@ } else {

function initDb(url, data) {
return client.connect(url)
.then(db => {
const requests = Object.keys(data).map(col => {
const collection = db.collection(col)
return collection.insert(data[col])
})
return Promise.all(requests)
})
}
function dropDb(url) {
return client.connect(url)
.then(db => db.collections())
.then(collections => {
const requests = collections.map(col => col.drop())
return Promise.all(requests)
})
}
module.exports = {

@@ -136,3 +159,5 @@ start,

clean,
drop
drop,
initDb,
dropDb,
}
{
"name": "mongo-unit",
"version": "1.1.0",
"version": "1.2.0",
"description": "mongo db for unit tests",

@@ -33,2 +33,3 @@ "main": "index.js",

"dependencies": {
"debug": "^3.0.1",
"mongodb": "~2.2.31",

@@ -41,2 +42,3 @@ "mongodb-prebuilt": "~6.3.3",

"chai": "^3.5.0",
"co": "^4.6.0",
"mocha": "^3.2.0",

@@ -43,0 +45,0 @@ "mongoose": "^4.7.6"

@@ -24,5 +24,8 @@ # mongo-unit

It starts mongod on one of available port and returns Promise with URL to connect to this db
`opts` i optional params, you can specify your own command line params for mongod
`opts` is optional params, you can specify some command line params for mongod
(more about it in documentation for [mongodb-prebuilt](https://github.com/winfinit/mongodb-prebuilt))
`opts.dbName` - specify name of test db, it will be `test` by default
`opts.port` - preferable mongo db port, default: `27017`
`opts.dbName` - name of test db, default: `test`
`opts.dbpath` - db path, default: `<node_modules/mongo-unit>\.mongo-unit`
`opts.verbose` - enable debug informaton for mongodb-prebuilt, default: `false`

@@ -29,0 +32,0 @@ ### `getUrl()`

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