Skip to content

Commit

Permalink
fix coverall
Browse files Browse the repository at this point in the history
  • Loading branch information
kimiko88 committed Mar 10, 2020
1 parent 34f6a5c commit c2ef9cf
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "myhttprequest",
"version": "1.0.12",
"version": "1.0.13",
"description": "",
"main": "request.js",
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions request.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const requests = {
const bodyResponse = body.toString('utf8')
if (response.headers['content-type'].startsWith('application/json')) {
try {
resolve({ data: JSON.parse(bodyResponse), headers: response.headers, code: response.statusCode })
resolve({ data: bodyResponse ? JSON.parse(bodyResponse) : undefined, headers: response.headers, code: response.statusCode })
} catch (err) {
console.error(err)
resolve(undefined)
Expand All @@ -62,7 +62,7 @@ const requests = {
var form = querystring.stringify(bodyData)
headers['content-length'] = form.length
return form
} else if ((headers['content-type'] && headers['content-type'].startsWith('application/json')) || (headers['Content-Type'] && headers['Content-Type'].startsWith('application/json'))|| (headers['Content-type'] && headers['Content-type'].startsWith('application/json'))) {
} else if ((headers['content-type'] && headers['content-type'].startsWith('application/json')) || (headers['Content-Type'] && headers['Content-Type'].startsWith('application/json')) || (headers['Content-type'] && headers['Content-type'].startsWith('application/json'))) {
return JSON.stringify(bodyData)
}
return bodyData
Expand Down
5 changes: 4 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,8 @@ describe('request', () => {
assert.equal(res.code, 200)
})


it('getSize', async () => {
var res = await request.getSize('https://jsonplaceholder.typicode.com/posts/1')
assert.equal(res, "292")
})
})

0 comments on commit c2ef9cf

Please sign in to comment.