Skip to content

Commit 6ffe62a

Browse files
committed
fix(MongoMemoryServer): pass-through option "launchTimeout" correctly
re #710
1 parent 85f7e5e commit 6ffe62a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

packages/mongodb-memory-server-core/src/MongoMemoryServer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export interface AutomaticAuth {
7272
keyfileContent?: string;
7373
}
7474

75+
// TODO: consider some way to not forget to add changes from "MongoMemoryInstanceOpts"
7576
/**
7677
* Data used by _startUpInstance's "data" variable
7778
*/
@@ -84,6 +85,7 @@ export interface StartupInstanceData {
8485
replSet?: NonNullable<MongoMemoryInstanceOpts['replSet']>;
8586
tmpDir?: tmp.DirResult;
8687
keyfileLocation?: NonNullable<MongoMemoryInstanceOpts['keyfileLocation']>;
88+
launchTimeout?: NonNullable<MongoMemoryInstanceOpts['launchTimeout']>;
8789
}
8890

8991
/**
@@ -364,6 +366,7 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced {
364366
port = await this.getNewPort(port);
365367
}
366368

369+
// consider directly using "this.opts.instance", to pass through all options, even if not defined in "StartupInstanceData"
367370
const data: StartupInstanceData = {
368371
port: port,
369372
dbName: generateDbName(instOpts.dbName),
@@ -373,6 +376,7 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced {
373376
dbPath: instOpts.dbPath,
374377
tmpDir: undefined,
375378
keyfileLocation: instOpts.keyfileLocation,
379+
launchTimeout: instOpts.launchTimeout,
376380
};
377381

378382
if (isNullOrUndefined(this._instanceInfo)) {

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

+21
Original file line numberDiff line numberDiff line change
@@ -1106,4 +1106,25 @@ describe('MongoMemoryServer', () => {
11061106
}
11071107
});
11081108
});
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+
});
11091130
});

0 commit comments

Comments
 (0)