Skip to content

Commit ad252b4

Browse files
committed
chore: update dependencies
BREAKING CHANGE: migrate codebase from Flowtype to TypeScript
1 parent 74ad96a commit ad252b4

File tree

4 files changed

+577
-409
lines changed

4 files changed

+577
-409
lines changed

.markdownlint.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"line-length": false,
3+
"no-trailing-punctuation": {
4+
"punctuation": ",;"
5+
},
6+
"no-inline-html": false,
7+
"ol-prefix": false,
8+
"first-line-h1": false,
9+
"first-heading-h1": false
10+
}

README.md

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Every `MongoMemoryServer` instance creates and starts fresh MongoDB server on so
1515
Perfectly [works with Travis CI](https://github.com/nodkz/graphql-compose-mongoose/commit/7a6ac2de747d14281f9965f418065e97a57cfb37) without additional `services` and `addons` options in `.travis.yml`.
1616

1717
## Installation
18-
```
18+
19+
```bash
1920
yarn add mongodb-memory-server --dev
2021
OR
2122
npm install mongodb-memory-server --save-dev
@@ -24,6 +25,7 @@ npm install mongodb-memory-server --save-dev
2425
## Usage
2526

2627
### Simple server start:
28+
2729
```js
2830
import MongoMemoryServer from 'mongodb-memory-server';
2931

@@ -42,7 +44,9 @@ mongod.stop();
4244
```
4345

4446
### Available options
47+
4548
All options are optional.
49+
4650
```js
4751
const mongod = new MongoMemoryServer({
4852
instance: {
@@ -104,43 +108,45 @@ replSet.stop();
104108
// or it should be stopped automatically when you exit from script
105109
```
106110

107-
### Available options
111+
### Available options for Replica Set
112+
108113
All options are optional.
114+
109115
```js
110116
const replSet = new MongoMemoryReplSet({
111117
autoStart, // same as for MongoMemoryServer
112118
binary: binaryOpts, // same as for MongoMemoryServer
113119
debug, // same as for MongoMemoryServer
114120
instanceOpts: [
115121
{
116-
args, // any additional instance specific args
117-
port, // port number for the instance
122+
args, // any additional instance specific args
123+
port, // port number for the instance
118124
dbPath, // path to database files for this instance
119-
storageEngine, // same storage engine options
125+
storageEngine, // same storage engine options
120126
},
121127
// each entry will result in a MongoMemoryServer
122128
],
123129
// unless otherwise noted below these values will be in common with all instances spawned.
124130
replSet: {
125-
name, // replica set name (default: 'testset')
126-
auth, // enable auth support? (default: false)
127-
args, // any args specified here will be combined with any per instance args from `instanceOpts`
128-
count, // number of `mongod` processes to start; (default: 1)
129-
dbName, // default database for db URI strings. (default: uuid.v4())
130-
ip, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`
131-
oplogSize, // size (in MB) for the oplog; (default: 1)
132-
spawn, // spawn options when creating the child processes
133-
storageEngine, // default storage engine for instance. (Can be overridden per instance)
134-
}
131+
name, // replica set name (default: 'testset')
132+
auth, // enable auth support? (default: false)
133+
args, // any args specified here will be combined with any per instance args from `instanceOpts`
134+
count, // number of `mongod` processes to start; (default: 1)
135+
dbName, // default database for db URI strings. (default: uuid.v4())
136+
ip, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`
137+
oplogSize, // size (in MB) for the oplog; (default: 1)
138+
spawn, // spawn options when creating the child processes
139+
storageEngine, // default storage engine for instance. (Can be overridden per instance)
140+
},
135141
});
136142
```
137143
138-
139144
### Simple test with MongoClient
140145
141146
Take a look at this [test file](https://github.com/nodkz/mongodb-memory-server/blob/master/src/__tests__/singleDB-test.js).
142147
143148
### Provide connection string to mongoose
149+
144150
```js
145151
import mongoose from 'mongoose';
146152
import MongoMemoryServer from 'mongodb-memory-server';
@@ -149,7 +155,8 @@ const mongoServer = new MongoMemoryServer();
149155

150156
mongoose.Promise = Promise;
151157
mongoServer.getConnectionString().then((mongoUri) => {
152-
const mongooseOpts = { // options for mongoose 4.11.3 and above
158+
const mongooseOpts = {
159+
// options for mongoose 4.11.3 and above
153160
autoReconnect: true,
154161
reconnectTries: Number.MAX_VALUE,
155162
reconnectInterval: 1000,
@@ -171,10 +178,11 @@ mongoServer.getConnectionString().then((mongoUri) => {
171178
});
172179
});
173180
```
174-
For additional information I recommend you to read this article [Testing a GraphQL Server using Jest with Mongoose](https://medium.com/entria/testing-a-graphql-server-using-jest-4e00d0e4980e)
175181
182+
For additional information I recommend you to read this article [Testing a GraphQL Server using Jest with Mongoose](https://medium.com/entria/testing-a-graphql-server-using-jest-4e00d0e4980e)
176183
177184
### Several mongoose connections simultaneously
185+
178186
```js
179187
import mongoose from 'mongoose';
180188
import MongoMemoryServer from 'mongodb-memory-server';
@@ -245,6 +253,7 @@ export default {
245253
```
246254
247255
Note: When you create mongoose connection manually, you should do:
256+
248257
```js
249258
import mongoose from 'mongoose';
250259

@@ -253,7 +262,9 @@ const conn = mongoose.createConnection(); // just create connection instance
253262
const User = conn.model('User', new mongoose.Schema({ name: String })); // define model
254263
conn.open(uri, opts); // open connection to database (NOT `connect` method!)
255264
```
265+
256266
With default connection:
267+
257268
```js
258269
import mongoose from 'mongoose';
259270

@@ -262,8 +273,6 @@ mongoose.connect(uri, opts);
262273
const User = mongoose.model('User', new mongoose.Schema({ name: String })); // define model
263274
```
264275
265-
266-
267276
### Simple Mocha/Chai test example
268277
269278
Start Mocha with `--timeout 60000` cause first download of MongoDB binaries may take a time.
@@ -277,11 +286,14 @@ const opts = { useMongoClient: true }; // remove this option if you use mongoose
277286

278287
before((done) => {
279288
mongoServer = new MongoMemoryServer();
280-
mongoServer.getConnectionString().then((mongoUri) => {
281-
return mongoose.connect(mongoUri, opts, (err) => {
282-
if (err) done(err);
283-
});
284-
}).then(() => done());
289+
mongoServer
290+
.getConnectionString()
291+
.then((mongoUri) => {
292+
return mongoose.connect(mongoUri, opts, (err) => {
293+
if (err) done(err);
294+
});
295+
})
296+
.then(() => done());
285297
});
286298

287299
after(() => {
@@ -290,7 +302,7 @@ after(() => {
290302
});
291303

292304
describe('...', () => {
293-
it("...", async () => {
305+
it('...', async () => {
294306
const User = mongoose.model('User', new mongoose.Schema({ name: String }));
295307
const cnt = await User.count();
296308
expect(cnt).to.equal(0);
@@ -299,6 +311,7 @@ describe('...', () => {
299311
```
300312
301313
### Simple Jest test example
314+
302315
```js
303316
import mongoose from 'mongoose';
304317
import MongoMemoryServer from 'mongodb-memory-server';
@@ -317,13 +330,13 @@ beforeAll(async () => {
317330
});
318331
});
319332

320-
afterAll(() => {
333+
afterAll(async () => {
321334
mongoose.disconnect();
322-
mongoServer.stop();
335+
await mongoServer.stop();
323336
});
324337

325338
describe('...', () => {
326-
it("...", async () => {
339+
it('...', async () => {
327340
const User = mongoose.model('User', new mongoose.Schema({ name: String }));
328341
const cnt = await User.count();
329342
expect(cnt).toEqual(0);
@@ -332,14 +345,17 @@ describe('...', () => {
332345
```
333346
334347
Additional examples of Jest tests:
348+
335349
- simple example with `mongodb` in [tests in current package](https://github.com/nodkz/mongodb-memory-server/blob/master/src/__tests__/)
336350
- more complex example with `mongoose` in [graphql-compose-mongoose](https://github.com/nodkz/graphql-compose-mongoose/blob/master/src/__mocks__/mongooseCommon.js)
337351
338352
### AVA test runner
353+
339354
For AVA written [detailed tutorial](https://github.com/zellwk/ava/blob/8b7ccba1d80258b272ae7cae6ba4967cd1c13030/docs/recipes/endpoint-testing-with-mongoose.md) how to test mongoose models by @zellwk.
340355
341356
### Docker Alpine
342-
There isn't currently an official MongoDB release for alpine linux. This means that we can't pull binaries for Alpine
357+
358+
There isn't currently an official MongoDB release for alpine linux. This means that we can't pull binaries for Alpine
343359
(or any other platform that isn't officially supported by MongoDB), but you can use a Docker image that already has mongod
344360
built in and then set the MONGOMS_SYSTEM_BINARY variable to point at that binary. This should allow you to use
345361
mongodb-memory-server on any system on which you can install mongod.
@@ -348,14 +364,17 @@ mongodb-memory-server on any system on which you can install mongod.
348364
349365
**It is very important** to limit spawned number of Jest workers for avoiding race condition. Cause Jest spawn huge amount of workers for every node environment on same machine. [More details](https://github.com/facebook/jest/issues/3765)
350366
Use `--maxWorkers 4` or `--runInBand` option.
367+
351368
```diff
352369
script:
353370
- - yarn run coverage
354371
+ - yarn run coverage -- --maxWorkers 4
355372
```
356373
357374
## Credits
375+
358376
Inspired by alternative runners for [mongodb-prebuilt](https://github.com/winfinit/mongodb-prebuilt):
377+
359378
- [mockgoose](https://github.com/mockgoose/Mockgoose)
360379
- [mongomem](https://github.com/CImrie/mongomem)
361380
@@ -366,4 +385,4 @@ MIT
366385
## Maintainers
367386
368387
- [@nodkz](https://github.com/nodkz) Pavel Chertorogov
369-
- [@AJRdev](https://github.com/AJRdev) Andre Ranarivelo
388+
- [@AJRdev](https://github.com/AJRdev) Andre Ranarivelo

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@
2929
"@types/find-cache-dir": "^2.0.0",
3030
"@types/get-port": "^4.0.1",
3131
"@types/getos": "^3.0.0",
32-
"@types/jest": "^24.0.9",
32+
"@types/jest": "^24.0.11",
3333
"@types/lockfile": "^1.0.1",
3434
"@types/md5-file": "^4.0.0",
3535
"@types/mkdirp": "^0.5.2",
36-
"@types/mongodb": "^3.1.20",
37-
"@types/node": "^11.10.4",
36+
"@types/mongodb": "^3.1.22",
37+
"@types/node": "^11.11.0",
3838
"@types/tmp": "0.0.34",
3939
"@types/uuid": "^3.4.4",
4040
"@typescript-eslint/eslint-plugin": "^1.4.2",
4141
"cross-env": "^5.2.0",
4242
"cz-conventional-changelog": "^2.1.0",
43-
"eslint": "^5.15.0",
43+
"eslint": "^5.15.1",
4444
"eslint-config-prettier": "^4.1.0",
4545
"eslint-plugin-prettier": "^3.0.1",
4646
"flowgen": "^1.6.0",
47-
"jest": "^24.1.0",
47+
"jest": "^24.3.1",
4848
"mongodb": "^3.1.13",
4949
"npm-run-all": "^4.1.5",
5050
"prettier": "^1.16.4",

0 commit comments

Comments
 (0)