Page MenuHomePhabricator

Don't use "wikimedia/jquery" in selenium .eslintrc
Closed, ResolvedPublic

Description

Although wdio uses $ and $$ this has nothing to do with jquery and the jquery features are mostly not used in the tests. The only way jquery could be used in the tests would by inside of browser.execute() calls but I would not expect that very jquery heavy things are done in there.

So my suggestion is to remove the wikimedia/jquery rule-set from the tests/selenium/.eslintrc.json files and rather add "$": "readonly" and "$$": "readonly".

This would also have the advantage that we do not need to disable the no-jquery/no-global-selector rule in every selenium eslint file. ( Which in theory should not apply anyways since we're not dealing with jquery here :-) )

Event Timeline

@Esanders is doing a lot of eslint clenaup. What do you think?

There are couple of possible solutions:

  1. For the jQuery issue specifically, require that a different alias is used in the client, e.g. jQuery instead of $. The jQuery linting plugin can then be configured to only target jQuery instead of $, by adding "settings": { "no-jquery": { "constructorAliases": ["jQuery"] } } }.
  2. Move all browser code to separate files in a sub-folder that has client-side linting applied, so no client-side code appears in the same file as browser.execute. This is more appropriate a lot of code is being executed in the client, and is the technique I used for VE's screenshot tests: https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/VisualEditor/+/589718/
  3. Create an ESLint pre-processor to lint code inside excute separate. This would be very complicated is probably excessive
  4. Do nothing for smaller snippets of code and turn off client/jQuery linting. The code will still be linted by the common rules. (as suggested in this task description)

I think this approach (4) is fine for now though. It doesn't appear there are many large selenium tests, or ones using much jQuery.

webdriverio also provide their own recommended config: https://github.com/webdriverio/webdriverio/blob/master/packages/eslint-plugin-wdio/index.js

I've created an upstream task to create a config for this: https://github.com/wikimedia/eslint-config-wikimedia/issues/261

@Vidhi-Mody you might be interested in this.

Change 607003 had a related patch set uploaded (by WMDE-Fisch; owner: WMDE-Fisch):
[mediawiki/extensions/ProofreadPage@master] build: Update devDependencies and use wikimedia/selenium

https://gerrit.wikimedia.org/r/607003

Change 607005 had a related patch set uploaded (by WMDE-Fisch; owner: WMDE-Fisch):
[mediawiki/extensions/TemplateWizard@master] build: Update devDependencies and use wikimedia/selenium

https://gerrit.wikimedia.org/r/607005

Change 607006 had a related patch set uploaded (by WMDE-Fisch; owner: WMDE-Fisch):
[mediawiki/extensions/Newsletter@master] build: Update devDependencies and use wikimedia/selenium

https://gerrit.wikimedia.org/r/607006

Change 607003 merged by jenkins-bot:
[mediawiki/extensions/ProofreadPage@master] build: Update devDependencies and use wikimedia/selenium

https://gerrit.wikimedia.org/r/607003

Change 607005 merged by jenkins-bot:
[mediawiki/extensions/TemplateWizard@master] build: Update devDependencies and use wikimedia/selenium

https://gerrit.wikimedia.org/r/607005

Change 607006 merged by jenkins-bot:
[mediawiki/extensions/Newsletter@master] build: Update devDependencies and use wikimedia/selenium

https://gerrit.wikimedia.org/r/607006