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

Add queryElements test helper, remove t.plan #1343

Merged
merged 9 commits into from
May 5, 2020
Merged

Conversation

smhigley
Copy link
Contributor

Resolves #1312

Adds t.context.queryElements helper function that wraps t.context.session.findElements, and fails the test if no elements are found.

Removes t.plan(), now that it isn't needed to ensure that tests are run.

Removes some unrelated unused imports caught while updating the above.

Copy link
Member

@zcorpan zcorpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a lint check to make sure t.plan() and findElements() aren't accidentally added in the future?

Edit: or, maybe not lint against t.plan(); there may be cases where it's still useful.

test/util/queryElements.js Outdated Show resolved Hide resolved
test/util/queryElements.js Outdated Show resolved Hide resolved
Copy link
Member

@zcorpan zcorpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a lint check would be good. We also need to update our documentation in the wiki for this change.

@zcorpan
Copy link
Member

zcorpan commented Mar 4, 2020

I added a lint check in c16088f -- there were still 12 uses (not counting the one in queryElement.js). Do you think those should be changed to use queryElements?

/Users/zcorpan/git/w3c/aria-practices/test/index.js
  89:16  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/tests/checkbox_checkbox-2.js
   55:14  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties
   85:12  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties
  201:12  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/tests/combobox_autocomplete-both.js
  60:31  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/tests/combobox_autocomplete-list.js
  61:31  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/tests/combobox_autocomplete-none.js
  61:31  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/tests/combobox_grid-combo.js
  137:31  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/tests/grid_LayoutGrids.js
  125:16  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/tests/tabs_tabs-1.js
  355:12  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/tests/tabs_tabs-2.js
  363:12  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

/Users/zcorpan/git/w3c/aria-practices/test/util/assertAriaDescribedby.js
  51:36  error  'findElements' is restricted from being used. Please use t.context.queryElements()  no-restricted-properties

✖ 12 problems (12 errors, 0 warnings)

Copy link
Member

@zcorpan zcorpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed my own comments. :-)

@zcorpan
Copy link
Member

zcorpan commented Mar 6, 2020

Documentation in the wiki should be updated. I don't want to do this now since my changes haven't been reviewed and I don't want the documentation to be out of sync with what's in master.

@mcking65
Copy link
Contributor

mcking65 commented Mar 9, 2020

@smhigley, could you please look at Simon's changes?

It would be good to have a review of the entire PR from @sh0ji or @spectranaut as well.

Given the number of files touched, I'd like to get this merged as soon as we can.

@@ -5,6 +5,10 @@
},
"rules": {
"no-unused-vars": 0,
"no-undef": 0
"no-undef": 0,
"no-restricted-properties": [2, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should plan be added if you're trying to discourage it too?

test/index.js Outdated
@@ -1,3 +1,5 @@
/* eslint no-restricted-properties: 0 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might makes sense to use a single line ignore instead of a file level one

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it can be re-enabled now

Copy link
Contributor

@spectranaut spectranaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! but I don't think we can merge until this issue Simon brought up is resolved.

Simon said:

I added a lint check in c16088f -- there were still 12 uses (not counting the one in queryElement.js). Do you think those should be changed to use queryElements?

These would take more work to replace, because some of them make sure we get zero results from the query (which would cause a failure). I think our options are to (1) allow findElements in linter because of this case or (2) add a helper function for this particular scenario, and otherwise use queryElements. Preferences, @zcorpan or @smhigley ?

@smhigley
Copy link
Contributor Author

smhigley commented Mar 9, 2020

I left those 12 in there intentionally because they dealt with testing the number returned, rather than just assuming within the test that there would be a non-empty array. I think that could still be a valid use case for findElements instead of queryElements.

What if we add a lint rule for t.plan instead, as @nschonni recommended? If that seems like it increases complexity too much for people writing tests, I also like @spectranaut's suggestion of a helper for that specific scenario. Perhaps something like assertNotEmpty or assertNumberOfElements (I'm bad at naming things... 😝)

@zcorpan
Copy link
Member

zcorpan commented Mar 10, 2020

I considered linting plan but wasn't sure if there are still cases where it's needed. If there aren't then we can lint it.

For the cases where findElements is still used, we want to assert that the length is 0? A separate helper function for that which fails if the length is not 0 seems cleanest to me. assertNoElement() maybe?

@mcking65
Copy link
Contributor

What is the best approach to arriving at a decision for how to resolve the remaining issue here? The technical aspect of this discussion is beyond my expertise.

One thing I hope we optimize for is clarity of code, especially for new comers to test writing.

@smhigley
Copy link
Contributor Author

I like @zcorpan's suggestion of assertNoElements. I'll push up a commit with it in just a bit :)

@smhigley
Copy link
Contributor Author

I rebased and removed all the remaining uses of findElements, apart from the two in the queryElements and assertNoElements helpers.

@spectranaut / @zcorpan / @nschonni, how do you feel about the PR after those changes?

Copy link
Contributor

@nschonni nschonni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor indenting things, maybe need to run eslint fix for.
Didn't go through them all, but might want to check that the /* eslint no-restricted-properties: 0 */ lines still make sense

test/index.js Outdated
@@ -1,3 +1,5 @@
/* eslint no-restricted-properties: 0 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it can be re-enabled now

@@ -1,10 +1,13 @@
/* eslint no-restricted-properties: 0 */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think this can be re-enabled again

@smhigley
Copy link
Contributor Author

@nschonni I removed the now-unnecessary eslint no-restricted-properties. eslint . --fix doesn't seem to be catching or changing anything, though

@nschonni
Copy link
Contributor

@smhigley don't worry about it then :)
Looks like some mixed 2/4 spaces in some functions, but if the lint isn't catching it then the rules aren't enforcing it right now and shouldn't matter here

@smhigley
Copy link
Contributor Author

smhigley commented Apr 3, 2020

@spectranaut are you ok with the PR now/do you have any outstanding concerns?

@zcorpan zcorpan requested a review from spectranaut April 30, 2020 13:18
Copy link
Member

@zcorpan zcorpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing on behalf of @spectranaut :)

LGTM. This now has conflicts though.

@zcorpan
Copy link
Member

zcorpan commented Apr 30, 2020

(I didn't get to resolving conflicts today.)

@smhigley smhigley force-pushed the 1312-plan-helper branch from 4fd14ca to 0f80db3 Compare May 3, 2020 06:38
@smhigley
Copy link
Contributor Author

smhigley commented May 3, 2020

@zcorpan conflicts resolved :)

Copy link
Member

@zcorpan zcorpan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but a test in CI failed.

not ok 629 - NoSuchSessionError: Tried to run command without establishing a connection

Maybe this was a flaky failure? If so, we can try rerunning CI. (Done by closing and reopening.)

@zcorpan zcorpan closed this May 4, 2020
@zcorpan zcorpan reopened this May 4, 2020
@mcking65 mcking65 merged commit b9f352d into master May 5, 2020
@mcking65 mcking65 deleted the 1312-plan-helper branch May 5, 2020 08:15
michael-n-cooper pushed a commit that referenced this pull request May 5, 2020
Infrastructure: Add queryElements test helper, remove t.plan from regression tests (pull #1343)

Resolves issue #1312 with changes that:
* add queryElements helper
* update findElements to queryElements in tests, remove unused imports
* update missing awaits
* Add a lint check for findElements and exclude current uses
* Document `t` argument, unconditionally return `result`
* add assertNoElements test helper
* removed unnecessary eslit no-restricted-props
* update carousel tests to use queryElements

Co-authored-by: Simon Pieters <zcorpan@gmail.com>
Co-authored-by: Matt King <a11yThinker@Gmail.com>
smhigley added a commit that referenced this pull request May 20, 2020
…ression tests (pull #1343)

Resolves issue #1312 with changes that:
* add queryElements helper
* update findElements to queryElements in tests, remove unused imports
* update missing awaits
* Add a lint check for findElements and exclude current uses
* Document `t` argument, unconditionally return `result`
* add assertNoElements test helper
* removed unnecessary eslit no-restricted-props
* update carousel tests to use queryElements

Co-authored-by: Simon Pieters <zcorpan@gmail.com>
Co-authored-by: Matt King <a11yThinker@Gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Helper function to eliminate need for t.plan()
5 participants