mochajs / mocha

☕️ simple, flexible, fun javascript test framework for node.js & the browser
https://mochajs.org
MIT License
22.64k stars 3.02k forks source link

🚀 Feature: Support log level configuration #4180

Closed Sayan751 closed 11 months ago

Sayan751 commented 4 years ago

Is your feature request related to a problem or a nice-to-have?? Please describe.

While running the tests it happens that there are several console.log in the source code. Sometimes those are necessary. However, during the tests, I don't want those log crowding the console, as then it gets difficult to detect whether those logs are intentional or those are actual errors.

Describe the solution you'd like

I would like a logLevel configuration option. Karma supports this with a configuration option with the same name: http://karma-runner.github.io/4.0/config/configuration-file.html. There one can define how much logging informations are intended. For example, when the logLevel is set to 'error', mocha won't show the console.logs in console.

Describe alternatives you've considered

The solutions floating around on several GH issues or in SO suggests to replace the console.log in the hooks of the suites. But that is a solution, I don't want to go for, as it meddles with the globals. A far desirable solution is to handle is properly in mocha.

Additional context

JoshuaKGoldberg commented 11 months ago

This conflicts with #2943.

It appears that the default spec reporter uses console.log rather than the built-in process.stdout that other reporters use. And there doesn't seem to be a pattern to which reporters use which output method.

Per https://github.com/mochajs/mocha/issues/2943#issuecomment-319508521, Mocha is going to move to process.stdout.write. So this is a wontfix. Sorry to be the bearer of bad news!