Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save goldbergyoni/5d8bc948cf7097628631781141e401eb to your computer and use it in GitHub Desktop.

Select an option

Save goldbergyoni/5d8bc948cf7097628631781141e401eb to your computer and use it in GitHub Desktop.
Jest-global-setup
const MongodbMemoryServer = require('mongodb-memory-server');
const globalConfigPath = join(__dirname, 'globalConfig.json');
const mongod = new MongodbMemoryServer.default();
module.exports = async () => {
if (!mongod.isRunning) {
await mongod.start();
}
const mongoConfig = {
mongoDBName: 'testing-db',
mongoUri: await mongod.getConnectionString()
};
// Write global config to disk because tests might run in different processes and won't have access to env var
fs.writeFileSync(globalConfigPath, JSON.stringify(mongoConfig));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment