Skip to content

Commit 4e49f8f

Browse files
committed
test(MongoBinary): add test for "RUNTIME_DOWNLOAD" "false" and no binary found
1 parent 94ee82d commit 4e49f8f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/mongodb-memory-server-core/src/util/__tests__/MongoBinary.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ describe('MongoBinary', () => {
7777
expect(MongoBinary.download).toHaveBeenCalledTimes(1);
7878
});
7979

80+
it('should not trigger an download an error if "RUNTIME_DOWNLOAD" is false and no binary is found', async () => {
81+
process.env[envName(ResolveConfigVariables.RUNTIME_DOWNLOAD)] = 'false';
82+
jest.spyOn(DryMongoBinary, 'locateBinary').mockResolvedValue(undefined);
83+
jest
84+
.spyOn(MongoBinary, 'download')
85+
.mockImplementation(() => fail('Expect this function to not have been called'));
86+
87+
try {
88+
await MongoBinary.getPath();
89+
fail('Expected "getPath" to fail');
90+
} catch (err) {
91+
expect(err.message).toEqual(
92+
'MongoBinary.getPath: could not find an valid binary path! (Got: "undefined", RUNTIME_DOWNLOAD: "false")'
93+
);
94+
expect(DryMongoBinary.locateBinary).toBeCalledTimes(1);
95+
expect(MongoBinary.download).not.toHaveBeenCalled();
96+
}
97+
});
98+
8099
describe('systemBinary', () => {
81100
const sysBinaryPath = '/path/to/binary';
82101
beforeEach(() => {

0 commit comments

Comments
 (0)