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-4519): deprecate promiseLibrary and PromiseProvider #3403

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/mongo_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,10 @@ export interface MongoClientOptions extends BSONSerializeOptions, SupportedNodeC
raw?: boolean;
/** A primary key factory function for generation of custom `_id` keys */
pkFactory?: PkFactory;
/** A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible */
/**
* A Promise library class the application wishes to use such as Bluebird, must be ES6 compatible
* @deprecated Setting a custom promise library is deprecated the next major version will use the global Promise constructor only.
*/
promiseLibrary?: any;
/** The logging level */
loggerLevel?: LoggerLevel;
Expand Down
9 changes: 9 additions & 0 deletions test/integration/node-specific/custom_promise_library.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict';

const { once } = require('events');
const { expect } = require('chai');
const { PromiseProvider } = require('../../../src/promise_provider');
const { MongoClient } = require('../../../src/mongo_client');

class CustomPromise extends Promise {}
CustomPromise.prototype.isCustomMongo = true;
Expand All @@ -11,6 +13,13 @@ describe('Optional PromiseLibrary', function () {
PromiseProvider.set(Promise);
});

it('should emit a deprecation warning when a promiseLibrary is set', async () => {
const willEmitWarning = once(process, 'warning');
new MongoClient('mongodb://iLoveJavascript', { promiseLibrary: () => {} });
const [warning] = await willEmitWarning;
expect(warning).to.have.property('message', 'promiseLibrary is a deprecated option');
});

it('should correctly implement custom dependency-less promise', function (done) {
const getCustomPromise = v => new CustomPromise(resolve => resolve(v));
const getNativePromise = v => new Promise(resolve => resolve(v));
Expand Down
1 change: 1 addition & 0 deletions test/types/mongodb.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare const options: MongoDBDriver.MongoClientOptions;
expectDeprecated(options.w);
expectDeprecated(options.journal);
expectDeprecated(options.wtimeoutMS);
expectDeprecated(options.promiseLibrary);
expectNotDeprecated(options.writeConcern);
expectType<WriteConcernSettings | WriteConcern | undefined>(options.writeConcern);

Expand Down