-
Notifications
You must be signed in to change notification settings - Fork 87
New API RFC #75
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
Comments
I've worked now with several of the test framework axe extensions. Based on that experience, I have some thoughts about the approach cypress-axe is taking to provide many options for filtering out and reporting. Many of the extensions are just taking on the job of making it easy to inject axe and scan the html and just returning results to the users. e.g.: jest-axe takes a similar approach: https://github.com/nickcolley/jest-axe#testing-react For cypress-axe, could it work to drop some of the proposed options from checkA11y?
checkAlly would then look something like (the following is slightly pseudocode)
and then, as shown, the user can do what they need with filtering, reporting and then calling an assert to pass or fail the test. However, I think the above approach could reduce some maintenance burden from this library as some of the requests like #40 and #62 could then be easily resolved by the coder instead of having to be handled in this package. I also want to call out that there are a few more open source reporters that have come out recently: These can be used in any javascript code, so it doesn't matter which test framework you have. |
@kristina-hager Thanks for the comment! The problem with this approach is that it requires too much setup from the user to have anything useful. I want to have a zero-config (as much as possible) tool that allows extension. Not a tool where I have to do everything myself, and spend hours or days googling and reading docs, trying to glue several libraries that are supposed to work together but just don't ;-) Honestly, I'm really tired of this. maxViolations: 0, // remove this and let user create their own assert
minImpact: 'minor', //remove this and let the user inspect the results and create their own assert The reason for these two options is to allow gradual adoption. I'm not sure what you mean by “their onw assert” and how it will help with that. But I agree there might be a better API. reporters: [ // remove this and give the full results object back to user This is exactly what it does but I don't see reasons why not provide useful defaults.
This is interesting, I'll definitely have a look! |
I second @kristina-hager 's comment to make Specifying Also, by decoupling those parts, I believe it won't make cypress-axe extremely difficult to use, since other similar extensions also making the same approach. For example, this one: https://github.com/dequelabs/axe-core-npm/tree/develop/packages/webdriverjs, where the only responsibility is to inject axe-core and analyze. |
The request really is about separation of concerns. I'll make a PR to illustrate what I mean. |
Here's the PR (still WIP) to illustrate what I mean. I still need to test this and beef up readme changes. |
Sorry but such API is extremely difficult to use. If that's what you really need, you could use axe-core directly. I'm happy to make the API more flexible, if it doesn't cover any use cases, but it shouldn't be at the cost of the majority of the users. |
Well, I suppose reasonable people may disagree on this matter. However, all the extra functionality this package wraps may be ignored by the user especially if the following changes can be included:
In addition, this change would bring this library in line with the majority of other axe-core extensions that do not provide such features and do not do the assert for the user while allowing the additional bells/whistles that some find appealing to remain. |
👍
This will make an unfortunate default making the library do nothing by default, I'm sure it will confuse many people trying to use it. Let's keep the defaults helpful, you could change them as you wish via the new However, I think we can make a more generic method for managing failure instead of proposed shouldFail(violations: RunResults[], results: RunResults[]) => boolean With default value that would fail on any number of violations. It will be one line function to implement |
Well, again, I think this is a matter where we don't agree. Based on experience with other libs, the injecting of axe is the confusing part. With just this covered, the library has value. Ultimately, I'm advocating for the use case we have, which is that we need the full results object back for analysis and users can generally handle writing their asserts (or they can use the embedded assert functionality if they like). That said:
This sounds interesting! I'd look forward to seeing the new draft of the API. There have been enough changes that i've lost track a bit. |
I've updated the initial comment so we have the single source of truth here. I've also simplified reporters: now it's just a function that gets the full results object and is free to do what it wishes with it. |
Thanks! looks basically good to me. i'd be glad to review any PR when you're ready. |
I think I want to migrate the code to TypeScript first — it will be easier to work on the new API, and also we'll have our own typings. |
Hahah, well, I won't get into debates about typescript vs javascript for relatively small codebases. 😄 |
Very good idea. |
I am a fan of this new API proposal. I agree that returning all results is useful in case someone wants to do something more custom, but I also personally appreciate having a nice default reporter so I don't have to put in extra effort there. |
@sapegin - is this the API you will go with? If so, I may move our internal fork to align to ease the transition back to this version when it is ready. That is, unless you have some plan to release this anytime "soon" (e.g. this year?). |
Came to this issue by searching the tracker for the ability to assert/log on a threshold of "needs review" items, aka the |
I agree with sgregson - my issue with not having the full results object, is that the current cypress-axe provides access to only the violations object... by default the form-field-multiple-labels rule is listed as "needs review" (https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md) which is in the "incomplete" array, not the violations list (https://www.deque.com/axe/core-documentation/api-documentation/#results-object)... so at the moment it would appear your facade on axe-core is preventing me from accessing / reporting on these types of rule results... Also other rules can do both - for example color-contrast will fail for solid backgrounds but return needs-review for gradient backgrounds (and I'm sure there are others)... so these results end up in two different locations. I'll try increasing the violation level on that rule (and perhaps others)... but it took me a while to figure out why the "rules were not running" - (experimental rules are not run by default, but all the others are)... it's just being filtered out for me, like warnings don't matter. Please consider changing the interface to allow for either the full result object to be returned, or wrap the other properties on it or some-such-thing... eg have a fuller, better facade on the result object, than just filtering the violations. |
Hi, is there a schedule for the implementation of the new API? In the near future, I will start working on a11y testing with Cypress. The new proposed API fits my requirements so I will be happy to contribute to the development. |
Is there still any effort planned on these changes? Just checking. My team made an internal fork to deal with some needed updates, but we'd much rather move back to open source. |
Chaining would be awesome 🎉 |
I also welcome more flexible custom reporting. The reporting format I would like to use: But right now cypress-axe works like this: if (violations.length) {
if (violationCallback) {
violationCallback(violations);
}
violations.forEach(function (v) {
var selectors = v.nodes
.reduce(function (acc, node) { return acc.concat(node.target); }, [])
.join(', ');
Cypress.log({
$el: Cypress.$(selectors),
name: 'a11y error!',
consoleProps: function () { return v; },
message: v.id + " on " + v.nodes.length + " Node" + (v.nodes.length === 1 ? '' : 's'),
});
});
} So I can't configure a custom reporting without having the default reporting in there too (well, unless I use tricks like |
Can you just please make a callback to access all axe-core results object ? IMHO, making small changes will be helpful instead of big changes, an by receiving feedback, things will be clearer if it worth the effort or not (Just my thought). |
Issues with the current API
checkA11y()
method make it awkward to use and very difficult to extend. We have several open pull requests that are adding a new argument at the end.checkA11y()
method, and uses a customcontext
argument. This makes the usage less idiomatic and doesn't allow integration with tools like Cypress Testing Library.checkA11y()
method, we have to pass things likeviolationCallback
in every call or create a custom command.Related issues: #40, #49, #62, #67, #68
New API proposal
context
argument of thecheckA11y()
method, and rely on the Cypress chaining instead:The defaults are going to be:
Reporters are replacing the
violationCallback
: they are more flexible, have access to both passes and violations, and you could have global reporters that would run after all tests, or pass a reporter for a separatecheckA11y()
method call. The default reporter is printing an overall summary after all tests.checkA11y()
method:Similar to labels
describe()
orit()
methods, to identify results of a particular call.It should accept the same object as the
checkA11y()
method, and set default values that could be overwritten incheckA11y()
.I hope this covers all the use cases we have. I'm not sure that all the names are clear, so if you have any feedback, leave a comment ;-)
The text was updated successfully, but these errors were encountered: