From eef706f7fef6ffe5caa0f0f8b3b99b168d8d7d2a Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sat, 8 Jun 2024 13:53:20 +0200 Subject: [PATCH] fix: remove deprecated boolean cleanup argument (stop / cleanup) already in 9.x it threw a error, now the error is removed too. --- .../src/MongoMemoryReplSet.ts | 10 ------ .../src/MongoMemoryServer.ts | 10 ------ .../src/__tests__/MongoMemoryReplSet.test.ts | 32 ------------------- .../src/__tests__/MongoMemoryServer.test.ts | 32 ------------------- .../MongoMemoryReplSet.test.ts.snap | 4 --- .../MongoMemoryServer.test.ts.snap | 8 ----- 6 files changed, 96 deletions(-) diff --git a/packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts b/packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts index 345afd4fa..797c8a75b 100644 --- a/packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts +++ b/packages/mongodb-memory-server-core/src/MongoMemoryReplSet.ts @@ -534,11 +534,6 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced /** Default to cleanup temporary, but not custom dbpaths */ let cleanup: Cleanup = { doCleanup: true, force: false }; - // TODO: for next major release (10.0), this should be removed - if (typeof cleanupOptions === 'boolean') { - throw new Error('Unsupported argument type: boolean'); - } - // handle the new way of setting what and how to cleanup if (typeof cleanupOptions === 'object') { cleanup = cleanupOptions; @@ -589,11 +584,6 @@ export class MongoMemoryReplSet extends EventEmitter implements ManagerAdvanced /** Default to doing cleanup, but not forcing it */ let cleanup: Cleanup = { doCleanup: true, force: false }; - // TODO: for next major release (10.0), this should be removed - if (typeof options === 'boolean') { - throw new Error('Unsupported argument type: boolean'); - } - // handle the new way of setting what and how to cleanup if (typeof options === 'object') { cleanup = options; diff --git a/packages/mongodb-memory-server-core/src/MongoMemoryServer.ts b/packages/mongodb-memory-server-core/src/MongoMemoryServer.ts index 9f9ad7d83..70bdd35db 100644 --- a/packages/mongodb-memory-server-core/src/MongoMemoryServer.ts +++ b/packages/mongodb-memory-server-core/src/MongoMemoryServer.ts @@ -550,11 +550,6 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced { /** Default to cleanup temporary, but not custom dbpaths */ let cleanup: Cleanup = { doCleanup: true, force: false }; - // TODO: for next major release (10.0), this should be removed - if (typeof cleanupOptions === 'boolean') { - throw new Error('Unsupported argument type: boolean'); - } - // handle the new way of setting what and how to cleanup if (typeof cleanupOptions === 'object') { cleanup = cleanupOptions; @@ -598,11 +593,6 @@ export class MongoMemoryServer extends EventEmitter implements ManagerAdvanced { /** Default to doing cleanup, but not forcing it */ let cleanup: Cleanup = { doCleanup: true, force: false }; - // TODO: for next major release (10.0), this should be removed - if (typeof options === 'boolean') { - throw new Error('Unsupported argument type: boolean'); - } - // handle the new way of setting what and how to cleanup if (typeof options === 'object') { cleanup = options; 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 a4d7cbee5..ccd52218e 100644 --- a/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryReplSet.test.ts +++ b/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryReplSet.test.ts @@ -590,22 +590,6 @@ describe('MongoMemoryReplSet', () => { } as utils.Cleanup); }); - it('should not support boolean arguments', async () => { - const replSet = new MongoMemoryReplSet(); - - try { - await replSet.stop( - // @ts-expect-error Testing a non-existing overload - true - ); - fail('Expected to fail'); - } catch (err) { - expect(err).toBeInstanceOf(Error); - assertIsError(err); - expect(err.message).toMatchSnapshot(); - } - }); - it('should call cleanup and pass-through cleanup options', async () => { const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } }); @@ -676,22 +660,6 @@ describe('MongoMemoryReplSet', () => { } as utils.Cleanup); }); - it('should not support boolean arguments', async () => { - const replSet = new MongoMemoryReplSet(); - - try { - await replSet.cleanup( - // @ts-expect-error Testing a non-existing overload - true - ); - fail('Expected to fail'); - } catch (err) { - expect(err).toBeInstanceOf(Error); - assertIsError(err); - expect(err.message).toMatchSnapshot(); - } - }); - it('should run cleanup with cleanup options and pass-through options to lower', async () => { const replSet = await MongoMemoryReplSet.create({ replSet: { count: 1 } }); diff --git a/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryServer.test.ts b/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryServer.test.ts index 22266ed24..f811acaf7 100644 --- a/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryServer.test.ts +++ b/packages/mongodb-memory-server-core/src/__tests__/MongoMemoryServer.test.ts @@ -628,22 +628,6 @@ describe('MongoMemoryServer', () => { expect(cleanupSpy).toHaveBeenCalledWith({ doCleanup: true } as utils.Cleanup); }); - it('should not support boolean arguments', async () => { - const mongoServer = new MongoMemoryServer(); - - try { - await mongoServer.stop( - // @ts-expect-error Testing a non-existing overload - true - ); - fail('Expected to fail'); - } catch (err) { - expect(err).toBeInstanceOf(Error); - assertIsError(err); - expect(err.message).toMatchSnapshot(); - } - }); - it('should call cleanup and pass-through cleanup options', async () => { const mongoServer = new MongoMemoryServer(); @@ -796,22 +780,6 @@ describe('MongoMemoryServer', () => { expect(mongoServer.instanceInfo).toBeUndefined(); }); - it('should not support boolean arguments', async () => { - const mongoServer = new MongoMemoryServer(); - - try { - await mongoServer.cleanup( - // @ts-expect-error Testing a non-existing overload - true - ); - fail('Expected to fail'); - } catch (err) { - expect(err).toBeInstanceOf(Error); - assertIsError(err); - expect(err.message).toMatchSnapshot(); - } - }); - it('should properly cleanup with tmpDir with default no force (new)', async () => { const mongoServer = await MongoMemoryServer.create(); const dbPath = mongoServer.instanceInfo!.dbPath; diff --git a/packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryReplSet.test.ts.snap b/packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryReplSet.test.ts.snap index ee783ed7b..1f9043902 100644 --- a/packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryReplSet.test.ts.snap +++ b/packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryReplSet.test.ts.snap @@ -2,10 +2,6 @@ exports[`MongoMemoryReplSet "_waitForPrimary" should throw an error if timeout is reached 1`] = `"{\\"timeout\\":1}"`; -exports[`MongoMemoryReplSet .cleanup() should not support boolean arguments 1`] = `"Unsupported argument type: boolean"`; - -exports[`MongoMemoryReplSet .stop() should not support boolean arguments 1`] = `"Unsupported argument type: boolean"`; - exports[`MongoMemoryReplSet getters & setters setter of "replSetOpts" should throw an error if count is 1 or above 1`] = `"ReplSet Count needs to be 1 or higher! (specified count: \\"0\\")"`; exports[`MongoMemoryReplSet getters & setters state errors setter of "binaryOpts" should throw an error if state is not "stopped" 1`] = ` diff --git a/packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryServer.test.ts.snap b/packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryServer.test.ts.snap index da3d83286..11c9d82d8 100644 --- a/packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryServer.test.ts.snap +++ b/packages/mongodb-memory-server-core/src/__tests__/__snapshots__/MongoMemoryServer.test.ts.snap @@ -2,12 +2,6 @@ exports[`MongoMemoryServer "createAuth" should throw an error if called without "this.auth" defined 1`] = `"\\"createAuth\\" got called, but \\"this.auth\\" is undefined!"`; -exports[`MongoMemoryServer cleanup() should not support boolean arguments 1`] = ` -"Incorrect State for operation: \\"new\\", allowed States: \\"[stopped]\\" -This may be because of using a v6.x way of calling functions, look at the following guide if anything applies: -https://nodkz.github.io/mongodb-memory-server/docs/guides/migration/migrate7#no-function-other-than-start-create-ensureinstance-will-be-starting-anything" -`; - exports[`MongoMemoryServer cleanup() should throw an error if state is not "stopped" 1`] = ` "Incorrect State for operation: \\"new\\", allowed States: \\"[stopped]\\" This may be because of using a v6.x way of calling functions, look at the following guide if anything applies: @@ -64,5 +58,3 @@ exports[`MongoMemoryServer start() should throw an error if state is not "new" o This may be because of using a v6.x way of calling functions, look at the following guide if anything applies: https://nodkz.github.io/mongodb-memory-server/docs/guides/migration/migrate7#no-function-other-than-start-create-ensureinstance-will-be-starting-anything" `; - -exports[`MongoMemoryServer stop() should not support boolean arguments 1`] = `"Unsupported argument type: boolean"`;