-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: pass optional promise lib to maybePromise
passes `promiseLibrary` option from `MongoClient` to `maybePromise` function and removes `devDependency` `bluebird`.
- Loading branch information
Thomas Reggi
authored
Apr 29, 2020
1 parent
fa052a5
commit 52be01f
Showing
9 changed files
with
115 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,81 @@ | ||
'use strict'; | ||
|
||
const maybePromise = require('./../../lib/utils').maybePromise; | ||
var expect = require('chai').expect; | ||
|
||
describe('BYO Promises', function() { | ||
it('should Correctly Use Blurbird promises library', { | ||
metadata: { | ||
requires: { | ||
topology: ['single', 'ssl', 'wiredtiger'] | ||
} | ||
}, | ||
|
||
test: function(done) { | ||
var self = this; | ||
const configuration = this.configuration; | ||
var Promise = require('bluebird'); | ||
|
||
const client = configuration.newClient( | ||
{}, | ||
{ | ||
promiseLibrary: Promise, | ||
sslValidate: false | ||
} | ||
); | ||
|
||
client.connect().then(function(client) { | ||
var db = client.db(self.configuration.db); | ||
var promise = db.collection('test').insert({ a: 1 }); | ||
expect(promise).to.be.an.instanceOf(Promise); | ||
|
||
promise.then(function() { | ||
client.close(done); | ||
}); | ||
}); | ||
} | ||
class CustomPromise extends Promise {} | ||
CustomPromise.prototype.isCustomMongo = true; | ||
|
||
const parent = { s: { promiseLibrary: CustomPromise } }; | ||
|
||
describe('Optional PromiseLibrary / maybePromise', function() { | ||
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)); | ||
expect(getNativePromise()).to.not.have.property('isCustomMongo'); | ||
expect(getCustomPromise()).to.have.property('isCustomMongo'); | ||
expect(getNativePromise()).to.have.property('then'); | ||
expect(getCustomPromise()).to.have.property('then'); | ||
done(); | ||
}); | ||
|
||
it('should return a promise with extra property CustomMongo', function() { | ||
const prom = maybePromise(parent, undefined, () => 'example'); | ||
expect(prom).to.have.property('isCustomMongo'); | ||
expect(prom).to.have.property('then'); | ||
}); | ||
|
||
it('should return a native promise with no parent', function(done) { | ||
const prom = maybePromise(undefined, undefined, () => 'example'); | ||
expect(prom).to.not.have.property('isCustomMongo'); | ||
expect(prom).to.have.property('then'); | ||
done(); | ||
}); | ||
|
||
it('should return a native promise with empty parent', function(done) { | ||
const prom = maybePromise({}, undefined, () => 'example'); | ||
expect(prom).to.not.have.property('isCustomMongo'); | ||
expect(prom).to.have.property('then'); | ||
done(); | ||
}); | ||
|
||
it('should return a native promise with emtpy "s"', function(done) { | ||
const prom = maybePromise({ s: {} }, undefined, () => 'example'); | ||
expect(prom).to.not.have.property('isCustomMongo'); | ||
expect(prom).to.have.property('then'); | ||
done(); | ||
}); | ||
|
||
it('should have cursor return native promise', function(done) { | ||
const configuration = this.configuration; | ||
const client = this.configuration.newClient({ w: 1 }, { poolSize: 1 }); | ||
client.connect((err, client) => { | ||
expect(err).to.not.exist; | ||
const db = client.db(configuration.db); | ||
const collection = db.collection('test'); | ||
const cursor = collection.find({}); | ||
const isPromise = cursor.toArray(); | ||
expect(isPromise).to.not.have.property('isCustomMongo'); | ||
expect(isPromise).to.have.property('then'); | ||
isPromise.then(() => client.close(done)); | ||
}); | ||
}); | ||
|
||
it('should have cursor return custom promise from new client options', function(done) { | ||
const configuration = this.configuration; | ||
const client = this.configuration.newClient( | ||
{ w: 1 }, | ||
{ poolSize: 1, promiseLibrary: CustomPromise } | ||
); | ||
client.connect((err, client) => { | ||
const db = client.db(configuration.db); | ||
expect(err).to.be.null; | ||
const collection = db.collection('test'); | ||
const cursor = collection.find({}); | ||
const isPromise = cursor.toArray(); | ||
expect(isPromise).to.have.property('isCustomMongo'); | ||
expect(isPromise).to.have.property('then'); | ||
isPromise.then(() => client.close(done)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters