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

feat: add a reference to the node a rule failed on #1321

Merged
merged 10 commits into from
Jan 21, 2019

Conversation

stephenmathieson
Copy link
Member

@stephenmathieson stephenmathieson commented Jan 16, 2019

This patch adds a .node reference to an errored rule result. This can be used to determine which node the rule errored on and will be helpful for debugging purposes.

Closes #1317.

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

  • Follows the commit message policy, appropriate for next version
  • Has documentation updated, a DU ticket, or requires no documentation change
  • Includes new tests, or was unnecessary
  • Code is reviewed for security by: @WilcoFiers

This patch adds a `.node` reference to an errored rule result. This can be used to determine which node the rule errored on and will be helpful for debugging purposes.

Closes #1317.
@stephenmathieson stephenmathieson requested a review from a team January 16, 2019 19:39
@stephenmathieson stephenmathieson requested a review from a team as a code owner January 16, 2019 19:39
@stephenmathieson
Copy link
Member Author

Seems this isn't quite as simple as I had hoped. Since the results object is serialized (JSON.stringify()), we can't just attach the node here (due to circular references). Perhaps a unique selector for the element would work instead?

Thoughts anyone?

@straker
Copy link
Contributor

straker commented Jan 16, 2019

Would getting the outerHTML be sufficient for debugging in these cases?

@stephenmathieson
Copy link
Member Author

I don't think outerHTML would be enough by itself, since it won't always point to a single node. For example, if axe-core errored on one of the <span>s in the below chunk of HTML, we wouldn't know which:

<div>
  <span>hello</span>
  <span>hello</span>
  <span>hello</span>
</div>

This is why I was thinking a (unique) selector would work, since we'd get back something like: div > span:nth-child(2) which paints a clearer picture.

This said, perhaps an object which resembles the following would work?

{
  "html": "<span>hello</span>",
  "selector": "div > span:nth-child(2)"
}

@straker
Copy link
Contributor

straker commented Jan 16, 2019

I guess since axe reports issues using a unique selector then it would work. Though not being able to click on the inspect node button right above it might still be problematic for DOM that repeats structure. But I can't think of a better alternative without having the actual node to reference.

@jeeyyy
Copy link
Contributor

jeeyyy commented Jan 18, 2019

@stephenmathieson, is it a DqElement at this point? If yes, there is a getter named selector which can return a unique CSS selector for the element

See - https://github.com/dequelabs/axe-core/blob/develop/lib/core/utils/dq-element.js#L56

Copy link
Contributor

@WilcoFiers WilcoFiers left a comment

Choose a reason for hiding this comment

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

Actually, Jey is right, we should get the selector and HTML of the element, not the element itself.

@stephenmathieson
Copy link
Member Author

Looks like we can use the toJSON method which should provide all necessary information.

@stephenmathieson
Copy link
Member Author

Turns out, this isn't a DqElement. It's something else. I'm trying to figure out what's going on here.

Didn't think this was going to be nearly as complicated as seems to be 🤷‍♀️

@stephenmathieson
Copy link
Member Author

I figured out how to make node a DqElement here, but the tests are now erroring with:

Error: Expect axe._selectorData to be set up
    at generateSelector (http://localhost:9876/tmp/core/utils/get-selector.js:308:9)
    at Object.createUniqueSelector [as getSelector] (http://localhost:9876/tmp/core/utils/get-selector.js:377:10)
    at DqElement.get selector [as selector] (http://localhost:9876/tmp/core/utils/dq-element.js:58:43)
    at DqElement.toJSON (http://localhost:9876/tmp/core/utils/dq-element.js:84:19)

I do not understand the error here, so any help/suggestions would be appreciated.

@jeeyyy jeeyyy requested a review from WilcoFiers January 21, 2019 11:02
@jeeyyy
Copy link
Contributor

jeeyyy commented Jan 21, 2019

Updated. Tests are fixed.

@@ -58,6 +58,7 @@ Check.prototype.enabled = true;
* @param {Function} callback Function to fire when check is complete
*/
Check.prototype.run = function(node, options, context, resolve, reject) {
/* eslint max-statements:0 */
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems unnecessary.

Copy link
Member Author

Choose a reason for hiding this comment

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

The "max statements" rule seems unnecessary. We always increase the minimum rather than refactoring our code. IMO it should be disabled.

@WilcoFiers WilcoFiers merged commit 68741de into develop Jan 21, 2019
@WilcoFiers WilcoFiers deleted the add-error-node-ref branch January 21, 2019 11:51
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.

4 participants