From c395428c220f33c7c9c3f16e4d6f779e81eb17a2 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Wed, 2 Aug 2023 13:57:05 -0400 Subject: [PATCH 1/2] feat(NODE-5444)!: emit deprecation warning for useNewUrlParser and useUnifiedTopology --- src/connection_string.ts | 12 ++++++--- test/unit/connection_string.test.ts | 39 +++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/connection_string.ts b/src/connection_string.ts index 0d8e511eb0e..358611a3e23 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -1223,9 +1223,15 @@ export const OPTIONS = { pfx: { type: 'any' }, secureProtocol: { type: 'any' }, index: { type: 'any' }, - // Legacy Options, these are unused but left here to avoid errors with CSFLE lib - useNewUrlParser: { type: 'boolean' } as OptionDescriptor, - useUnifiedTopology: { type: 'boolean' } as OptionDescriptor, + // Legacy options from v3 era + useNewUrlParser: { + type: 'boolean', + deprecated: 'useNewUrlParser is no longer used it can be removed' + } as OptionDescriptor, + useUnifiedTopology: { + type: 'boolean', + deprecated: 'useUnifiedTopology is no longer used it can be removed' + } as OptionDescriptor, // MongoLogger // TODO(NODE-4849): Tighten the type of mongodbLogPath mongodbLogPath: { type: 'any' } diff --git a/test/unit/connection_string.test.ts b/test/unit/connection_string.test.ts index 0439d49984c..eb98b61185c 100644 --- a/test/unit/connection_string.test.ts +++ b/test/unit/connection_string.test.ts @@ -1,3 +1,6 @@ +import { once } from 'node:events'; +import * as process from 'node:process'; + import { expect } from 'chai'; import * as dns from 'dns'; import * as sinon from 'sinon'; @@ -761,4 +764,40 @@ describe('Connection String', function () { expect(() => new MongoClient('mango://localhost:23')).to.throw(/Invalid scheme/i); expect(() => new MongoClient('mango+srv://localhost:23')).to.throw(/Invalid scheme/i); }); + + describe('when deprecated options are used', () => { + it('useNewUrlParser emits a warning', async () => { + let willBeWarning = once(process, 'warning'); + parseOptions('mongodb://host?useNewUrlParser=true'); + let [warning] = await willBeWarning; + expect(warning) + .to.have.property('message') + .that.matches(/useNewUrlParser is a deprecated option/); + + willBeWarning = once(process, 'warning'); + //@ts-expect-error: using unsupported option on purpose + parseOptions('mongodb://host', { useNewUrlParser: true }); + [warning] = await willBeWarning; + expect(warning) + .to.have.property('message') + .that.matches(/useNewUrlParser is a deprecated option/); + }); + + it('useUnifiedTopology emits a warning', async () => { + let willBeWarning = once(process, 'warning'); + parseOptions('mongodb://host?useUnifiedTopology=true'); + let [warning] = await willBeWarning; + expect(warning) + .to.have.property('message') + .that.matches(/useUnifiedTopology is a deprecated option/); + + willBeWarning = once(process, 'warning'); + //@ts-expect-error: using unsupported option on purpose + parseOptions('mongodb://host', { useUnifiedTopology: true }); + [warning] = await willBeWarning; + expect(warning) + .to.have.property('message') + .that.matches(/useUnifiedTopology is a deprecated option/); + }); + }); }); From d6d82bba2411b64ca5e14888e9f4fe01f487cae5 Mon Sep 17 00:00:00 2001 From: Neal Beeken Date: Thu, 3 Aug 2023 11:06:36 -0400 Subject: [PATCH 2/2] fix: message --- src/connection_string.ts | 6 ++++-- test/unit/connection_string.test.ts | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/connection_string.ts b/src/connection_string.ts index 358611a3e23..5b3da011ed4 100644 --- a/src/connection_string.ts +++ b/src/connection_string.ts @@ -1226,11 +1226,13 @@ export const OPTIONS = { // Legacy options from v3 era useNewUrlParser: { type: 'boolean', - deprecated: 'useNewUrlParser is no longer used it can be removed' + deprecated: + 'useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' } as OptionDescriptor, useUnifiedTopology: { type: 'boolean', - deprecated: 'useUnifiedTopology is no longer used it can be removed' + deprecated: + 'useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version' } as OptionDescriptor, // MongoLogger // TODO(NODE-4849): Tighten the type of mongodbLogPath diff --git a/test/unit/connection_string.test.ts b/test/unit/connection_string.test.ts index eb98b61185c..54c4733aa2f 100644 --- a/test/unit/connection_string.test.ts +++ b/test/unit/connection_string.test.ts @@ -772,7 +772,7 @@ describe('Connection String', function () { let [warning] = await willBeWarning; expect(warning) .to.have.property('message') - .that.matches(/useNewUrlParser is a deprecated option/); + .that.matches(/useNewUrlParser has no effect/); willBeWarning = once(process, 'warning'); //@ts-expect-error: using unsupported option on purpose @@ -780,7 +780,7 @@ describe('Connection String', function () { [warning] = await willBeWarning; expect(warning) .to.have.property('message') - .that.matches(/useNewUrlParser is a deprecated option/); + .that.matches(/useNewUrlParser has no effect/); }); it('useUnifiedTopology emits a warning', async () => { @@ -789,7 +789,7 @@ describe('Connection String', function () { let [warning] = await willBeWarning; expect(warning) .to.have.property('message') - .that.matches(/useUnifiedTopology is a deprecated option/); + .that.matches(/useUnifiedTopology has no effect/); willBeWarning = once(process, 'warning'); //@ts-expect-error: using unsupported option on purpose @@ -797,7 +797,7 @@ describe('Connection String', function () { [warning] = await willBeWarning; expect(warning) .to.have.property('message') - .that.matches(/useUnifiedTopology is a deprecated option/); + .that.matches(/useUnifiedTopology has no effect/); }); }); });