Skip to content

Commit 00a6f76

Browse files
Trotttargos
authored andcommitted
test,console: add testing for monkeypatching of console stdio
lib/internal/console/constructor.js contains setters for console._stdout and console._stderr but these setters are not used in our tests or in Node.js core. (This is confirmed by our nightly coverage reports.) Add a test to check monkeypatching _stdout and _stderr on a console object. PR-URL: #26561 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 72cda51 commit 00a6f76

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
// Test that monkeypatching console._stdout and console._stderr works.
4+
const common = require('../common');
5+
6+
const { Writable } = require('stream');
7+
const { Console } = require('console');
8+
9+
const streamToNowhere = new Writable({ write: common.mustCall() });
10+
const anotherStreamToNowhere = new Writable({ write: common.mustCall() });
11+
const myConsole = new Console(process.stdout);
12+
13+
// Overriding the _stdout and _stderr properties this way is what we are
14+
// testing. Don't change this to be done via arguments passed to the constructor
15+
// above.
16+
myConsole._stdout = streamToNowhere;
17+
myConsole._stderr = anotherStreamToNowhere;
18+
19+
myConsole.log('fhqwhgads');
20+
myConsole.error('fhqwhgads');

0 commit comments

Comments
 (0)