Skip to content

Commit

Permalink
Update test to handle EPIPE in test
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jan 26, 2020
1 parent 0566bcc commit c8cb72d
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions test/integration/api-support/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,30 @@ function runTests(dev = false) {
})

it('should return error exceeded body limit', async () => {
const data = await fetchViaHTTP(appPort, '/api/parse', null, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(json),
})
let res
let error

try {
res = await fetchViaHTTP(appPort, '/api/parse', null, {
method: 'POST',
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify(json),
})
} catch (err) {
error = err
}

expect(data.status).toEqual(413)
expect(data.statusText).toEqual('Body exceeded 1mb limit')
if (error) {
// This is a temporary workaround for testing since node doesn't handle
// closed connections when POSTing data to an endpoint correctly
// https://github.com/nodejs/node/issues/12339
expect(error.code).toBe('EPIPE')
} else {
expect(res.status).toEqual(413)
expect(res.statusText).toEqual('Body exceeded 1mb limit')
}
})

it('should parse bigger body then 1mb', async () => {
Expand Down

0 comments on commit c8cb72d

Please sign in to comment.