fix for build error running itests
This commit is contained in:
parent
f6700793e8
commit
b46c995b3d
@ -68,12 +68,14 @@ jobs:
|
||||
env:
|
||||
TEST_ENV_FILE: ./environment.test.env
|
||||
NODE_ENV: test
|
||||
MONGOMS_VERSION: 4.4.28
|
||||
run: npm run test:integration:contract
|
||||
|
||||
- name: Run Jest integration tests
|
||||
env:
|
||||
TEST_ENV_FILE: ./environment.test.env
|
||||
NODE_ENV: test
|
||||
MONGOMS_VERSION: 4.4.28
|
||||
run: npm run test:integration:jest -- --ci
|
||||
|
||||
- name: Upload Jest results
|
||||
|
||||
@ -20,6 +20,7 @@ const { MongoMemoryServer } = require('mongodb-memory-server');
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
let mongod = null;
|
||||
const MONGOMS_VERSION = process.env.MONGOMS_VERSION || '4.4.28';
|
||||
|
||||
/**
|
||||
* Start the in-memory MongoDB server and connect mongoose.
|
||||
@ -28,7 +29,15 @@ let mongod = null;
|
||||
async function connectDB() {
|
||||
if (mongoose.connection.readyState !== 0) return; // already connected
|
||||
|
||||
mongod = await MongoMemoryServer.create();
|
||||
try {
|
||||
mongod = await MongoMemoryServer.create({
|
||||
binary: { version: MONGOMS_VERSION },
|
||||
});
|
||||
} catch (error) {
|
||||
error.message = `${error.message}\nFailed to start mongodb-memory-server with MongoDB ${MONGOMS_VERSION}. ` +
|
||||
'If this runner lacks AVX support, keep MONGOMS_VERSION pinned to a 4.4.x release.';
|
||||
throw error;
|
||||
}
|
||||
const uri = mongod.getUri();
|
||||
|
||||
mongoose.set('strictPopulate', false);
|
||||
@ -59,6 +68,9 @@ async function disconnectDB() {
|
||||
* Call this inside beforeEach() / afterEach() to keep tests isolated.
|
||||
*/
|
||||
async function clearCollection(model) {
|
||||
if (!model || typeof model.deleteMany !== 'function') {
|
||||
throw new Error('clearCollection received an invalid model. Check that connectDB completed successfully before using test models.');
|
||||
}
|
||||
await model.deleteMany({});
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user