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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃殌 Feature: JSON reporter with optional formatting #4889

Open
dandandy opened this issue May 24, 2022 · 3 comments 路 May be fixed by #5017
Open

馃殌 Feature: JSON reporter with optional formatting #4889

dandandy opened this issue May 24, 2022 · 3 comments 路 May be fixed by #5017
Labels
area: reporters involving a specific reporter status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal

Comments

@dandandy
Copy link

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

The problem is the Mocha JSON reporter is hardcoded to output the JSON object over multiple lines. This makes it impossible to use with Splunk which requires the object to just be on one line.

This is the line of code I am referring to: https://github.com/mochajs/mocha/blob/master/lib/reporters/json.js#L81

...
var json = JSON.stringify(obj, null, 2);
...

Describe the solution you'd like

I would like the spacing in the JSON reporter output to be an option so we can configure this as required.

We could add a option to the reporter which allows the user to set the whitespace, but defaults to the current value if it's not provided so the change is backwards compatible.

For example, the line I linked above would be changed to something like this:

var json = JSON.stringify(obj, null, options.jsonStringifyWhitespace ?? 2);

Describe alternatives you've considered
An alternative is forking the code and creating my own reporter, but it is such a small change and I believe the community would benefit from this extra option so I would rather make the change here.

@dandandy dandandy added the type: feature enhancement proposal label May 24, 2022
@dandandy
Copy link
Author

If this feature request is accepted I am happy to make the pull request

@dandandy dandandy changed the title JSON reporter with no formatting JSON reporter with optional formatting May 24, 2022
@JoshuaKGoldberg JoshuaKGoldberg changed the title JSON reporter with optional formatting 馃殌 Feature: JSON reporter with optional formatting Dec 27, 2023
@JoshuaKGoldberg
Copy link
Member

Seems pretty straightforward to me to add a --reporter-option specifically for JSON.

I'm not convinced that jsw/jsonStringifyWhitespace would be the right name for it. It seems kind of verbose. If it's a option specifically for the JSON reporter, then it doesn't need to mention "json" by name... 馃

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! area: reporters involving a specific reporter labels Feb 6, 2024
@dandandy
Copy link
Author

dandandy commented Feb 7, 2024

Yes thank you for your suggestion. I鈥檒l give it a shot and work on a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: reporters involving a specific reporter status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants