-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add aXe rule and infrastructure to evaluate JS
* Create a new method in the collectors `evaluate` that accepts a `script` in `string` format and will return a `Promise`. * Document how to evaluate JavaScript. * Add `aXe` rule with configuration and validation. * Refactor how collectors are tested. Now each area has its own section instead of each collector its file. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Fix #129 Fix #128 Close #178
- Loading branch information
Showing
21 changed files
with
953 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# How to evaluate JavaScript | ||
|
||
Sometimes a rule needs to evaluate some JavaScript in the context of the page. | ||
To do that you need to use `context.evaluate`. This method will always return | ||
a `Promise` even if your code does not return one. | ||
|
||
One important thing is that your code needs to be wrapped in an Immediate | ||
Invoked Function Expression to work. | ||
|
||
The following scripts will work: | ||
|
||
<!-- eslint-disable --> | ||
```js | ||
const script = | ||
`(function() { | ||
return true; | ||
}())`; | ||
|
||
context.evaluate(script); | ||
``` | ||
|
||
```js | ||
const script = | ||
`(function() { | ||
return Promise.resolve(true); | ||
}())`; | ||
|
||
context.evaluate(script); | ||
``` | ||
|
||
The following does not: | ||
|
||
```js | ||
const script = `return true;`; | ||
|
||
context.evaluate(script); | ||
``` | ||
|
||
```js | ||
const script = `return Promise.resolve(true);`; | ||
|
||
context.evaluate(script); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
# Accessibility assesment with aXe | ||
|
||
aXe is the Accessibility Engine for automated testing of HTML-based user | ||
interfaces. This rules performs the default accessibility tests (WCAG 2.0 | ||
Level A and Level AA rules) and alerts if something fails. | ||
|
||
## Why is this important? | ||
|
||
> The Web is an increasingly important resource in many aspects of life: education, | ||
employment, government, commerce, health care, recreation, and more. It is | ||
essential that the Web be accessible in order to provide **equal access** and **equal | ||
opportunity** to people with disabilities. An accessible Web can also help people | ||
with disabilities more actively participate in society. | ||
> | ||
> The Web offers the possibility of **unprecedented access to information and | ||
interaction** for many people with disabilities. That is, the accessibility barriers | ||
to print, audio, and visual media can be much more easily overcome through Web | ||
technologies. | ||
> | ||
> The document ["Social Factors in Developing a Web Accessibility Business Case for | ||
Your Organization"](https://www.w3.org/WAI/bcase/soc) discusses how the Web | ||
impacts the lives of people with disabilities, the overlap with digital divide | ||
issues, and Web accessibility as an aspect of corporate social responsibility. | ||
> | ||
> Another important consideration for organizations is that Web accessibility is | ||
required by laws and policies in some cases. | ||
|
||
***From [WAI's Introduction to Web Accessibility](https://www.w3.org/WAI/intro/accessibility.php).*** | ||
|
||
## What does the rule check? | ||
|
||
By default this rule runs all the [WCAG 2.0](https://www.w3.org/TR/WCAG20/) | ||
Level A and Level AA rules included in [axe-core](https://github.com/dequelabs/axe-core/) | ||
with `document` as the target. Visit the | ||
[full list of default enabled rules](https://github.com/dequelabs/axe-core/blob/develop/doc/rule-descriptions.md) | ||
for more information of what they do. | ||
|
||
## Can the rule be configured? | ||
|
||
This rule uses | ||
[`axe.run`](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#api-name-axerun) | ||
and the default values ([WCAG 2.0](https://www.w3.org/TR/WCAG20/) Level A and | ||
Level AA rules) over the `document`. | ||
You can modify what rules or categories are executed via an `options` object | ||
that follows | ||
[aXe's documentation](https://github.com/dequelabs/axe-core/blob/develop/doc/API.md#options-parameter). | ||
|
||
Some examples of configurations: | ||
|
||
* Run only WCAG 2.0 Level A rules: | ||
|
||
```json | ||
{ | ||
"axe": ["error", { | ||
"runOnly": { | ||
"type": "tag", | ||
"values": ["wcag2a"] | ||
} | ||
}] | ||
} | ||
``` | ||
|
||
* Run only a specified set of rules: | ||
|
||
```json | ||
{ | ||
"axe": ["error", { | ||
"runOnly": { | ||
"type": "rule", | ||
"values": ["ruleId1", "ruleId2", "ruleId3" ] | ||
} | ||
}] | ||
} | ||
``` | ||
|
||
* Run all enabled rules except for a list of rules: | ||
|
||
```json | ||
{ | ||
"axe": ["error",{ | ||
"rules": { | ||
"color-contrast": { "enabled": false }, | ||
"valid-lang": { "enabled": false } | ||
} | ||
}] | ||
} | ||
``` | ||
|
||
## Further Reading | ||
|
||
* [Deque Univeristy](https://dequeuniversity.com/) | ||
* [aXe core GitHub page](https://github.com/dequelabs/axe-core) | ||
* [Web Accessibility Initiative (WAI)](https://www.w3.org/WAI/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.