Skip to content

Commit 2cbfb58

Browse files
committed
test(MongoMemoryReplSet): better cleanup created temporary directories
1 parent ead7958 commit 2cbfb58

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -551,9 +551,7 @@ describe('MongoMemoryReplSet', () => {
551551
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });
552552

553553
const cleanupSpy = jest.spyOn(replSet, 'cleanup');
554-
const cleanupInstance0Spy = jest
555-
.spyOn(replSet.servers[0], 'cleanup')
556-
.mockResolvedValue(void 0);
554+
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');
557555

558556
await replSet.stop();
559557

@@ -568,9 +566,7 @@ describe('MongoMemoryReplSet', () => {
568566
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });
569567

570568
const cleanupSpy = jest.spyOn(replSet, 'cleanup');
571-
const cleanupInstance0Spy = jest
572-
.spyOn(replSet.servers[0], 'cleanup')
573-
.mockResolvedValue(void 0);
569+
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');
574570

575571
await replSet.stop(false);
576572

@@ -593,9 +589,7 @@ describe('MongoMemoryReplSet', () => {
593589
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });
594590

595591
const cleanupSpy = jest.spyOn(replSet, 'cleanup');
596-
const cleanupInstance0Spy = jest
597-
.spyOn(replSet.servers[0], 'cleanup')
598-
.mockResolvedValue(void 0);
592+
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');
599593

600594
await replSet.stop({ doCleanup: false, force: false });
601595

@@ -620,9 +614,7 @@ describe('MongoMemoryReplSet', () => {
620614
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });
621615

622616
const cleanupSpy = jest.spyOn(replSet, 'cleanup');
623-
const cleanupInstance0Spy = jest
624-
.spyOn(replSet.servers[0], 'cleanup')
625-
.mockResolvedValue(void 0);
617+
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');
626618

627619
await replSet.stop({ doCleanup: false });
628620
await replSet.cleanup();
@@ -638,9 +630,7 @@ describe('MongoMemoryReplSet', () => {
638630
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });
639631

640632
const cleanupSpy = jest.spyOn(replSet, 'cleanup');
641-
const cleanupInstance0Spy = jest
642-
.spyOn(replSet.servers[0], 'cleanup')
643-
.mockResolvedValue(void 0);
633+
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');
644634

645635
await replSet.stop({ doCleanup: false });
646636
await replSet.cleanup(false);
@@ -655,9 +645,7 @@ describe('MongoMemoryReplSet', () => {
655645

656646
await replSet.start();
657647

658-
const cleanupInstance1Spy = jest
659-
.spyOn(replSet.servers[0], 'cleanup')
660-
.mockResolvedValue(void 0);
648+
const cleanupInstance1Spy = jest.spyOn(replSet.servers[0], 'cleanup');
661649

662650
await replSet.stop({ doCleanup: false });
663651
await replSet.cleanup(true);
@@ -671,9 +659,7 @@ describe('MongoMemoryReplSet', () => {
671659
const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } });
672660

673661
const cleanupSpy = jest.spyOn(replSet, 'cleanup');
674-
const cleanupInstance0Spy = jest
675-
.spyOn(replSet.servers[0], 'cleanup')
676-
.mockResolvedValue(void 0);
662+
const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup');
677663

678664
await replSet.stop({ doCleanup: false });
679665
await replSet.cleanup({ doCleanup: true, force: true });
@@ -723,5 +709,10 @@ describe('MongoMemoryReplSet', () => {
723709
utils.assertion(!utils.isNullOrUndefined(instanceInfo));
724710
expect(instanceInfo.instance).toBeDefined();
725711
expect(instanceInfo?.launchTimeout).toStrictEqual(2000);
712+
713+
await utils.removeDir(
714+
// @ts-expect-error "_instanceInfo" is protected
715+
replSet.servers[0]._instanceInfo.tmpDir!
716+
); // manual cleanup
726717
});
727718
});

0 commit comments

Comments
 (0)