Skip to content

Commit

Permalink
feat(NODE-5444)!: emit deprecation warning for useNewUrlParser and us…
Browse files Browse the repository at this point in the history
…eUnifiedTopology (#3792)

Co-authored-by: Durran Jordan <durran@gmail.com>
  • Loading branch information
nbbeeken and durran authored Aug 4, 2023
1 parent 844aa52 commit c08060d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/connection_string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1223,9 +1223,17 @@ 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 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 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
mongodbLogPath: { type: 'any' }
Expand Down
39 changes: 39 additions & 0 deletions test/unit/connection_string.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 has no effect/);

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 has no effect/);
});

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 has no effect/);

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 has no effect/);
});
});
});

0 comments on commit c08060d

Please sign in to comment.