Open shellscape opened 7 years ago
We would need to verify that none of the uses of console.log
in reporters aren't relying on any formatting behavior of console.log
that isn't present in the direct process.stdout
methods, or else recreate the effect. Off the top of my head, I want to say that console.log
has four formatting behaviors:
%
or something magic like thatinspect
-awarenessIt's possible some of those are shared by stdout
methods, but we'll want to double-check.
this sounds workable to me if someone wants to send a PR. ideally, a reporter should have utility method(s) available on its instance to deal with this, e.g. this.print()
for dot
and this.println()
for spec
, as to not have to reach into mocha.process
.
this is also ideally semver-patch
JSONStream reporter is similarly afflicted (#3521).
The title of this issue is the crux. It appears that the default
spec
reporter usesconsole.log
rather than the built-inprocess.stdout
that other reporters use. And there doesn't seem to be a pattern to which reporters use which output method.Some reporters like spec (https://github.com/mochajs/mocha/blob/master/lib/reporters/spec.js#L40) are using console.log, some like dot(https://github.com/mochajs/mocha/blob/503627c756cd4feef76772aafadccd0da255756f/lib/reporters/dot.js#L31) use stdout.
My use case involves utilizing headless chrome to run mocha tests. I'm providing a proxy to
window.mocha.process.stdout
to use a message bus that I've injected, that pipes raw messages back to the node app which catches them via the Chrome DevTools Protocol. It might sound complex, but it's rather simple. Without knowing which actor (user code or mocha) is callingconsole.log
, I can't effectively show console messages in the terminal with any distinction between actors.The "simple" fix would be to standardize all reports on one output method - preferably
mocha.process.stdout
.