mocha
                                
                                 mocha copied to clipboard
                                
                                    mocha copied to clipboard
                            
                            
                            
                        mark Runnable#retries and Runnable#currentRetry methods as public
This change makes it easier for Mocha reporters to report retriable and regular tests differently, should they choose to do so.
Description of the Change
I'd like the Serenity/JS Mocha reporter to be able to report differently on regular and retriable Mocha scenarios. In order to do so, a Mocha reporter needs to be able to tell the difference between the two.
The easiest way to do it is to mark the already existing Runnable#retries and Runnable#currentRetry methods as public to expose the required information.
Alternate Designs
Any alternative designs would require marking at least Runnable#currentRetry as public, so changing the JSDoc seems like the most efficient way to reach my objective.
Why should this be in core?
This functionality can't be implemented in an external module.
Benefits
This change allows any Mocha reporter to treat retriable and regular scenarios differently and therefore provide better quality information to developers using them. If the PR makes it to core, I'm also planning to raise another one for @types/mocha
Possible Drawbacks
Marking those APIs as public might encourage developers to use them in their tests, which they probably shouldn't be doing. Having said that, they can do that already.
Applicable issues
N/A
Coverage remained the same at 93.932% when pulling 904609dbacf7dadb059370e467135811e6e1af93 on jan-molak:features/public-retry-apis into 7c8896c70faf58d942249190df1343f7349cf946 on mochajs:master.
Hey @boneskull,
I need both retries and currentRetry, so Runnable seemed (?) like the place to do it.
Here's an example of how I use those APIs.
So in my reporter:
runner.on(Runner.constants.EVENT_TEST_RETRY,  (test: Test, err: Error) => {
    if (test.retries() >= 0) {
      // do something with test.currentRetry();
    }                
});
I could move the change to interface visibility from Runnable#retries() to Context#retries() (or apply it in both places?)
However, I don't see currentRetries on Context?
Let me know which approach you prefer and I can update the PR.
Thanks, Jan
OK, so that looks like a reporter.  That example code should fail in parallel mode, since test.retries() is not a function.
This is what you should do:
- [ ] Add $$retries: this._retriesto the object returned byTest#serialize(). This convention will tell the object serializer to create a functionretries()which returns the value ofthis._retries.Runnable#retries()is just a setter/getter.
- [ ] All functions in that object (denoted by a $$prefix) should be public, since they are intended to be consumed by reporters. Mark the following functions inRunnableas@public(you may need@memberofas well; if you want to generate the API docs, runnpm start docs.apiand opendocs/_site/api/index.html):- [ ] slow()
- [ ] isPending()
- [ ] retries()
- [ ] currentRetry()
 
- [ ] 
- [ ] slow,isPendingandcurrentRetryshould have been@public; this is in error. However, givenslow()andretries()are both combination setters/getters and reporters should not use them as setters, I think it's wise to make this clear in the documentation. I don't know how to do that other than remove the@paramtags from each of these, so they appear to not accept parameters.
It's pretty obvious the combination setters/getters are problematic from an API surface standpoint. We really ought to reconsider all of them, because of problems like this and the lack of uniformity.