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

Debug logging broken in beta (14.0.0-beta.5) #2745

Closed
2 tasks done
GeoffreyPlitt opened this issue May 22, 2024 · 1 comment
Closed
2 tasks done

Debug logging broken in beta (14.0.0-beta.5) #2745

GeoffreyPlitt opened this issue May 22, 2024 · 1 comment
Labels

Comments

@GeoffreyPlitt
Copy link

GeoffreyPlitt commented May 22, 2024

Please avoid duplicates

Reproducible test case

node ./node_modules/mocha/bin/mocha test.js

Nock Version

14.0.0-beta.5

Node Version

18.20.2

TypeScript Version

No response

What happened?

I am unable to see nock debug logs, and I've tried everything recommended by the docs. I've used every env var combination of {DEBUG, NODE_DEBUG} and values {nock, nock.*}.

I use debug-logging of my own on this machine plenty and it works fine, but it stopped working recently for nock. Perhaps caused by your removal of debug in favor of node's built-in debuglog?

In theory I could switch back to non-beta nock, but the beta's are the only ones that work with fetch() (including streams and buffers and other little details) for me.

Here's my test.js file:

const nock = require('nock');

describe('suite', () => {
	afterEach(async () => {
		nock.cleanAll();
		nock.enableNetConnect();
	});

	it('test', async () => {
		const scope1 = nock('https://www.google.com')
			.persist()
			.post('/')
			.reply((uri) => {
				return [200, 'nock fake result'];
			});

		const response = await fetch('https://www.google.com', { method: 'POST' });
		const result = await response.text();
		console.log('received:', result);

		scope1.done();
	});
});

Here's the result in the terminal:

 DEBUG=nock node ./node_modules/mocha/bin/mocha test.js

  suite
received: nock fake result
    ✔ test


  1 passing (20ms)

~/nock_probs ❯❯❯ DEBUG=nock.* node ./node_modules/mocha/bin/mocha test.js


  suite
received: nock fake result
    ✔ test


  1 passing (18ms)

~/nock_probs ❯❯❯ NODE_DEBUG=nock.* node ./node_modules/mocha/bin/mocha test.js


  suite
received: nock fake result
    ✔ test


  1 passing (18ms)

~/nock_probs ❯❯❯ NODE_DEBUG=nock node ./node_modules/mocha/bin/mocha test.js 


  suite
received: nock fake result
    ✔ test


  1 passing (18ms)

In case you need it, here's the package.json:

{
  "dependencies": {
    "mocha": "^10.4.0",
    "nock": "^14.0.0-beta.5"
  },
  "engines": {
    "node": "18.20.2"
  },
  "volta": {
    "node": "18.20.2"
  }
}

Would you be interested in contributing a fix?

  • yes
@GeoffreyPlitt
Copy link
Author

Embarassingly, the issue was I was using "NODE_DEBUG=nock." instead of "NODE_DEBUG=nock:". Make sure to use a colon, not a period.

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

1 participant