File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
packages/mongodb-memory-server-core/src/util Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -232,7 +232,16 @@ export class DryMongoBinary {
232232 log ( `generateDownloadPath: Generating Download Path, preferGlobal: "${ preferGlobal } "` ) ;
233233 const paths = await this . generatePaths ( opts ) ;
234234
235- log ( 'generateDownloadPath: Paths:' , paths ) ;
235+ log ( 'generateDownloadPath: Paths:' , paths , opts . systemBinary ) ;
236+
237+ // SystemBinary will only be returned if defined and paths exists
238+ if ( ! ! opts . systemBinary && ( await pathExists ( opts . systemBinary ) ) ) {
239+ const sysPath = await this . getSystemPath ( opts . systemBinary ) ;
240+
241+ if ( ! isNullOrUndefined ( sysPath ) ) {
242+ return [ true , sysPath ] ;
243+ }
244+ }
236245
237246 // Section where paths are probed for an existing binary
238247 if ( await pathExists ( paths . resolveConfig ) ) {
Original file line number Diff line number Diff line change @@ -182,9 +182,33 @@ describe('DryBinary', () => {
182182 delete process . env [ envName ( ResolveConfigVariables . PREFER_GLOBAL_PATH ) ] ;
183183 filesExist . clear ( ) ;
184184 ( binary . DryMongoBinary . generatePaths as jest . Mock ) . mockClear ( ) ;
185+
186+ if ( jest . isMockFunction ( binary . DryMongoBinary . getSystemPath ) ) {
187+ ( binary . DryMongoBinary . getSystemPath as jest . Mock ) . mockRestore ( ) ;
188+ }
185189 } ) ;
186190
187191 describe ( 'should return exists' , ( ) => {
192+ it ( 'should return system binary if provided and exists' , async ( ) => {
193+ jest . spyOn ( binary . DryMongoBinary , 'getSystemPath' ) ;
194+ jest . spyOn ( fspromises , 'access' ) . mockResolvedValueOnce ( void 0 ) ;
195+ const expectedPath = '/some/systembinary/somewhere' ;
196+ expectedPaths = {
197+ legacyHomeCache : '' ,
198+ modulesCache : '' ,
199+ relative : '' ,
200+ resolveConfig : '' ,
201+ } ;
202+ filesExist . add ( expectedPath ) ;
203+ const returnValue = await binary . DryMongoBinary . generateDownloadPath ( {
204+ ...opts ,
205+ systemBinary : expectedPath ,
206+ } ) ;
207+ expect ( binary . DryMongoBinary . generatePaths ) . toHaveBeenCalledTimes ( 1 ) ;
208+ expect ( binary . DryMongoBinary . getSystemPath ) . toHaveBeenCalledTimes ( 1 ) ;
209+ expect ( returnValue ) . toStrictEqual ( [ true , expectedPath ] ) ;
210+ } ) ;
211+
188212 it ( 'should return the DOWNLOAD_DIR when provided' , async ( ) => {
189213 const expectedPath = '/some/custom/path/binary' ;
190214 expectedPaths = {
You can’t perform that action at this time.
0 commit comments