File tree 3 files changed +9
-10
lines changed
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');
11
11
// eslint-disable-next-line import/order
12
12
const debug = require ( 'debug' ) ( 'jest-mongodb:environment' ) ;
13
13
14
- const cwd = process . cwd ( ) ;
15
-
16
- const globalConfigPath = pathJoin ( cwd , 'globalConfig.json' ) ;
17
14
const options = getMongodbMemoryOptions ( ) ;
18
15
const isReplSet = Boolean ( options . replSet ) ;
19
16
@@ -22,14 +19,16 @@ debug(`isReplSet`, isReplSet);
22
19
const mongo = isReplSet ? new MongoMemoryReplSet ( options ) : new MongoMemoryServer ( options ) ;
23
20
24
21
module . exports = class MongoEnvironment extends TestEnvironment {
22
+ globalConfigPath : string
25
23
constructor ( config : JestEnvironmentConfig , context : EnvironmentContext ) {
26
24
super ( config , context ) ;
25
+ this . globalConfigPath = pathJoin ( config . projectConfig . rootDir , 'globalConfig.json' ) ;
27
26
}
28
27
29
28
async setup ( ) {
30
29
debug ( 'Setup MongoDB Test Environment' ) ;
31
30
32
- const globalConfig = JSON . parse ( readFileSync ( globalConfigPath , 'utf-8' ) ) ;
31
+ const globalConfig = JSON . parse ( readFileSync ( this . globalConfigPath , 'utf-8' ) ) ;
33
32
34
33
if ( globalConfig . mongoUri ) {
35
34
this . global . __MONGO_URI__ = globalConfig . mongoUri ;
Original file line number Diff line number Diff line change 8
8
shouldUseSharedDBForAllJestWorkers ,
9
9
} from './helpers' ;
10
10
import type { Mongo } from './types' ;
11
+ import type { JestEnvironmentConfig } from '@jest/environment'
11
12
12
13
const debug = require ( 'debug' ) ( 'jest-mongodb:setup' ) ;
13
14
const mongoMemoryServerOptions = getMongodbMemoryOptions ( ) ;
@@ -20,10 +21,9 @@ const mongo: Mongo = isReplSet
20
21
? new MongoMemoryReplSet ( mongoMemoryServerOptions )
21
22
: new MongoMemoryServer ( mongoMemoryServerOptions ) ;
22
23
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' ) ;
25
26
26
- module . exports = async ( ) => {
27
27
const options = getMongodbMemoryOptions ( ) ;
28
28
const mongoConfig : { mongoUri ?: string ; mongoDBName ?: string } = { } ;
29
29
Original file line number Diff line number Diff line change 1
1
import { join } from 'path' ;
2
2
import { unlink } from 'fs' ;
3
+ import type { JestEnvironmentConfig } from '@jest/environment'
3
4
4
5
const debug = require ( 'debug' ) ( 'jest-mongodb:teardown' ) ;
5
6
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' ) ;
8
9
9
- module . exports = async function ( ) {
10
10
debug ( 'Teardown mongod' ) ;
11
11
if ( global . __MONGOD__ ) {
12
12
await global . __MONGOD__ . stop ( ) ;
You can’t perform that action at this time.
0 commit comments