Skip to content

Commit

Permalink
fix: response.complete must be true after res.end
Browse files Browse the repository at this point in the history
  • Loading branch information
doochik committed Jul 1, 2019
1 parent 6820e54 commit 09a8ebc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/request_overrider.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ function RequestOverrider(req, options, interceptors, remove, cb) {
} else {
debug('ending response stream')
response.push(null)
// https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_message_complete
response.complete = true
interceptor.scope.emit('replied', req, interceptor)
}
})
Expand Down
27 changes: 27 additions & 0 deletions tests/test_request_overrider.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,30 @@ test("mocked requests have 'method' property", t => {
})
req.end()
})

// https://github.com/nock/nock/issues/1493
test("response have 'complete' property and it's true after end", t => {
const scope = nock('http://example.test')
.get('/')
.reply(200, 'Hello World!')

const req = http.request(
{
host: 'example.test',
method: 'GET',
path: '/',
port: 80,
},
res => {
res.on('end', () => {
t.is(res.complete, true)
scope.done()
t.end()
})
// Streams start in 'paused' mode and must be started.
// See https://nodejs.org/api/stream.html#stream_class_stream_readable
res.resume()
}
)
req.end()
})

0 comments on commit 09a8ebc

Please sign in to comment.