Skip to content

Commit 394ea3a

Browse files
committed
fix(MongoInstance): assert "this.mongodProcess.pid" before usage (childprocess pid can be undefined)
1 parent 84f59a5 commit 394ea3a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

packages/mongodb-memory-server-core/src/util/MongoInstance.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ export class MongoInstance extends EventEmitter implements ManagerBase {
286286
}
287287
this.debug('start: Starting Processes');
288288
this.mongodProcess = this._launchMongod(mongoBin);
289+
// This assertion is here because somewhere between nodejs 12 and 16 the types for "childprocess.pid" changed to include "| undefined"
290+
// it is tested and a error is thrown in "this_launchMongod", but typescript somehow does not see this yet as of 4.3.5
291+
assertion(
292+
!isNullOrUndefined(this.mongodProcess.pid),
293+
new Error('MongoD Process failed to spawn')
294+
);
289295
this.killerProcess = this._launchKiller(process.pid, this.mongodProcess.pid);
290296

291297
await launch;

0 commit comments

Comments
 (0)