From c3a05b776208c7082e2835d7fe0ea02d67e07dcf Mon Sep 17 00:00:00 2001 From: Erik Singleton Date: Mon, 4 Feb 2019 14:01:15 -0800 Subject: [PATCH] Adds test for #6968 Fixes tests from #6413 --- __tests__/util/request-manager.js | 24 +++++++++++++++++++++++- src/util/request-manager.js | 2 +- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/__tests__/util/request-manager.js b/__tests__/util/request-manager.js index be9b964653..e671c845a7 100644 --- a/__tests__/util/request-manager.js +++ b/__tests__/util/request-manager.js @@ -186,6 +186,7 @@ test('RequestManager.execute timeout error with default maxRetryAttempts', async for (const statusCode of [403, 442]) { test(`RequestManager.execute Request ${statusCode} error`, async () => { + jest.resetModules(); // The await await is just to silence Flow - https://github.com/facebook/flow/issues/6064 const config = await await Config.create({}, new Reporter()); const mockStatusCode = statusCode; @@ -203,13 +204,34 @@ for (const statusCode of [403, 442]) { resolve: body => {}, reject: err => { expect(err.message).toBe( - `https://localhost:port/?nocache: Request "https://localhost:port/?nocache" returned a 403`, + `https://localhost:port/?nocache: Request "https://localhost:port/?nocache" returned a ${statusCode}`, ); }, }); }); } +test('RequestManager.execute propagates non HTTP errors', async () => { + jest.resetModules(); + jest.mock('request', factory => options => { + options.callback(new Error('bad stuff happened'), {}, ''); + return { + on: () => {}, + }; + }); + const config = await await Config.create({}, new Reporter()); + await config.requestManager.execute({ + params: { + url: `https://localhost:port/?nocache`, + headers: {Connection: 'close'}, + }, + resolve: body => {}, + reject: err => { + expect(err.message).toBe('https://localhost:port/?nocache: bad stuff happened'); + }, + }); +}); + test('RequestManager.execute one time password error on npm request', async () => { jest.resetModules(); jest.mock('request', factory => options => { diff --git a/src/util/request-manager.js b/src/util/request-manager.js index 60cdb442f2..09e47df2c8 100644 --- a/src/util/request-manager.js +++ b/src/util/request-manager.js @@ -356,7 +356,7 @@ export default class RequestManager { */ execute(opts: RequestOptions) { - const {params} = opts; + const {params} = {...opts}; const {reporter} = this; const buildNext = fn => data => {