Skip to content

Commit c3a05b7

Browse files
author
Erik Singleton
committed
Adds test for yarnpkg#6968
Fixes tests from yarnpkg#6413
1 parent 19ec98c commit c3a05b7

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

__tests__/util/request-manager.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ test('RequestManager.execute timeout error with default maxRetryAttempts', async
186186

187187
for (const statusCode of [403, 442]) {
188188
test(`RequestManager.execute Request ${statusCode} error`, async () => {
189+
jest.resetModules();
189190
// The await await is just to silence Flow - https://github.com/facebook/flow/issues/6064
190191
const config = await await Config.create({}, new Reporter());
191192
const mockStatusCode = statusCode;
@@ -203,13 +204,34 @@ for (const statusCode of [403, 442]) {
203204
resolve: body => {},
204205
reject: err => {
205206
expect(err.message).toBe(
206-
`https://localhost:port/?nocache: Request "https://localhost:port/?nocache" returned a 403`,
207+
`https://localhost:port/?nocache: Request "https://localhost:port/?nocache" returned a ${statusCode}`,
207208
);
208209
},
209210
});
210211
});
211212
}
212213

214+
test('RequestManager.execute propagates non HTTP errors', async () => {
215+
jest.resetModules();
216+
jest.mock('request', factory => options => {
217+
options.callback(new Error('bad stuff happened'), {}, '');
218+
return {
219+
on: () => {},
220+
};
221+
});
222+
const config = await await Config.create({}, new Reporter());
223+
await config.requestManager.execute({
224+
params: {
225+
url: `https://localhost:port/?nocache`,
226+
headers: {Connection: 'close'},
227+
},
228+
resolve: body => {},
229+
reject: err => {
230+
expect(err.message).toBe('https://localhost:port/?nocache: bad stuff happened');
231+
},
232+
});
233+
});
234+
213235
test('RequestManager.execute one time password error on npm request', async () => {
214236
jest.resetModules();
215237
jest.mock('request', factory => options => {

src/util/request-manager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export default class RequestManager {
356356
*/
357357

358358
execute(opts: RequestOptions) {
359-
const {params} = opts;
359+
const {params} = {...opts};
360360
const {reporter} = this;
361361

362362
const buildNext = fn => data => {

0 commit comments

Comments
 (0)