Skip to content

Commit 5911cdc

Browse files
jloveridgenodkz
authored andcommitted
feat: add MongoMemoryReplSet class (#81) thanks @jloveridge
* 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.
1 parent 21a0769 commit 5911cdc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2894
-922
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# top-most EditorConfig file
2+
root = true
3+
4+
# Unix-style newlines with a newline ending every file
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
indent_size = 2
9+
indent_style = space
10+
tab_width = 2
11+
trim_trailing_whitespace = true
12+
13+
# Set default charset
14+
[*.{js,ts}]
15+
charset = utf-8

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"javascript.validate.enable": false
3+
}

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ All options are optional.
4848
const mongod = new MongodbMemoryServer({
4949
instance: {
5050
port?: ?number, // by default choose any free port
51-
ip?: string, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`,
51+
ip?: string, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`,
5252
dbName?: string, // by default generate random dbName
5353
dbPath?: string, // by default create in temp directory
5454
storageEngine?: string, // by default `ephemeralForTest`, available engines: [ 'devnull', 'ephemeralForTest', 'mmapv1', 'wiredTiger' ]
@@ -76,6 +76,57 @@ MONGOMS_ARCH=x64
7676
MONGOMS_VERSION=3
7777
MONGOMS_DEBUG=1 # also available case-insensitive values: "on" "yes" "true"
7878
```
79+
80+
### Replica Set start:
81+
```js
82+
import { MongoMemoryReplSet } from 'mongodb-memory-server';
83+
84+
const replSet = new MongoMemoryReplSet();
85+
await replSet.waitUntilRunning();
86+
const uri = await mongod.getConnectionString();
87+
const port = await mongod.getPort();
88+
const dbPath = await mongod.getDbPath();
89+
const dbName = await mongod.getDbName();
90+
91+
// some code
92+
93+
// stop replica set manually
94+
replSet.stop();
95+
// or it should be stopped automatically when you exit from script
96+
```
97+
98+
### Available options
99+
All options are optional.
100+
```js
101+
const replSet = new MongoMemoryReplSet({
102+
autoStart, // same as for MongoMemoryServer
103+
binary: binaryOpts, // same as for MongoMemoryServer
104+
debug, // same as for MongoMemoryServer
105+
instanceOpts: [
106+
{
107+
args, // any additional instance specific args
108+
port, // port number for the instance
109+
dbPath, // path to database files for this instance
110+
storageEngine, // same storage engine options
111+
},
112+
// each entry will result in a MongoMemoryServer
113+
],
114+
// unless otherwise noted below these values will be in common with all instances spawned.
115+
replSet: {
116+
name, // replica set name (default: 'testset')
117+
auth, // enable auth support? (default: false)
118+
args, // any args specified here will be combined with any per instance args from `instanceOpts`
119+
count, // number of `mongod` processes to start; (default: 1)
120+
dbName, // default database for db URI strings. (default: uuid.v4())
121+
ip, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`
122+
oplogSize, // size (in MB) for the oplog; (default: 1)
123+
spawn, // spawn options when creating the child processes
124+
storageEngine, // default storage engine for instance. (Can be overridden per instance)
125+
}
126+
});
127+
```
128+
129+
79130
### Simple test with MongoClient
80131
81132
Take a look at this [test file](https://github.com/nodkz/mongodb-memory-server/blob/master/src/__tests__/singleDB-test.js).
Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// flow-typed signature: aec7ecc0f2e19d71dc843408c2c4461d
2-
// flow-typed version: <<STUB>>/babel-eslint_v^7.1.1/flow_v0.47.0
1+
// flow-typed signature: 5454b4b2383aacfc357f78dd3176ffff
2+
// flow-typed version: <<STUB>>/babel-eslint_v^9.0.0/flow_v0.80.0
33

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

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

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

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

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

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

49-
declare module 'babel-eslint/babylon-to-espree/toTokens' {
49+
declare module 'babel-eslint/lib/babylon-to-espree/toToken' {
50+
declare module.exports: any;
51+
}
52+
53+
declare module 'babel-eslint/lib/babylon-to-espree/toTokens' {
54+
declare module.exports: any;
55+
}
56+
57+
declare module 'babel-eslint/lib/index' {
58+
declare module.exports: any;
59+
}
60+
61+
declare module 'babel-eslint/lib/parse-with-patch' {
62+
declare module.exports: any;
63+
}
64+
65+
declare module 'babel-eslint/lib/parse-with-scope' {
66+
declare module.exports: any;
67+
}
68+
69+
declare module 'babel-eslint/lib/parse' {
70+
declare module.exports: any;
71+
}
72+
73+
declare module 'babel-eslint/lib/patch-eslint-scope' {
74+
declare module.exports: any;
75+
}
76+
77+
declare module 'babel-eslint/lib/visitor-keys' {
5078
declare module.exports: any;
5179
}
5280

5381
// Filename aliases
54-
declare module 'babel-eslint/babylon-to-espree/attachComments.js' {
55-
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/attachComments'>;
82+
declare module 'babel-eslint/lib/analyze-scope.js' {
83+
declare module.exports: $Exports<'babel-eslint/lib/analyze-scope'>;
84+
}
85+
declare module 'babel-eslint/lib/babylon-to-espree/attachComments.js' {
86+
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/attachComments'>;
87+
}
88+
declare module 'babel-eslint/lib/babylon-to-espree/convertComments.js' {
89+
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/convertComments'>;
90+
}
91+
declare module 'babel-eslint/lib/babylon-to-espree/convertTemplateType.js' {
92+
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/convertTemplateType'>;
93+
}
94+
declare module 'babel-eslint/lib/babylon-to-espree/index.js' {
95+
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/index'>;
96+
}
97+
declare module 'babel-eslint/lib/babylon-to-espree/toAST.js' {
98+
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/toAST'>;
5699
}
57-
declare module 'babel-eslint/babylon-to-espree/convertComments.js' {
58-
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/convertComments'>;
100+
declare module 'babel-eslint/lib/babylon-to-espree/toToken.js' {
101+
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/toToken'>;
59102
}
60-
declare module 'babel-eslint/babylon-to-espree/convertTemplateType.js' {
61-
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/convertTemplateType'>;
103+
declare module 'babel-eslint/lib/babylon-to-espree/toTokens.js' {
104+
declare module.exports: $Exports<'babel-eslint/lib/babylon-to-espree/toTokens'>;
62105
}
63-
declare module 'babel-eslint/babylon-to-espree/index.js' {
64-
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/index'>;
106+
declare module 'babel-eslint/lib/index.js' {
107+
declare module.exports: $Exports<'babel-eslint/lib/index'>;
65108
}
66-
declare module 'babel-eslint/babylon-to-espree/toAST.js' {
67-
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/toAST'>;
109+
declare module 'babel-eslint/lib/parse-with-patch.js' {
110+
declare module.exports: $Exports<'babel-eslint/lib/parse-with-patch'>;
68111
}
69-
declare module 'babel-eslint/babylon-to-espree/toToken.js' {
70-
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/toToken'>;
112+
declare module 'babel-eslint/lib/parse-with-scope.js' {
113+
declare module.exports: $Exports<'babel-eslint/lib/parse-with-scope'>;
71114
}
72-
declare module 'babel-eslint/babylon-to-espree/toTokens.js' {
73-
declare module.exports: $Exports<'babel-eslint/babylon-to-espree/toTokens'>;
115+
declare module 'babel-eslint/lib/parse.js' {
116+
declare module.exports: $Exports<'babel-eslint/lib/parse'>;
74117
}
75-
declare module 'babel-eslint/index' {
76-
declare module.exports: $Exports<'babel-eslint'>;
118+
declare module 'babel-eslint/lib/patch-eslint-scope.js' {
119+
declare module.exports: $Exports<'babel-eslint/lib/patch-eslint-scope'>;
77120
}
78-
declare module 'babel-eslint/index.js' {
79-
declare module.exports: $Exports<'babel-eslint'>;
121+
declare module 'babel-eslint/lib/visitor-keys.js' {
122+
declare module.exports: $Exports<'babel-eslint/lib/visitor-keys'>;
80123
}

flow-typed/npm/babel-jest_vx.x.x.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// flow-typed signature: c5f56507f22abc799fee64c0abfe30c0
2-
// flow-typed version: <<STUB>>/babel-jest_v^20.0.3/flow_v0.47.0
1+
// flow-typed signature: 100f17029f54328f1dfa94490bf59822
2+
// flow-typed version: <<STUB>>/babel-jest_v^23.6.0/flow_v0.80.0
33

44
/**
55
* This is an autogenerated libdef stub for:

flow-typed/npm/cz-conventional-changelog_vx.x.x.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// flow-typed signature: 98fa4f62b7a9ad35a7a43f0fc38c54f6
2-
// flow-typed version: <<STUB>>/cz-conventional-changelog_v^2.0.0/flow_v0.47.0
1+
// flow-typed signature: ec6c2145acd80dfdb66741b56c8dd4a7
2+
// flow-typed version: <<STUB>>/cz-conventional-changelog_v^2.1.0/flow_v0.80.0
33

44
/**
55
* This is an autogenerated libdef stub for:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Flowtype definitions for decompress v4.2
3+
*/
4+
5+
declare module "decompress" {
6+
declare interface File {
7+
data: Buffer;
8+
mode: number;
9+
mtime: string;
10+
path: string;
11+
type: string;
12+
}
13+
14+
declare interface DecompressOptions {
15+
/**
16+
* Filter out files before extracting
17+
*/
18+
filter(file: File): boolean;
19+
20+
/**
21+
* Map files before extracting
22+
*/
23+
map(file: File): File;
24+
25+
/**
26+
* Array of plugins to use.
27+
* Default: [decompressTar(), decompressTarbz2(), decompressTargz(), decompressUnzip()]
28+
*/
29+
plugins?: any[];
30+
31+
/**
32+
* Remove leading directory components from extracted files.
33+
* Default: 0
34+
*/
35+
strip?: number;
36+
}
37+
38+
declare var decompress: (input: string | Buffer, output: string, opts?: DecompressOptions) => Promise<File>;
39+
40+
declare module.exports: typeof decompress;
41+
}

flow-typed/npm/eslint-config-airbnb-base_vx.x.x.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// flow-typed signature: 7dd13c80f73219071633f222958e8ef8
2-
// flow-typed version: <<STUB>>/eslint-config-airbnb-base_v^11.2.0/flow_v0.47.0
1+
// flow-typed signature: c8ee7810dd58c563a615855bdb1b9de5
2+
// flow-typed version: <<STUB>>/eslint-config-airbnb-base_v^13.1.0/flow_v0.80.0
33

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

61+
declare module 'eslint-config-airbnb-base/test/requires' {
62+
declare module.exports: any;
63+
}
64+
6165
declare module 'eslint-config-airbnb-base/test/test-base' {
6266
declare module.exports: any;
6367
}
6468

69+
declare module 'eslint-config-airbnb-base/whitespace' {
70+
declare module.exports: any;
71+
}
72+
6573
// Filename aliases
6674
declare module 'eslint-config-airbnb-base/index' {
6775
declare module.exports: $Exports<'eslint-config-airbnb-base'>;
@@ -96,6 +104,12 @@ declare module 'eslint-config-airbnb-base/rules/style.js' {
96104
declare module 'eslint-config-airbnb-base/rules/variables.js' {
97105
declare module.exports: $Exports<'eslint-config-airbnb-base/rules/variables'>;
98106
}
107+
declare module 'eslint-config-airbnb-base/test/requires.js' {
108+
declare module.exports: $Exports<'eslint-config-airbnb-base/test/requires'>;
109+
}
99110
declare module 'eslint-config-airbnb-base/test/test-base.js' {
100111
declare module.exports: $Exports<'eslint-config-airbnb-base/test/test-base'>;
101112
}
113+
declare module 'eslint-config-airbnb-base/whitespace.js' {
114+
declare module.exports: $Exports<'eslint-config-airbnb-base/whitespace'>;
115+
}

flow-typed/npm/eslint-config-prettier_vx.x.x.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// flow-typed signature: 476ffef6e88e9a1dc433e0859eaad231
2-
// flow-typed version: <<STUB>>/eslint-config-prettier_v^2.1.1/flow_v0.47.0
1+
// flow-typed signature: 4a8a03bde41dfa420f385bac3f87e785
2+
// flow-typed version: <<STUB>>/eslint-config-prettier_v^3.0.1/flow_v0.80.0
33

44
/**
55
* This is an autogenerated libdef stub for:
@@ -38,6 +38,14 @@ declare module 'eslint-config-prettier/react' {
3838
declare module.exports: any;
3939
}
4040

41+
declare module 'eslint-config-prettier/standard' {
42+
declare module.exports: any;
43+
}
44+
45+
declare module 'eslint-config-prettier/unicorn' {
46+
declare module.exports: any;
47+
}
48+
4149
// Filename aliases
4250
declare module 'eslint-config-prettier/bin/cli.js' {
4351
declare module.exports: $Exports<'eslint-config-prettier/bin/cli'>;
@@ -57,3 +65,9 @@ declare module 'eslint-config-prettier/index.js' {
5765
declare module 'eslint-config-prettier/react.js' {
5866
declare module.exports: $Exports<'eslint-config-prettier/react'>;
5967
}
68+
declare module 'eslint-config-prettier/standard.js' {
69+
declare module.exports: $Exports<'eslint-config-prettier/standard'>;
70+
}
71+
declare module 'eslint-config-prettier/unicorn.js' {
72+
declare module.exports: $Exports<'eslint-config-prettier/unicorn'>;
73+
}

0 commit comments

Comments
 (0)