Skip to content

Commit d82a992

Browse files
authored
fix: node-fetch doesn't support the qs option (#213)
1 parent bbf75ee commit d82a992

File tree

3 files changed

+4
-9
lines changed

3 files changed

+4
-9
lines changed

src/targets/node/fetch.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ module.exports = function (source, options) {
2222
var code = new CodeBuilder(opts.indent)
2323

2424
code.push('const fetch = require(\'node-fetch\');')
25-
var url = source.url
25+
var url = source.fullUrl
2626
var reqOpts = {
2727
method: source.method
2828
}
2929

30-
if (Object.keys(source.queryObj).length) {
31-
reqOpts.qs = source.queryObj
32-
}
33-
3430
if (Object.keys(source.headersObj).length) {
3531
reqOpts.headers = source.headersObj
3632
}

test/fixtures/output/node/fetch/full.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ const encodedParams = new URLSearchParams();
44

55
encodedParams.set('foo', 'bar');
66

7-
let url = 'http://mockbin.com/har';
7+
let url = 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value';
88

99
let options = {
1010
method: 'POST',
11-
qs: {foo: ['bar', 'baz'], baz: 'abc', key: 'value'},
1211
headers: {
1312
accept: 'application/json',
1413
'content-type': 'application/x-www-form-urlencoded',

test/fixtures/output/node/fetch/query.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const fetch = require('node-fetch');
22

3-
let url = 'http://mockbin.com/har';
3+
let url = 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value';
44

5-
let options = {method: 'GET', qs: {foo: ['bar', 'baz'], baz: 'abc', key: 'value'}};
5+
let options = {method: 'GET'};
66

77
fetch(url, options)
88
.then(res => res.json())

0 commit comments

Comments
 (0)