Skip to content

Commit 5fedf0f

Browse files
sam-githubBethGriggs
authored andcommitted
doc: add guidance on console output in tests
PR-URL: #26456 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Bryan English <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ujjwal Sharma <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 4065785 commit 5fedf0f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

doc/guides/writing-tests.md

+26
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,32 @@ assert.throws(
281281
);
282282
```
283283

284+
### Console output
285+
286+
Output written by tests to stdout or stderr, such as with `console.log()` or
287+
`console.error()`, can be useful when writing tests, as well as for debugging
288+
them during later maintenance. The output will be supressed by the test runner
289+
(`./tools/test.py`) unless the test fails, but will always be displayed when
290+
running tests directly with `node`. For failing tests, the test runner will
291+
include the output along with the failed test assertion in the test report.
292+
293+
Some output can help debugging by giving context to test failures. For example,
294+
when troubleshooting tests that timeout in CI. With no log statements, we have
295+
no idea where the test got hung up. There have been cases where tests fail
296+
without `console.log()`, and then pass when its added, so be cautious about its
297+
use, particularly in tests of the I/O and streaming APIs.
298+
299+
Excessive use of console output is discouraged as it can overwhelm the display,
300+
including the Jenkins console and test report displays. Be particularly
301+
cautious of output in loops, or other contexts where output may be repeated many
302+
times in the case of failure.
303+
304+
In some tests, it can be unclear whether a `console.log()` statement is required
305+
as part of the test (message tests, tests that check output from child
306+
processes, etc.), or is there as a debug aide. If there is any chance of
307+
confusion, use comments to make the purpose clear.
308+
309+
284310
### ES.Next features
285311

286312
For performance considerations, we only use a selected subset of ES.Next

0 commit comments

Comments
 (0)