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.5.1 to 2.0.0

.mongo-unit/diagnostic.data/metrics.2020-02-29T10-22-41Z-00000

59

index.js

@@ -5,2 +5,3 @@ 'use strict'

const MongoClient = require('mongodb').MongoClient
const { MongoMemoryServer } = require('mongodb-memory-server')
const fs = require('fs')

@@ -19,17 +20,26 @@ const ps = require('ps-node')

var mongodHelper
var dbUrl = null
var client
var dbName
let mongod = null
let dbUrl = null
let client
let dbName
function runMogo(opts, port) {
const MongodHelper = require('mongodb-prebuilt').MongodHelper
opts.port = port
mongodHelper = new MongodHelper(['--port', port, '--dbpath', opts.dbpath, '--storageEngine', 'ephemeralForTest'], {
version: opts.version,
function runMongo(opts, port) {
mongod = new MongoMemoryServer({
instance: {
port: port,
dbPath: opts.dbpath,
dbName: opts.dbName,
storageEngine: 'ephemeralForTest',
},
binary: {
version: opts.version,
},
autoStart: false,
})
return mongodHelper
.run()
return mongod
.start()
.then(() => {
dbName = opts.dbName
return mongod.getDbName()
})
.then(dbName => {
dbUrl = 'mongodb://localhost:' + port + '/' + dbName

@@ -42,3 +52,5 @@ debug(`mongo is started on ${dbUrl}`)

client = dbClient
return dbUrl
})
.catch(err => console.error(err))
}

@@ -58,3 +70,3 @@

.then(() => getFreePort(mongo_opts.port))
.then(port => runMogo(mongo_opts, port))
.then(port => runMongo(mongo_opts, port))
}

@@ -66,8 +78,12 @@ }

}
function stop() {
return client.close(true).then(() => {
mongodHelper && mongodHelper.mongoBin.childProcess.kill()
dbUrl = null
return delay(100) //this is small delay to make sure kill signal is sent
})
return client
.close(true)
.then(() => mongod.stop())
.then(() => {
// mongodHelper && mongodHelper.mongoBin.childProcess.kill()
dbUrl = null
return delay(100) //this is small delay to make sure kill signal is sent
})
}

@@ -146,3 +162,8 @@

if (process) {
console.log('KILL PID: %s, COMMAND: %s, ARGUMENTS: %s', process.pid, process.command, process.arguments)
console.log(
'KILL PID: %s, COMMAND: %s, ARGUMENTS: %s',
process.pid,
process.command,
process.arguments
)
ps.kill(process.pid)

@@ -149,0 +170,0 @@ }

{
"name": "mongo-unit",
"version": "1.5.1",
"version": "2.0.0",
"description": "mongo db for unit tests",

@@ -10,3 +10,5 @@ "main": "index.js",

"test-example": "mocha ./examples/test.it.js --delay",
"release": "git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish"
"test-format": "prettier --check '**/*.{js,json}'",
"release": "git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish",
"format": "prettier --write '**/*.{js,json}'"
},

@@ -26,3 +28,4 @@ "repository": {

"mongodb",
"mongoose"
"mongoose",
"mongodb-memory-server"
],

@@ -38,3 +41,3 @@ "author": "Mikhail Angelov",

"mongodb": "^3.3.3",
"mongodb-prebuilt": "~6.5.0",
"mongodb-memory-server": "^6.3.1",
"portfinder": "^1.0.10",

@@ -46,5 +49,6 @@ "ps-node": "^0.1.4"

"co": "^4.6.0",
"mocha": "^3.2.0",
"mongoose": "^5.7.7"
"mocha": "^7.1.0",
"mongoose": "^5.7.7",
"prettier": "^1.19.1"
}
}
# mongo-unit
This library is done to simplify creation of integration tests for node.js application with Mongo DB.
I starts local mongodb process using [mongodb-prebuilt](https://github.com/winfinit/mongodb-prebuilt) library,
I starts local mongodb process using [mongodb-memory-server](https://github.com/nodkz/mongodb-memory-server) library,
and it work in "InMemory" mode, which improve performance of your tests.

@@ -28,5 +28,5 @@

mongoUnit.start().then(url => {
console.log('fake mongo is started: ', url)
process.env.DATABASE_URL = url // this var process.env.DATABASE_URL = will keep link to fake mongo
mongoUnit.start().then(() => {
console.log('fake mongo is started: ', mongoUnit.getUrl())
process.env.DATABASE_URL = mongoUnit.getUrl() // this var process.env.DATABASE_URL = will keep link to fake mongo
run() // this line start mocha tests

@@ -129,3 +129,3 @@ })

## Requirements
It works on Node.js 8+
It works on Node.js 10+

@@ -139,8 +139,7 @@ ## Installation

It starts mongod on one of available port and returns Promise with URL to connect to this db
`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` is optional params, you can specify some command line params for mongod
`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`
`opts.verbose` - enable debug logs, default: `false`

@@ -147,0 +146,0 @@ ### `stop()`

Sorry, the diff of this file is not supported yet

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