Created
May 5, 2019 18:39
-
-
Save goldbergyoni/5d8bc948cf7097628631781141e401eb to your computer and use it in GitHub Desktop.
Jest-global-setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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