diff --git a/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts b/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts index e773d442..564ba5ef 100644 --- a/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts +++ b/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts @@ -87,7 +87,7 @@ export class DryMongoBinary { if (!!useOpts.systemBinary) { log(`locateBinary: env "SYSTEM_BINARY" was provided with value: "${useOpts.systemBinary}"`); - const systemReturn = await this.getSystemPath(useOpts.systemBinary); + const systemReturn = await this.getSystemPath(path.resolve(useOpts.systemBinary)); if (isNullOrUndefined(systemReturn)) { throw new BinaryNotFoundError(useOpts.systemBinary, ' (systemBinary)'); diff --git a/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts b/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts index 67ba5832..ba2517fa 100644 --- a/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts +++ b/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts @@ -499,6 +499,18 @@ describe('DryBinary', () => { expect(fspromises.access).toHaveBeenCalled(); }); + it('should return SystemBinary with absolute path', async () => { + const mockBinary = 'bin/mongod'; + process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = mockBinary; + jest.spyOn(fspromises, 'access').mockResolvedValue(void 0); + + const returnValue = await binary.DryMongoBinary.locateBinary({ version: '1.1.1' }); + expect(returnValue).not.toEqual(mockBinary); + expect(returnValue).toEqual(path.resolve(mockBinary)); + expect(binary.DryMongoBinary.binaryCache.size).toBe(0); // system binaries dont get added to the cache + expect(fspromises.access).toHaveBeenCalled(); + }); + it('should throw an error if SystemBinary was provided, but not found', async () => { const mockBinary = '/usr/local/bin/mongod'; process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = mockBinary;