forwardemail / forwardemail/supertest
Supertest pipe and Jest
- Dominant language
- JavaScript
- Stars
- 14.4k
- Forks
- 782
- PR merge metrics
- No merged PRs in 30d
Description
Hi there,
I am developing a REST API based service in Node.js.
Im am testing the endpoints using Jest and Supertest.
My tests usually have a request -> get / send -> then syntax and work fine.
I have one test for a download endpoint that returns a file. It treats the response as a stream and pipes it into a file. The test runs passes fine and everything is green. However, if I have this particular test running, Jest does not end its process and does not return to the console. Note that done() is called successfully so not even a timeout is applied.
Hope someone has a hint on that, here is the code:
` test(`It should return the test file from ${ downloadFileURI }`, (done) => {
let ws = fs.createWriteStream(localTestFileURI)
let req = request(app).get(downloadFileURI)
req.set({
keyname: akamaiKeyname,
key: akamaiKey,
serviceuri: akamaiServiceURI
})
req.on('response', (res) => {
expect(res.statusCode).toBe(200)
})
ws.on('finish', () => {
expect(fs.statSync(localTestFileURI).size).toBe(downloadFileSize)
done()
})
req.pipe(ws, {end: true})
}, 10000)`
Contributor guide
Assessment
This issue has not been assessed yet.