Skip to content

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Oct 19, 2021
1 parent 0aef5b7 commit 41904e1
Show file tree
Hide file tree
Showing 2 changed files with 1,884 additions and 1,714 deletions.
29 changes: 14 additions & 15 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,28 @@ const { MongoMemoryServer } = require('mongodb-memory-server');

const mongooseCommonPlugin = require('..');

const mongoServer = new MongoMemoryServer();

mongoose.Promise = global.Promise;
mongoServer.getUri().then(mongoUri => {
const mongooseOpts = {
autoReconnect: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000
};

mongoose.connect(mongoUri, mongooseOpts);

mongoose.connection.on('error', e => {
const mongooseOpts = {
autoReconnect: true,
reconnectTries: Number.MAX_VALUE,
reconnectInterval: 1000
};

test.before(async () => {
const mongod = await MongoMemoryServer.create();
const uri = mongod.getUri();
await mongoose.connect(uri, mongooseOpts);

mongoose.connection.on('error', async e => {
if (e.message.code === 'ETIMEDOUT') {
console.log(e);
mongoose.connect(mongoUri, mongooseOpts);
await mongoose.connect(uri, mongooseOpts);
}

console.log(e);
});

mongoose.connection.once('open', () => {
console.log(`MongoDB successfully connected to ${mongoUri}`);
console.log(`MongoDB successfully connected to ${uri}`);
});
});

Expand Down
Loading

0 comments on commit 41904e1

Please sign in to comment.