File tree 2 files changed +25
-0
lines changed
packages/mongodb-memory-server-core/src
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ export interface AutomaticAuth {
72
72
keyfileContent ?: string ;
73
73
}
74
74
75
+ // TODO: consider some way to not forget to add changes from "MongoMemoryInstanceOpts"
75
76
/**
76
77
* Data used by _startUpInstance's "data" variable
77
78
*/
@@ -84,6 +85,7 @@ export interface StartupInstanceData {
84
85
replSet ?: NonNullable < MongoMemoryInstanceOpts [ 'replSet' ] > ;
85
86
tmpDir ?: tmp . DirResult ;
86
87
keyfileLocation ?: NonNullable < MongoMemoryInstanceOpts [ 'keyfileLocation' ] > ;
88
+ launchTimeout ?: NonNullable < MongoMemoryInstanceOpts [ 'launchTimeout' ] > ;
87
89
}
88
90
89
91
/**
@@ -364,6 +366,7 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced {
364
366
port = await this . getNewPort ( port ) ;
365
367
}
366
368
369
+ // consider directly using "this.opts.instance", to pass through all options, even if not defined in "StartupInstanceData"
367
370
const data : StartupInstanceData = {
368
371
port : port ,
369
372
dbName : generateDbName ( instOpts . dbName ) ,
@@ -373,6 +376,7 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced {
373
376
dbPath : instOpts . dbPath ,
374
377
tmpDir : undefined ,
375
378
keyfileLocation : instOpts . keyfileLocation ,
379
+ launchTimeout : instOpts . launchTimeout ,
376
380
} ;
377
381
378
382
if ( isNullOrUndefined ( this . _instanceInfo ) ) {
Original file line number Diff line number Diff line change @@ -1106,4 +1106,25 @@ describe('MongoMemoryServer', () => {
1106
1106
}
1107
1107
} ) ;
1108
1108
} ) ;
1109
+
1110
+ it ( 'should transfer "launchTimeout" option to the MongoInstance' , async ( ) => {
1111
+ const createSpy = jest . spyOn ( MongoInstance , 'create' ) . mockImplementation (
1112
+ // @ts -expect-error This can work, because the instance is not used in the function that is tested here, beyond setting some extra options
1113
+ ( ) => Promise . resolve ( { } )
1114
+ ) ;
1115
+
1116
+ const mongoServer = new MongoMemoryServer ( { instance : { launchTimeout : 2000 } } ) ;
1117
+
1118
+ await mongoServer . _startUpInstance ( ) ;
1119
+
1120
+ // @ts -expect-error "_instanceInfo" is protected
1121
+ const instanceInfo = mongoServer . _instanceInfo ;
1122
+ expect ( instanceInfo ) . toBeDefined ( ) ;
1123
+ utils . assertion ( ! utils . isNullOrUndefined ( instanceInfo ) ) ;
1124
+ expect ( instanceInfo . instance ) . toBeDefined ( ) ;
1125
+ expect ( instanceInfo ?. launchTimeout ) . toStrictEqual ( 2000 ) ;
1126
+
1127
+ expect ( createSpy . mock . calls . length ) . toStrictEqual ( 1 ) ;
1128
+ expect ( createSpy . mock . calls [ 0 ] [ 0 ] . instance ) . toHaveProperty ( 'launchTimeout' , 2000 ) ;
1129
+ } ) ;
1109
1130
} ) ;
You can’t perform that action at this time.
0 commit comments