mongodb-memory-server
Advanced tools
Comparing version 2.3.0 to 2.4.0
@@ -12,2 +12,8 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "MongoMemoryReplSet", { | ||
enumerable: true, | ||
get: function get() { | ||
return _MongoMemoryReplSet.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "MongoInstance", { | ||
@@ -29,2 +35,4 @@ enumerable: true, | ||
var _MongoMemoryReplSet = _interopRequireDefault(require("./MongoMemoryReplSet")); | ||
var _MongoInstance = _interopRequireDefault(require("./util/MongoInstance")); | ||
@@ -31,0 +39,0 @@ |
/// <reference types='node' /> | ||
import { ChildProcess } from 'child_process'; | ||
import { ChildProcess, SpawnOptions } from 'child_process'; | ||
import MongoInstance from './util/MongoInstance'; | ||
import { MongoBinaryOpts } from './util/MongoBinary'; | ||
import { CallbackFn, DebugFn, MongoMemoryInstancePropT, StorageEngineT } from './types'; | ||
export interface MongoMemoryServerOptsT { | ||
instance: { | ||
port?: number; | ||
dbPath?: string; | ||
dbName?: string; | ||
storageEngine?: string; | ||
debug?: boolean | ((...args: any[]) => any); | ||
replSet?: string; | ||
auth?: boolean; | ||
args?: string[]; | ||
}; | ||
binary: { | ||
version?: string; | ||
downloadDir?: string; | ||
platform?: string; | ||
arch?: string; | ||
debug?: boolean | ((...args: any[]) => any); | ||
}; | ||
instance: MongoMemoryInstancePropT; | ||
binary: MongoBinaryOpts; | ||
debug?: boolean; | ||
spawn: any; | ||
spawn: SpawnOptions; | ||
autoStart?: boolean; | ||
@@ -34,3 +21,3 @@ } | ||
uri: string; | ||
storageEngine: string; | ||
storageEngine: StorageEngineT; | ||
instance: MongoInstance; | ||
@@ -40,3 +27,3 @@ childProcess: ChildProcess; | ||
name: string; | ||
removeCallback: ((...args: any[]) => any); | ||
removeCallback: CallbackFn; | ||
}; | ||
@@ -50,3 +37,3 @@ replSet?: string; | ||
opts: MongoMemoryServerOptsT; | ||
debug: ((...args: any[]) => any); | ||
debug: DebugFn; | ||
@@ -63,4 +50,2 @@ constructor(opts?: Partial<MongoMemoryServerOptsT>); | ||
getDbName(): Promise<string>; | ||
protected _startUpInstance(): Promise<MongoInstanceDataT>; | ||
} |
@@ -8,4 +8,2 @@ "use strict"; | ||
var _v = _interopRequireDefault(require("uuid/v4")); | ||
var _tmp = _interopRequireDefault(require("tmp")); | ||
@@ -17,2 +15,4 @@ | ||
var _db_util = require("./util/db_util"); | ||
var _MongoInstance = _interopRequireDefault(require("./util/MongoInstance")); | ||
@@ -30,14 +30,3 @@ | ||
function generateDbName(_x) { | ||
return _generateDbName.apply(this, arguments); | ||
} | ||
function _generateDbName() { | ||
_generateDbName = _asyncToGenerator(function* (dbName) { | ||
return dbName || (0, _v.default)(); | ||
}); | ||
return _generateDbName.apply(this, arguments); | ||
} | ||
function generateConnectionString(_x2, _x3) { | ||
function generateConnectionString(_x, _x2) { | ||
return _generateConnectionString.apply(this, arguments); | ||
@@ -120,3 +109,3 @@ } | ||
_this2.debug.enabled = !!_this2.opts.debug; | ||
data.dbName = yield generateDbName(instOpts.dbName); | ||
data.dbName = (0, _db_util.generateDbName)(instOpts.dbName); | ||
data.uri = yield generateConnectionString(data.port, data.dbName); | ||
@@ -213,3 +202,3 @@ data.storageEngine = instOpts.storageEngine || 'ephemeralForTest'; | ||
return generateConnectionString(port, (yield generateDbName())); | ||
return generateConnectionString(port, (0, _db_util.generateDbName)()); | ||
} | ||
@@ -216,0 +205,0 @@ |
@@ -0,1 +1,3 @@ | ||
import { DebugPropT } from '../types'; | ||
export interface MongoBinaryCache { | ||
@@ -10,3 +12,3 @@ [version: string]: string; | ||
arch?: string; | ||
debug?: boolean | ((...args: any[]) => any); | ||
debug?: DebugPropT; | ||
} | ||
@@ -13,0 +15,0 @@ |
@@ -0,1 +1,3 @@ | ||
import { DebugPropT, DebugFn, DownloadProgressT } from '../types'; | ||
export interface MongoBinaryDownloadOpts { | ||
@@ -6,15 +8,8 @@ version: string; | ||
arch: string; | ||
debug?: boolean | Function; | ||
debug?: DebugPropT; | ||
} | ||
interface dlProgress { // tslint:disable-line | ||
current: number; | ||
length: number; | ||
totalMb: number; | ||
lastPrintedAt: number; | ||
} | ||
export default class MongoBinaryDownload { | ||
debug: Function; | ||
dlProgress: dlProgress; | ||
debug: DebugFn; | ||
dlProgress: DownloadProgressT; | ||
@@ -21,0 +16,0 @@ downloadDir: string; |
@@ -163,3 +163,4 @@ "use strict"; | ||
console.log(`Downloading${proxy ? ` via proxy ${proxy}` : ''}:`, downloadUrl); | ||
_this3.debug(`Downloading${proxy ? ` via proxy ${proxy}` : ''}:`, downloadUrl); | ||
const downloadedFile = yield _this3.httpDownload(downloadOptions, downloadLocation, tempDownloadLocation); | ||
@@ -166,0 +167,0 @@ return downloadedFile; |
/// <reference types='getos' /> | ||
import {Os as OS} from 'getos'; | ||
import * as getos from 'getos'; | ||
@@ -9,6 +9,11 @@ export interface MongoBinaryDownloadUrlOpts { | ||
arch: string; | ||
os?: OS; // getos() result | ||
os?: getos.Os | null; // getos() result | ||
} | ||
export default class MongoBinaryDownloadUrl { | ||
platform: string; | ||
arch: string; | ||
version: string; | ||
os: getos.Os | null | undefined; | ||
constructor(opts: MongoBinaryDownloadUrlOpts); | ||
@@ -20,13 +25,13 @@ getDownloadUrl(): Promise<string>; | ||
getArchiveNameLinux(): Promise<string>; | ||
getos(): Promise<OS>; | ||
getLinuxOSVersionString(os: OS): string; | ||
getDebianVersionString(os: OS): string; | ||
getFedoraVersionString(os: OS): string; | ||
getRhelVersionString(os: OS): string; | ||
getElementaryOSVersionString(os: OS): string; | ||
getLegacyVersionString(os: OS): string; | ||
getSuseVersionString(os: any): string; | ||
getUbuntuVersionString(os: OS): string; | ||
getos(): Promise<getos.Os>; | ||
getLinuxOSVersionString(os: getos.Os): string; | ||
getDebianVersionString(os: getos.Os): string; | ||
getFedoraVersionString(os: getos.Os): string; | ||
getRhelVersionString(os: getos.Os): string; | ||
getElementaryOSVersionString(os: getos.Os): string; | ||
getLegacyVersionString(os: getos.Os): string; | ||
getSuseVersionString(os: getos.Os): string; | ||
getUbuntuVersionString(os: getos.Os): string; | ||
translatePlatform(platform: string): string; | ||
translateArch(arch: string, mongoPlatform: string): string; | ||
} |
/// <reference types='node' /> | ||
import { ChildProcess } from 'child_process'; | ||
import { ChildProcess, SpawnOptions } from 'child_process'; | ||
import { MongoBinaryOpts } from './MongoBinary'; | ||
import { DebugFn, DebugPropT, CallbackFn, StorageEngineT } from '../types'; | ||
@@ -10,5 +11,5 @@ export interface MongodOps { | ||
port: number; | ||
storageEngine?: string; | ||
storageEngine?: StorageEngineT; | ||
dbPath: string; | ||
debug?: boolean | ((...args: any[]) => any); | ||
debug?: DebugPropT; | ||
replSet?: string; | ||
@@ -23,14 +24,5 @@ args?: string[]; | ||
// child process spawn options | ||
spawn?: { | ||
cwd?: string; | ||
env?: object; | ||
argv0?: string; | ||
stdio?: string | any[]; | ||
detached?: boolean; | ||
uid?: number; | ||
gid?: number; | ||
shell?: boolean | string; | ||
}; | ||
spawn?: SpawnOptions; | ||
debug?: boolean | ((...args: any[]) => any); | ||
debug?: DebugPropT; | ||
} | ||
@@ -42,7 +34,7 @@ | ||
opts: MongodOps; | ||
debug: ((...args: any[]) => any); | ||
debug: DebugFn; | ||
childProcess: ChildProcess; | ||
killerProcess: ChildProcess; | ||
instanceReady: ((...args: any[]) => any); | ||
instanceFailed: ((...args: any[]) => any); | ||
instanceReady: CallbackFn; | ||
instanceFailed: CallbackFn; | ||
@@ -60,5 +52,2 @@ constructor(opts: MongodOps); | ||
stdoutHandler(message: string | Buffer): void; | ||
private _launchMongod(mongoBin: string): ChildProcess; | ||
private _launchKiller(parentPid: number, childPid: number): ChildProcess; | ||
} |
{ | ||
"name": "mongodb-memory-server", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"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.", | ||
@@ -50,3 +50,3 @@ "main": "lib/index.js", | ||
"jest": "^23.6.0", | ||
"mongodb": "3.1.4", | ||
"mongodb": "^3.1.6", | ||
"npm-run-all": "^4.1.3", | ||
@@ -72,3 +72,5 @@ "prettier": "^1.14.2", | ||
}, | ||
"peerDependencies": {}, | ||
"peerDependencies": { | ||
"mongodb": ">= 3.0" | ||
}, | ||
"scripts": { | ||
@@ -75,0 +77,0 @@ "build": "npm-run-all build:*", |
@@ -51,3 +51,3 @@ # mongodb-memory-server | ||
port?: ?number, // by default choose any free port | ||
ip?: string, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`, | ||
ip?: string, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`, | ||
dbName?: string, // by default generate random dbName | ||
@@ -80,2 +80,53 @@ dbPath?: string, // by default create in temp directory | ||
``` | ||
### Replica Set start: | ||
```js | ||
import { MongoMemoryReplSet } from 'mongodb-memory-server'; | ||
const replSet = new MongoMemoryReplSet(); | ||
await replSet.waitUntilRunning(); | ||
const uri = await mongod.getConnectionString(); | ||
const port = await mongod.getPort(); | ||
const dbPath = await mongod.getDbPath(); | ||
const dbName = await mongod.getDbName(); | ||
// some code | ||
// stop replica set manually | ||
replSet.stop(); | ||
// or it should be stopped automatically when you exit from script | ||
``` | ||
### Available options | ||
All options are optional. | ||
```js | ||
const replSet = new MongoMemoryReplSet({ | ||
autoStart, // same as for MongoMemoryServer | ||
binary: binaryOpts, // same as for MongoMemoryServer | ||
debug, // same as for MongoMemoryServer | ||
instanceOpts: [ | ||
{ | ||
args, // any additional instance specific args | ||
port, // port number for the instance | ||
dbPath, // path to database files for this instance | ||
storageEngine, // same storage engine options | ||
}, | ||
// each entry will result in a MongoMemoryServer | ||
], | ||
// unless otherwise noted below these values will be in common with all instances spawned. | ||
replSet: { | ||
name, // replica set name (default: 'testset') | ||
auth, // enable auth support? (default: false) | ||
args, // any args specified here will be combined with any per instance args from `instanceOpts` | ||
count, // number of `mongod` processes to start; (default: 1) | ||
dbName, // default database for db URI strings. (default: uuid.v4()) | ||
ip, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0` | ||
oplogSize, // size (in MB) for the oplog; (default: 1) | ||
spawn, // spawn options when creating the child processes | ||
storageEngine, // default storage engine for instance. (Can be overridden per instance) | ||
} | ||
}); | ||
``` | ||
### Simple test with MongoClient | ||
@@ -82,0 +133,0 @@ |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
135821
42
2034
357
12