From 2cbfb585365b101038d0e5dd98ea2316db5515fc Mon Sep 17 00:00:00 2001 From: hasezoey Date: Fri, 9 Jun 2023 19:56:16 +0200 Subject: [PATCH] test(MongoMemoryReplSet): better cleanup created temporary directories --- .../src/__tests__/MongoMemoryReplSet.test.ts | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryReplSet.test.ts b/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryReplSet.test.ts index 2329b97ea..a886d1fee 100644 --- a/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryReplSet.test.ts +++ b/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryReplSet.test.ts @@ -551,9 +551,7 @@ describe('MongoMemoryReplSet', () => { const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } }); const cleanupSpy = jest.spyOn(replSet, 'cleanup'); - const cleanupInstance0Spy = jest - .spyOn(replSet.servers[0], 'cleanup') - .mockResolvedValue(void 0); + const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup'); await replSet.stop(); @@ -568,9 +566,7 @@ describe('MongoMemoryReplSet', () => { const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } }); const cleanupSpy = jest.spyOn(replSet, 'cleanup'); - const cleanupInstance0Spy = jest - .spyOn(replSet.servers[0], 'cleanup') - .mockResolvedValue(void 0); + const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup'); await replSet.stop(false); @@ -593,9 +589,7 @@ describe('MongoMemoryReplSet', () => { const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } }); const cleanupSpy = jest.spyOn(replSet, 'cleanup'); - const cleanupInstance0Spy = jest - .spyOn(replSet.servers[0], 'cleanup') - .mockResolvedValue(void 0); + const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup'); await replSet.stop({ doCleanup: false, force: false }); @@ -620,9 +614,7 @@ describe('MongoMemoryReplSet', () => { const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } }); const cleanupSpy = jest.spyOn(replSet, 'cleanup'); - const cleanupInstance0Spy = jest - .spyOn(replSet.servers[0], 'cleanup') - .mockResolvedValue(void 0); + const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup'); await replSet.stop({ doCleanup: false }); await replSet.cleanup(); @@ -638,9 +630,7 @@ describe('MongoMemoryReplSet', () => { const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } }); const cleanupSpy = jest.spyOn(replSet, 'cleanup'); - const cleanupInstance0Spy = jest - .spyOn(replSet.servers[0], 'cleanup') - .mockResolvedValue(void 0); + const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup'); await replSet.stop({ doCleanup: false }); await replSet.cleanup(false); @@ -655,9 +645,7 @@ describe('MongoMemoryReplSet', () => { await replSet.start(); - const cleanupInstance1Spy = jest - .spyOn(replSet.servers[0], 'cleanup') - .mockResolvedValue(void 0); + const cleanupInstance1Spy = jest.spyOn(replSet.servers[0], 'cleanup'); await replSet.stop({ doCleanup: false }); await replSet.cleanup(true); @@ -671,9 +659,7 @@ describe('MongoMemoryReplSet', () => { const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } }); const cleanupSpy = jest.spyOn(replSet, 'cleanup'); - const cleanupInstance0Spy = jest - .spyOn(replSet.servers[0], 'cleanup') - .mockResolvedValue(void 0); + const cleanupInstance0Spy = jest.spyOn(replSet.servers[0], 'cleanup'); await replSet.stop({ doCleanup: false }); await replSet.cleanup({ doCleanup: true, force: true }); @@ -723,5 +709,10 @@ describe('MongoMemoryReplSet', () => { utils.assertion(!utils.isNullOrUndefined(instanceInfo)); expect(instanceInfo.instance).toBeDefined(); expect(instanceInfo?.launchTimeout).toStrictEqual(2000); + + await utils.removeDir( + // @ts-expect-error "_instanceInfo" is protected + replSet.servers[0]._instanceInfo.tmpDir! + ); // manual cleanup }); });