@sa11y/jest 6.9.5-alpha.4 → 6.9.5
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/automatic.d.ts +0 -1
- package/dist/automatic.d.ts.map +1 -1
- package/dist/automatic.js +12 -70
- package/dist/groupViolationResultsProcessor.d.ts.map +1 -1
- package/dist/groupViolationResultsProcessor.js +51 -28
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +0 -4
- package/package.json +7 -7
package/dist/automatic.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ export type AutoCheckOpts = {
|
|
|
6
6
|
cleanupAfterEach?: boolean;
|
|
7
7
|
consolidateResults?: boolean;
|
|
8
8
|
filesFilter?: string[];
|
|
9
|
-
runDOMMutationObserver?: boolean;
|
|
10
9
|
};
|
|
11
10
|
export declare const setOriginalDocumentBodyHtml: (bodyHtml: string | null) => void;
|
|
12
11
|
export declare const getOriginalDocumentBodyHtml: () => string | null;
|
package/dist/automatic.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automatic.d.ts","sourceRoot":"","sources":["../src/automatic.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAI7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"automatic.d.ts","sourceRoot":"","sources":["../src/automatic.ts"],"names":[],"mappings":"AAeA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IACxB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAI7B,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AAcF,eAAO,MAAM,2BAA2B,aAAc,MAAM,GAAG,IAAI,SAElE,CAAC;AAEF,eAAO,MAAM,2BAA2B,qBAEvC,CAAC;AAEF;;GAEG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,WAAW,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,CAUtF;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAAC,IAAI,GAAE,aAAoC,GAAG,OAAO,CAAC,IAAI,CAAC,CAkD9F;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAE,aAAoC,GAAG,IAAI,CAQ7F"}
|
package/dist/automatic.js
CHANGED
|
@@ -24,7 +24,6 @@ const defaultAutoCheckOpts = {
|
|
|
24
24
|
filesFilter: [],
|
|
25
25
|
};
|
|
26
26
|
let originalDocumentBodyHtml = null;
|
|
27
|
-
let mutatedNodes = [];
|
|
28
27
|
const setOriginalDocumentBodyHtml = (bodyHtml) => {
|
|
29
28
|
originalDocumentBodyHtml = bodyHtml ?? null;
|
|
30
29
|
};
|
|
@@ -66,53 +65,24 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
66
65
|
// Create a DOM walker filtering only elements (skipping text, comment nodes etc)
|
|
67
66
|
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
|
|
68
67
|
let currNode = walker.firstChild();
|
|
69
|
-
|
|
68
|
+
const customRules = (0, common_1.useCustomRules)();
|
|
70
69
|
try {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// W-10004832 - Exclude descendancy based rules from automatic checks
|
|
80
|
-
if (customRules.length === 0)
|
|
81
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
|
|
82
|
-
else
|
|
83
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
|
|
84
|
-
currNode = walker.nextSibling();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
customRules = [];
|
|
70
|
+
while (currNode !== null) {
|
|
71
|
+
// TODO (spike): Use a logger lib with log levels selectable at runtime
|
|
72
|
+
// console.log(
|
|
73
|
+
// `♿ [DEBUG] Automatically checking a11y of ${currNode.nodeName}
|
|
74
|
+
// for test "${expect.getState().currentTestName}"
|
|
75
|
+
// : ${testPath}`
|
|
76
|
+
// );
|
|
77
|
+
// W-10004832 - Exclude descendancy based rules from automatic checks
|
|
89
78
|
if (customRules.length === 0)
|
|
90
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(
|
|
79
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
|
|
91
80
|
else
|
|
92
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(
|
|
93
|
-
|
|
94
|
-
// loop mutated nodes
|
|
95
|
-
for await (const mutatedNode of mutatedNodes) {
|
|
96
|
-
if (mutatedNode) {
|
|
97
|
-
document.body.innerHTML = mutatedNode;
|
|
98
|
-
// remove walker
|
|
99
|
-
// const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
|
|
100
|
-
// let currNode = walker.firstChild();
|
|
101
|
-
// while (currNode !== null) {
|
|
102
|
-
if (customRules.length === 0)
|
|
103
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(document.body, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
|
|
104
|
-
else
|
|
105
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(document.body, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
|
|
106
|
-
// currNode = walker.nextSibling();
|
|
107
|
-
// }
|
|
108
|
-
}
|
|
109
|
-
}
|
|
81
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
|
|
82
|
+
currNode = walker.nextSibling();
|
|
110
83
|
}
|
|
111
84
|
}
|
|
112
85
|
finally {
|
|
113
|
-
if (opts.runDOMMutationObserver) {
|
|
114
|
-
mutatedNodes = [];
|
|
115
|
-
}
|
|
116
86
|
(0, exports.setOriginalDocumentBodyHtml)(null);
|
|
117
87
|
document.body.innerHTML = currentDocumentHtml;
|
|
118
88
|
if (opts.cleanupAfterEach)
|
|
@@ -127,43 +97,15 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
127
97
|
}
|
|
128
98
|
}
|
|
129
99
|
exports.automaticCheck = automaticCheck;
|
|
130
|
-
function observerCallback(mutations, _observer) {
|
|
131
|
-
for (const mutation of mutations) {
|
|
132
|
-
mutation.addedNodes.forEach((node) => {
|
|
133
|
-
if (node?.parentElement?.innerHTML) {
|
|
134
|
-
mutatedNodes.push(node.parentElement.innerHTML);
|
|
135
|
-
}
|
|
136
|
-
else if (node?.outerHTML) {
|
|
137
|
-
mutatedNodes.push(node?.outerHTML);
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserverInit
|
|
143
|
-
const observerOptions = {
|
|
144
|
-
subtree: true,
|
|
145
|
-
childList: true,
|
|
146
|
-
attributes: true,
|
|
147
|
-
characterData: true, // monitor changes to the character data contained within nodes
|
|
148
|
-
};
|
|
149
100
|
/**
|
|
150
101
|
* Register accessibility checks to be run automatically after each test
|
|
151
102
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
152
103
|
*/
|
|
153
104
|
function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
|
|
154
105
|
if (opts.runAfterEach) {
|
|
155
|
-
const observer = new MutationObserver(observerCallback);
|
|
156
106
|
// TODO (fix): Make registration idempotent
|
|
157
107
|
(0, common_1.log)('Registering sa11y checks to be run automatically after each test');
|
|
158
|
-
beforeEach(() => {
|
|
159
|
-
if (opts.runDOMMutationObserver) {
|
|
160
|
-
observer.observe(document.body, observerOptions);
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
108
|
afterEach(async () => {
|
|
164
|
-
if (opts.runDOMMutationObserver) {
|
|
165
|
-
observer.disconnect(); // stop mutation observer
|
|
166
|
-
}
|
|
167
109
|
await automaticCheck(opts);
|
|
168
110
|
});
|
|
169
111
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"groupViolationResultsProcessor.d.ts","sourceRoot":"","sources":["../src/groupViolationResultsProcessor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAA+B,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"groupViolationResultsProcessor.d.ts","sourceRoot":"","sources":["../src/groupViolationResultsProcessor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAA+B,MAAM,mBAAmB,CAAC;AA6MlF;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAa5E;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAaxF"}
|
|
@@ -3,44 +3,64 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.resultsProcessorManualChecks = exports.resultsProcessor = void 0;
|
|
4
4
|
const common_1 = require("@sa11y/common");
|
|
5
5
|
const format_1 = require("@sa11y/format");
|
|
6
|
-
const formatSpacing = '\t'.repeat(
|
|
7
|
-
const formatForAxeMessage = `\n${formatSpacing}\t
|
|
6
|
+
const formatSpacing = '\t'.repeat(4);
|
|
7
|
+
const formatForAxeMessage = `\n${formatSpacing}\t`;
|
|
8
8
|
const axeMessages = {
|
|
9
9
|
toSolveAny: `${formatForAxeMessage}- More Info: To solve the problem, you need to fix at least (1) of the following:\n`,
|
|
10
10
|
toSolveFirst: `${formatForAxeMessage}- More Info: To solve the problem, you need to fix one of the following:\n`,
|
|
11
11
|
toSolveSecond: `${formatForAxeMessage}- And fix the following:\n`,
|
|
12
|
+
relatedNodes: `${formatForAxeMessage}- Related Nodes: \n`,
|
|
12
13
|
};
|
|
13
14
|
/**
|
|
14
15
|
* Create a test failure html elements array grouped by rule violation
|
|
15
16
|
*/
|
|
16
17
|
function createA11yErrorElements(errorElements) {
|
|
17
18
|
const a11yErrorElements = [];
|
|
19
|
+
let onlyOneSummary = false;
|
|
20
|
+
const appendRelatedNodes = (errorMessage, relatedNodes) => {
|
|
21
|
+
return relatedNodes ? `${errorMessage}${axeMessages.relatedNodes}${relatedNodes}` : errorMessage;
|
|
22
|
+
};
|
|
18
23
|
errorElements.forEach((errorElement, index) => {
|
|
19
|
-
let errorMessage = `${formatSpacing}(${index + 1})
|
|
24
|
+
let errorMessage = `${formatSpacing}(${index + 1}) - HTML element : ${errorElement.html
|
|
20
25
|
.replace(/</g, '<')
|
|
21
|
-
.replace(/>/, '>')}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
.replace(/>/, '>')}`;
|
|
27
|
+
errorMessage += `${formatForAxeMessage}- CSS selector(s) : ${errorElement.selectors.replace(/>/, '>')}`;
|
|
28
|
+
errorMessage += `${formatForAxeMessage}- HTML Tag Hierarchy : ${errorElement.hierarchy}`;
|
|
29
|
+
const isAny = errorElement.any?.length > 0;
|
|
30
|
+
const isAll = errorElement.all?.length > 0;
|
|
31
|
+
const isNone = errorElement.none?.length > 0;
|
|
32
|
+
if (!onlyOneSummary) {
|
|
33
|
+
if (isAny) {
|
|
34
|
+
errorMessage += `${axeMessages.toSolveAny}${errorElement.any}`;
|
|
35
|
+
errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeAny);
|
|
36
|
+
if (isAll) {
|
|
37
|
+
errorMessage += `${axeMessages.toSolveSecond}${errorElement.all}`;
|
|
38
|
+
errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeAll);
|
|
39
|
+
}
|
|
40
|
+
if (isNone) {
|
|
41
|
+
errorMessage += `${axeMessages.toSolveSecond}${errorElement.none}`;
|
|
42
|
+
errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeNone);
|
|
43
|
+
}
|
|
28
44
|
}
|
|
29
|
-
if (
|
|
30
|
-
errorMessage += `${axeMessages.
|
|
45
|
+
else if (isAll) {
|
|
46
|
+
errorMessage += `${axeMessages.toSolveFirst}${errorElement.all}`;
|
|
47
|
+
errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeAll);
|
|
48
|
+
if (isNone) {
|
|
49
|
+
errorMessage += `${axeMessages.toSolveSecond}${errorElement.none}`;
|
|
50
|
+
errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeNone);
|
|
51
|
+
}
|
|
31
52
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
53
|
+
else {
|
|
54
|
+
if (isNone) {
|
|
55
|
+
errorMessage += `${axeMessages.toSolveFirst}${errorElement.none}`;
|
|
56
|
+
errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeNone);
|
|
57
|
+
}
|
|
37
58
|
}
|
|
38
59
|
}
|
|
39
60
|
else {
|
|
40
|
-
|
|
41
|
-
errorMessage += `${axeMessages.toSolveFirst}${errorElement.none}`;
|
|
42
|
-
}
|
|
61
|
+
errorMessage = appendRelatedNodes(errorMessage, errorElement.relatedNodeAny);
|
|
43
62
|
}
|
|
63
|
+
onlyOneSummary = isAny && !isAll && !isNone;
|
|
44
64
|
a11yErrorElements.push(errorMessage);
|
|
45
65
|
});
|
|
46
66
|
return a11yErrorElements.join('\n');
|
|
@@ -83,21 +103,24 @@ function processA11yDetailsAndMessages(error, a11yFailureMessages) {
|
|
|
83
103
|
any: a11yResult.any,
|
|
84
104
|
all: a11yResult.all,
|
|
85
105
|
none: a11yResult.none,
|
|
106
|
+
relatedNodeAny: a11yResult.relatedNodeAny,
|
|
107
|
+
relatedNodeAll: a11yResult.relatedNodeAll,
|
|
108
|
+
relatedNodeNone: a11yResult.relatedNodeNone,
|
|
86
109
|
});
|
|
87
110
|
});
|
|
88
111
|
const a11yFailureMessage = `
|
|
89
|
-
|
|
90
|
-
|
|
112
|
+
The test has failed the accessibility check. Accessibility Stacktrace/Issues:
|
|
113
|
+
${a11yErrorElementsCount} HTML elements have accessibility issue(s). ${a11yRuleViolationsCount} rules failed.
|
|
91
114
|
|
|
92
|
-
|
|
115
|
+
${Object.values(a11yRuleViolations)
|
|
93
116
|
.map((a11yRuleViolation, index) => createA11yRuleViolation(a11yRuleViolation, index + 1))
|
|
94
117
|
.join('\n')}
|
|
95
118
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
119
|
+
|
|
120
|
+
For more info about automated accessibility testing: https://sfdc.co/a11y-test
|
|
121
|
+
For tips on fixing accessibility bugs: https://sfdc.co/a11y
|
|
122
|
+
For technical questions regarding Salesforce accessibility tools, contact our Sa11y team: http://sfdc.co/sa11y-users
|
|
123
|
+
For guidance on accessibility related specifics, contact our A11y team: http://sfdc.co/tmp-a11y
|
|
101
124
|
`;
|
|
102
125
|
a11yFailureMessages.push(a11yFailureMessage);
|
|
103
126
|
}
|
package/dist/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAA6C,MAAM,eAAe,CAAC;AACtF,OAAO,EACH,aAAa,EAIhB,MAAM,aAAa,CAAC;AAIrB,eAAO,MAAM,aAAa,UAiBzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,aAAa,EAAE,aAAa,CAAC;CAKhC,CAAC;
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAA6C,MAAM,eAAe,CAAC;AACtF,OAAO,EACH,aAAa,EAIhB,MAAM,aAAa,CAAC;AAIrB,eAAO,MAAM,aAAa,UAiBzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,aAAa,EAAE,aAAa,CAAC;CAKhC,CAAC;AAkCF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,SAA4B,GAAG,IAAI,CA6C9D;AACD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAU3C;AACD;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,UAAU,CAKhG;AACD,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,WAAgB,GAAG,UAAU,CAM3F"}
|
package/dist/setup.js
CHANGED
|
@@ -38,7 +38,6 @@ const defaultSa11yOpts = {
|
|
|
38
38
|
runAfterEach: false,
|
|
39
39
|
cleanupAfterEach: false,
|
|
40
40
|
consolidateResults: false,
|
|
41
|
-
runDOMMutationObserver: false,
|
|
42
41
|
},
|
|
43
42
|
};
|
|
44
43
|
function registerRemoveChild() {
|
|
@@ -104,9 +103,6 @@ function setup(opts = defaultSa11yOpts) {
|
|
|
104
103
|
'ui-help-components/modules/forceHelp/searchResults/__tests__/searchResults.spec.js',
|
|
105
104
|
'ui-help-components/modules/forceHelp/linkToKnownIssue/__tests__/linkToKnownIssue.spec.js',
|
|
106
105
|
]);
|
|
107
|
-
// TODO: For testing purposes, using SA11Y_CUSTOM_RULES config
|
|
108
|
-
// autoCheckOpts.runDOMMutationObserver ||= !!process.env.SA11Y_ENABLE_DOM_MUTATION_CHECKS;
|
|
109
|
-
autoCheckOpts.runDOMMutationObserver || (autoCheckOpts.runDOMMutationObserver = !!process.env.SA11Y_CUSTOM_RULES);
|
|
110
106
|
(0, automatic_1.registerSa11yAutomaticChecks)(autoCheckOpts);
|
|
111
107
|
}
|
|
112
108
|
exports.setup = setup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sa11y/jest",
|
|
3
|
-
"version": "6.9.5
|
|
3
|
+
"version": "6.9.5",
|
|
4
4
|
"description": "Accessibility testing matcher for Jest",
|
|
5
5
|
"license": "BSD-3-Clause",
|
|
6
6
|
"homepage": "https://github.com/salesforce/sa11y/tree/master/packages/jest#readme",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@jest/test-result": "^27",
|
|
27
|
-
"@sa11y/assert": "6.9.5
|
|
28
|
-
"@sa11y/format": "6.9.5
|
|
29
|
-
"@sa11y/preset-rules": "6.9.5
|
|
27
|
+
"@sa11y/assert": "6.9.5",
|
|
28
|
+
"@sa11y/format": "6.9.5",
|
|
29
|
+
"@sa11y/preset-rules": "6.9.5",
|
|
30
30
|
"jest-matcher-utils": "^27"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@jest/globals": "28.1.3",
|
|
37
|
-
"@sa11y/common": "6.9.5
|
|
38
|
-
"@sa11y/test-utils": "6.9.5
|
|
37
|
+
"@sa11y/common": "6.9.5",
|
|
38
|
+
"@sa11y/test-utils": "6.9.5"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": "^16 || ^18 || ^20"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "20778083b656180c2b077a4a7148cf813c05d040"
|
|
47
47
|
}
|