When trying to start MongoMemoryServer i get this:
RUNS test/user.test.js
Starting the instance failed, please enable debug for more infomation
at node_modules/mongodb-memory-server-core/src/MongoMemoryServer.ts:111:19
console.log
Mongod instance closed with code "100"
I am trying to use a memory server for integration testing. This is my code:
import supertest from 'supertest';
import mongoose from 'mongoose';
import validator from 'validator';
import { MongoMemoryServer } from 'mongodb-memory-server';
import { app } from '../src/app.js';
jest.setTimeout(600000);
let mockServer;
beforeAll(async () => {
// mockServer = new MongoMemoryServer();
mockServer = await MongoMemoryServer.create({
autoStart: true,
debug: true,
binary: { version: 'latest' },
});
const uri = await mockServer.getUri();
const opts = {
useNewUrlParser: true,
useCreateIndex: true,
useUnifiedTopology: true,
};
await mongoose.connect(uri, opts, (err) => {
if (err) console.log(err);
});
});
afterAll(async (done) => {
mongoose.disconnect(done);
await mockServer.stop();
});
afterEach(async () => {
const collections = await mongoose.connection.db.collections();
for (const collection of collections) {
await collection.deleteMany();
}
});
Its seems like the initial setup of the memory server is not working at all..
I cant find an answer to this problem anywhere, and I have tried every setup of the server i could find. Thanks in advance.
I been sitting with this problem for far too many hours now but i finally solved it. The `latest` version of mongodb is some kind of nightly build or something. Not stable at all. version 4.9.0-alpha-949-gd13b8b8
RépondreSupprimerIf you use enter a stable version number instead, like "4.4.2" it will work! Have a nice weekend