nock.recorder don't log redirection (302) with axios
See original GitHub issueWhat 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 |
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Nock Reply With 302 And 404 Throws An Httperror - ADocLib
Javascript queries related to axios.interceptors.request example.axios ... issue on Mar 18 2019.nock.recorder don't log redirection 302 with axios #1479.
Read more >Axios is not passing cookies upon 302 redirect - Stack Overflow
I'm trying to implement an admin request submission class in node.js. There are two API calls, one is Login and the second is...
Read more >nock - npm
Global no match event. Nock Back. Setup. Options. Usage. Options. Example. Modes. Common issues. Axios; Memory issues with Jest.
Read more >node-fetch Alternatives - Node.js HTTP | LibHunt
10.0 9.7 L3 node-fetch VS axios ... 8.7 8.4 L4 node-fetch VS Nock ... :dash: Simple yet powerful file-based mock server with recording...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We just ran into this as well (moving from the deprecated
request
library 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 😢