Monkeypatch for stdout with knobs. For testing purposes, or other things.
npm install stdout-monkey
var stdout = require('stdout-monkey');
var monkey = stdout(function(str, enc, cb){
this.log('I want more bananas!');
})
console.log('Hey, stop it!');
// -> I want more bananas!You don't want to spam stdout for testing. You want to batch data or you want to transform data before it reaches stdout.
Below when I write stdout I really want to write process.stdout.write.
var monkey = require('stdout-monkey')([callback])
Calling the module with a function returns a monkeypatched stdout disabled by default. Instead the arguments are passed to the given callback.
Note: that is not really accurate since the object is not a writable stream.
Default method returned from the module. Patch stdout and disable it. Use the given callback instead.
Returns the monkey instance.
Restore stdout. Optionaly write something.
Patch stdout but only to include the callback. stdout will work as normal, you can spy but not modify what is written.
Use the original process.stdout.write even if it was patched.
Use console.log even if stdout was patched.
All above methods are chainable.
The monkey has a state property indicating if process.stdout.write was patched or if he used the restore or listen methods.
NOTE: the state is not changed when calling the log or write methods.
npm test
- make the
monkeyathroughstream.