Skip to content

Commit

Permalink
fix: use extend instead of object.assign (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Jul 9, 2021
1 parent ed00e63 commit 8c8dcdd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -2,6 +2,7 @@

var { PassThrough } = require('stream');
var debug = require('debug')('retry-request');
var extend = require('extend');

var DEFAULTS = {
objectMode: false,
Expand Down Expand Up @@ -66,7 +67,7 @@ function retryRequest(requestOpts, opts, callback) {
}

var manualCurrentRetryAttemptWasSet = opts && typeof opts.currentRetryAttempt === 'number';
opts = Object.assign({}, DEFAULTS, opts);
opts = extend({}, DEFAULTS, opts);

if (typeof opts.request === 'undefined') {
try {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -24,7 +24,8 @@
"node": ">=8.10.0"
},
"dependencies": {
"debug": "^4.1.1"
"debug": "^4.1.1",
"extend": "^3.0.2"
},
"devDependencies": {
"async": "^3.0.1",
Expand Down
19 changes: 19 additions & 0 deletions test.js
Expand Up @@ -216,6 +216,25 @@ describe('retry-request', function () {
});

describe('overriding', function () {
it('should ignore undefined options', function (done) {
var numAttempts = 0;
var error = new Error('ENOTFOUND');

var opts = {
noResponseRetries: undefined,
request: function (_, callback) {
numAttempts++;
callback(error);
}
};

retryRequest(URI_NON_EXISTENT, opts, function (err) {
assert.strictEqual(numAttempts, 3);
assert.strictEqual(err, error);
done();
});
});

it('should allow overriding retries', function (done) {
var opts = { retries: 0 };

Expand Down

0 comments on commit 8c8dcdd

Please sign in to comment.