File tree Expand file tree Collapse file tree 3 files changed +11
-19
lines changed
Expand file tree Collapse file tree 3 files changed +11
-19
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ module.exports = class MongoEnvironment extends TestEnvironment {
2121 globalConfigPath : string ;
2222 constructor ( config : JestEnvironmentConfig , context : EnvironmentContext ) {
2323 super ( config , context ) ;
24- this . globalConfigPath = pathJoin ( config . projectConfig . rootDir , 'globalConfig.json' ) ;
24+ this . globalConfigPath = pathJoin ( config . globalConfig . rootDir , 'globalConfig.json' ) ;
2525 }
2626
2727 async setup ( ) {
Original file line number Diff line number Diff line change @@ -22,8 +22,7 @@ const mongo: Mongo = isReplSet
2222 : new MongoMemoryServer ( mongoMemoryServerOptions ) ;
2323
2424module . exports = async ( config : JestEnvironmentConfig [ 'globalConfig' ] ) => {
25- const projects = config . projects . length ? config . projects : [ config . rootDir ] ;
26- const globalConfigPaths = projects . map ( project => join ( project , 'globalConfig.json' ) ) ;
25+ const globalConfigPath = join ( config . rootDir , 'globalConfig.json' ) ;
2726
2827 const options = getMongodbMemoryOptions ( ) ;
2928 const mongoConfig : { mongoUri ?: string ; mongoDBName ?: string } = { } ;
@@ -49,9 +48,6 @@ module.exports = async (config: JestEnvironmentConfig['globalConfig']) => {
4948 mongoConfig . mongoDBName = options . instance . dbName ;
5049
5150 // Write global config to disk because all tests run in different contexts.
52- // write one for each registered "project"
53- for ( const path of globalConfigPaths ) {
54- writeFileSync ( path , JSON . stringify ( mongoConfig ) ) ;
55- }
51+ writeFileSync ( globalConfigPath , JSON . stringify ( mongoConfig ) ) ;
5652 debug ( 'Config is written' ) ;
5753} ;
Original file line number Diff line number Diff line change @@ -5,22 +5,18 @@ import type {JestEnvironmentConfig} from '@jest/environment';
55const debug = require ( 'debug' ) ( 'jest-mongodb:teardown' ) ;
66
77module . exports = async function ( config : JestEnvironmentConfig [ 'globalConfig' ] ) {
8- const projects = config . projects . length ? config . projects : [ config . rootDir ] ;
9- const globalConfigPaths = projects . map ( project => join ( project , 'globalConfig.json' ) ) ;
8+ const globalConfigPath = join ( config . rootDir , 'globalConfig.json' ) ;
109
1110 debug ( 'Teardown mongod' ) ;
1211 if ( global . __MONGOD__ ) {
1312 await global . __MONGOD__ . stop ( ) ;
1413 }
14+ unlink ( globalConfigPath , err => {
15+ if ( err ) {
16+ debug ( 'Config could not be deleted' ) ;
1517
16- for ( const path of globalConfigPaths ) {
17- unlink ( path , err => {
18- if ( err ) {
19- debug ( 'Config could not be deleted' ) ;
20-
21- return ;
22- }
23- debug ( 'Config is deleted' ) ;
24- } ) ;
25- }
18+ return ;
19+ }
20+ debug ( 'Config is deleted' ) ;
21+ } ) ;
2622} ;
You can’t perform that action at this time.
0 commit comments