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

Implement support for multiple reporters #1681

Closed
wants to merge 2 commits into from
Closed

Implement support for multiple reporters #1681

wants to merge 2 commits into from

Conversation

benvinegar
Copy link
Contributor

Squashed commit of #1360 (previously #930), against v3.0.0.

Necessary for completion:

@dasilvacontin
Copy link
Contributor

Thanks for working on this, @benvinegar! :)

@dasilvacontin
Copy link
Contributor

benvinegar: Okay, just tried merging up with master and noticed that mocha introduced --reporter-options (7ce102b) ... which appears to only be used by the XUnit reporter and is not documented on mochajs.org.

benvinegar: well, it seems that there are external plugins that do use it
https://github.com/juhovh/mocha-jenkins-reporter#programmatic-configuration

So in the end, we can't ignore --reporter-options.

@dasilvacontin
Copy link
Contributor

For the reporters that use special characters to move the cursor, change colors, clear lines, etc. we will write those as-is if the target is a file.

@benvinegar
Copy link
Contributor Author

@dasilvacontin – can you comment on my latest changes and whether you feel the approach is correct? Right now, only the XUnit reporter is set up to go, but with your go-ahead I'll continue converting the remaining reporters to use the new write methods.

For now, you can verify the behavior from the command line like so:

bin/_mocha --reporter dot,xunit=tmp

@dasilvacontin
Copy link
Contributor

I'll check it out tonight, looking forward to it!

try {
Reporter = require(program.reporter);
reporter = reporterConfig.split(':')[0];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be easier to understand as reporterName or something similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

@dasilvacontin
Copy link
Contributor

Looks quite good, thanks for working on it @benvinegar! 😄

var _reporter = reporterConfig.fn
, path = reporterConfig.path;

options.reporterOptions = reporterConfig.options;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of gross (changing the value of this.options per-reporter), but I did this to keep backwards compatibility with external reporters that have been using this.options.reporterOptions. For example, this Slack reporter.

Open to alternative suggestions.

@benvinegar
Copy link
Contributor Author

After the latest set of changes, Mocha now accepts per-reporter --reporter-options using a syntax previously approved of by @dasilvacontin and @travisjeffery here.

Example:

mocha --reporter spec,json:tmp/out.json --reporter-options spec{style=prettyprint,color=blue},json{prettify,indent=tabs}

The original syntax still works, but if multiple reporters are present, it will apply that configuration to "all" active reporters.

In the example below, "style=prettyprint" is passed to both the "spec" and "json" reporters (which they may ignore).

mocha --reporter spec,json:tmp/out.json --reporter-options style=prettyprint

program.reporterOptions.split(",").forEach(

// Two possible formats ...
/\w+{(\w+:\w+)+}/.test(program.reporterOptions) ?
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dasilvacontin – Is there an existing test for bin/_mocha that I've missed? If not, how would you recommend I test these changes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielstjules I notice those files are on master, but not on v3.0.0.

Should I merge v3.0.0 up w/ master (or someone else)? Should I be targeting master instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely missed what branch this was targeting. I haven't been involved with the 3.0.0 branch, so I'm gonna defer this to @boneskull :) He'll be able to answer that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice those files are on master, but not on v3.0.0.

Indeed, master commits should be in v3.0.0.

Why target v3.0.0? Is this PR breaking backwards compatibility?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, the new syntax for --reporter-options has been added. Sorry, I missed that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original syntax still works, but if multiple reporters are present, it will apply that configuration to "all" active reporters.

Then it's not breaking. (?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why target v3.0.0? Is this PR breaking backwards compatibility?

Somebody in the last PR asked me to. I will close and switch it back (sigh).

@wethinkagile
Copy link

This is cool! Could you provide short code snippet on how to let mocha run with a spec and e.g. a bamboo reporter? We are using grunt-mocha-test.

@benvinegar
Copy link
Contributor Author

Going to recreate and target master.

@rcbop
Copy link

rcbop commented May 10, 2016

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants