I implemented this on Windows 10. Unfortunately it is not working. getConnectionString() never returns anything and test times out. This happened even if I increased jest timeout to 1 min. Am I missing something?
const mongoose = require('mongoose'); const { MongoMemoryServer } = require('mongodb-memory-server'); const mongoUnit = require('mongo-unit'); const mongod = new MongoMemoryServer(); jest.setTimeout(60000); module.exports.connect = function(callback) { mongod.getUri().then((mongoUri) => { const mongooseOpts = { autoReconnect: true, reconnectTries: Number.MAX_VALUE, reconnectInterval: 1000, }; mongoose.connect(mongoUri, mongooseOpts); mongoose.connection.on('error', (e) => { if (e.message.code === 'ETIMEDOUT') { console.log(e); mongoose.connect(mongoUri, mongooseOpts); } console.log(e); }); mongoose.connection.once('open', () => { console.log(`MongoDB successfully connected to ${mongoUri}`); callback(); }); }); } module.exports.closeDatabase = async () => { await mongoose.connection.dropDatabase(); await mongoose.connection.close(); await mongod.stop(); } module.exports.clearDatabase = async () => { const collections = mongoose.connection.collections; for (const key in collections) { const collection = collections[key]; await collection.deleteMany(); } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I implemented this on Windows 10. Unfortunately it is not working. getConnectionString() never returns anything and test times out. This happened even if I increased jest timeout to 1 min. Am I missing something?