cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.8k stars 3.17k forks source link

Scaffolded example specs fail recommended Cypress linting `cypress/no-unnecessary-waiting` #29131

Open MikeMcC399 opened 6 months ago

MikeMcC399 commented 6 months ago

Current behavior

"Scaffold example specs" loaded into the cypress/e2e/2-advanced-examples directory by the Cypress E2E onboarding process fail linting using the recommended configuration as defined by the Cypress-provided cypress-io/eslint-plugin-cypress npm module.

The following two files fail the rule cypress/no-unnecessary-waiting:

Desired behavior

All "Scaffold example specs" loaded into the cypress/e2e/2-advanced-examples directory by the Cypress E2E onboarding process should pass linting using the recommended configuration as defined by the Cypress-provided cypress-io/eslint-plugin-cypress npm module.

The two files which break the cypress/no-unnecessary-waiting rule are legitimately using cy.wait() and should not be called out for this in linting. This is "necessary waiting" not "unnecessary waiting".

Test code to reproduce

git clone --branch cypress-linting https://github.com/MikeMcC399/cypress-test-tiny
cd cypress-test-tiny
npm ci
npm run cypress:lint

Note the 15 linting failures concerning cypress/no-unnecessary-waiting.

Cypress Version

First reported on version 13.7.0 Reproducible also on version 13.15.0

Node version

v20.12.2 v20.17.0

Operating System

Ubuntu 22.04.4 LTS

Debug Logs

$ npm run cypress:lint

> cypress-test-tiny@1.0.0 cypress:lint
> eslint cypress

/cypress-test-tiny/cypress/e2e/2-advanced-examples/viewport.cy.js
  28:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  30:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  32:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  34:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  36:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  38:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  40:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  42:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  44:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  46:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  51:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  53:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting

/cypress-test-tiny/cypress/e2e/2-advanced-examples/waiting.cy.js
  12:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  14:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting
  16:5  error  Do not wait for arbitrary time periods  cypress/no-unnecessary-waiting

✖ 15 problems (15 errors, 0 warnings)

Other

The original source of the examples is cypress-io/cypress-example-kitchensink.

Rule Resolved in
cypress/no-unnecessary-waiting v2.0.0

eslint Version

8.57.0 9.10.0

eslint-plugin-cypress Version

2.15.1 3.5.0

jennifer-shehane commented 6 months ago

@MikeMcC399 That's interesting. I don't recall why we decided to strip these rules. Looks like this was done 7 years ago, so it's just been there forever.

MikeMcC399 commented 3 months ago

To (temporarily?) mitigate this issue, the example https://github.com/cypress-io/eslint-plugin-cypress/blob/master/FLAT-CONFIG.md#cypress-recommended is shown with the rule cypress/no-unnecessary-waiting set to off:

import pluginCypress from 'eslint-plugin-cypress/flat'
export default [
  pluginCypress.configs.recommended,
  {
    rules: {
      'cypress/no-unnecessary-waiting': 'off'
    }
  }
]