Is there a way that I can catch eventual console output caused by console.log(...)
within node.js to prevent cloggering the terminal whilst unit testing a module?
Thanks
Is there a way that I can catch eventual console output caused by console.log(...)
within node.js to prevent cloggering the terminal whilst unit testing a module?
Thanks
A better way could be to directly hook up the output you to need to catch data of, because with Linus method if some module write directly to stdout with
process.stdout.write('foo')
for example, it wont be caught.EDIT
console.log()
ends its output with a newline, you may want to strip it so you'd better write:EDIT
Improved, generic way to do this on any method of any object with async support See the gist.
Simply add the following snippet to your code will let you catch the logs and still print it in the console:
module.js:
program:
Edit: Obviously you can collect the log messages for later if you wish:
capture-console solves this problem nicely.
and later