Skip to content

Commit

Permalink
Merge branch 'develop' into async-report-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
WilcoFiers committed Aug 2, 2023
2 parents 59dbd7f + 33b0314 commit 0ef8333
Show file tree
Hide file tree
Showing 115 changed files with 190 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build/rule-generator/get-files-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const getRuleSpecFileMeta = (ruleName, ruleHasMatches, ruleChecks) => {
content: JSON.stringify(
{
id: ruleName,
impact: '',
selector: '*',
...(ruleHasMatches && {
matches: `${ruleName}-matches`
Expand Down Expand Up @@ -121,7 +122,6 @@ const getCheckSpecFileMeta = (name, dir) => {
id: `${name}`,
evaluate: `${name}-evaluate`,
metadata: {
impact: '',
messages: {
pass: '',
fail: '',
Expand Down
3 changes: 2 additions & 1 deletion build/tasks/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ function createSchemas() {
conform: 'Must have at least two valid messages'
}
},
// @deprecated: Use impact on rules instead
impact: {
required: true,
type: 'string',
enum: ['minor', 'moderate', 'serious', 'critical']
}
Expand All @@ -134,6 +134,7 @@ function createSchemas() {
type: 'string'
},
impact: {
required: true,
type: 'string',
enum: ['minor', 'moderate', 'serious', 'critical']
},
Expand Down
2 changes: 1 addition & 1 deletion doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ axe.configure({
- The rules attribute is an Array of rule objects
- each rule object can contain the following attributes
- `id` - string(required). This uniquely identifies the rule. If the rule already exists, it will be overridden with any of the attributes supplied. The attributes below that are marked required, are only required for new rules.
- `impact` - string(optional). Override the impact defined by checks
- `impact` - string(required). Sets the impact of that rule's results
- `reviewOnFail` - boolean(option, default `false`). Override the result of a rule to return "Needs Review" rather than "Violation" if the rule fails.
- `selector` - string(optional, default `*`). A [CSS selector](./developer-guide.md#supported-css-selectors) used to identify the elements that are passed into the rule for evaluation.
- `excludeHidden` - boolean(optional, default `true`). This indicates whether elements that are hidden from all users are to be passed into the rule for evaluation.
Expand Down
4 changes: 2 additions & 2 deletions doc/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ After execution, a Check will return `true`, `false`, or `undefined` depending o
Rules are defined by JSON files in the [lib/rules directory](../lib/rules). The JSON object is used to seed the [Rule object](../lib/core/base/rule.js#L30). A valid Rule JSON consists of the following:

- `id` - `String` A unique name of the Rule.
- `impact` - `String` (one of `minor`, `moderate`, `serious`, or `critical`). Sets the impact of the results of this rule
- `selector` - **optional** `String` which is a [CSS selector](#supported-css-selectors) that specifies the elements of the page on which the Rule runs. axe-core will look inside of the light DOM and _open_ [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Shadow_DOM) trees for elements matching the provided selector. If omitted, the rule will run against every node.
- `excludeHidden` - **optional** `Boolean` Whether the rule should exclude hidden elements. Defaults to `true`.
- `enabled` - **optional** `Boolean` Whether the rule is enabled by default. Defaults to `true`.
- `pageLevel` - **optional** `Boolean` Whether the rule is page level. Page level rules will only run if given an entire `document` as context.
- `matches` - **optional** `String` The ID of the filtering function that will exclude elements that match the `selector` property. See the [`metadata-function-map`](../lib/core/base/metadata-function-map.js) file for all defined IDs.
- `impact` - **optional** `String` (one of `minor`, `moderate`, `serious`, or `critical`). Override the impact defined by checks.
- `tags` - **optional** `Array` Strings of the accessibility guidelines of which the Rule applies.
- `metadata` - `Object` Consisting of:
- `description` - `String` Text string that describes what the rule does.
Expand Down Expand Up @@ -155,7 +155,7 @@ Similar to Rules, Checks are defined by JSON files in the [lib/checks directory]
- `after` - **optional** `String` The ID of the function that gets called for checks that operate on a page-level basis, to process the results from the iframes.
- `options` - **optional** `Object` Any information the Check needs that you might need to customize and/or is locale specific. Options can be overridden at runtime (with the options parameter) or config-time. For example, the [valid-lang](../lib/checks/language/valid-lang.json) Check defines what ISO 639-1 language codes it should accept as valid. Options do not need to follow any specific format or type; it is up to the author of a Check to determine the most appropriate format.
- `metadata` - `Object` Consisting of:
- `impact` - `String` (one of `minor`, `moderate`, `serious`, or `critical`)
- `impact` - **Deprecated** `String` (one of `minor`, `moderate`, `serious`, or `critical`)
- `messages` - `Object` These messages are displayed when the Check passes or fails
- `pass` - `String` [doT.js](http://olado.github.io/doT/) template string displayed when the Check passes
- `fail` - `String` [doT.js](http://olado.github.io/doT/) template string displayed when the Check fails
Expand Down
37 changes: 19 additions & 18 deletions doc/examples/jsdom/test/a11y.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/* global describe, it */
const axe = require('axe-core');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const assert = require('assert');

describe('axe', () => {
const { window } = new JSDOM(`<!DOCTYPE html>
const { document } = new JSDOM(`<!DOCTYPE html>
<html lang="en">
<head>
<title>JSDOM Example</title>
Expand All @@ -18,30 +19,30 @@ describe('axe', () => {
<p>Not a label</p><input type="text" id="no-label">
</div>
</body>
</html>`);

const axe = require('axe-core');
</html>`).window;
const config = {
rules: {
'color-contrast': { enabled: false }
}
};

it('should report that good HTML is good', function (done) {
var n = window.document.getElementById('working');
axe.run(n, config, function (err, result) {
assert.equal(err, null, 'Error is not null');
assert.equal(result.violations.length, 0, 'Violations is not empty');
done();
});
it('reports that good HTML is good', async () => {
const node = document.getElementById('working');
const result = await axe.run(node, config);
assert.equal(result.violations.length, 0, 'Violations is not empty');
});

it('reports that bad HTML is bad', async () => {
const node = document.getElementById('broken');
const results = await axe.run(node, config);
assert.equal(results.violations.length, 1, 'Violations.length is not 1');
});

it('should report that bad HTML is bad', function (done) {
var n = window.document.getElementById('broken');
axe.run(n, config, function (err, result) {
assert.equal(err, null, 'Error is not null');
assert.equal(result.violations.length, 1, 'Violations.length is not 1');
done();
});
it('allows commons after axe.setup() is called', () => {
axe.setup(document);
const input = document.querySelector('input');
const role = axe.commons.aria.getRole(input);
assert.equal(role, 'textbox');
axe.teardown();
});
});
1 change: 1 addition & 0 deletions lib/commons/standards/implicit-html-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ const implicitHtmlRoles = {
option: 'option',
output: 'status',
progress: 'progressbar',
search: 'search',
section: vNode => {
return hasAccessibleName(vNode) ? 'region' : null;
},
Expand Down
10 changes: 4 additions & 6 deletions lib/core/public/run.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getReporter } from './reporter';
import normalizeRunParams from './run/normalize-run-params';
import { setupGlobals, resetGlobals } from './run/globals-setup';
import { setupGlobals } from './run/globals-setup';
import { assert } from '../utils';

const noop = () => {};
Expand Down Expand Up @@ -36,10 +36,10 @@ export default function run(...args) {
axe.utils.performanceTimer.start();
}

function handleRunRules(rawResults, cleanup) {
function handleRunRules(rawResults, teardown) {
const respond = results => {
axe._running = false;
cleanup();
teardown();
try {
resolve(results);
} catch (e) {
Expand All @@ -48,7 +48,7 @@ export default function run(...args) {
};
const wrappedReject = err => {
axe._running = false;
cleanup();
teardown();
try {
reject(err);
} catch (e) {
Expand All @@ -72,7 +72,6 @@ export default function run(...args) {
axe.utils.performanceTimer.end();
}
axe._running = false;
resetGlobals();
callback(err);
reject(err);
}
Expand Down Expand Up @@ -104,7 +103,6 @@ function createReport(rawResults, options, respond, reject) {
}

function handleError(err, callback) {
resetGlobals();
if (typeof callback === 'function' && callback !== noop) {
callback(err.message);
return;
Expand Down
10 changes: 10 additions & 0 deletions lib/core/public/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getFlattenedTree, getSelectorData } from '../utils';
import { setupGlobals } from './run/globals-setup';

/**
* Setup axe-core so axe.common functions can work properly.
Expand All @@ -10,7 +11,16 @@ function setup(node) {
'Axe is already setup. Call `axe.teardown()` before calling `axe.setup` again.'
);
}
// Normalize document
if (
node &&
typeof node.documentElement === 'object' &&
typeof node.defaultView === 'object'
) {
node = node.documentElement;
}

setupGlobals(node);
axe._tree = getFlattenedTree(node);
axe._selectorData = getSelectorData(axe._tree);

Expand Down
1 change: 1 addition & 0 deletions lib/rules/accesskeys.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "accesskeys",
"impact": "serious",
"selector": "[accesskey]",
"excludeHidden": false,
"tags": ["cat.keyboard", "best-practice"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/area-alt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "area-alt",
"impact": "critical",
"selector": "map area[href]",
"excludeHidden": false,
"tags": [
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-allowed-attr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-allowed-attr",
"impact": "critical",
"matches": "aria-allowed-attr-matches",
"tags": ["cat.aria", "wcag2a", "wcag412", "EN-301-549", "EN-9.4.1.2"],
"actIds": ["5c01ea"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-allowed-role.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-allowed-role",
"impact": "minor",
"excludeHidden": false,
"selector": "[role]",
"matches": "aria-allowed-role-matches",
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-braille-equivalent.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-braille-equivalent",
"impact": "serious",
"selector": "[aria-brailleroledescription], [aria-braillelabel]",
"tags": ["cat.aria", "wcag2a", "wcag412", "EN-301-549", "EN-9.4.1.2"],
"metadata": {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-command-name.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-command-name",
"impact": "serious",
"selector": "[role=\"link\"], [role=\"button\"], [role=\"menuitem\"]",
"matches": "no-naming-method-matches",
"tags": [
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-conditional-attr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-conditional-attr",
"impact": "serious",
"matches": "aria-allowed-attr-matches",
"tags": ["cat.aria", "wcag2a", "wcag412", "EN-301-549", "EN-9.4.1.2"],
"actIds": ["5c01ea"],
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/aria-deprecated-role.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "aria-deprecated-role",
"impact": "minor",
"selector": "[role]",
"matches": "no-empty-role-matches",
"tags": ["cat.aria", "wcag2a", "wcag412", "EN-301-549", "EN-9.4.1.2"],
"impact": "minor",
"actIds": ["674b10"],
"metadata": {
"description": "Ensures elements do not use deprecated roles",
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-dialog-name.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-dialog-name",
"impact": "serious",
"selector": "[role=\"dialog\"], [role=\"alertdialog\"]",
"matches": "no-naming-method-matches",
"tags": ["cat.aria", "best-practice"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-hidden-body.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-hidden-body",
"impact": "critical",
"selector": "body",
"excludeHidden": false,
"matches": "is-initiator-matches",
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-hidden-focus.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-hidden-focus",
"impact": "serious",
"selector": "[aria-hidden=\"true\"]",
"matches": "aria-hidden-focus-matches",
"excludeHidden": false,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-input-field-name.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-input-field-name",
"impact": "serious",
"selector": "[role=\"combobox\"], [role=\"listbox\"], [role=\"searchbox\"], [role=\"slider\"], [role=\"spinbutton\"], [role=\"textbox\"]",
"matches": "no-naming-method-matches",
"tags": [
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-meter-name.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-meter-name",
"impact": "serious",
"selector": "[role=\"meter\"]",
"matches": "no-naming-method-matches",
"tags": ["cat.aria", "wcag2a", "wcag111", "EN-301-549", "EN-9.1.1.1"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-progressbar-name.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-progressbar-name",
"impact": "serious",
"selector": "[role=\"progressbar\"]",
"matches": "no-naming-method-matches",
"tags": ["cat.aria", "wcag2a", "wcag111", "EN-301-549", "EN-9.1.1.1"],
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/aria-prohibited-attr.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "aria-prohibited-attr",
"impact": "serious",
"matches": "aria-allowed-attr-matches",
"tags": ["cat.aria", "wcag2a", "wcag412", "EN-301-549", "EN-9.4.1.2"],
"actIds": ["5c01ea"],
"impact": "serious",
"metadata": {
"description": "Ensures ARIA attributes are not prohibited for an element's role",
"help": "Elements must only use permitted ARIA attributes"
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-required-attr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-required-attr",
"impact": "critical",
"selector": "[role]",
"tags": ["cat.aria", "wcag2a", "wcag412", "EN-301-549", "EN-9.4.1.2"],
"actIds": ["4e8ab6"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-required-children.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-required-children",
"impact": "critical",
"selector": "[role]",
"matches": "aria-required-children-matches",
"tags": ["cat.aria", "wcag2a", "wcag131", "EN-301-549", "EN-9.1.3.1"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-required-parent.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-required-parent",
"impact": "critical",
"selector": "[role]",
"matches": "aria-required-parent-matches",
"tags": ["cat.aria", "wcag2a", "wcag131", "EN-301-549", "EN-9.1.3.1"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-roledescription.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-roledescription",
"impact": "serious",
"selector": "[aria-roledescription]",
"tags": [
"cat.aria",
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-text.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-text",
"impact": "serious",
"selector": "[role=text]",
"tags": ["cat.aria", "best-practice"],
"metadata": {
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-toggle-field-name.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-toggle-field-name",
"impact": "serious",
"selector": "[role=\"checkbox\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"], [role=\"radio\"], [role=\"switch\"], [role=\"option\"]",
"matches": "no-naming-method-matches",
"tags": [
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-tooltip-name.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-tooltip-name",
"impact": "serious",
"selector": "[role=\"tooltip\"]",
"matches": "no-naming-method-matches",
"tags": ["cat.aria", "wcag2a", "wcag412", "EN-301-549", "EN-9.4.1.2"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-treeitem-name.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-treeitem-name",
"impact": "serious",
"selector": "[role=\"treeitem\"]",
"matches": "no-naming-method-matches",
"tags": ["cat.aria", "best-practice"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/aria-valid-attr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "aria-valid-attr",
"impact": "critical",
"matches": "aria-has-attr-matches",
"tags": ["cat.aria", "wcag2a", "wcag412", "EN-301-549", "EN-9.4.1.2"],
"actIds": ["5f99a7"],
Expand Down
1 change: 1 addition & 0 deletions lib/rules/audio-caption.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "audio-caption",
"impact": "critical",
"selector": "audio",
"enabled": false,
"excludeHidden": false,
Expand Down
1 change: 1 addition & 0 deletions lib/rules/autocomplete-valid.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"id": "autocomplete-valid",
"impact": "serious",
"matches": "autocomplete-matches",
"tags": [
"cat.forms",
Expand Down

0 comments on commit 0ef8333

Please sign in to comment.