Skip to content

Commit bddb81a

Browse files
authored
update javascript fetch request to match node-fetch (#210)
* update javascript fetch request to match node-fetch Vanilla JS did not return the json from the request, the node.js version does, now they should behave the same * update test
1 parent 21fd9d5 commit bddb81a

File tree

16 files changed

+16
-0
lines changed

16 files changed

+16
-0
lines changed

src/targets/javascript/fetch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ module.exports = function (source, options) {
6565

6666
code
6767
.push(`fetch("${source.fullUrl}", ${JSON.stringify(options, null, opts.indent)})`)
68+
.push('.then(response => response.json())')
6869
.push('.then(response => {')
6970
.push(1, 'console.log(response);')
7071
.push('})')

test/fixtures/output/javascript/fetch/application-form-encoded.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fetch("http://mockbin.com/har", {
88
"hello": "world"
99
}
1010
})
11+
.then(response => response.json())
1112
.then(response => {
1213
console.log(response);
1314
})

test/fixtures/output/javascript/fetch/application-json.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fetch("http://mockbin.com/har", {
55
},
66
"body": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}"
77
})
8+
.then(response => response.json())
89
.then(response => {
910
console.log(response);
1011
})

test/fixtures/output/javascript/fetch/cookies.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fetch("http://mockbin.com/har", {
44
"cookie": "foo=bar; bar=baz"
55
}
66
})
7+
.then(response => response.json())
78
.then(response => {
89
console.log(response);
910
})

test/fixtures/output/javascript/fetch/custom-method.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ fetch("http://mockbin.com/har", {
22
"method": "PROPFIND",
33
"headers": {}
44
})
5+
.then(response => response.json())
56
.then(response => {
67
console.log(response);
78
})

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ fetch("http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value", {
99
"foo": "bar"
1010
}
1111
})
12+
.then(response => response.json())
1213
.then(response => {
1314
console.log(response);
1415
})

test/fixtures/output/javascript/fetch/headers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fetch("http://mockbin.com/har", {
55
"x-foo": "Bar"
66
}
77
})
8+
.then(response => response.json())
89
.then(response => {
910
console.log(response);
1011
})

test/fixtures/output/javascript/fetch/https.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ fetch("https://mockbin.com/har", {
22
"method": "GET",
33
"headers": {}
44
})
5+
.then(response => response.json())
56
.then(response => {
67
console.log(response);
78
})

test/fixtures/output/javascript/fetch/jsonObj-multiline.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fetch("http://mockbin.com/har", {
55
},
66
"body": "{\"foo\":\"bar\"}"
77
})
8+
.then(response => response.json())
89
.then(response => {
910
console.log(response);
1011
})

test/fixtures/output/javascript/fetch/jsonObj-null-value.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fetch("http://mockbin.com/har", {
55
},
66
"body": "{\"foo\":null}"
77
})
8+
.then(response => response.json())
89
.then(response => {
910
console.log(response);
1011
})

0 commit comments

Comments
 (0)