test,console: add testing for monkeypatching of console stdio · nodejs/node@00a6f76 (original) (raw)

Original file line number Diff line number Diff 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');