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

Un-deprecate the "suite" event #4760

Closed
beatfactor opened this issue Oct 1, 2021 · 11 comments · Fixed by #4764
Closed

Un-deprecate the "suite" event #4760

beatfactor opened this issue Oct 1, 2021 · 11 comments · Fixed by #4764
Labels
area: integrations related to working with 3rd party software (e.g., babel, typescript)

Comments

@beatfactor
Copy link
Contributor

Hi there,

We are using Mocha as an alternative test runner in Nightwatch.js and we are in the process of migrating it to use Mocha 9. I noticed that the 'suite' event is deprecated and it would be great if you would consider un-deprecating it. This is the only clean way for us to start the Nightwatch session before the Mocha suite is execute and without it we'd have to result to inefficient and complicated workarounds.

Thanks!

@juergba
Copy link
Member

juergba commented Oct 1, 2021

Afaik the suite event is not deprecated. Why do you think so?

@beatfactor
Copy link
Contributor Author

It is according to the API docs. Event EVENT_SUITE_ADD_SUITE is listed as deprecated.

@DudaGod
Copy link

DudaGod commented Oct 1, 2021

Hello. I want too use event 'suite' without deprecation warnings. Moreover I need other deprecated events. For example in our tool we does not add ability to users use beforeAll and afterAll hooks. So when event with beforeAll triggered we throw error.

The problem is here - https://github.com/mochajs/mocha/blob/master/lib/suite.js#L686-L693.

@juergba
Copy link
Member

juergba commented Oct 1, 2021

@beatfactor All those EVENT_SUITE_ADD* events are triggered during the parsing cycle, while the test files are read and the test runner is created. Therefore before any test/hook will be executed. In our own code they have no purpose.

This is the only clean way for us to start the Nightwatch session before the Mocha suite is execute [...]

You are talking about "suite is execute", so the execution cycle (not parsing cycle). Couldn't you listen to the runner events as EVENT_RUN_BEGIN (Emitted when Root Suite execution begins (all files have been parsed and hooks/tests are ready for execution))?

@beatfactor
Copy link
Contributor Author

@juergba No, I am actually talking about the parsing cycle as well, even before the test suite is execute. Listening to the runner events doesn't help because we need to be able to extend the test suite before it's being executed. The EVENT_SUITE_ADD event allows us to do just that.

It's up to you and your team of course to decide if you're going to keep it or not but for us it is very helpful and if it's removed from future versions that means that we will have to probably work with a fork of Mocha, which is fine but not ideal, since it will inevitably be always behind the latest version.

@juergba
Copy link
Member

juergba commented Oct 2, 2021

@beatfactor Can you explain we need to be able to extend the test suite? Just for curiosity.

Could you open a PR, please? All in lib/suite.js.

  • remove deprecatedEvents
  • remove newListener listener
  • update the docs
  • evtl. there may be some test to remove, I don't know

@beatfactor
Copy link
Contributor Author

In Nightwatch we have a bunch of custom stuff added to the describe interface. You can do things like defining tags for instance:

describe('homepage test with describe', function() {
  // defining tags using bdd
  this.tags = ['login', 'authentication''];

  test('...', function() {...});
});

You can see more about it here. This is in our own version of the describe interface, which has been added since v1.3 but you can also use Mocha as a test runner since v0.9. However, the bundled version of Mocha in Nightwatch is based on Mocha 6 and also it lacks the ability to use tags and other Nightwatch-related things, which you can do in our own version of the describe interface.

But since Nightwatch v2 we are upgrading our bundled version of the Mocha runner to be based on Mocha 9 and so we need to be able to extend the test suite in one way or another. Listening to the test suite add event proved to be the most straightforward way to do that.

Sure, I will go ahead and send a PR soon. Thanks!

@juergba
Copy link
Member

juergba commented Oct 2, 2021

Which test runner are you using with your own describe interface?
You could also add your own interface to Mocha by extending its existing bdd interface.

I don't know wether those EVENT_SUITE_ADD* are the best way to achieve your goals. I'm unsure, but anyway there is no risk in un-deprecating them.

@beatfactor
Copy link
Contributor Author

Our own test runner. I have looked into adding an extra interface but we actually want users to be able to set their own interface when using the Mocha runner so this won't work. We also need to extend the Mocha runner itself and adapt the runnables. If you're interested, the whole thing will be online in a few days and if you'd like you can have a look at it.

@juergba juergba linked a pull request Oct 3, 2021 that will close this issue
@juergba juergba added the area: integrations related to working with 3rd party software (e.g., babel, typescript) label Oct 3, 2021
@beatfactor
Copy link
Contributor Author

@juergba thanks for merging the PR. Do you have an indication on when it's going to be in NPM?

@juergba
Copy link
Member

juergba commented Oct 5, 2021

@beatfactor In 7-10 days latest, I first need another (browser) issue fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: integrations related to working with 3rd party software (e.g., babel, typescript)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants