mirror of https://github.com/facebook/jest.git
27 lines
676 B
JavaScript
27 lines
676 B
JavaScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import {MongoMemoryServer} from '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.getUri(),
|
|
};
|
|
|
|
// 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.
|
|
globalThis.__MONGOD__ = mongod;
|
|
};
|