question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nock is not working when I am using proxy

See original GitHub issue

Hello,

Nock seems unable to intercept the requests when I have declared environment variables HTTP_PROXY and HTTPS_PROXY. Could you please check on this?

Proxies are mandatory in my scenario, so I cant get rid of them.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
wanjunthamcommented, Oct 1, 2020

Alternatively you could unset the proxy env vars when you’re running tests and leave your mocks on the real hosts.

Why didn’t I think of this earlier?! It works flawlessly now!

To everyone who are checking this issue, what I did to make it work is by writing these at the beginning of my code:

process.env.HTTP_PROXY = ''
process.env.HTTPS_PROXY = ''

By doing so, nock will capture accordingly without being messed up by mocks.

3reactions
paulmelnikowcommented, Sep 29, 2020

Hmm, if I’m understanding correctly, it sounds like the requests are honoring the proxy, so they’re being made to the proxy host. To intercept those, you need to set mock requests for the proxied request on the proxy host.

Alternatively you could unset the proxy env vars when you’re running tests and leave your mocks on the real hosts.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NodeJS - Nock doesn't intercept request made using the ` ...
In my tests, i'm trying to intercept HTTP request made by the request/request . But it doesn't work. When I use http.request() nock...
Read more >
nock-proxy
Start using nock-proxy in your project by running `npm i nock-proxy`. There are no other projects in the npm registry using nock-proxy.
Read more >
How to use the nock.restore function in nock
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >
nock
This means that you can intercept 2 or more calls to the same URL and return different things on each of them. It...
Read more >
Network Requests
You don't have to do any work on the server. Your application will have no idea its requests are being stubbed, so there...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found