@@ -10,18 +10,18 @@ import {getMongodbMemoryOptions} from './helpers';
1010// eslint-disable-next-line import/order
1111const debug = require ( 'debug' ) ( 'jest-mongodb:environment' ) ;
1212
13- const options = getMongodbMemoryOptions ( ) ;
14- const isReplSet = Boolean ( options . replSet ) ;
15-
16- debug ( `isReplSet` , isReplSet ) ;
17-
18- const mongo = isReplSet ? new MongoMemoryReplSet ( options ) : new MongoMemoryServer ( options ) ;
19-
2013module . exports = class MongoEnvironment extends TestEnvironment {
2114 globalConfigPath : string ;
15+ mongo : MongoMemoryReplSet | MongoMemoryServer ;
2216 constructor ( config : JestEnvironmentConfig , context : EnvironmentContext ) {
2317 super ( config , context ) ;
2418 this . globalConfigPath = pathJoin ( config . globalConfig . rootDir , 'globalConfig.json' ) ;
19+
20+ const options = getMongodbMemoryOptions ( config . globalConfig . rootDir ) ;
21+ const isReplSet = Boolean ( options . replSet ) ;
22+ debug ( `isReplSet` , isReplSet ) ;
23+
24+ this . mongo = isReplSet ? new MongoMemoryReplSet ( options ) : new MongoMemoryServer ( options ) ;
2525 }
2626
2727 async setup ( ) {
@@ -32,9 +32,9 @@ module.exports = class MongoEnvironment extends TestEnvironment {
3232 if ( globalConfig . mongoUri ) {
3333 this . global . __MONGO_URI__ = globalConfig . mongoUri ;
3434 } else {
35- await mongo . start ( ) ;
35+ await this . mongo . start ( ) ;
3636
37- this . global . __MONGO_URI__ = mongo . getUri ( ) ;
37+ this . global . __MONGO_URI__ = this . mongo . getUri ( ) ;
3838 }
3939
4040 this . global . __MONGO_DB_NAME__ = globalConfig . mongoDBName || randomUUID ( ) ;
@@ -45,7 +45,7 @@ module.exports = class MongoEnvironment extends TestEnvironment {
4545 async teardown ( ) {
4646 debug ( 'Teardown MongoDB Test Environment' ) ;
4747
48- await mongo . stop ( ) ;
48+ await this . mongo . stop ( ) ;
4949
5050 await super . teardown ( ) ;
5151 }
0 commit comments