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

Improve debug logging #2731

Open
1 of 2 tasks
fregante opened this issue Mar 27, 2024 · 2 comments
Open
1 of 2 tasks

Improve debug logging #2731

fregante opened this issue Mar 27, 2024 · 2 comments
Labels

Comments

@fregante
Copy link

fregante commented Mar 27, 2024

Please avoid duplicates

Context

I'm trying to migrate from axios/axios-mock-adapter to fetch/nock and I'm having really hard time understanding why some requests are not being matched. I use nock.disableNetConnect() to ensure that all requests are "caught" but even with debugging enabled, I don't know what nock is doing:

NOCK:COMMON 14419: options.host: oauthconfigapp.automationanywhere.digital
NOCK:COMMON 14419: options.hostname in the end: "oauthconfigapp.automationanywhere.digital"
NOCK:COMMON 14419: options.host in the end: "oauthconfigapp.automationanywhere.digital:443"
NOCK:INTERCEPT 14419: interceptors for "oauthconfigapp.automationanywhere.digital:443"
NOCK:INTERCEPT 14419: filtering interceptors for basepath https://oauthconfigapp.automationanywhere.digital:443
NOCK:INTERCEPT 14419: falling back to original ClientRequest
NOCK:COMMON 14419: options.host: oauthconfigapp.automationanywhere.digital:443
NOCK:COMMON 14419: options.hostname in the end: "oauthconfigapp.automationanywhere.digital"
NOCK:COMMON 14419: options.host in the end: "oauthconfigapp.automationanywhere.digital:443"
NOCK:INTERCEPT 14419: Net connect not enabled for oauthconfigapp.automationanywhere.digital:443
NOCK:SCOPE:LOCALHOST 14419: reply.headers: {}
NOCK:SCOPE:LOCALHOST 14419: reply.rawHeaders: [ 'Content-Type', 'application/json' ]
NOCK:SCOPE:LOCALHOST 14419: reply.headers: {}
NOCK:SCOPE:LOCALHOST 14419: reply.rawHeaders: []
  • What's NOCK:COMMON 14419: options.host? Is it a request being handled?
  • What does interceptors for mean? Is it an event? Is it matching? Is it supposed to be followed by a list of interceptors?
  • What about falling back to original ClientRequest? Why is it falling back? Why is my nock("https://oauthconfigapp.automationanywhere.digital").persist().post("/*").reply(200, {}).get("/*").reply(200, {}) not catching these requests?

Alternatives

Improve the logging to clarify what's actually happening, for example:

NOCK:REQUEST: new request POST https://oauthconfigapp.automationanywhere.digital:443/blablah with body
NOCK:REQUEST: matches '/*'
NOCK:REQUEST: intercepted
NOCK:REQUEST: new request GET https://oauthconfigapp.automationanywhere.digital:443/blablah?url=param
NOCK:REQUEST: does not match
NOCK:REQUEST: fell through, but net connections disabled

If the feature request is accepted, would you be willing to submit a PR?

  • yes
@fregante
Copy link
Author

fregante commented Mar 27, 2024

Additionally, I don't know if it's related but it I have this issue in tests that have to deal with multiple hosts:

const appApiMock = nock("http://localhost");
const externalHost = nock("https://oauthconfigapp.automationanywhere.digital")

Is this supported? I see no mention of "multiple scopes" in the readme.

I'm using 14.0.0-beta.5 and https://github.com/sindresorhus/ky

@mikicho
Copy link
Contributor

mikicho commented Mar 27, 2024

Why is it falling back?

Probably because you don't use the regex syntax: https://github.com/nock/nock?tab=readme-ov-file#specifying-path

Regarding the debugging. Debug mode is verbose and includes internal details. Luckily, Nock's API is pretty straightforward and well-documented:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants