forked from impulsoteam/atena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
25 lines (20 loc) · 700 Bytes
/
setup.js
File metadata and controls
25 lines (20 loc) · 700 Bytes
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
const path = require("path");
const fs = require("fs");
const { MongoMemoryServer } = require("mongodb-memory-server");
const globalConfigPath = path.join(__dirname, "globalConfig.json");
const mongod = new MongoMemoryServer({
autoStart: false
});
module.exports = async () => {
if (!mongod.isRunning) {
await mongod.start();
}
const mongoConfig = {
mongoDBName: "jest",
mongoUri: await mongod.getConnectionString()
};
// Write global config to disk because all tests run in different contexts.
fs.writeFileSync(globalConfigPath, JSON.stringify(mongoConfig));
// Set reference to mongod in order to close the server during teardown.
global.__MONGOD__ = mongod;
};