Skip to content
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

🐛 Bug: Inconsistent Reporter Use of Console and Stdout #2943

Open
shellscape opened this issue Aug 1, 2017 · 4 comments
Open

🐛 Bug: Inconsistent Reporter Use of Console and Stdout #2943

shellscape opened this issue Aug 1, 2017 · 4 comments
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes" status: accepting prs Mocha can use your help with this one! type: chore generally involving deps, tooling, configuration, etc.

Comments

@shellscape
Copy link

The title of this issue is the crux. 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.

Some reporters like spec (https://github.com/mochajs/mocha/blob/master/lib/reporters/spec.js#L40) are using console.log, some like dot(

process.stdout.write('\n');
) 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 calling console.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.

@shellscape shellscape changed the title Inconsistent Report Use of Console and Stdout Inconsistent Reporter Use of Console and Stdout Aug 1, 2017
@ScottFreeCode
Copy link
Contributor

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:

  • format strings if the first argument has a % or something magic like that
  • automatic newlines after each message
  • spaces between multiple arguments when no format string
  • automatic stringification with inspect-awareness

It's possible some of those are shared by stdout methods, but we'll want to double-check.

@boneskull
Copy link
Contributor

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.

@boneskull
Copy link
Contributor

this is also ideally semver-patch

@boneskull boneskull added type: chore generally involving deps, tooling, configuration, etc. status: accepting prs Mocha can use your help with this one! semver-patch implementation requires increase of "patch" version number; "bug fixes" labels Oct 6, 2017
@plroebuck
Copy link
Contributor

JSONStream reporter is similarly afflicted (#3521).

@JoshuaKGoldberg JoshuaKGoldberg changed the title Inconsistent Reporter Use of Console and Stdout 🐛 Bug: Inconsistent Reporter Use of Console and Stdout Dec 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-patch implementation requires increase of "patch" version number; "bug fixes" status: accepting prs Mocha can use your help with this one! type: chore generally involving deps, tooling, configuration, etc.
Projects
None yet
Development

No branches or pull requests

4 participants