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

🚀 Feature: Make cleanReferencesAfterRun a Mocha option #4589

Open
RossVertizan opened this issue Feb 26, 2021 · 1 comment
Open

🚀 Feature: Make cleanReferencesAfterRun a Mocha option #4589

RossVertizan opened this issue Feb 26, 2021 · 1 comment
Labels
status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal

Comments

@RossVertizan
Copy link

Is your feature request related to a problem or a nice-to-have?? Please describe.
The request is a nice-to-have. I am working on integrating our tool Vitaq with Webdriverio and Mocha for use for web and app testing. Mocha is invoked from within a plugin maintained by Webdriverio.

The Vitaq tool needs to be able to run Suites multiple times and that capability was addressed by this issue (#2783) by setting the cleanReferencesAfterRun flag to be false. The solution works well for what I need to be able to do. However, the flag can only be set by calling the cleanReferencesAfterRun method on the mocha object. To set this from Webdriverio, would therefore mean a code modification. However, Webdriverio supports passing all of the Mocha options through to the mocha instance. It would be very helpful if cleanReferencesAfterRun could be elevated to be a Mocha option.

Describe the solution you'd like
When the cleanReferencesAfterRun key is provided as an option, then the cleanReferencesAfterRun method should be called and the value of the option set. I would suggest the following lines of code be inserted in the file mocha.js as the Mocha instance is being initialised (line 162ish) between the handling of the retries option and the general handling of the options. I looked at adding it to the general options, but that appears to be setup only for options which default to false. The default for this would be true.

  if ('retries' in options) {
    this.retries(options.retries);
  }

  // ----> INSERT
  // Read the cleanReferencesAfterRun option
  if ('cleanReferencesAfterRun' in options) {
    this.cleanReferencesAfterRun(options.cleanReferencesAfterRun);
  }
  // <---- END

  [
    'allowUncaught',
    'asyncOnly',
    'bail',
    'checkLeaks',

Describe alternatives you've considered
I've not really considered any other options, this is a fairly basic feature request and I can't really see an alternative. Either the option is recognised or it is not. If this is not accepted, I would need to fork the webdriverio mocha-framework, so that I could access the mocha object and run the cleanReferencesAfterRun method.

Additional context
No additional context.

@RossVertizan RossVertizan added the type: feature enhancement proposal label Feb 26, 2021
RossVertizan added a commit to RossVertizan/vitaq-mocha that referenced this issue Mar 9, 2021
@JoshuaKGoldberg JoshuaKGoldberg changed the title Make cleanReferencesAfterRun a Mocha option 🚀 Feature: Make cleanReferencesAfterRun a Mocha option Dec 28, 2023
@JoshuaKGoldberg
Copy link
Member

Seems like a pretty straightforward addition to the Mocha config. Hovering between considering this a bug and a feature, really.

@JoshuaKGoldberg JoshuaKGoldberg added the status: accepting prs Mocha can use your help with this one! label Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: feature enhancement proposal
Projects
None yet
Development

No branches or pull requests

2 participants