Loading lib/bluebird-captured-trace-fresh.jsdeleted 100644 → 0 +0 −1 Original line number Diff line number Diff line module.exports = require("bluebird/js/main/captured_trace")(); lib/bluebird-fresh.jsdeleted 100644 → 0 +0 −2 Original line number Diff line number Diff line // See: https://github.com/petkaantonov/bluebird#for-library-authors module.exports = require("bluebird/js/main/promise")(); lib/rp.js +1 −27 Original line number Diff line number Diff line 'use strict'; var Bluebird = require('./bluebird-fresh.js'), CapturedTrace = require('./bluebird-captured-trace-fresh.js'), var Bluebird = require('bluebird'), assign = require('lodash/object/assign'), forEach = require('lodash/collection/forEach'), isFunction = require('lodash/lang/isFunction'), Loading Loading @@ -85,11 +84,6 @@ function RP$callback(err, response, body) { throw thrownException; } // Mimic original behavior of errors emitted by request with no error listener registered if (err && isFunction(self._rp_callbackOrig) === false && self._rp_promise_in_use !== true && self.listeners('error').length === 1) { throw err; } } var originalInit = request.Request.prototype.init; Loading @@ -105,7 +99,6 @@ request.Request.prototype.init = function RP$initInterceptor(options) { self._rp_resolve = resolve; self._rp_reject = reject; }); self._rp_promise._rp_in_use = false; self._rp_callbackOrig = self.callback; self.callback = RP$callback; Loading @@ -124,11 +117,6 @@ request.Request.prototype.init = function RP$initInterceptor(options) { }; function markPromiseInUse(requestInstance) { requestInstance._rp_promise_in_use = true; requestInstance._rp_promise._rp_in_use = true; } function expose(methodToExpose, exposeAs) { exposeAs = exposeAs || methodToExpose; Loading @@ -140,7 +128,6 @@ function expose(methodToExpose, exposeAs) { } request.Request.prototype[exposeAs] = function RP$exposed() { markPromiseInUse(this); return this._rp_promise[methodToExpose].apply(this._rp_promise, arguments); }; Loading @@ -151,21 +138,8 @@ expose('catch'); expose('finally'); request.Request.prototype.promise = function RP$promise() { markPromiseInUse(this); return this._rp_promise; }; var printRejectionReason = CapturedTrace.formatAndLogError || CapturedTrace.possiblyUnhandledRejection; Bluebird.onPossiblyUnhandledRejection(function (reason, promise) { // For whatever reason we don't see _rp_in_use here at all after then is called. --> We compare to false instead of true. if (promise._rp_in_use !== false) { printRejectionReason(reason, 'Possibly unhandled '); } // else: The user did not call .then(...) // --> We need to assume that this request is processed with a callback or a pipe etc. }); module.exports = request; test/spec/request-test.js +85 −11 Original line number Diff line number Diff line Loading @@ -726,7 +726,7 @@ describe('Request-Promise', function () { process.stderr.write = origStderrWrite; }); it('by muting them if .then(...) was not called yet', function (done) { it('by printing them if .then(...) was not called yet', function (done) { rp('http://localhost:1/200', function (err) { if (!err) { Loading @@ -734,8 +734,8 @@ describe('Request-Promise', function () { return; } setTimeout(function () { if (stderr.length > 0) { done(new Error('Observed unexpected output to stderr.')); if (stderr.length === 0) { done(new Error('Observed no output to stderr.')); } else { done(); } Loading Loading @@ -852,16 +852,51 @@ describe('Request-Promise', function () { describe("should not alter Request's original behavior", function () { it('for emitting errors with no listener', function () { expect(function () { rp({}); }).to.throw(); describe('but also include unhandled rejections', function () { var origStderrWrite, stderr; beforeEach(function () { origStderrWrite = process.stderr.write; stderr = []; process.stderr.write = function (string, encoding, fd) { stderr.push(string); }; }); afterEach(function () { process.stderr.write = origStderrWrite; }); it('for emitting errors to the callback', function (done) { it('when emitting errors to the callback', function (done) { var counter = 2; function countDown() { counter -= 1; if (counter === 0) { done(); } } rp({}, function (err) { if (err) { done(); } if (err) { countDown(); } else { done(new Error('Observed no output to stderr.')); } }); // Unhandled rejection expected setTimeout(function () { if (stderr.length === 0) { done(new Error('Observed no output to stderr.')); } else { countDown(); } }); }); }); it('for registering a handler to the emitted complete event', function (done) { Loading Loading @@ -912,6 +947,45 @@ describe('Request-Promise', function () { }); describe("should alter Request's original behavior", function () { describe('by preferring unhandled rejections', function () { var origStderrWrite, stderr; beforeEach(function () { origStderrWrite = process.stderr.write; stderr = []; process.stderr.write = function(string, encoding, fd) { stderr.push(string); }; }); afterEach(function () { process.stderr.write = origStderrWrite; }); it('when emitting errors with no listener', function (done) { expect(function () { rp({}); }).to.not.throw(); // Unhandled rejection expected setTimeout(function () { if (stderr.length === 0) { done(new Error('Observed no output to stderr.')); } else { done(); } }); }); }); }); describe('should still allow to require Request independently', function (done) { it('by not interfering with Request required afterwards', function (done) { Loading Loading
lib/bluebird-captured-trace-fresh.jsdeleted 100644 → 0 +0 −1 Original line number Diff line number Diff line module.exports = require("bluebird/js/main/captured_trace")();
lib/bluebird-fresh.jsdeleted 100644 → 0 +0 −2 Original line number Diff line number Diff line // See: https://github.com/petkaantonov/bluebird#for-library-authors module.exports = require("bluebird/js/main/promise")();
lib/rp.js +1 −27 Original line number Diff line number Diff line 'use strict'; var Bluebird = require('./bluebird-fresh.js'), CapturedTrace = require('./bluebird-captured-trace-fresh.js'), var Bluebird = require('bluebird'), assign = require('lodash/object/assign'), forEach = require('lodash/collection/forEach'), isFunction = require('lodash/lang/isFunction'), Loading Loading @@ -85,11 +84,6 @@ function RP$callback(err, response, body) { throw thrownException; } // Mimic original behavior of errors emitted by request with no error listener registered if (err && isFunction(self._rp_callbackOrig) === false && self._rp_promise_in_use !== true && self.listeners('error').length === 1) { throw err; } } var originalInit = request.Request.prototype.init; Loading @@ -105,7 +99,6 @@ request.Request.prototype.init = function RP$initInterceptor(options) { self._rp_resolve = resolve; self._rp_reject = reject; }); self._rp_promise._rp_in_use = false; self._rp_callbackOrig = self.callback; self.callback = RP$callback; Loading @@ -124,11 +117,6 @@ request.Request.prototype.init = function RP$initInterceptor(options) { }; function markPromiseInUse(requestInstance) { requestInstance._rp_promise_in_use = true; requestInstance._rp_promise._rp_in_use = true; } function expose(methodToExpose, exposeAs) { exposeAs = exposeAs || methodToExpose; Loading @@ -140,7 +128,6 @@ function expose(methodToExpose, exposeAs) { } request.Request.prototype[exposeAs] = function RP$exposed() { markPromiseInUse(this); return this._rp_promise[methodToExpose].apply(this._rp_promise, arguments); }; Loading @@ -151,21 +138,8 @@ expose('catch'); expose('finally'); request.Request.prototype.promise = function RP$promise() { markPromiseInUse(this); return this._rp_promise; }; var printRejectionReason = CapturedTrace.formatAndLogError || CapturedTrace.possiblyUnhandledRejection; Bluebird.onPossiblyUnhandledRejection(function (reason, promise) { // For whatever reason we don't see _rp_in_use here at all after then is called. --> We compare to false instead of true. if (promise._rp_in_use !== false) { printRejectionReason(reason, 'Possibly unhandled '); } // else: The user did not call .then(...) // --> We need to assume that this request is processed with a callback or a pipe etc. }); module.exports = request;
test/spec/request-test.js +85 −11 Original line number Diff line number Diff line Loading @@ -726,7 +726,7 @@ describe('Request-Promise', function () { process.stderr.write = origStderrWrite; }); it('by muting them if .then(...) was not called yet', function (done) { it('by printing them if .then(...) was not called yet', function (done) { rp('http://localhost:1/200', function (err) { if (!err) { Loading @@ -734,8 +734,8 @@ describe('Request-Promise', function () { return; } setTimeout(function () { if (stderr.length > 0) { done(new Error('Observed unexpected output to stderr.')); if (stderr.length === 0) { done(new Error('Observed no output to stderr.')); } else { done(); } Loading Loading @@ -852,16 +852,51 @@ describe('Request-Promise', function () { describe("should not alter Request's original behavior", function () { it('for emitting errors with no listener', function () { expect(function () { rp({}); }).to.throw(); describe('but also include unhandled rejections', function () { var origStderrWrite, stderr; beforeEach(function () { origStderrWrite = process.stderr.write; stderr = []; process.stderr.write = function (string, encoding, fd) { stderr.push(string); }; }); afterEach(function () { process.stderr.write = origStderrWrite; }); it('for emitting errors to the callback', function (done) { it('when emitting errors to the callback', function (done) { var counter = 2; function countDown() { counter -= 1; if (counter === 0) { done(); } } rp({}, function (err) { if (err) { done(); } if (err) { countDown(); } else { done(new Error('Observed no output to stderr.')); } }); // Unhandled rejection expected setTimeout(function () { if (stderr.length === 0) { done(new Error('Observed no output to stderr.')); } else { countDown(); } }); }); }); it('for registering a handler to the emitted complete event', function (done) { Loading Loading @@ -912,6 +947,45 @@ describe('Request-Promise', function () { }); describe("should alter Request's original behavior", function () { describe('by preferring unhandled rejections', function () { var origStderrWrite, stderr; beforeEach(function () { origStderrWrite = process.stderr.write; stderr = []; process.stderr.write = function(string, encoding, fd) { stderr.push(string); }; }); afterEach(function () { process.stderr.write = origStderrWrite; }); it('when emitting errors with no listener', function (done) { expect(function () { rp({}); }).to.not.throw(); // Unhandled rejection expected setTimeout(function () { if (stderr.length === 0) { done(new Error('Observed no output to stderr.')); } else { done(); } }); }); }); }); describe('should still allow to require Request independently', function (done) { it('by not interfering with Request required afterwards', function (done) { Loading