diff --git a/.gitea/workflows/run-tests.yaml b/.gitea/workflows/run-tests.yaml index 6141330..68c459d 100644 --- a/.gitea/workflows/run-tests.yaml +++ b/.gitea/workflows/run-tests.yaml @@ -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 diff --git a/Development/server/tests/integration/jest.setup.js b/Development/server/tests/integration/jest.setup.js index 6da01a3..3dbfc3f 100644 --- a/Development/server/tests/integration/jest.setup.js +++ b/Development/server/tests/integration/jest.setup.js @@ -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({}); }