Skip to content

Commit

Permalink
Adds test for yarnpkg#6968
Browse files Browse the repository at this point in the history
Fixes tests from yarnpkg#6413
  • Loading branch information
Erik Singleton committed Feb 4, 2019
1 parent 19ec98c commit c3a05b7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 23 additions & 1 deletion __tests__/util/request-manager.js
Expand Up @@ -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;
Expand All @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/util/request-manager.js
Expand Up @@ -356,7 +356,7 @@ export default class RequestManager {
*/

execute(opts: RequestOptions) {
const {params} = opts;
const {params} = {...opts};
const {reporter} = this;

const buildNext = fn => data => {
Expand Down

0 comments on commit c3a05b7

Please sign in to comment.