question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Write Lint Checks for the End-to-End Tests

See original GitHub issue

This issue is on hold while @ShivamJhaa completes the E2E migration.

To improve the quality of our end-to-end testing code, we want to create lint checks for common bad practices. If you would like to help with this issue, please leave a comment on this issue with the task you want to work on.

How to Write E2E Lint Checks

  1. First think about how you can identify the bad practice based solely on the text of the code. Imagine you get a code file as a string. How would you look for any cases of the practice you are writing a check against? While you won’t know the types of variables in the code, you can take advantage of linters’ abstract syntax trees representing the parsed code. Note that you might conclude it’s not possible to enforce a practice with a linter. For example, we discovered that with action.clear. If this happens, please let us know so we can remove it from the list.
  2. Follow the instructions on the linter wiki page for adding a new lint check. Since you’re linting the E2E code, you’ll want to write a custom ESLint check. You’ll probably do something like this:
  3. Remove the node_modules/eslint-plugin-oppia/ directory and run yarn install to install your linter.
  4. Run python -m scripts.run_custom_eslint_tests to check that the tests you wrote pass.
  5. Run your lint checks with:
    python -m scripts.linters.pre_commit_linter --path core/tests/protractor
    python -m scripts.linters.pre_commit_linter --path core/tests/protractor_desktop
    python -m scripts.linters.pre_commit_linter --path core/tests/protractor_utils
    
    and fix any errors.
  6. Create a PR to add your lint check!

You can also check out #11734 as an example of how to add these checks. If you have any questions, please reach out to @U8NWXD.

Lint Checks to Add

  • Use action.click instead of calling .click() on an element. @U8NWXD
  • Use action.sendKeys instead of calling .sendKeys on an element. @U8NWXD
  • Do not access pages by URLs.
  • Do not call .first() on a list of ElementArrayFinders. Reserved for GSoC
  • Do not call .last() on a list of ElementArrayFinders. Reserved for GSoC
  • Do not call .get() on a list of ElementArrayFinders. Reserved for GSoC
  • Do not use browser.sleep() calls @AdityaDubey0
  • Usernames, email addresses, topic names, skill names, exploration names, story names, and chapter names should be reliably unique as described in the wiki.
  • Do not index into ElementArrayFinders with bracket notation ([]).
  • Do not access .length of ElementArrayFinders.
  • Do not use browser.switchTo().activeElement(). There might be some exceptions.
  • Make sure to have nested awaits for await (await browser.switchTo().activeElement()).sendKeys(explanation);. There should be no exceptions to this.
  • Do not use forEach. @vashuteotia123
  • Do not use filter.
  • Do not use .then(). @MA86

Notes

  • It isn’t possible to write a lint check for using action.clear instead of calling .clear() on an element. This is because it’s valid to call .clear() on rich text editors.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:76 (55 by maintainers)

github_iconTop GitHub Comments

1reaction
abderrahmaneMustaphacommented, Sep 24, 2021

hi @U8NWXD iwas busy this week but i can start working on this tomorrow

1reaction
U8NWXDcommented, Sep 3, 2021

Deassigned @suryasiriki4 @ahreehong @iabouara24 @SAEb-ai @Varun8216889 @MA86 due to inactivity. If you are still working on your tasks, let me know and I’ll re-assign you

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Test Custom Lint Checks - Infinum
Tests help make sure the check behaves correctly in every possible case, but can also help with debugging.
Read more >
What Is a Linter? - Everything You Need to Know - testRigor
In a nutshell, lint, or a linter, is used to analyze the static source code of your software project to look for problems...
Read more >
AWS Amplify: code lint & end-to-end testing with Cypress
Source code linter (ESLint / Pylint) and end-to-end tests with Cypress, in automated AWS Amplify CI/CD pipeline.
Read more >
Beginner's guide to writing end-to-end tests - GitLab Docs
Check both GitLab Community Edition and GitLab Enterprise Edition coverage projects for previously-written tests for this feature. For analyzing the code ...
Read more >
Playwright End To End Testing Tutorial: A Complete Guide
At the time of writing this blog on Playwright end to end testing, ... your commands to run the test, build your code,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found