Skip to content

Commit 9c04a7c

Browse files
zero1fiveszmarczak
authored andcommittedJun 21, 2019
Fix default retry option value when specifying a number (#809)
Co-authored-by: Szymon Marczak <sz.marczak@gmail.com>
1 parent 3fdabce commit 9c04a7c

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed
 

‎source/merge.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,24 @@ export default function merge<Target extends Record<string, unknown>, Source ext
4343
}
4444

4545
export function mergeOptions<T extends Options>(...sources: T[]): T & {hooks: Partial<Hooks>} {
46-
const mergedOptions = merge({} as T & {hooks: Partial<Hooks>}, ...sources.map(source => source || {}));
46+
sources = sources.map(source => {
47+
if (!source) {
48+
return {};
49+
}
50+
51+
if (is.object(source.retry)) {
52+
return source;
53+
}
54+
55+
return {
56+
...source,
57+
retry: {
58+
retries: source.retry
59+
}
60+
};
61+
}) as T[];
62+
63+
const mergedOptions = merge({} as T & {hooks: Partial<Hooks>}, ...sources);
4764

4865
const hooks = knownHookEvents.reduce((accumulator, current) => ({...accumulator, [current]: []}), {}) as Record<HookEvent, HookType[]>;
4966

‎test/retry.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ test('doesn\'t retry when set to false', withServer, async (t, server, got) => {
274274
t.is(retryCount, 0);
275275
});
276276

277-
test('works when defaults.options.retry is not an object', withServer, async (t, server, got) => {
277+
test('works when defaults.options.retry is a number', withServer, async (t, server, got) => {
278278
server.get('/', handler413);
279279

280280
const instance = got.extend({
@@ -284,7 +284,7 @@ test('works when defaults.options.retry is not an object', withServer, async (t,
284284
const {retryCount} = await instance({
285285
throwHttpErrors: false
286286
});
287-
t.is(retryCount, 0);
287+
t.is(retryCount, 2);
288288
});
289289

290290
test('retry function can throw', withServer, async (t, server, got) => {

0 commit comments

Comments
 (0)
Please sign in to comment.