-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Allow writing JSON reporter to write directly to file #3255
Conversation
Mo Kamioner seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
Thanks. I'm not convinced Mocha needs this feature, since you can pipe to a file, like you mentioned. If we do want to be able to write directly to a file (and I'm not sure how necessary that is for the userbase, because pipes), I'd rather make it happen in the general case by swapping the output stream, instead of a reporter-by-reporter basis. Please don't let this discourage you from contributing to Mocha! There are plenty of issues labeled |
Guess I wasted my time doing basically the same enhancement, except I threw out the existing "json.spec.js" and based my tests on revamped version of XUnit's spec (which did stream checking). I have a use case for our project (which programmatically uses Mocha under the covers for RAML-based test automation) referenced in this issue (for one). If someone adds |
@boneskull BTW, had two questions left after doing my enhancement -- could you shed some light on them?
If these variables were exported from Base, would the individual reporters need to have same code repeated? |
|
Not having a way to redirect the json output to a file can be an issue when launched within a test suite: |
@boneskull Is it possible to remove the "extra" stuff that comes out when piping? For example, when I run something like:
My
Obviously this isn't a valid JSON file because of the initial output. Is it possible to get rid of that and just pipe the JSON result? |
that output is from cypress not mocha |
Oh, shoot. My apologies! |
regarding nyc output, you could suppress that instead and write to file. not ideal... this being said I would support adding the ability to swap the output stream (generally just this would allow these sorts of situations—mocha combined with other tools—to work together more nicely. implementation would just be something like a “default” stream for each reporter—probably in the Base reporter—which can be swapped out via reporter options. |
Description of the Change
Add feature for reporterOption in JSON reporter to output directly to file system. Method is similar to how
xunit
is implementedAlternate Designs
It would be simple to write the JSON to the stdout and then just pipe that into a file. However when using certain tools like
mocha-multi-reporters
there is no way around writing JSON and the spec reporter to the stdout. Furthermore, with bash andjq
JSON is a great way to parse the results while still allowing for human readable output with spec.Why should this be in core?
There are so many different JSON reporters but non are managed and they all fall through. This is a simple fix that would be a great feature that will help many
Benefits
The ability to write JSON files of your output thereby making analyzation of your tests easier to parse
Possible Drawbacks
None that I can think of right now (happy to hear if someone has some ideas)
Applicable issues
This is an enhancement (minor release) I think