Skip to content

Instantly share code, notes, and snippets.

@grantcarthew
Created March 2, 2019 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grantcarthew/082d7f6da9a659c67f9b67f61ca6d252 to your computer and use it in GitHub Desktop.
Save grantcarthew/082d7f6da9a659c67f9b67f61ca6d252 to your computer and use it in GitHub Desktop.
medium-mongo-environment.js
// 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