nock: nock.recorder don't log redirection (302) with axios
What is the expected behavior? nock seems to record 302 redirections ( I’ve seen an unit test with super agent, working )
What is the actual behavior? nock doesn’t record the redirection when called by axios (only the first call recorded)
Possible solution
How to reproduce the issue
Here is a test I wrote in test_recorder.js :
const axios = require('axios')
test('test 302 on axios', t => {
const exampleText = '<html><body>example</body></html>'
const server = http.createServer((request, response) => {
switch (require('url').parse(request.url).pathname) {
case '/':
response.writeHead(302, { Location: '/abc' })
break
case '/abc':
response.write(exampleText)
break
}
response.end()
})
t.once('end', () => server.close())
nock.restore()
nock.recorder.clear()
t.equal(nock.recorder.play().length, 0)
nock.recorder.rec({
dont_print: true,
output_objects: true,
})
server.listen(async () => {
let resp, resp2
try {
resp = await axios.get(`http://localhost:${server.address().port}`)
} catch (e) {
t.ok(false)
}
t.ok(resp)
t.ok(resp.headers)
t.strictEqual(resp.data, exampleText)
nock.restore()
const recorded = nock.recorder.play()
nock.recorder.clear()
nock.activate()
t.equal(recorded.length, 2)
const nocks = nock.define(recorded)
try {
resp2 = axios.get(
`http://localhost:${server.address().port}`,
)
t.strictEqual(resp2.text, exampleText)
nocks.forEach(nock => nock.done())
t.end()
} catch (e) {
t.ok(false)
}
})
})
Does the bug have a test case? not for the moment
Versions tested with last npm, last béta, and from github
| Software | Version(s) |
|---|---|
| Node | V11.10.0 |
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 15 (6 by maintainers)
We just ran into this as well (moving from the deprecated
requestlibrary toaxios). So would very much appreciate if this old ticket could be picked up again! CheersI didn’t dig into this, but I was curios if this was still an issue. I can confirm on Node 14.2, Nock 13.0, and Axios 0.19.2, this is still not working 😢