File tree Expand file tree Collapse file tree 3 files changed +9
-10
lines changed
Expand file tree Collapse file tree 3 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -11,9 +11,6 @@ const uuid = require('uuid');
1111// eslint-disable-next-line import/order
1212const debug = require ( 'debug' ) ( 'jest-mongodb:environment' ) ;
1313
14- const cwd = process . cwd ( ) ;
15-
16- const globalConfigPath = pathJoin ( cwd , 'globalConfig.json' ) ;
1714const options = getMongodbMemoryOptions ( ) ;
1815const isReplSet = Boolean ( options . replSet ) ;
1916
@@ -22,14 +19,16 @@ debug(`isReplSet`, isReplSet);
2219const mongo = isReplSet ? new MongoMemoryReplSet ( options ) : new MongoMemoryServer ( options ) ;
2320
2421module . exports = class MongoEnvironment extends TestEnvironment {
22+ globalConfigPath : string
2523 constructor ( config : JestEnvironmentConfig , context : EnvironmentContext ) {
2624 super ( config , context ) ;
25+ this . globalConfigPath = pathJoin ( config . projectConfig . rootDir , 'globalConfig.json' ) ;
2726 }
2827
2928 async setup ( ) {
3029 debug ( 'Setup MongoDB Test Environment' ) ;
3130
32- const globalConfig = JSON . parse ( readFileSync ( globalConfigPath , 'utf-8' ) ) ;
31+ const globalConfig = JSON . parse ( readFileSync ( this . globalConfigPath , 'utf-8' ) ) ;
3332
3433 if ( globalConfig . mongoUri ) {
3534 this . global . __MONGO_URI__ = globalConfig . mongoUri ;
Original file line number Diff line number Diff line change 88 shouldUseSharedDBForAllJestWorkers ,
99} from './helpers' ;
1010import type { Mongo } from './types' ;
11+ import type { JestEnvironmentConfig } from '@jest/environment'
1112
1213const debug = require ( 'debug' ) ( 'jest-mongodb:setup' ) ;
1314const mongoMemoryServerOptions = getMongodbMemoryOptions ( ) ;
@@ -20,10 +21,9 @@ const mongo: Mongo = isReplSet
2021 ? new MongoMemoryReplSet ( mongoMemoryServerOptions )
2122 : new MongoMemoryServer ( mongoMemoryServerOptions ) ;
2223
23- const cwd = process . cwd ( ) ;
24- const globalConfigPath = join ( cwd , 'globalConfig.json' ) ;
24+ module . exports = async ( config : JestEnvironmentConfig [ 'projectConfig' ] ) => {
25+ const globalConfigPath = join ( config . rootDir , 'globalConfig.json' ) ;
2526
26- module . exports = async ( ) => {
2727 const options = getMongodbMemoryOptions ( ) ;
2828 const mongoConfig : { mongoUri ?: string ; mongoDBName ?: string } = { } ;
2929
Original file line number Diff line number Diff line change 11import { join } from 'path' ;
22import { unlink } from 'fs' ;
3+ import type { JestEnvironmentConfig } from '@jest/environment'
34
45const debug = require ( 'debug' ) ( 'jest-mongodb:teardown' ) ;
56
6- const cwd = process . cwd ( ) ;
7- const globalConfigPath = join ( cwd , 'globalConfig.json' ) ;
7+ module . exports = async function ( config : JestEnvironmentConfig [ 'projectConfig' ] ) {
8+ const globalConfigPath = join ( config . rootDir , 'globalConfig.json' ) ;
89
9- module . exports = async function ( ) {
1010 debug ( 'Teardown mongod' ) ;
1111 if ( global . __MONGOD__ ) {
1212 await global . __MONGOD__ . stop ( ) ;
You can’t perform that action at this time.
0 commit comments