Skip to content

Commit 9cd0061

Browse files
committed
Moving tests to mongodb-memory-server from mongodb-runner
The memory server is faster and simpler. MongoDB runner has hella security flags that never get updated.
1 parent 99c2f01 commit 9cd0061

5 files changed

Lines changed: 552 additions & 1295 deletions

File tree

__tests__/methods/Model.create.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
const test = require('ava');
22
const mongoose = require('mongoose');
3+
const { MongoMemoryServer } = require('mongodb-memory-server');
34
const authz = require('../../');
45
const IncompatibleMethodError = require('../../src/IncompatibleMethodError');
56

7+
let mongoServer;
8+
69
test.before(async () => {
7-
await mongoose.connect('mongodb://localhost:27017/ModelCreateTests');
10+
mongoServer = new MongoMemoryServer();
11+
const uri = await mongoServer.getConnectionString();
12+
await mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true });
813
});
914

1015
test('Model.create should not be callable with plugin installed', (t) => {
@@ -27,4 +32,5 @@ test('Model.create should be callable without the plugin installed', async (t) =
2732

2833
test.after.always(async () => {
2934
await mongoose.disconnect();
35+
await mongoServer.stop();
3036
});

__tests__/methods/Model.remove.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
const test = require('ava');
22
const mongoose = require('mongoose');
3+
const { MongoMemoryServer } = require('mongodb-memory-server');
34
const authz = require('../../');
45
const IncompatibleMethodError = require('../../src/IncompatibleMethodError');
56

7+
let mongoServer;
8+
69
test.before(async () => {
7-
await mongoose.connect('mongodb://localhost:27017/ModelRemoveTests');
10+
mongoServer = new MongoMemoryServer();
11+
const uri = await mongoServer.getConnectionString();
12+
await mongoose.connect(uri, { useNewUrlParser: true, useCreateIndex: true });
813
});
914

1015
test('Model.remove should not be callable with plugin installed', (t) => {
@@ -27,4 +32,5 @@ test('Model.remove should be callable without the plugin installed', async (t) =
2732

2833
test.after.always(async () => {
2934
await mongoose.disconnect();
35+
await mongoServer.stop();
3036
});

0 commit comments

Comments
 (0)