UNPKG

@shelf/jest-mongodb

Version:

Run your tests using Jest & MongoDB in Memory server

52 lines (51 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMongoURLEnvName = getMongoURLEnvName; exports.getMongodbMemoryOptions = getMongodbMemoryOptions; exports.isMongoMemoryReplSetOptions = isMongoMemoryReplSetOptions; exports.shouldUseSharedDBForAllJestWorkers = shouldUseSharedDBForAllJestWorkers; var _path = require("path"); const configFile = process.env.MONGO_MEMORY_SERVER_FILE || 'jest-mongodb-config.js'; function isMongoMemoryReplSetOptions(options) { return Boolean(options.replSet); } function getMongodbMemoryOptions(cwd) { try { const { mongodbMemoryServerOptions } = require((0, _path.resolve)(cwd, configFile)); return mongodbMemoryServerOptions; } catch { return { binary: { checkMD5: false }, instance: {} }; } } function getMongoURLEnvName(cwd) { try { const { mongoURLEnvName } = require((0, _path.resolve)(cwd, configFile)); return mongoURLEnvName || 'MONGO_URL'; } catch (e) { return 'MONGO_URL'; } } function shouldUseSharedDBForAllJestWorkers(cwd) { try { const { useSharedDBForAllJestWorkers } = require((0, _path.resolve)(cwd, configFile)); if (typeof useSharedDBForAllJestWorkers === 'undefined') { return true; } return useSharedDBForAllJestWorkers; } catch (e) { return true; } }