Skip to content

Commit

Permalink
feat: add MongoMemoryReplSet class (#81) thanks @jloveridge
Browse files Browse the repository at this point in the history
* chore(flow-types): Update flow-typed definitions.

Newly provided definitions:
  * get-port
  * getos

New definition via `flow-typed install`:
  * rimraf

* chore(types): Make flow and TypeScript types a bit more specific.

* chore(editorconfig): add .editorconfig so compatible editors will honor code style by default.

* chore(vscode, flow): Prevent VSCode from complaining about flow types in `js` files.

* chore(replset): Implement MongoMemoryReplSet

* docs(replset): Add documentation on replica set usage.
  • Loading branch information
jloveridge authored and nodkz committed Sep 30, 2018
1 parent 21a0769 commit 5911cdc
Show file tree
Hide file tree
Showing 45 changed files with 2,894 additions and 922 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_size = 2
indent_style = space
tab_width = 2
trim_trailing_whitespace = true

# Set default charset
[*.{js,ts}]
charset = utf-8
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"javascript.validate.enable": false
}
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ All options are optional.
const mongod = new MongodbMemoryServer({
instance: {
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
dbPath?: string, // by default create in temp directory
storageEngine?: string, // by default `ephemeralForTest`, available engines: [ 'devnull', 'ephemeralForTest', 'mmapv1', 'wiredTiger' ]
Expand Down Expand Up @@ -76,6 +76,57 @@ MONGOMS_ARCH=x64
MONGOMS_VERSION=3
MONGOMS_DEBUG=1 # also available case-insensitive values: "on" "yes" "true"
```
### 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
Take a look at this [test file](https://github.com/nodkz/mongodb-memory-server/blob/master/src/__tests__/singleDB-test.js).
Expand Down
97 changes: 70 additions & 27 deletions flow-typed/npm/babel-eslint_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// flow-typed signature: aec7ecc0f2e19d71dc843408c2c4461d
// flow-typed version: <<STUB>>/babel-eslint_v^7.1.1/flow_v0.47.0
// flow-typed signature: 5454b4b2383aacfc357f78dd3176ffff
// flow-typed version: <<STUB>>/babel-eslint_v^9.0.0/flow_v0.80.0

/**
* This is an autogenerated libdef stub for:
Expand All @@ -22,59 +22,102 @@ declare module 'babel-eslint' {
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'babel-eslint/babylon-to-espree/attachComments' {
declare module 'babel-eslint/lib/analyze-scope' {
declare module.exports: any;
}

declare module 'babel-eslint/babylon-to-espree/convertComments' {
declare module 'babel-eslint/lib/babylon-to-espree/attachComments' {
declare module.exports: any;
}

declare module 'babel-eslint/babylon-to-espree/convertTemplateType' {
declare module 'babel-eslint/lib/babylon-to-espree/convertComments' {
declare module.exports: any;
}

declare module 'babel-eslint/babylon-to-espree/index' {
declare module 'babel-eslint/lib/babylon-to-espree/convertTemplateType' {
declare module.exports: any;
}

declare module 'babel-eslint/babylon-to-espree/toAST' {
declare module 'babel-eslint/lib/babylon-to-espree/index' {
declare module.exports: any;
}

declare module 'babel-eslint/babylon-to-espree/toToken' {
declare module 'babel-eslint/lib/babylon-to-espree/toAST' {
declare module.exports: any;
}

declare module 'babel-eslint/babylon-to-espree/toTokens' {
declare module 'babel-eslint/lib/babylon-to-espree/toToken' {
declare module.exports: any;
}

declare module 'babel-eslint/lib/babylon-to-espree/toTokens' {
declare module.exports: any;
}

declare module 'babel-eslint/lib/index' {
declare module.exports: any;
}

declare module 'babel-eslint/lib/parse-with-patch' {
declare module.exports: any;
}

declare module 'babel-eslint/lib/parse-with-scope' {
declare module.exports: any;
}

declare module 'babel-eslint/lib/parse' {
declare module.exports: any;
}

declare module 'babel-eslint/lib/patch-eslint-scope' {
declare module.exports: any;
}

declare module 'babel-eslint/lib/visitor-keys' {
declare module.exports: any;
}

// Filename aliases
declare module 'babel-eslint/babylon-to-espree/attachComments.js' {
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/attachComments'>;
declare module 'babel-eslint/lib/analyze-scope.js' {
declare module.exports: $Exports<'babel-eslint/lib/analyze-scope'>;
}
declare module 'babel-eslint/lib/babylon-to-espree/attachComments.js' {
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/attachComments'>;
}
declare module 'babel-eslint/lib/babylon-to-espree/convertComments.js' {
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/convertComments'>;
}
declare module 'babel-eslint/lib/babylon-to-espree/convertTemplateType.js' {
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/convertTemplateType'>;
}
declare module 'babel-eslint/lib/babylon-to-espree/index.js' {
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/index'>;
}
declare module 'babel-eslint/lib/babylon-to-espree/toAST.js' {
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/toAST'>;
}
declare module 'babel-eslint/babylon-to-espree/convertComments.js' {
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/convertComments'>;
declare module 'babel-eslint/lib/babylon-to-espree/toToken.js' {
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/toToken'>;
}
declare module 'babel-eslint/babylon-to-espree/convertTemplateType.js' {
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/convertTemplateType'>;
declare module 'babel-eslint/lib/babylon-to-espree/toTokens.js' {
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/toTokens'>;
}
declare module 'babel-eslint/babylon-to-espree/index.js' {
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/index'>;
declare module 'babel-eslint/lib/index.js' {
declare module.exports: $Exports<'babel-eslint/lib/index'>;
}
declare module 'babel-eslint/babylon-to-espree/toAST.js' {
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/toAST'>;
declare module 'babel-eslint/lib/parse-with-patch.js' {
declare module.exports: $Exports<'babel-eslint/lib/parse-with-patch'>;
}
declare module 'babel-eslint/babylon-to-espree/toToken.js' {
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/toToken'>;
declare module 'babel-eslint/lib/parse-with-scope.js' {
declare module.exports: $Exports<'babel-eslint/lib/parse-with-scope'>;
}
declare module 'babel-eslint/babylon-to-espree/toTokens.js' {
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/toTokens'>;
declare module 'babel-eslint/lib/parse.js' {
declare module.exports: $Exports<'babel-eslint/lib/parse'>;
}
declare module 'babel-eslint/index' {
declare module.exports: $Exports<'babel-eslint'>;
declare module 'babel-eslint/lib/patch-eslint-scope.js' {
declare module.exports: $Exports<'babel-eslint/lib/patch-eslint-scope'>;
}
declare module 'babel-eslint/index.js' {
declare module.exports: $Exports<'babel-eslint'>;
declare module 'babel-eslint/lib/visitor-keys.js' {
declare module.exports: $Exports<'babel-eslint/lib/visitor-keys'>;
}
4 changes: 2 additions & 2 deletions flow-typed/npm/babel-jest_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// flow-typed signature: c5f56507f22abc799fee64c0abfe30c0
// flow-typed version: <<STUB>>/babel-jest_v^20.0.3/flow_v0.47.0
// flow-typed signature: 100f17029f54328f1dfa94490bf59822
// flow-typed version: <<STUB>>/babel-jest_v^23.6.0/flow_v0.80.0

/**
* This is an autogenerated libdef stub for:
Expand Down
4 changes: 2 additions & 2 deletions flow-typed/npm/cz-conventional-changelog_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// flow-typed signature: 98fa4f62b7a9ad35a7a43f0fc38c54f6
// flow-typed version: <<STUB>>/cz-conventional-changelog_v^2.0.0/flow_v0.47.0
// flow-typed signature: ec6c2145acd80dfdb66741b56c8dd4a7
// flow-typed version: <<STUB>>/cz-conventional-changelog_v^2.1.0/flow_v0.80.0

/**
* This is an autogenerated libdef stub for:
Expand Down
41 changes: 41 additions & 0 deletions flow-typed/npm/decompress_v4.2.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Flowtype definitions for decompress v4.2
*/

declare module "decompress" {
declare interface File {
data: Buffer;
mode: number;
mtime: string;
path: string;
type: string;
}

declare interface DecompressOptions {
/**
* Filter out files before extracting
*/
filter(file: File): boolean;

/**
* Map files before extracting
*/
map(file: File): File;

/**
* Array of plugins to use.
* Default: [decompressTar(), decompressTarbz2(), decompressTargz(), decompressUnzip()]
*/
plugins?: any[];

/**
* Remove leading directory components from extracted files.
* Default: 0
*/
strip?: number;
}

declare var decompress: (input: string | Buffer, output: string, opts?: DecompressOptions) => Promise<File>;

declare module.exports: typeof decompress;
}
18 changes: 16 additions & 2 deletions flow-typed/npm/eslint-config-airbnb-base_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// flow-typed signature: 7dd13c80f73219071633f222958e8ef8
// flow-typed version: <<STUB>>/eslint-config-airbnb-base_v^11.2.0/flow_v0.47.0
// flow-typed signature: c8ee7810dd58c563a615855bdb1b9de5
// flow-typed version: <<STUB>>/eslint-config-airbnb-base_v^13.1.0/flow_v0.80.0

/**
* This is an autogenerated libdef stub for:
Expand Down Expand Up @@ -58,10 +58,18 @@ declare module 'eslint-config-airbnb-base/rules/variables' {
declare module.exports: any;
}

declare module 'eslint-config-airbnb-base/test/requires' {
declare module.exports: any;
}

declare module 'eslint-config-airbnb-base/test/test-base' {
declare module.exports: any;
}

declare module 'eslint-config-airbnb-base/whitespace' {
declare module.exports: any;
}

// Filename aliases
declare module 'eslint-config-airbnb-base/index' {
declare module.exports: $Exports<'eslint-config-airbnb-base'>;
Expand Down Expand Up @@ -96,6 +104,12 @@ declare module 'eslint-config-airbnb-base/rules/style.js' {
declare module 'eslint-config-airbnb-base/rules/variables.js' {
declare module.exports: $Exports<'eslint-config-airbnb-base/rules/variables'>;
}
declare module 'eslint-config-airbnb-base/test/requires.js' {
declare module.exports: $Exports<'eslint-config-airbnb-base/test/requires'>;
}
declare module 'eslint-config-airbnb-base/test/test-base.js' {
declare module.exports: $Exports<'eslint-config-airbnb-base/test/test-base'>;
}
declare module 'eslint-config-airbnb-base/whitespace.js' {
declare module.exports: $Exports<'eslint-config-airbnb-base/whitespace'>;
}
18 changes: 16 additions & 2 deletions flow-typed/npm/eslint-config-prettier_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// flow-typed signature: 476ffef6e88e9a1dc433e0859eaad231
// flow-typed version: <<STUB>>/eslint-config-prettier_v^2.1.1/flow_v0.47.0
// flow-typed signature: 4a8a03bde41dfa420f385bac3f87e785
// flow-typed version: <<STUB>>/eslint-config-prettier_v^3.0.1/flow_v0.80.0

/**
* This is an autogenerated libdef stub for:
Expand Down Expand Up @@ -38,6 +38,14 @@ declare module 'eslint-config-prettier/react' {
declare module.exports: any;
}

declare module 'eslint-config-prettier/standard' {
declare module.exports: any;
}

declare module 'eslint-config-prettier/unicorn' {
declare module.exports: any;
}

// Filename aliases
declare module 'eslint-config-prettier/bin/cli.js' {
declare module.exports: $Exports<'eslint-config-prettier/bin/cli'>;
Expand All @@ -57,3 +65,9 @@ declare module 'eslint-config-prettier/index.js' {
declare module 'eslint-config-prettier/react.js' {
declare module.exports: $Exports<'eslint-config-prettier/react'>;
}
declare module 'eslint-config-prettier/standard.js' {
declare module.exports: $Exports<'eslint-config-prettier/standard'>;
}
declare module 'eslint-config-prettier/unicorn.js' {
declare module.exports: $Exports<'eslint-config-prettier/unicorn'>;
}

0 comments on commit 5911cdc

Please sign in to comment.