Skip to content

Commit 93a0017

Browse files
authored
remove runtime dependency on request (#5076)
1 parent 4dc4a3a commit 93a0017

File tree

13 files changed

+2703
-2776
lines changed

13 files changed

+2703
-2776
lines changed

package-lock.json

Lines changed: 2402 additions & 2407 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"commander": "2.18.0",
2929
"deepcopy": "1.0.0",
3030
"express": "4.16.2",
31+
"follow-redirects": "1.5.8",
3132
"intersect": "1.0.1",
3233
"lodash": "4.17.11",
3334
"lru-cache": "4.1.3",
@@ -36,7 +37,6 @@
3637
"parse": "2.1.0",
3738
"pg-promise": "8.4.6",
3839
"redis": "2.8.0",
39-
"request": "2.88.0",
4040
"semver": "5.5.1",
4141
"tv4": "1.3.0",
4242
"uuid": "^3.1.0",
@@ -69,6 +69,7 @@
6969
"nodemon": "1.18.4",
7070
"nyc": "^12.0.2",
7171
"prettier": "1.14.3",
72+
"request": "2.88.0",
7273
"request-promise": "4.2.2",
7374
"supports-color": "^5.4.0"
7475
},

spec/HTTPRequest.spec.js

Lines changed: 27 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -50,104 +50,60 @@ describe('httpRequest', () => {
5050
it('should do /hello', done => {
5151
httpRequest({
5252
url: httpRequestServer + '/hello',
53-
}).then(
54-
function(httpResponse) {
55-
expect(httpResponse.status).toBe(200);
56-
expect(httpResponse.buffer).toEqual(new Buffer('{"response":"OK"}'));
57-
expect(httpResponse.text).toEqual('{"response":"OK"}');
58-
expect(httpResponse.data.response).toEqual('OK');
59-
done();
60-
},
61-
function() {
62-
fail('should not fail');
63-
done();
64-
}
65-
);
66-
});
67-
68-
it('should do /hello with callback and promises', done => {
69-
let calls = 0;
70-
httpRequest({
71-
url: httpRequestServer + '/hello',
72-
success: function() {
73-
calls++;
74-
},
75-
error: function() {
76-
calls++;
77-
},
78-
}).then(
79-
function(httpResponse) {
80-
expect(calls).toBe(1);
81-
expect(httpResponse.status).toBe(200);
82-
expect(httpResponse.buffer).toEqual(new Buffer('{"response":"OK"}'));
83-
expect(httpResponse.text).toEqual('{"response":"OK"}');
84-
expect(httpResponse.data.response).toEqual('OK');
85-
done();
86-
},
87-
function() {
88-
fail('should not fail');
89-
done();
90-
}
91-
);
53+
}).then(function(httpResponse) {
54+
expect(httpResponse.status).toBe(200);
55+
expect(httpResponse.buffer).toEqual(new Buffer('{"response":"OK"}'));
56+
expect(httpResponse.text).toEqual('{"response":"OK"}');
57+
expect(httpResponse.data.response).toEqual('OK');
58+
done();
59+
}, done.fail);
9260
});
9361

9462
it('should do not follow redirects by default', done => {
9563
httpRequest({
9664
url: httpRequestServer + '/301',
97-
}).then(
98-
function(httpResponse) {
99-
expect(httpResponse.status).toBe(301);
100-
done();
101-
},
102-
function() {
103-
fail('should not fail');
104-
done();
105-
}
106-
);
65+
}).then(function(httpResponse) {
66+
expect(httpResponse.status).toBe(301);
67+
done();
68+
}, done.fail);
10769
});
10870

10971
it('should follow redirects when set', done => {
11072
httpRequest({
11173
url: httpRequestServer + '/301',
11274
followRedirects: true,
113-
}).then(
114-
function(httpResponse) {
115-
expect(httpResponse.status).toBe(200);
116-
expect(httpResponse.buffer).toEqual(new Buffer('{"response":"OK"}'));
117-
expect(httpResponse.text).toEqual('{"response":"OK"}');
118-
expect(httpResponse.data.response).toEqual('OK');
119-
done();
120-
},
121-
function() {
122-
fail('should not fail');
123-
done();
124-
}
125-
);
75+
}).then(function(httpResponse) {
76+
expect(httpResponse.status).toBe(200);
77+
expect(httpResponse.buffer).toEqual(new Buffer('{"response":"OK"}'));
78+
expect(httpResponse.text).toEqual('{"response":"OK"}');
79+
expect(httpResponse.data.response).toEqual('OK');
80+
done();
81+
}, done.fail);
12682
});
12783

12884
it('should fail on 404', done => {
12985
let calls = 0;
13086
httpRequest({
13187
url: httpRequestServer + '/404',
132-
success: function() {
88+
}).then(
89+
function() {
13390
calls++;
13491
fail('should not succeed');
13592
done();
13693
},
137-
error: function(httpResponse) {
94+
function(httpResponse) {
13895
calls++;
13996
expect(calls).toBe(1);
14097
expect(httpResponse.status).toBe(404);
14198
expect(httpResponse.buffer).toEqual(new Buffer('NO'));
14299
expect(httpResponse.text).toEqual('NO');
143100
expect(httpResponse.data).toBe(undefined);
144101
done();
145-
},
146-
});
102+
}
103+
);
147104
});
148105

149106
it('should post on echo', done => {
150-
let calls = 0;
151107
httpRequest({
152108
method: 'POST',
153109
url: httpRequestServer + '/echo',
@@ -157,15 +113,8 @@ describe('httpRequest', () => {
157113
headers: {
158114
'Content-Type': 'application/json',
159115
},
160-
success: function() {
161-
calls++;
162-
},
163-
error: function() {
164-
calls++;
165-
},
166116
}).then(
167117
function(httpResponse) {
168-
expect(calls).toBe(1);
169118
expect(httpResponse.status).toBe(200);
170119
expect(httpResponse.data).toEqual({ foo: 'bar' });
171120
done();
@@ -220,15 +169,10 @@ describe('httpRequest', () => {
220169
it('should fail gracefully', done => {
221170
httpRequest({
222171
url: 'http://not a good url',
223-
success: function() {
224-
fail('should not succeed');
225-
done();
226-
},
227-
error: function(error) {
228-
expect(error).not.toBeUndefined();
229-
expect(error).not.toBeNull();
230-
done();
231-
},
172+
}).then(done.fail, function(error) {
173+
expect(error).not.toBeUndefined();
174+
expect(error).not.toBeNull();
175+
done();
232176
});
233177
});
234178

0 commit comments

Comments
 (0)