accented 1.2.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +12 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +32 -0
- package/dist/constants.js.map +1 -1
- package/dist/scanner.d.ts.map +1 -1
- package/dist/scanner.js +79 -41
- package/dist/scanner.js.map +1 -1
- package/dist/utils/create-extended-element-with-issues.d.ts +3 -0
- package/dist/utils/create-extended-element-with-issues.d.ts.map +1 -0
- package/dist/utils/create-extended-element-with-issues.js +56 -0
- package/dist/utils/create-extended-element-with-issues.js.map +1 -0
- package/dist/utils/get-all-rules-from-axe-options.d.ts +3 -0
- package/dist/utils/get-all-rules-from-axe-options.d.ts.map +1 -0
- package/dist/utils/get-all-rules-from-axe-options.js +51 -0
- package/dist/utils/get-all-rules-from-axe-options.js.map +1 -0
- package/dist/utils/transform-violations.d.ts.map +1 -1
- package/dist/utils/transform-violations.js +2 -13
- package/dist/utils/transform-violations.js.map +1 -1
- package/dist/utils/update-elements-with-issues.d.ts +4 -3
- package/dist/utils/update-elements-with-issues.d.ts.map +1 -1
- package/dist/utils/update-elements-with-issues.js +36 -80
- package/dist/utils/update-elements-with-issues.js.map +1 -1
- package/package.json +4 -4
- package/src/constants.ts +34 -0
- package/src/scanner.ts +91 -45
- package/src/utils/create-extended-element-with-issues.ts +67 -0
- package/src/utils/get-all-rules-from-axe-options.test.ts +169 -0
- package/src/utils/get-all-rules-from-axe-options.ts +54 -0
- package/src/utils/transform-violations.ts +2 -14
- package/src/utils/update-elements-with-issues.test.ts +223 -139
- package/src/utils/update-elements-with-issues.ts +76 -107
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-elements-with-issues.js","sourceRoot":"","sources":["../../src/utils/update-elements-with-issues.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"update-elements-with-issues.js","s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QACH,CAAC;QAED,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,MAAM,CACvD,CAAC,OAAO,EAAE,EAAE,CACV,OAAO,CAAC,OAAO,CAAC,WAAW;YAC3B,CAAC,0BAA0B,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAClD,0BAA0B,CAAC,QAAQ,EAAE,OAAO,CAAC,CAC9C,CACJ,CAAC;QAEF,MAAM,yBAAyB,GAAG,0BAA0B,CAAC,KAAK,CAAC,MAAM,CACvE,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,IAAI,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,CAClF,CAAC;QAEF,+EAA+E;QAC/E,+CAA+C;QAC/C,IAAI,uBAAuB,CAAC,MAAM,GAAG,CAAC,IAAI,yBAAyB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/E,0BAA0B,CAAC,KAAK,GAAG,CAAC,GAAG,0BAA0B,CAAC,KAAK,CAAC;iBACrE,MAAM,CACL,CAAC,QAAQ,EAAE,EAAE,CACX,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAC1C,0BAA0B,CAAC,OAAO,EAAE,QAAQ,CAAC,CAC9C,CACJ;iBACA,MAAM,CACL,uBAAuB,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,+BAA+B,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CACrF,CAAC;QACN,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "accented",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "A frontend library for continuous accessibility testing and issue highlighting",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/accented.js",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"homepage": "https://accented.dev",
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@preact/signals-core": "^1.14.1",
|
|
31
|
-
"axe-core": "^4.11.
|
|
31
|
+
"axe-core": "^4.11.3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/jsdom": "^
|
|
35
|
-
"jsdom": "^29.0.
|
|
34
|
+
"@types/jsdom": "^28.0.1",
|
|
35
|
+
"jsdom": "^29.0.2"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "pnpm copyCommon && tsc",
|
package/src/constants.ts
CHANGED
|
@@ -5,3 +5,37 @@ export const issuesUrl = 'https://github.com/pomerantsev/accented/issues';
|
|
|
5
5
|
export const getAccentedElementNames = (name: string) => [`${name}-trigger`, `${name}-dialog`];
|
|
6
6
|
|
|
7
7
|
export const orderedImpacts: Array<Issue['impact']> = ['minor', 'moderate', 'serious', 'critical'];
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* axe-core rules whose pass/fail depends on the presence or absence of specific descendants
|
|
11
|
+
* (not just direct children). When any DOM mutation occurs, these rules must be re-evaluated
|
|
12
|
+
* against the full scan context, because the mutated node may be deep inside the element
|
|
13
|
+
* that the violation is reported on — and therefore outside the limited scan context.
|
|
14
|
+
*/
|
|
15
|
+
export const descendantDependentRules = new Set([
|
|
16
|
+
'aria-hidden-focus',
|
|
17
|
+
'aria-required-children',
|
|
18
|
+
'aria-text',
|
|
19
|
+
'document-title',
|
|
20
|
+
'landmark-no-duplicate-banner',
|
|
21
|
+
'landmark-no-duplicate-contentinfo',
|
|
22
|
+
'landmark-no-duplicate-main',
|
|
23
|
+
'landmark-one-main',
|
|
24
|
+
'nested-interactive',
|
|
25
|
+
'page-has-heading-one',
|
|
26
|
+
'scrollable-region-focusable',
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* axe-core violations (their ids) that may be flagged by axe-core
|
|
31
|
+
* as false positives if an Accented trigger is a descendant of the element with the issue.
|
|
32
|
+
*/
|
|
33
|
+
export const violationsAffectedByAccentedTriggers = new Set([
|
|
34
|
+
'aria-hidden-focus',
|
|
35
|
+
'aria-text',
|
|
36
|
+
'definition-list',
|
|
37
|
+
'label-content-name-mismatch',
|
|
38
|
+
'list',
|
|
39
|
+
'nested-interactive',
|
|
40
|
+
'scrollable-region-focusable', // The Accented trigger might make the content grow such that scrolling is required.
|
|
41
|
+
]);
|
package/src/scanner.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import axe from 'axe-core';
|
|
2
|
-
import { getAccentedElementNames, issuesUrl } from './constants.js';
|
|
2
|
+
import { descendantDependentRules, getAccentedElementNames, issuesUrl } from './constants.js';
|
|
3
3
|
import { logAndRethrow } from './log-and-rethrow.js';
|
|
4
4
|
import { elementsWithIssues, enabled, extendedElementsWithIssues } from './state.js';
|
|
5
5
|
import { TaskQueue } from './task-queue.js';
|
|
6
6
|
import type { AxeOptions, Callback, Context, Throttle } from './types.ts';
|
|
7
|
+
import { getAllRulesFromAxeOptions } from './utils/get-all-rules-from-axe-options.js';
|
|
7
8
|
import { getScanContext } from './utils/get-scan-context.js';
|
|
8
9
|
import { recalculatePositions } from './utils/recalculate-positions.js';
|
|
9
10
|
import { recalculateScrollableAncestors } from './utils/recalculate-scrollable-ancestors.js';
|
|
@@ -18,10 +19,70 @@ export function createScanner(
|
|
|
18
19
|
throttle: Required<Throttle>,
|
|
19
20
|
callback: Callback,
|
|
20
21
|
) {
|
|
22
|
+
const allRules = getAllRulesFromAxeOptions(axeOptions);
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Rules that only look at the element itself — safe to run
|
|
26
|
+
* against only the nodes affected by the current mutation.
|
|
27
|
+
*/
|
|
28
|
+
const limitedContextRules = new Set(
|
|
29
|
+
[...allRules].filter((rule) => !descendantDependentRules.has(rule)),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Rules whose pass/fail depends on descendants anywhere in the subtree.
|
|
34
|
+
* A mutation deep inside an element can change the outcome for the ancestor,
|
|
35
|
+
* so these must always run against the full scan context.
|
|
36
|
+
*/
|
|
37
|
+
const fullContextRules = new Set(
|
|
38
|
+
[...allRules].filter((rule) => descendantDependentRules.has(rule)),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Options shared by both axe.run() calls. The user's runOnly and rules are
|
|
43
|
+
* consumed by getAllRulesFromAxeOptions above and replaced by explicit rule
|
|
44
|
+
* sets, so they are not forwarded here.
|
|
45
|
+
*/
|
|
46
|
+
const baseAxeOptions: axe.RunOptions = {
|
|
47
|
+
/**
|
|
48
|
+
* By default, axe-core doesn't include element refs
|
|
49
|
+
* in the violations array,
|
|
50
|
+
* and we need those element refs.
|
|
51
|
+
*/
|
|
52
|
+
elementRef: true,
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Although axe-core can perform iframe scanning, I haven't succeeded in it,
|
|
56
|
+
* and the docs suggest that the axe-core script should be explicitly included
|
|
57
|
+
* in each of the iframed documents anyway.
|
|
58
|
+
* It seems preferable to disallow iframe scanning and not report issues in elements within iframes
|
|
59
|
+
* in the case that such issues are for some reason reported by axe-core.
|
|
60
|
+
* A consumer of Accented can instead scan the iframed document by calling Accented initialization from that document.
|
|
61
|
+
*/
|
|
62
|
+
iframes: false,
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The `preload` docs are not clear to me,
|
|
66
|
+
* but when it's set to `true` by default,
|
|
67
|
+
* axe-core tries to fetch cross-origin CSS,
|
|
68
|
+
* which fails in the absence of CORS headers.
|
|
69
|
+
* I'm not sure why axe-core needs to preload
|
|
70
|
+
* those resources in the first place,
|
|
71
|
+
* so disabling it seems to be the safe option.
|
|
72
|
+
*/
|
|
73
|
+
preload: false,
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* We're only interested in violations,
|
|
77
|
+
* not in passes or incomplete results.
|
|
78
|
+
*/
|
|
79
|
+
resultTypes: ['violations'],
|
|
80
|
+
};
|
|
81
|
+
|
|
21
82
|
const axeRunningWindowProp = `__${name}_axe_running__`;
|
|
22
83
|
const win = window as unknown as Record<string, boolean>;
|
|
23
84
|
const taskQueue = new TaskQueue<Node>(async (nodes) => {
|
|
24
|
-
// We may see errors coming from axe-core when Accented is toggled off and on in
|
|
85
|
+
// We may see errors coming from axe-core when Accented is toggled off and on in quick succession,
|
|
25
86
|
// which I've seen happen with hot reloading of a React application.
|
|
26
87
|
// This window property serves as a circuit breaker for that particular case.
|
|
27
88
|
if (win[axeRunningWindowProp]) {
|
|
@@ -33,48 +94,32 @@ export function createScanner(
|
|
|
33
94
|
|
|
34
95
|
win[axeRunningWindowProp] = true;
|
|
35
96
|
|
|
36
|
-
const
|
|
97
|
+
const limitedContext = getScanContext(nodes, context);
|
|
37
98
|
|
|
38
|
-
let
|
|
99
|
+
let limitedContextResult: axe.AxeResults | undefined;
|
|
100
|
+
let fullContextResult: axe.AxeResults | undefined;
|
|
39
101
|
|
|
40
102
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* but when it's set to `true` by default,
|
|
62
|
-
* axe-core tries to fetch cross-origin CSS,
|
|
63
|
-
* which fails in the absence of CORS headers.
|
|
64
|
-
* I'm not sure why axe-core needs to preload
|
|
65
|
-
* those resources in the first place,
|
|
66
|
-
* so disabling it seems to be the safe option.
|
|
67
|
-
*/
|
|
68
|
-
preload: false,
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* We're only interested in violations,
|
|
72
|
-
* not in passes or incomplete results.
|
|
73
|
-
*/
|
|
74
|
-
resultTypes: ['violations'],
|
|
75
|
-
|
|
76
|
-
...axeOptions,
|
|
77
|
-
});
|
|
103
|
+
// Run the scan against the limited context (only the mutated
|
|
104
|
+
// nodes, filtered to those within the user-provided context). Skip if no
|
|
105
|
+
// limited-context rules are active.
|
|
106
|
+
limitedContextResult =
|
|
107
|
+
limitedContextRules.size > 0
|
|
108
|
+
? await axe.run(limitedContext, {
|
|
109
|
+
...baseAxeOptions,
|
|
110
|
+
runOnly: { type: 'rule', values: [...limitedContextRules] },
|
|
111
|
+
})
|
|
112
|
+
: undefined;
|
|
113
|
+
|
|
114
|
+
// Run the supplemental scan against the full context so that ancestor-
|
|
115
|
+
// dependent rules always see the complete DOM. Skip if none are active.
|
|
116
|
+
fullContextResult =
|
|
117
|
+
fullContextRules.size > 0
|
|
118
|
+
? await axe.run(context, {
|
|
119
|
+
...baseAxeOptions,
|
|
120
|
+
runOnly: { type: 'rule', values: [...fullContextRules] },
|
|
121
|
+
})
|
|
122
|
+
: undefined;
|
|
78
123
|
} catch (error) {
|
|
79
124
|
console.error(
|
|
80
125
|
`Accented: axe-core (the accessibility testing engine) threw an error. Check the \`axeOptions\` property (https://accented.dev/api#axeoptions) that you’re passing to Accented. If you still think it’s a bug in Accented, file an issue at ${issuesUrl}.\n`,
|
|
@@ -86,7 +131,7 @@ export function createScanner(
|
|
|
86
131
|
const scanMeasure = performance.measure('scan', 'scan-start');
|
|
87
132
|
const scanDuration = Math.round(scanMeasure.duration);
|
|
88
133
|
|
|
89
|
-
if (!enabled.value || !
|
|
134
|
+
if (!enabled.value || (!limitedContextResult && !fullContextResult)) {
|
|
90
135
|
return;
|
|
91
136
|
}
|
|
92
137
|
|
|
@@ -94,8 +139,9 @@ export function createScanner(
|
|
|
94
139
|
|
|
95
140
|
updateElementsWithIssues({
|
|
96
141
|
extendedElementsWithIssues,
|
|
97
|
-
|
|
98
|
-
|
|
142
|
+
limitedContext,
|
|
143
|
+
limitedContextViolations: limitedContextResult?.violations ?? [],
|
|
144
|
+
fullContextViolations: fullContextResult?.violations ?? [],
|
|
99
145
|
name,
|
|
100
146
|
});
|
|
101
147
|
|
|
@@ -106,7 +152,7 @@ export function createScanner(
|
|
|
106
152
|
// Assuming that the {include, exclude} shape of the context object will be used less often
|
|
107
153
|
// than other variants, we'll output just the `include` array in case nothing is excluded
|
|
108
154
|
// in the scan.
|
|
109
|
-
scanContext:
|
|
155
|
+
scanContext: limitedContext.exclude.length > 0 ? limitedContext : limitedContext.include,
|
|
110
156
|
elementsWithIssues: elementsWithIssues.value,
|
|
111
157
|
performance: {
|
|
112
158
|
totalBlockingTime: scanDuration + domUpdateDuration,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { signal } from '@preact/signals-core';
|
|
2
|
+
import type { AccentedDialog } from '../elements/accented-dialog.ts';
|
|
3
|
+
import type { AccentedTrigger } from '../elements/accented-trigger.ts';
|
|
4
|
+
import type { ElementWithIssues, ExtendedElementWithIssues } from '../types.ts';
|
|
5
|
+
import { isSvgElement } from './dom-helpers.js';
|
|
6
|
+
import { getElementPosition } from './get-element-position.js';
|
|
7
|
+
import { getParent } from './get-parent.js';
|
|
8
|
+
import { getScrollableAncestors } from './get-scrollable-ancestors.js';
|
|
9
|
+
import { supportsAnchorPositioning } from './supports-anchor-positioning.js';
|
|
10
|
+
|
|
11
|
+
function shouldSkipRender(element: Element): boolean {
|
|
12
|
+
// Skip rendering if the element is inside an SVG:
|
|
13
|
+
// https://github.com/pomerantsev/accented/issues/62
|
|
14
|
+
const parent = getParent(element);
|
|
15
|
+
const isInsideSvg = Boolean(parent && isSvgElement(parent));
|
|
16
|
+
|
|
17
|
+
// Some issues, such as meta-viewport, are on <head> descendants,
|
|
18
|
+
// but since <head> is never rendered, we don't want to output anything
|
|
19
|
+
// for those in the DOM.
|
|
20
|
+
// We're not anticipating the use of shadow DOM in <head>,
|
|
21
|
+
// so the use of .closest() should be fine.
|
|
22
|
+
const isInsideHead = element.closest('head') !== null;
|
|
23
|
+
|
|
24
|
+
return isInsideSvg || isInsideHead;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let count = 0;
|
|
28
|
+
|
|
29
|
+
export function createExtendedElementWithIssues(
|
|
30
|
+
elementWithIssues: ElementWithIssues,
|
|
31
|
+
name: string,
|
|
32
|
+
): ExtendedElementWithIssues {
|
|
33
|
+
const id = count++;
|
|
34
|
+
const trigger = document.createElement(`${name}-trigger`) as AccentedTrigger;
|
|
35
|
+
const elementZIndex = Number.parseInt(getComputedStyle(elementWithIssues.element).zIndex, 10);
|
|
36
|
+
if (!Number.isNaN(elementZIndex)) {
|
|
37
|
+
trigger.style.setProperty('z-index', (elementZIndex + 1).toString(), 'important');
|
|
38
|
+
}
|
|
39
|
+
trigger.style.setProperty('position-anchor', `--${name}-anchor-${id}`, 'important');
|
|
40
|
+
trigger.dataset.id = id.toString();
|
|
41
|
+
const accentedDialog = document.createElement(`${name}-dialog`) as AccentedDialog;
|
|
42
|
+
trigger.dialog = accentedDialog;
|
|
43
|
+
const position = getElementPosition(elementWithIssues.element);
|
|
44
|
+
trigger.position = signal(position);
|
|
45
|
+
trigger.visible = signal(true);
|
|
46
|
+
trigger.element = elementWithIssues.element;
|
|
47
|
+
const scrollableAncestors = supportsAnchorPositioning()
|
|
48
|
+
? new Set<HTMLElement>()
|
|
49
|
+
: getScrollableAncestors(elementWithIssues.element);
|
|
50
|
+
const issues = signal(elementWithIssues.issues);
|
|
51
|
+
accentedDialog.issues = issues;
|
|
52
|
+
accentedDialog.element = elementWithIssues.element;
|
|
53
|
+
return {
|
|
54
|
+
id,
|
|
55
|
+
element: elementWithIssues.element,
|
|
56
|
+
skipRender: shouldSkipRender(elementWithIssues.element),
|
|
57
|
+
rootNode: elementWithIssues.rootNode,
|
|
58
|
+
visible: trigger.visible,
|
|
59
|
+
position: trigger.position,
|
|
60
|
+
scrollableAncestors: signal(scrollableAncestors),
|
|
61
|
+
anchorNameValue:
|
|
62
|
+
elementWithIssues.element.style.getPropertyValue('anchor-name') ||
|
|
63
|
+
getComputedStyle(elementWithIssues.element).getPropertyValue('anchor-name'),
|
|
64
|
+
trigger,
|
|
65
|
+
issues,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tests in this test suite have e2e counterparts in axe-options.spec.ts.
|
|
3
|
+
* If we ever change this file, we should make sure axe-options.spec.ts
|
|
4
|
+
* doesn't diverge.
|
|
5
|
+
* That way, we can be sure that our reimplementation of runOnly / rules
|
|
6
|
+
* is in sync with that in axe-core.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import assert from 'node:assert/strict';
|
|
10
|
+
import { suite, test } from 'node:test';
|
|
11
|
+
import { getAllRulesFromAxeOptions } from './get-all-rules-from-axe-options';
|
|
12
|
+
|
|
13
|
+
suite('getAllRulesFromAxeOptions', () => {
|
|
14
|
+
test('with no options, returns all rules', () => {
|
|
15
|
+
const rules = getAllRulesFromAxeOptions({});
|
|
16
|
+
assert.ok(rules.size > 90);
|
|
17
|
+
assert.ok(rules.has('page-has-heading-one'));
|
|
18
|
+
assert.ok(rules.has('color-contrast'));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('with no options, excludes disabled-by-default rules', () => {
|
|
22
|
+
const rules = getAllRulesFromAxeOptions({});
|
|
23
|
+
// axe-core disables some rules by default
|
|
24
|
+
assert.equal(rules.has('color-contrast-enhanced'), false);
|
|
25
|
+
assert.equal(rules.has('target-size'), false);
|
|
26
|
+
assert.equal(rules.has('audio-caption'), false);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('with runOnly type rule, returns exactly the specified rules', () => {
|
|
30
|
+
const rules = getAllRulesFromAxeOptions({
|
|
31
|
+
runOnly: { type: 'rule', values: ['color-contrast', 'button-name'] },
|
|
32
|
+
});
|
|
33
|
+
assert.equal(rules.size, 2);
|
|
34
|
+
assert.ok(rules.has('color-contrast'));
|
|
35
|
+
assert.ok(rules.has('button-name'));
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('with runOnly type rule, ignores rules.enabled: true for a rule not in runOnly', () => {
|
|
39
|
+
const rules = getAllRulesFromAxeOptions({
|
|
40
|
+
runOnly: { type: 'rule', values: ['button-name'] },
|
|
41
|
+
rules: { 'color-contrast': { enabled: true } },
|
|
42
|
+
});
|
|
43
|
+
assert.equal(rules.size, 1);
|
|
44
|
+
assert.equal(rules.has('color-contrast'), false);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('with runOnly type rule, ignores rules.enabled: false', () => {
|
|
48
|
+
const rules = getAllRulesFromAxeOptions({
|
|
49
|
+
runOnly: { type: 'rule', values: ['color-contrast'] },
|
|
50
|
+
rules: { 'color-contrast': { enabled: false } },
|
|
51
|
+
});
|
|
52
|
+
assert.equal(rules.size, 1);
|
|
53
|
+
assert.ok(rules.has('color-contrast'));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("with runOnly type 'rules' (plural), behaves the same as 'rule'", () => {
|
|
57
|
+
const rules = getAllRulesFromAxeOptions({
|
|
58
|
+
runOnly: { type: 'rules', values: ['button-name'] },
|
|
59
|
+
rules: { 'color-contrast': { enabled: true } },
|
|
60
|
+
});
|
|
61
|
+
assert.equal(rules.size, 1);
|
|
62
|
+
assert.ok(rules.has('button-name'));
|
|
63
|
+
assert.equal(rules.has('color-contrast'), false); // rules ignored, same as type 'rule'
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test('with runOnly type tag, returns rules matching those tags', () => {
|
|
67
|
+
const rules = getAllRulesFromAxeOptions({
|
|
68
|
+
runOnly: { type: 'tag', values: ['best-practice'] },
|
|
69
|
+
});
|
|
70
|
+
assert.ok(rules.has('page-has-heading-one'));
|
|
71
|
+
assert.equal(rules.has('color-contrast'), false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('with runOnly type tag and multiple tags, returns rules from all specified tags', () => {
|
|
75
|
+
const rules = getAllRulesFromAxeOptions({
|
|
76
|
+
runOnly: { type: 'tag', values: ['best-practice', 'wcag2aa'] },
|
|
77
|
+
});
|
|
78
|
+
assert.ok(rules.has('page-has-heading-one'));
|
|
79
|
+
assert.ok(rules.has('color-contrast'));
|
|
80
|
+
assert.equal(rules.has('button-name'), false); // wcag2a only, not in either tag
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('with runOnly type tag, rules.enabled: false removes a matching rule', () => {
|
|
84
|
+
const rules = getAllRulesFromAxeOptions({
|
|
85
|
+
runOnly: { type: 'tag', values: ['wcag2aa'] },
|
|
86
|
+
rules: { 'color-contrast': { enabled: false } },
|
|
87
|
+
});
|
|
88
|
+
assert.ok(rules.has('meta-viewport')); // another wcag2aa rule, still included
|
|
89
|
+
assert.equal(rules.has('color-contrast'), false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('with runOnly type tag, rules.enabled: true adds a non-matching rule', () => {
|
|
93
|
+
const rules = getAllRulesFromAxeOptions({
|
|
94
|
+
runOnly: { type: 'tag', values: ['best-practice'] },
|
|
95
|
+
rules: { 'color-contrast': { enabled: true } },
|
|
96
|
+
});
|
|
97
|
+
assert.ok(rules.has('page-has-heading-one'));
|
|
98
|
+
assert.ok(rules.has('color-contrast'));
|
|
99
|
+
assert.equal(rules.has('button-name'), false); // not in best-practice and not explicitly enabled
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("with runOnly type 'tags' (plural), behaves the same as 'tag'", () => {
|
|
103
|
+
const rules = getAllRulesFromAxeOptions({
|
|
104
|
+
runOnly: { type: 'tags', values: ['best-practice'] },
|
|
105
|
+
rules: { 'color-contrast': { enabled: true } },
|
|
106
|
+
});
|
|
107
|
+
assert.ok(rules.has('page-has-heading-one'));
|
|
108
|
+
assert.ok(rules.has('color-contrast')); // rules applied, same as type 'tag'
|
|
109
|
+
assert.equal(rules.has('button-name'), false);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('with no runOnly and rules overrides, still excludes disabled-by-default rules', () => {
|
|
113
|
+
const rules = getAllRulesFromAxeOptions({
|
|
114
|
+
rules: { 'color-contrast': { enabled: false }, 'button-name': { enabled: true } },
|
|
115
|
+
});
|
|
116
|
+
assert.equal(rules.has('color-contrast'), false); // explicitly disabled
|
|
117
|
+
assert.ok(rules.has('button-name')); // explicitly enabled
|
|
118
|
+
assert.equal(rules.has('color-contrast-enhanced'), false); // disabled by default, no override
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('with no runOnly, rules.enabled: false removes a rule', () => {
|
|
122
|
+
const rules = getAllRulesFromAxeOptions({
|
|
123
|
+
rules: { 'color-contrast': { enabled: false } },
|
|
124
|
+
});
|
|
125
|
+
assert.ok(rules.size > 90);
|
|
126
|
+
assert.equal(rules.has('color-contrast'), false);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('with runOnly as a tag array shorthand, treats it as tag values', () => {
|
|
130
|
+
const rules = getAllRulesFromAxeOptions({ runOnly: ['best-practice'] });
|
|
131
|
+
assert.ok(rules.has('page-has-heading-one'));
|
|
132
|
+
assert.equal(rules.has('color-contrast'), false);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test('with runOnly as a single tag string, treats it as a tag value', () => {
|
|
136
|
+
const rules = getAllRulesFromAxeOptions({ runOnly: 'best-practice' });
|
|
137
|
+
assert.ok(rules.has('page-has-heading-one'));
|
|
138
|
+
assert.equal(rules.has('color-contrast'), false);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('with runOnly as a rule ID string shorthand, returns that rule', () => {
|
|
142
|
+
const rules = getAllRulesFromAxeOptions({ runOnly: 'color-contrast' });
|
|
143
|
+
assert.equal(rules.size, 1);
|
|
144
|
+
assert.ok(rules.has('color-contrast'));
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('with runOnly as a rule ID array shorthand, returns exactly those rules', () => {
|
|
148
|
+
const rules = getAllRulesFromAxeOptions({ runOnly: ['color-contrast', 'button-name'] });
|
|
149
|
+
assert.equal(rules.size, 2);
|
|
150
|
+
assert.ok(rules.has('color-contrast'));
|
|
151
|
+
assert.ok(rules.has('button-name'));
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('with runOnly as a rule ID array shorthand, ignores rules overrides', () => {
|
|
155
|
+
const rules = getAllRulesFromAxeOptions({
|
|
156
|
+
runOnly: ['color-contrast', 'button-name'],
|
|
157
|
+
rules: { 'color-contrast': { enabled: false }, 'aria-label': { enabled: true } },
|
|
158
|
+
});
|
|
159
|
+
assert.equal(rules.size, 2);
|
|
160
|
+
assert.ok(rules.has('color-contrast'));
|
|
161
|
+
assert.ok(rules.has('button-name'));
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test('with runOnly as a mixed shorthand array (tag + rule ID), throws', () => {
|
|
165
|
+
assert.throws(() =>
|
|
166
|
+
getAllRulesFromAxeOptions({ runOnly: ['best-practice', 'color-contrast'] }),
|
|
167
|
+
);
|
|
168
|
+
});
|
|
169
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* Adapts two axe-core behaviors:
|
|
2
|
+
- shorthand string/array runOnly normalization from normalizeOptions:
|
|
3
|
+
https://github.com/dequelabs/axe-core/blob/9261d074b60527a84f4dce5a64a6d5a5843a0772/lib/core/base/audit.js#L408-L428
|
|
4
|
+
- which rules to include for a given runOnly/rules combination, from ruleShouldRun (lines 65–80,
|
|
5
|
+
omitting the rule.pageLevel check — axe applies that itself when we call axe.run):
|
|
6
|
+
https://github.com/dequelabs/axe-core/blob/9261d074b60527a84f4dce5a64a6d5a5843a0772/lib/core/utils/rule-should-run.js */
|
|
7
|
+
import axe from 'axe-core';
|
|
8
|
+
import type { AxeOptions } from '../types.ts';
|
|
9
|
+
|
|
10
|
+
function getRuleIds(tags?: Array<string>): Set<string> {
|
|
11
|
+
return new Set(axe.getRules(tags).map((r) => r.ruleId));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function applyOverrides(ruleSet: Set<string>, rules: AxeOptions['rules']): Set<string> {
|
|
15
|
+
if (!rules) return ruleSet;
|
|
16
|
+
for (const [ruleId, ruleConfig] of Object.entries(rules)) {
|
|
17
|
+
if (ruleConfig.enabled === false) ruleSet.delete(ruleId);
|
|
18
|
+
else if (ruleConfig.enabled === true) ruleSet.add(ruleId);
|
|
19
|
+
}
|
|
20
|
+
return ruleSet;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Normalizes the string/array shorthands of runOnly into the { type, values } object form.
|
|
24
|
+
function normalizeRunOnly(
|
|
25
|
+
runOnly: Exclude<AxeOptions['runOnly'], undefined>,
|
|
26
|
+
allRuleIds: Set<string>,
|
|
27
|
+
): { type: string; values: string[] } {
|
|
28
|
+
if (typeof runOnly !== 'string' && !Array.isArray(runOnly)) return runOnly;
|
|
29
|
+
const values = typeof runOnly === 'string' ? [runOnly] : runOnly;
|
|
30
|
+
const isRulePath = values.every((v) => allRuleIds.has(v));
|
|
31
|
+
const isTagPath = values.every((v) => !allRuleIds.has(v));
|
|
32
|
+
if (!isRulePath && !isTagPath)
|
|
33
|
+
throw new Error(`runOnly mixes rule IDs and tag values: ${values.join(', ')}`);
|
|
34
|
+
return { type: isRulePath ? 'rule' : 'tag', values };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getAllRulesFromAxeOptions(axeOptions: AxeOptions): Set<string> {
|
|
38
|
+
const allRuleIds = getRuleIds();
|
|
39
|
+
const { rules, runOnly } = axeOptions;
|
|
40
|
+
|
|
41
|
+
if (runOnly === undefined) {
|
|
42
|
+
// axe.getRules() includes rules disabled by default; axe skips them via rule.enabled !== false.
|
|
43
|
+
// Replicate that here using the internal _audit.rules, which exposes the enabled flag.
|
|
44
|
+
// @ts-expect-error: _audit is an undocumented internal axe-core API not present in its type definitions
|
|
45
|
+
for (const rule of axe._audit.rules) {
|
|
46
|
+
if (rule.enabled === false) allRuleIds.delete(rule.id);
|
|
47
|
+
}
|
|
48
|
+
return applyOverrides(allRuleIds, rules);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const { type, values } = normalizeRunOnly(runOnly, allRuleIds);
|
|
52
|
+
if (type === 'rule' || type === 'rules') return new Set(values);
|
|
53
|
+
return applyOverrides(getRuleIds(values), rules);
|
|
54
|
+
}
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import type { AxeResults } from 'axe-core';
|
|
2
|
-
import { issuesUrl, orderedImpacts } from '../constants.js';
|
|
2
|
+
import { issuesUrl, orderedImpacts, violationsAffectedByAccentedTriggers } from '../constants.js';
|
|
3
3
|
import type { ElementWithIssues, Issue } from '../types.ts';
|
|
4
4
|
|
|
5
|
-
// This is a list of axe-core violations (their ids) that may be flagged by axe-core
|
|
6
|
-
// as false positives if an Accented trigger is a descendant of the element with the issue.
|
|
7
|
-
const violationsAffectedByAccentedTriggers = [
|
|
8
|
-
'aria-hidden-focus',
|
|
9
|
-
'aria-text',
|
|
10
|
-
'definition-list',
|
|
11
|
-
'label-content-name-mismatch',
|
|
12
|
-
'list',
|
|
13
|
-
'nested-interactive',
|
|
14
|
-
'scrollable-region-focusable', // The Accented trigger might make the content grow such that scrolling is required.
|
|
15
|
-
];
|
|
16
|
-
|
|
17
5
|
function maybeCausedByAccented(violationId: string, element: HTMLElement, name: string) {
|
|
18
6
|
return (
|
|
19
|
-
violationsAffectedByAccentedTriggers.
|
|
7
|
+
violationsAffectedByAccentedTriggers.has(violationId) &&
|
|
20
8
|
Boolean(element.querySelector(`${name}-trigger`))
|
|
21
9
|
);
|
|
22
10
|
}
|