fix for build error running itests
This commit is contained in:
parent
f6700793e8
commit
b46c995b3d
@ -68,12 +68,14 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
TEST_ENV_FILE: ./environment.test.env
|
TEST_ENV_FILE: ./environment.test.env
|
||||||
NODE_ENV: test
|
NODE_ENV: test
|
||||||
|
MONGOMS_VERSION: 4.4.28
|
||||||
run: npm run test:integration:contract
|
run: npm run test:integration:contract
|
||||||
|
|
||||||
- name: Run Jest integration tests
|
- name: Run Jest integration tests
|
||||||
env:
|
env:
|
||||||
TEST_ENV_FILE: ./environment.test.env
|
TEST_ENV_FILE: ./environment.test.env
|
||||||
NODE_ENV: test
|
NODE_ENV: test
|
||||||
|
MONGOMS_VERSION: 4.4.28
|
||||||
run: npm run test:integration:jest -- --ci
|
run: npm run test:integration:jest -- --ci
|
||||||
|
|
||||||
- name: Upload Jest results
|
- name: Upload Jest results
|
||||||
|
|||||||
@ -20,6 +20,7 @@ const { MongoMemoryServer } = require('mongodb-memory-server');
|
|||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
|
|
||||||
let mongod = null;
|
let mongod = null;
|
||||||
|
const MONGOMS_VERSION = process.env.MONGOMS_VERSION || '4.4.28';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the in-memory MongoDB server and connect mongoose.
|
* Start the in-memory MongoDB server and connect mongoose.
|
||||||
@ -28,7 +29,15 @@ let mongod = null;
|
|||||||
async function connectDB() {
|
async function connectDB() {
|
||||||
if (mongoose.connection.readyState !== 0) return; // already connected
|
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();
|
const uri = mongod.getUri();
|
||||||
|
|
||||||
mongoose.set('strictPopulate', false);
|
mongoose.set('strictPopulate', false);
|
||||||
@ -59,6 +68,9 @@ async function disconnectDB() {
|
|||||||
* Call this inside beforeEach() / afterEach() to keep tests isolated.
|
* Call this inside beforeEach() / afterEach() to keep tests isolated.
|
||||||
*/
|
*/
|
||||||
async function clearCollection(model) {
|
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({});
|
await model.deleteMany({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user