Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-5444)!: emit deprecation warning for useNewUrlParser and useUnifiedTopology #3792

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
baileympearson marked this conversation as resolved.
Show resolved Hide resolved
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 () => {
baileympearson marked this conversation as resolved.
Show resolved Hide resolved
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/);
});
});
});