Skip to content

Commit 93aa055

Browse files
Sarat AddepalliSirR4T
authored andcommitted
test: add docs for common.debuglog behaviour
1 parent a9fb74a commit 93aa055

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

test/common/README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,20 @@ Platform normalizes the `dd` command
5959

6060
### debuglog([fmt, ]msg[, msgs])
6161
* `fmt` [<string>] Optional format string
62-
* `msg` [<string>] The string to be printed to stderr
62+
* `msg` [<string>] The string to be printed
6363
* `msgs` [<string>] Additional arguments to the function
6464

65-
Prints messages (optionally, formatted using `fmt`) to `process.stderr`,
66-
using `util.debuglog('test')`.
65+
Prints messages (optionally, formatted using `fmt`). Since [`util.debuglog()`]
66+
is used internally (invoked as `util.debuglog('test')`), these messages will be
67+
visible only when `NODE_DEBUG` environment variable is set with `test`.
68+
69+
```sh
70+
// when NODE_DEBUG is not set, or doesn\'t contain `test`, prints nothing.
71+
$ NODE_DEBUG=fs,net ./node test/fixtures/common-debuglog.js hello world
72+
// when NODE_DEBUG contains `test`, messages are printed to `process.stderr`
73+
$ NODE_DEBUG=test,fs,net ./node test/fixtures/common-debuglog.js hello world
74+
TEST 89440: hello world
75+
```
6776

6877
### disableCrashOnUnhandledRejection()
6978

@@ -810,3 +819,4 @@ implementation with tests from
810819
[`hijackstdio.hijackStdErr()`]: #hijackstderrlistener
811820
[`hijackstdio.hijackStdOut()`]: #hijackstdoutlistener
812821
[internationalization]: https://github.com/nodejs/node/wiki/Intl
822+
[`util.debuglog()`]: https://nodejs.org/api/util.html#util_util_debuglog_section

test/fixtures/common-debuglog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
const common = require('../common');
44

55
// argv[0] is the execPath, argv[1] is the test script filename
6-
common.debuglog.apply(null, process.argv.slice(2));
6+
common.debuglog(...process.argv.slice(2));

test/parallel/test-common-debuglog.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
require('../common');
44
const assert = require('assert');
5-
const path = require('path');
5+
const fixtures = require('../common/fixtures');
66
const { spawnSync } = require('child_process');
77

88
const message = 'message';
99

1010
{
1111
process.env.NODE_DEBUG = 'test';
1212
const { stderr } = spawnSync(process.execPath, [
13-
path.resolve(__dirname, '../fixtures/common-debuglog.js'),
13+
fixtures.path('common-debuglog.js'),
1414
message
1515
], { encoding: 'utf8' });
1616

@@ -21,7 +21,7 @@ const message = 'message';
2121
{
2222
delete process.env.NODE_DEBUG;
2323
const { stderr } = spawnSync(process.execPath, [
24-
path.resolve(__dirname, '../fixtures/common-debuglog.js'),
24+
fixtures.path('common-debuglog.js'),
2525
message
2626
], { encoding: 'utf8' });
2727

@@ -31,7 +31,7 @@ const message = 'message';
3131
{
3232
process.env.NODE_DEBUG = 'fs';
3333
const { stderr } = spawnSync(process.execPath, [
34-
path.resolve(__dirname, '../fixtures/common-debuglog.js'),
34+
fixtures.path('common-debuglog.js'),
3535
message
3636
], { encoding: 'utf8' });
3737

0 commit comments

Comments
 (0)