Created
March 2, 2019 04:13
-
-
Save grantcarthew/082d7f6da9a659c67f9b67f61ca6d252 to your computer and use it in GitHub Desktop.
medium-mongo-environment.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mongo-environment.js | |
const NodeEnvironment = require('jest-environment-node') | |
const path = require('path') | |
const fs = require('fs') | |
const globalConfigPath = path.join(__dirname, 'globalConfig.json') | |
const log = require('../../src/logger') | |
class MongoEnvironment extends NodeEnvironment { | |
constructor (config) { | |
super(config) | |
} | |
async setup () { | |
log.info('Setup MongoDB Test Environment') | |
const globalConfig = JSON.parse(fs.readFileSync(globalConfigPath, 'utf-8')) | |
this.global.__MONGO_URI__ = globalConfig.mongoUri | |
this.global.__MONGO_DB_NAME__ = globalConfig.mongoDBName | |
await super.setup() | |
} | |
async teardown () { | |
log.info('Teardown MongoDB Test Environment') | |
await super.teardown() | |
} | |
runScript (script) { | |
return super.runScript(script) | |
} | |
} | |
module.exports = MongoEnvironment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment