mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
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: https://github.com/nodejs/node/pull/26561 Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
2f9c9eebb4
commit
6913bd183b
20
test/parallel/test-console-stdio-setters.js
Normal file
20
test/parallel/test-console-stdio-setters.js
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
// Test that monkeypatching console._stdout and console._stderr works.
|
||||
const common = require('../common');
|
||||
|
||||
const { Writable } = require('stream');
|
||||
const { Console } = require('console');
|
||||
|
||||
const streamToNowhere = new Writable({ write: common.mustCall() });
|
||||
const anotherStreamToNowhere = new Writable({ write: common.mustCall() });
|
||||
const myConsole = new Console(process.stdout);
|
||||
|
||||
// Overriding the _stdout and _stderr properties this way is what we are
|
||||
// testing. Don't change this to be done via arguments passed to the constructor
|
||||
// above.
|
||||
myConsole._stdout = streamToNowhere;
|
||||
myConsole._stderr = anotherStreamToNowhere;
|
||||
|
||||
myConsole.log('fhqwhgads');
|
||||
myConsole.error('fhqwhgads');
|
Loading…
Reference in New Issue
Block a user