Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1836 fixes expected Node behaviour for http.get #1853

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/common.js
Expand Up @@ -99,7 +99,11 @@ function overrideRequests(newRequest) {
}
// https://nodejs.org/api/http.html#http_http_get_options_callback
module.get = function(input, options, callback) {
const req = module.request(input, options, callback)
const req = newRequest(proto, overriddenGet.bind(module), [
input,
options,
callback,
])
req.end()
return req
}
Expand Down
27 changes: 27 additions & 0 deletions tests/test_common.js
Expand Up @@ -512,3 +512,30 @@ test('testing timers are deleted correctly', t => {
t.end()
})
})

test('test correct node behavior by making sure that http.request is not called when using http.get', t => {
const scope = nock('http://example.test')
.get('/')
.reply()

const reqSpy = sinon.spy(http.request)
const origHttpReq = http.request

http.request = reqSpy

http.get('http://example.test', res => {
t.equal(res.statusCode, 200)

res.on('data', reqSpy)

res.on('end', () => {
t.equal(reqSpy.called, false)
t.end()
})
})

t.on('end', () => {
scope.done()
http.request = origHttpReq
})
})