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

Suggestion: add rule that prevents focused tests #57

Closed
khitrenovich opened this issue May 1, 2020 · 4 comments
Closed

Suggestion: add rule that prevents focused tests #57

khitrenovich opened this issue May 1, 2020 · 4 comments

Comments

@khitrenovich
Copy link

We have a rule that prevents focused tests by default in Jest eslint plugin (https://github.com/jest-community/eslint-plugin-jest/blob/master/docs/rules/no-focused-tests.md), but not in Cypress. As a workaround, we are adding https://www.npmjs.com/package/eslint-plugin-no-only-tests to our Cypress eslint configuration, but it would be nice to have this straight from plugin:cypress/recommended configuration.

@MikeMcC399
Copy link
Collaborator

An alternative to using the plugin eslint-plugin-no-only-tests as a workaround would be to use the plugin eslint-plugin-mocha instead.

plugin:mocha/recommended from eslint-plugin-mocha conveniently includes the rule mocha/no-exclusive-tests which addresses .only use cases:

This rule looks for every describe.only, it.only, suite.only, test.only, context.only and specify.only occurrences within the source code.

The rule mocha/no-exclusive-tests is better suited to Cypress tests than the no-only-tests/no-only-tests rule. The latter rule attempts to check usage of .only in scopes outside of Cypress' usage.

Example

In the cypress-io/cypress-example-kitchensink repo the two plugins – eslint-plugin-cypress and eslint-plugin-mocha – are successfully combined using:

  • eslint:recommended
  • plugin:cypress/recommended
  • plugin:mocha/recommended

adding also the rule:

  • "mocha/no-exclusive-tests": "error"

makes the tests fail instead of producing a warning in case an .only has inadvertently been left in the Cypress test specs.

@MikeMcC399
Copy link
Collaborator

@khitrenovich

Given that the .only test is available in mocha/no-exclusive-tests and that it is part of the default plugin:mocha/recommended from eslint-plugin-mocha, do you think it is necessary to duplicate this rule in eslint-plugin-cypress?

@khitrenovich
Copy link
Author

@khitrenovich

Given that the .only test is available in mocha/no-exclusive-tests and that it is part of the default plugin:mocha/recommended from eslint-plugin-mocha, do you think it is necessary to duplicate this rule in eslint-plugin-cypress?

Wow, May 2020 was two companies and several projects ago for me... We are still with Cypress, though, and looking at the current configuration I see that no-exclusive-tests rule from eslint-plugin-mocha is exactly what we use to lint Cypress tests now. So, from functionality perspective I think we are good here.

The question whether you want to rely on 3rd party plugin to help Cypress users I'm leaving to you :)

@MikeMcC399
Copy link
Collaborator

Thank you @khitrenovich for responding again after such a long time! It's good to hear that you are still with Cypress and that practical experience says that you can use mocha/no-exclusive-tests from eslint-plugin-mocha for the purpose that you originally submitted your suggestion for.

The question whether you want to rely on 3rd party plugin to help Cypress users I'm leaving to you :)

This plugin extensively relies on open source software from other contributors. When you install this plugin it currently says "added 92 packages". These are all npm modules from the npm registry. Installing eslint-plugin-mocha additionally shows "added 5 packages". This is all part of using open source software, with its risks and benefits!

I'm going to close this issue now as you have confirmed that your needs are met.

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

No branches or pull requests

2 participants