From 108f0e404bc0503c984877b2700c2049669b1304 Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Tue, 3 Mar 2020 12:17:39 +0100 Subject: [PATCH 1/3] feat: avoid parsing JSON in transform if responseType is JSON --- source/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/source/index.ts b/source/index.ts index 1dbf44679..9d508bbf0 100644 --- a/source/index.ts +++ b/source/index.ts @@ -69,6 +69,10 @@ const defaults: Defaults = { context: {}, _pagination: { transform: (response: Response) => { + if (response.request.optinos.responseType === 'json') { + return response.body; + } + return JSON.parse(response.body as string); }, paginate: response => { From 20b78b53bd80fd22fbafc89b3e02a00b1bf2854f Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Tue, 3 Mar 2020 12:32:57 +0100 Subject: [PATCH 2/3] fix: typo --- source/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/index.ts b/source/index.ts index 9d508bbf0..21882cdeb 100644 --- a/source/index.ts +++ b/source/index.ts @@ -69,7 +69,7 @@ const defaults: Defaults = { context: {}, _pagination: { transform: (response: Response) => { - if (response.request.optinos.responseType === 'json') { + if (response.request.options.responseType === 'json') { return response.body; } From 3389ee8183a942febc3168048c7341fde54e9789 Mon Sep 17 00:00:00 2001 From: Julian Hundeloh Date: Tue, 3 Mar 2020 13:43:35 +0000 Subject: [PATCH 3/3] test: add test --- test/pagination.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/pagination.ts b/test/pagination.ts index 031294dbe..5d457e8f3 100644 --- a/test/pagination.ts +++ b/test/pagination.ts @@ -47,6 +47,16 @@ test('retrieves all elements', withServer, async (t, server, got) => { t.deepEqual(result, [1, 2]); }); +test('retrieves all elements with JSON responseType', withServer, async (t, server, got) => { + attachHandler(server, 2); + + const result = await got.extend({ + responseType: 'json' + }).paginate.all(''); + + t.deepEqual(result, [1, 2]); +}); + test('points to defaults when extending Got without custom `_pagination`', withServer, async (t, server, got) => { attachHandler(server, 2);