fix for build error running itests
Some checks failed
Server Tests / Mocha – Unit & Utility Tests (push) Successful in 49s
Server Tests / Jest – Integration Tests (push) Failing after 1m17s

This commit is contained in:
Devin Major 2026-04-29 13:13:42 -04:00
parent f6700793e8
commit b46c995b3d
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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({});
}