-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(aria-roledescription): keep disabled with { runOnly: 'wcag2a' } (#…
…4526) Deprecated rules are disabled by default, but because they still have WCAG / best-practice tags, using tags can unintentionally turn them back on. This PR makes it so that rules with the `deprecated` tag do not run unless they are explicitly enabled. Closes: #4523
- Loading branch information
1 parent
f379c32
commit 5b4cb9d
Showing
5 changed files
with
147 additions
and
4 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
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,31 @@ | ||
<!doctype html> | ||
<html lang="en" xml:lang="en"> | ||
<head> | ||
<title>axe.configure({ tagExclude }) test</title> | ||
<meta charset="utf8" /> | ||
<link | ||
rel="stylesheet" | ||
type="text/css" | ||
href="/node_modules/mocha/mocha.css" | ||
/> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 10000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<img alt="" /> | ||
|
||
<div id="mocha"></div> | ||
<script src="/test/integration/no-ui-reporter.js"></script> | ||
<script src="/test/testutils.js"></script> | ||
<script src="tag-exclude.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |
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,112 @@ | ||
describe('all rules test', () => { | ||
const experimentalRuleId = 'img-alt-experimental'; | ||
const deprecatedRuleId = 'img-alt-deprecated'; | ||
|
||
beforeEach(() => { | ||
axe.configure({ | ||
rules: [ | ||
{ | ||
id: experimentalRuleId, | ||
impact: 'critical', | ||
selector: 'img', | ||
tags: ['wcag2a', 'experimental'], | ||
enabled: false, | ||
metadata: { | ||
description: | ||
'Ensures <img> elements have alternate text or a role of none or presentation', | ||
help: 'Images must have alternate text' | ||
}, | ||
all: [], | ||
any: ['has-alt'], | ||
none: [] | ||
}, | ||
{ | ||
id: deprecatedRuleId, | ||
impact: 'critical', | ||
selector: 'img', | ||
tags: ['wcag2a', 'deprecated'], | ||
enabled: false, | ||
metadata: { | ||
description: | ||
'Ensures <img> elements have alternate text or a role of none or presentation', | ||
help: 'Images must have alternate text' | ||
}, | ||
all: [], | ||
any: ['has-alt'], | ||
none: [] | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
after(() => { | ||
axe.reset(); | ||
}); | ||
|
||
function findResult(results, ruleId) { | ||
return [ | ||
...results.violations, | ||
...results.passes, | ||
...results.incomplete, | ||
...results.inapplicable | ||
].find(result => result.id === ruleId); | ||
} | ||
|
||
it('does not run experimental rules by default', async () => { | ||
const results = await axe.run({ | ||
runOnly: { | ||
type: 'tags', | ||
values: ['wcag2a'] | ||
} | ||
}); | ||
assert.isUndefined(findResult(results, experimentalRuleId)); | ||
}); | ||
|
||
it('does not run deprecated rules by default', async () => { | ||
const results = await axe.run({ | ||
runOnly: { | ||
type: 'tags', | ||
values: ['wcag2a'] | ||
} | ||
}); | ||
assert.isUndefined(findResult(results, deprecatedRuleId)); | ||
}); | ||
|
||
it('runs tagExclude rules when enabled with { rules }', async () => { | ||
const results = await axe.run({ | ||
runOnly: { | ||
type: 'tags', | ||
values: ['wcag2a'] | ||
}, | ||
rules: { | ||
[experimentalRuleId]: { enabled: true }, | ||
[deprecatedRuleId]: { enabled: true } | ||
} | ||
}); | ||
|
||
assert.isDefined(findResult(results, experimentalRuleId)); | ||
assert.isDefined(findResult(results, deprecatedRuleId)); | ||
}); | ||
|
||
it('runs tagExclude rules when enabled with { runOnly: { type: rule } }', async () => { | ||
const results = await axe.run({ | ||
runOnly: { | ||
type: 'rule', | ||
values: [experimentalRuleId, deprecatedRuleId] | ||
} | ||
}); | ||
assert.isDefined(findResult(results, experimentalRuleId)); | ||
assert.isDefined(findResult(results, deprecatedRuleId)); | ||
}); | ||
|
||
it('runs tagExclude rules when enabled with { runOnly: { type: tag } }', async () => { | ||
const results = await axe.run({ | ||
runOnly: { | ||
type: 'tag', | ||
values: ['wcag2a', 'experimental', 'deprecated'] | ||
} | ||
}); | ||
assert.isDefined(findResult(results, experimentalRuleId)); | ||
assert.isDefined(findResult(results, deprecatedRuleId)); | ||
}); | ||
}); |