New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
suppress stdout from test cases #290
Comments
not really sure what you mean since there's only one stdout, seems more like something that should be toggleable in your lib |
Does mocha not capture the stdout of the tests? I figured it did and just passed it along to the console. |
they run in the same process so it's the same stdout |
I choose to rewrite var util = require('util');
var log = fs.createWriteStream('var/stdout.log');
console.log = console.info = function(t) {
var out;
if (t && ~t.indexOf('%')) {
out = util.format.apply(util, arguments);
process.stdout.write(out + '\n');
return;
} else {
out = Array.prototype.join.call(arguments, ' ');
}
out && log.write(out + '\n');
}; As long as mocha uses I wonder if it's possible to replace all the It's reasonable to log something when an app is running. And it is best practice to keep its output pipe into While it's necessary to separate test reports from app logs, it is also convenient to keep the report in Maybe, however, multiple reporters is not really that necessary, an option to redirect all the |
Anything that wrote with process.stdout.write would still bypass the fake "silencing". In either case, I don't use console.log (and friends) for logging and instead use my own log library. I do what @visionmedia suggested and just have a way to silence log output in the library. As far as third party libraries go, they should never output to console unless I either asked them to or that is their job (test reporters and such obviously). It is not for them to decide how I do my logging. |
yeah unconditional logging to stdio is kinda rude, unless maybe the lib checks NODE_ENV but even then why not just provide a flag |
more or less, this is why I like devs using debug(https://github.com/visionmedia/debug) . Then i can tune verbosity to my needs. Or i can just have the --reporter dot . |
I've implemented a mocha reporter that captures (and hides) stdout and stderr during tests. It then displays the captured output only of the failed tests alongside their error messages. For me it significantly increases readability of a test report. Internally it just mocks Maybe you'll find it useful: https://github.com/biern/mocha-dd-reporter |
Something nice to have would be a way to silence the stdout from the tests themselves (not the reporters). That way if I have trace output in my program I can easily suppress it to see some nice test output :)
The text was updated successfully, but these errors were encountered: