mongodb-js/connect-mongodb-session

How to close MongoClient?

MithileshHinge opened this issue · 1 comments

I am aware that there is client property exposed but for some reason it's null? Also, the db property is null as well.
I am using @shelf/jest-mongodb to test an express app. It uses an in-memory mongo db server. Everything works fine, sessions are getting stored, but jest doesn't exit cleanly exit because MongoClient never closes.

const MongoDBStore = ConnectMongoDBSession(session);

  const mockStore = new MongoDBStore({
    uri: process.env.MONGO_URL!, // env variable automatically set by @shelf/jest-mongodb
    collection: config.database.sessionCollection,
    connectionOptions: {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    } as MongoClientOptions,
  });

So basically Jest hangs after all tests finish running. In other tests, I have used the mongodb in-memory server for testing and I faced the same problem, but I simply called MongoClient.close() method to solve it. In this case, however, I don't seem to have access to the MongoClient. Any help is appreciated.

mockStore.client.close()