Add feature to allow user to define a function for next Suite selection #4591
Labels
status: waiting for author
waiting on response from OP - more information needed
type: feature
enhancement proposal
Is your feature request related to a problem or a nice-to-have?? Please describe.
This feature request is a nice-to-have.
Currently, the runner simply iterates through the Suites using:
because this is the standard usage model for Mocha. However, there may be a number of applications where users would like to be able to specify a function for how to select the next suite to run, maybe based on the outcome of the previous suite. For example, one can imagine building logic to skip Suites if a previous suite had failed. In my case I am wanting to integrate our Vitaq tool with Webdriverio and Mocha for use for web and app testing. Mocha is invoked from within a plugin maintained by Webdriverio. The Vitaq tool selects the next action (Suite) to run using AI and functional coverage targets to achieve the user journeys specified by the user. In order to re-use the Mocha framework, it would be necessary to have a function to select the next action.
Describe the solution you'd like
I have developed a prototype solution to demonstrate the idea. In the file runner.js, in the method runSuite I have replaced the line 883:
with:
I have assumed that the nextSuiteSelectFunction be passed as an option, and is a function that has a signature of (suite, curr), thereby allowing the user function to determine the state of the previous suite (passing/failing) and make selections about which suite to run next. The user function would be responsible for handling hierarchical suites if they were to be used. This solution requires the options to be passed through to the runner object and into the runSuite method. I don't like the fact that I have used the eval function, but as a proof of concept I think this is OK for now. The function itself is made available on the global namespace. I accept there are a number of things that could be tidied up here and I'm sure those more familiar with Mocha may have better suggestions regarding implementation details.
Describe alternatives you've considered
This is the cleanest way I could see to implement this functionality. I looked at hooks, but as far as I can see they are only for use within the Suite itself.
Additional context
No additional context
The text was updated successfully, but these errors were encountered: