-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(Disconnect): Add
closing db connection
and shut downing mongod
.
- Loading branch information
Showing
7 changed files
with
126 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Multiple mongoServers should start several servers 1`] = ` | ||
Object { | ||
"n": 2, | ||
"ok": 1, | ||
} | ||
`; | ||
|
||
exports[`Multiple mongoServers should start several servers 2`] = ` | ||
Object { | ||
"n": 2, | ||
"ok": 1, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Single mongoServer should start mongo server 1`] = ` | ||
Object { | ||
"n": 2, | ||
"ok": 1, | ||
} | ||
`; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* @flow */ | ||
|
||
import MongoDBMemoryServer from '../index'; | ||
import { MongoClient } from 'mongodb'; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; | ||
|
||
let db1; | ||
let db2; | ||
let mongoServer1; | ||
let mongoServer2; | ||
beforeAll(async () => { | ||
mongoServer1 = new MongoDBMemoryServer(); | ||
const mongoUri = await mongoServer1.getConnectionString(); | ||
db1 = await MongoClient.connect(mongoUri); | ||
|
||
mongoServer2 = new MongoDBMemoryServer(); | ||
const mongoUri2 = await mongoServer2.getConnectionString(); | ||
db2 = await MongoClient.connect(mongoUri2); | ||
}); | ||
|
||
afterAll(() => { | ||
db1.close(); | ||
db2.close(); | ||
mongoServer1.stop(); | ||
mongoServer2.stop(); | ||
}); | ||
|
||
describe('Multiple mongoServers', () => { | ||
it('should start several servers', async () => { | ||
const col1 = db1.collection('test'); | ||
const result1 = await col1.insert([{ a: 1 }, { b: 1 }]); | ||
expect(result1.result).toMatchSnapshot(); | ||
expect(await col1.count({})).toBe(2); | ||
|
||
const col2 = db2.collection('test'); | ||
const result2 = await col2.insert([{ a: 2 }, { b: 2 }]); | ||
expect(result2.result).toMatchSnapshot(); | ||
expect(await col2.count({})).toBe(2); | ||
}); | ||
|
||
it('should have different uri', async () => { | ||
const uri1 = await mongoServer1.getConnectionString(); | ||
const uri2 = await mongoServer2.getConnectionString(); | ||
|
||
expect(uri1).not.toEqual(uri2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* @flow */ | ||
|
||
import MongoDBMemoryServer from '../index'; | ||
import { MongoClient } from 'mongodb'; | ||
|
||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000; | ||
|
||
let db; | ||
let mongoServer; | ||
beforeAll(async () => { | ||
mongoServer = new MongoDBMemoryServer(); | ||
const mongoUri = await mongoServer.getConnectionString(); | ||
db = await MongoClient.connect(mongoUri); | ||
}); | ||
|
||
afterAll(() => { | ||
db.close(); | ||
mongoServer.stop(); | ||
}); | ||
|
||
describe('Single mongoServer', () => { | ||
it('should start mongo server', async () => { | ||
const col = db.collection('test'); | ||
const result = await col.insert([{ a: 1 }, { b: 1 }]); | ||
expect(result.result).toMatchSnapshot(); | ||
expect(await col.count({})).toBe(2); | ||
}); | ||
}); |