Skip to content

Commit

Permalink
Revert "add test case for clone function"
Browse files Browse the repository at this point in the history
This reverts commit 88aa12e.
  • Loading branch information
Emman committed Nov 9, 2020
1 parent 88aa12e commit 917bfec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 34 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"request": "^2.88.0",
"rsvp": "^4.8.4",
"sinon": "^6.1.4",
"updtr": "^3.1.0"
"updtr": "^3.1.0",
"rewire": "^5.0.0"
}
}
21 changes: 21 additions & 0 deletions test/clone.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const rewire = require('rewire');
const _cloneOptions = rewire('../').__get__('_cloneOptions');
const http = require('http');
const t = require('chai').assert;

describe('Clone option function', function () {
it('should not clone agent and non-own properties', function (done) {
const options = Object.create({ parent: true });
options.cloneable = { a: 1 };
options.agent = new http.Agent({ keepAlive: true });
const cloned = _cloneOptions(options);
t.strictEqual(options.agent, cloned.agent);
t.notStrictEqual(options.cloneable, cloned.cloneable);
t.equal(options.cloneable.a, cloned.cloneable.a)
t.isUndefined(cloned.parent);
t.isTrue(options.parent);
done();
});
});
33 changes: 0 additions & 33 deletions test/strategies.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

var request = require('../');
const http = require('http');
var t = require('chai').assert;

describe('RetryStrategies', function () {
Expand Down Expand Up @@ -44,38 +43,6 @@ describe('RetryStrategies', function () {
});
});

it('should not clone `options.agent`', function (done) {
const agent = new http.Agent({ keepAlive: true });
const cloneable = { a: true };
var strategy = function (err, response, body, options) {
options.url = 'http://www.filltext.com/?rows=1&err=200'; //overwrite url to return 200
t.strictEqual(agent, options.agent);
t.deepEqual(cloneable, options.cloneable);
t.notEqual(cloneable, options.cloneable);
return {
mustRetry: true,
options: options,
};
};

request({
url: 'http://www.filltext.com/?rows=1&err=500', // returns a 500 status
maxAttempts: 3,
agent: agent,
retryDelay: 100,
cloneable: cloneable,
retryStrategy: strategy
}, function(err, response, body) {
if(err) done(err);

t.strictEqual(200, response.statusCode);
t.strictEqual(agent, this.options.agent);
t.deepEqual(cloneable, this.options.cloneable);
t.notEqual(cloneable, this.options.cloneable);
done();
});
});

it('should not overwrite `options` object if strategy did not returned it', function (done) {
var strategy = function (err, response, body, options) {
options.url = 'http://www.filltext.com/?rows=1&err=200'; //overwrite url to return 200
Expand Down

0 comments on commit 917bfec

Please sign in to comment.