From 842803c7efd5a811a2e96b432e610b9acf98d0af Mon Sep 17 00:00:00 2001 From: Brian C Date: Tue, 20 Jun 2017 08:59:07 -0500 Subject: [PATCH] Fix over-eager deprecation warnings (#1333) * WIP * Remove console.log messages --- lib/query.js | 14 +++++++++++-- lib/utils.js | 2 +- test/integration/client/deprecation-tests.js | 22 ++++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 test/integration/client/deprecation-tests.js diff --git a/lib/query.js b/lib/query.js index 652db38e..b8f6d77e 100644 --- a/lib/query.js +++ b/lib/query.js @@ -57,8 +57,18 @@ Query.prototype.catch = function(callback) { Query.prototype._getPromise = function () { if (this._promise) return this._promise; this._promise = new Promise(function(resolve, reject) { - this._once('end', resolve); - this._once('error', reject); + var onEnd = function (result) { + this.removeListener('error', onError); + this.removeListener('end', onEnd); + resolve(result); + }; + var onError = function (err) { + this.removeListener('error', onError); + this.removeListener('end', onEnd); + reject(err); + }; + this._on('end', onEnd); + this._on('error', onError); }.bind(this)); return this._promise; }; diff --git a/lib/utils.js b/lib/utils.js index 5049b5af..eccf5069 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -139,7 +139,7 @@ function normalizeQueryConfig (config, values, callback) { return config; } -var queryEventEmitterOverloadDeprecationMessage = 'Using the automatically created return value from client.query as an event emitter is deprecated. Please see the upgrade guide at https://node-postgres.com/guides/upgrading'; +var queryEventEmitterOverloadDeprecationMessage = 'Using the automatically created return value from client.query as an event emitter is deprecated and will be removed in pg@7.0. Please see the upgrade guide at https://node-postgres.com/guides/upgrading'; var deprecateEventEmitter = function(Emitter) { var Result = function () { diff --git a/test/integration/client/deprecation-tests.js b/test/integration/client/deprecation-tests.js new file mode 100644 index 00000000..39160d5a --- /dev/null +++ b/test/integration/client/deprecation-tests.js @@ -0,0 +1,22 @@ +var helper = require('./test-helper') +process.noDeprecation = false +process.on('warning', function () { + throw new Error('Should not emit deprecation warning') +}) + +var client = new helper.pg.Client() + +client.connect(function (err) { + if (err) throw err + client.query('SELECT NOW()') + .then(function (res) { + client.query('SELECT NOW()', function () { + client.end(function () { + }) + }) + }).catch(function (err) { + setImmediate(function () { + throw err + }) + }) +})