Skip to content

Commit ef037e1

Browse files
committed
build(Travis): Add basic tests before publishing package
1 parent b142af9 commit ef037e1

File tree

6 files changed

+117
-12
lines changed

6 files changed

+117
-12
lines changed

.travis.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ notifications:
88
email: true
99
node_js:
1010
- "7"
11-
# - "6"
12-
# - "5"
13-
# - "4"
11+
- "6"
12+
- "5"
13+
- "4"
1414
script:
15-
# - yarn run coverage
15+
- yarn run coverage
1616
- yarn run build
1717
after_success:
1818
- 'curl -Lo travis_after_all.py https://git.io/travis_after_all'
1919
- python travis_after_all.py
2020
- export $(cat .to_export_back) &> /dev/null
21-
# - if [[ "$TRAVIS_JOB_NUMBER" == *.1 && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then bash <(curl -s https://codecov.io/bash); fi
21+
- if [[ "$TRAVIS_JOB_NUMBER" == *.1 && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then bash <(curl -s https://codecov.io/bash); fi
2222
- if [[ "$TRAVIS_JOB_NUMBER" == *.1 && "$TRAVIS_BRANCH" == "master" && "$TRAVIS_PULL_REQUEST" == "false" ]]; then npm run semantic-release; fi
2323
branches:
2424
except:

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# mongodb-memory-server
22

3+
[![travis build](https://img.shields.io/travis/nodkz/mongodb-memory-server.svg)](https://travis-ci.org/nodkz/mongodb-memory-server)
34
[![NPM version](https://img.shields.io/npm/v/mongodb-memory-server.svg)](https://www.npmjs.com/package/mongodb-memory-server)
45
[![Downloads stat](https://img.shields.io/npm/dt/mongodb-memory-server.svg)](http://www.npmtrends.com/mongodb-memory-server)
56
[![Travis](https://img.shields.io/travis/nodkz/mongodb-memory-server.svg?maxAge=2592000)](https://travis-ci.org/nodkz/mongodb-memory-server)
@@ -11,7 +12,7 @@ This package use [mongodb-prebuilt](https://github.com/winfinit/mongodb-prebuilt
1112

1213
Every `MongodbMemoryServer` instance creates and starts fresh MongoDB server on some free port. You may start up several mongod simultaneously. When you terminate your script or call `stop()` MongoDB server(s) will be automatically shutdown.
1314

14-
Perfectly [works with Travis CI](https://github.com/nodkz/graphql-compose-mongoose/commit/7a6ac2de747d14281f9965f418065e97a57cfb37) without additional `services` and `addons` options in `.travis.yml`.
15+
Perfectly [works with Travis CI](https://github.com/nodkz/graphql-compose-mongoose/commit/7a6ac2de747d14281f9965f418065e97a57cfb37) without additional `services` and `addons` options in `.travis.yml`.
1516

1617
## Installation
1718
```

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"devDependencies": {
2424
"babel-cli": "^6.22.2",
2525
"babel-eslint": "^7.1.1",
26+
"babel-jest": "^20.0.3",
2627
"babel-plugin-transform-class-properties": "^6.24.1",
2728
"babel-plugin-transform-flow-strip-types": "^6.22.0",
2829
"babel-plugin-transform-object-rest-spread": "^6.22.0",
@@ -36,7 +37,7 @@
3637
"eslint-plugin-prettier": "^2.1.1",
3738
"flow-bin": "^0.47.0",
3839
"jest": "^20.0.4",
39-
"jest-babel": "^1.0.1",
40+
"mongodb": "^2.2.28",
4041
"npm-run-all": "^4.0.1",
4142
"prettier": "^1.4.2",
4243
"rimraf": "^2.5.4",
@@ -62,7 +63,7 @@
6263
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
6364
},
6465
"jest": {
65-
"testPathDirs": [
66+
"roots": [
6667
"<rootDir>/src"
6768
]
6869
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`MongoDBMemoryServer should start mongo server 1`] = `
4+
Object {
5+
"n": 2,
6+
"ok": 1,
7+
}
8+
`;
9+
10+
exports[`MongoDBMemoryServer should start several servers 1`] = `
11+
Object {
12+
"n": 2,
13+
"ok": 1,
14+
}
15+
`;
16+
17+
exports[`MongoDBMemoryServer should start several servers 2`] = `
18+
Object {
19+
"n": 2,
20+
"ok": 1,
21+
}
22+
`;

src/__tests__/index-test.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* @flow */
2+
3+
import MongoDBMemoryServer from '../index';
4+
import { MongoClient } from 'mongodb';
5+
6+
describe('MongoDBMemoryServer', () => {
7+
it('should start mongo server', async () => {
8+
const server = new MongoDBMemoryServer();
9+
const mongoUri = await server.getConnectionString();
10+
const db = await MongoClient.connect(mongoUri);
11+
const col = db.collection('test');
12+
13+
const result = await col.insert([{ a: 1 }, { b: 1 }]);
14+
expect(result.result).toMatchSnapshot();
15+
expect(await col.count({})).toBe(2);
16+
});
17+
18+
it('should start several servers', async () => {
19+
const server1 = new MongoDBMemoryServer();
20+
const mongoUri1 = await server1.getConnectionString();
21+
const db1 = await MongoClient.connect(mongoUri1);
22+
const col1 = db1.collection('test');
23+
24+
const server2 = new MongoDBMemoryServer();
25+
const mongoUri2 = await server2.getConnectionString();
26+
const db2 = await MongoClient.connect(mongoUri2);
27+
const col2 = db2.collection('test');
28+
29+
expect(mongoUri1).not.toEqual(mongoUri2);
30+
31+
const result1 = await col1.insert([{ a: 1 }, { b: 1 }]);
32+
expect(result1.result).toMatchSnapshot();
33+
expect(await col1.count({})).toBe(2);
34+
35+
const result2 = await col2.insert([{ a: 2 }, { b: 2 }]);
36+
expect(result2.result).toMatchSnapshot();
37+
expect(await col2.count({})).toBe(2);
38+
});
39+
});

yarn.lock

+46-4
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ bser@^2.0.0:
883883
dependencies:
884884
node-int64 "^0.4.0"
885885

886+
bson@~1.0.4:
887+
version "1.0.4"
888+
resolved "https://registry.yarnpkg.com/bson/-/bson-1.0.4.tgz#93c10d39eaa5b58415cbc4052f3e53e562b0b72c"
889+
886890
buffer-crc32@~0.2.3:
887891
version "0.2.13"
888892
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
@@ -1383,6 +1387,10 @@ es6-map@^0.1.3:
13831387
es6-symbol "~3.1.1"
13841388
event-emitter "~0.3.5"
13851389

1390+
1391+
version "3.2.1"
1392+
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-3.2.1.tgz#ec56233868032909207170c39448e24449dd1fc4"
1393+
13861394
es6-set@~0.1.5:
13871395
version "0.1.5"
13881396
resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1"
@@ -2357,10 +2365,6 @@ istanbul-reports@^1.1.1:
23572365
dependencies:
23582366
handlebars "^4.0.3"
23592367

2360-
jest-babel@^1.0.1:
2361-
version "1.0.1"
2362-
resolved "https://registry.yarnpkg.com/jest-babel/-/jest-babel-1.0.1.tgz#ef659df0e9397b083c0f6aebd4cb8cfaa77df8bf"
2363-
23642368
jest-changed-files@^20.0.3:
23652369
version "20.0.3"
23662370
resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-20.0.3.tgz#9394d5cc65c438406149bef1bf4d52b68e03e3f8"
@@ -2927,6 +2931,13 @@ minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0:
29272931
dependencies:
29282932
minimist "0.0.8"
29292933

2934+
2935+
version "2.1.12"
2936+
resolved "https://registry.yarnpkg.com/mongodb-core/-/mongodb-core-2.1.12.tgz#1531192511bc16ef160ac6ae0cc46776ffd8451d"
2937+
dependencies:
2938+
bson "~1.0.4"
2939+
require_optional "~1.0.0"
2940+
29302941
mongodb-download@^2.2.1:
29312942
version "2.2.1"
29322943
resolved "https://registry.yarnpkg.com/mongodb-download/-/mongodb-download-2.2.1.tgz#061df0835be6b33596480da0ce83fdabbfb9cbb4"
@@ -2950,6 +2961,14 @@ mongodb-prebuilt@^6.2.0:
29502961
spawn-sync "1.0.15"
29512962
yargs "^3.26.0"
29522963

2964+
mongodb@^2.2.28:
2965+
version "2.2.28"
2966+
resolved "https://registry.yarnpkg.com/mongodb/-/mongodb-2.2.28.tgz#d8ff45754366e03973fa259bf4f11447858da657"
2967+
dependencies:
2968+
es6-promise "3.2.1"
2969+
mongodb-core "2.1.12"
2970+
readable-stream "2.2.7"
2971+
29532972
29542973
version "0.7.1"
29552974
resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098"
@@ -3436,6 +3455,18 @@ read-pkg@^2.0.0:
34363455
normalize-package-data "^2.3.2"
34373456
path-type "^2.0.0"
34383457

3458+
3459+
version "2.2.7"
3460+
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.7.tgz#07057acbe2467b22042d36f98c5ad507054e95b1"
3461+
dependencies:
3462+
buffer-shims "~1.0.0"
3463+
core-util-is "~1.0.0"
3464+
inherits "~2.0.1"
3465+
isarray "~1.0.0"
3466+
process-nextick-args "~1.0.6"
3467+
string_decoder "~1.0.0"
3468+
util-deprecate "~1.0.1"
3469+
34393470
readable-stream@^2.0.0, "readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.2, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.2:
34403471
version "2.2.9"
34413472
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.9.tgz#cf78ec6f4a6d1eb43d26488cac97f042e74b7fc8"
@@ -3635,10 +3666,21 @@ require-uncached@^1.0.2:
36353666
caller-path "^0.1.0"
36363667
resolve-from "^1.0.0"
36373668

3669+
require_optional@~1.0.0:
3670+
version "1.0.0"
3671+
resolved "https://registry.yarnpkg.com/require_optional/-/require_optional-1.0.0.tgz#52a86137a849728eb60a55533617f8f914f59abf"
3672+
dependencies:
3673+
resolve-from "^2.0.0"
3674+
semver "^5.1.0"
3675+
36383676
resolve-from@^1.0.0:
36393677
version "1.0.1"
36403678
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226"
36413679

3680+
resolve-from@^2.0.0:
3681+
version "2.0.0"
3682+
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-2.0.0.tgz#9480ab20e94ffa1d9e80a804c7ea147611966b57"
3683+
36423684
36433685
version "1.1.7"
36443686
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

0 commit comments

Comments
 (0)