-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
38 lines (29 loc) · 929 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const MClient = require('mongodb').MongoClient;
const test = require('micro-analytics-cli/adapter-tests/unit-tests');
const path = require('path');
const collectionName = process.env.MAA_MONGODB_COLLECTION_NAME || 'ma-events';
const URL = process.env.MAA_MONGODB_URL || `mongodb://127.0.0.1:27017/ma-analyticsdb-test`;
let DB;
async function getMACollection() {
if(!DB) {
DB = await MClient.connect(URL);
}
return await DB.collection(collectionName);
}
function runTest() {
test({
name: 'mongodb',
modulePath: path.resolve(__dirname, './index.js'),
beforeEach: async (adapter) => {
const collection = await getMACollection();
return await collection.deleteMany({});
},
afterAll: async (adapter) => {
const collection = await getMACollection();
await collection.deleteMany({});
await collection.drop();
return adapter.close();
}
});
}
runTest();