Skip to content

Commit

Permalink
Fix normalizeArguments() not copying non-enumerable properties
Browse files Browse the repository at this point in the history
Fixes #1186
  • Loading branch information
szmarczak committed May 2, 2020
1 parent 767d745 commit 278c421
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
options.maxRedirects = options.maxRedirects ?? 0;

// Set non-enumerable properties
setNonEnumerableProperties([defaults, options], options);
setNonEnumerableProperties([defaults, rawOptions], options);

return options as NormalizedOptions;
}
Expand Down
11 changes: 11 additions & 0 deletions test/normalize-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@ test('should merge options replacing responseType', t => {

t.is(options.responseType, responseType);
});

test('should copy non-numerable properties', t => {
const options = {
json: {hello: '123'}
};

const merged = got.mergeOptions(got.defaults.options, options);
const mergedTwice = got.mergeOptions(got.defaults.options, merged);

t.is(mergedTwice.json, options.json);
});
12 changes: 8 additions & 4 deletions test/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ test('ignores the `resolveBodyOnly` option', withServer, async (t, server, got)
t.deepEqual(items, [1, 2]);
});

test.failing('allowGetBody sends json payload with .paginate()', withBodyParsingServer, async (t, server, got) => {
test('allowGetBody sends json payload with .paginate()', withBodyParsingServer, async (t, server, got) => {
server.get('/', (request, response) => {
if (request.body.hello !== 'world') {
response.statusCode = 400;
Expand All @@ -318,15 +318,19 @@ test.failing('allowGetBody sends json payload with .paginate()', withBodyParsing
response.end(JSON.stringify([1, 2, 3]));
});

const iterator = got.paginate({
const iterator = got.paginate<number>({
allowGetBody: true,
json: {hello: 'world'},
retry: 0
});

const result = await iterator.next();
const results: number[] = [];

for await (const item of iterator) {
results.push(item);
}

t.deepEqual(result.value, [1, 2, 3]);
t.deepEqual(results, [1, 2, 3]);
});

test('`requestLimit` works', withServer, async (t, server, got) => {
Expand Down

0 comments on commit 278c421

Please sign in to comment.