@sa11y/jest 6.7.1-alpha.4 → 6.9.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/automatic.d.ts +0 -1
- package/dist/automatic.d.ts.map +1 -1
- package/dist/automatic.js +13 -60
- package/dist/groupViolationResultsProcessor.js +5 -5
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +2 -4
- package/package.json +8 -8
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
|
};
|
|
@@ -68,43 +67,22 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
currNode = walker.nextSibling();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
for (let i = 0; i < mutatedNodes.length; i++) {
|
|
89
|
-
if (mutatedNodes[i]) {
|
|
90
|
-
document.body.innerHTML = mutatedNodes[i];
|
|
91
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
|
|
92
|
-
let currNode = walker.firstChild();
|
|
93
|
-
while (currNode !== null) {
|
|
94
|
-
if (customRules.length === 0)
|
|
95
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
|
|
96
|
-
else
|
|
97
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
|
|
98
|
-
currNode = walker.nextSibling();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
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
|
|
78
|
+
if (customRules.length === 0)
|
|
79
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
|
|
80
|
+
else
|
|
81
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
|
|
82
|
+
currNode = walker.nextSibling();
|
|
102
83
|
}
|
|
103
84
|
}
|
|
104
85
|
finally {
|
|
105
|
-
if (opts.runDOMMutationObserver) {
|
|
106
|
-
mutatedNodes = [];
|
|
107
|
-
}
|
|
108
86
|
(0, exports.setOriginalDocumentBodyHtml)(null);
|
|
109
87
|
document.body.innerHTML = currentDocumentHtml;
|
|
110
88
|
if (opts.cleanupAfterEach)
|
|
@@ -119,40 +97,15 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
119
97
|
}
|
|
120
98
|
}
|
|
121
99
|
exports.automaticCheck = automaticCheck;
|
|
122
|
-
function observerCallback(mutations, _observer) {
|
|
123
|
-
for (const mutation of mutations) {
|
|
124
|
-
mutation.addedNodes.forEach((node) => {
|
|
125
|
-
if (node?.parentElement?.innerHTML) {
|
|
126
|
-
mutatedNodes.push(node.parentElement.innerHTML);
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserverInit
|
|
132
|
-
const observerOptions = {
|
|
133
|
-
subtree: true,
|
|
134
|
-
childList: true,
|
|
135
|
-
attributes: true,
|
|
136
|
-
characterData: true, // monitor changes to the character data contained within nodes
|
|
137
|
-
};
|
|
138
100
|
/**
|
|
139
101
|
* Register accessibility checks to be run automatically after each test
|
|
140
102
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
141
103
|
*/
|
|
142
104
|
function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
|
|
143
105
|
if (opts.runAfterEach) {
|
|
144
|
-
const observer = new MutationObserver(observerCallback);
|
|
145
106
|
// TODO (fix): Make registration idempotent
|
|
146
107
|
(0, common_1.log)('Registering sa11y checks to be run automatically after each test');
|
|
147
|
-
beforeEach(() => {
|
|
148
|
-
if (opts.runDOMMutationObserver) {
|
|
149
|
-
observer.observe(document.body, observerOptions);
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
108
|
afterEach(async () => {
|
|
153
|
-
if (opts.runDOMMutationObserver) {
|
|
154
|
-
observer.disconnect(); // stop mutation observer
|
|
155
|
-
}
|
|
156
109
|
await automaticCheck(opts);
|
|
157
110
|
});
|
|
158
111
|
}
|
|
@@ -15,11 +15,11 @@ const axeMessages = {
|
|
|
15
15
|
function createA11yErrorElements(errorElements) {
|
|
16
16
|
const a11yErrorElements = [];
|
|
17
17
|
errorElements.forEach((errorElement, index) => {
|
|
18
|
-
let errorMessage = `${formatSpacing}(${index + 1})
|
|
18
|
+
let errorMessage = `${formatSpacing}(${index + 1}) - HTML element : ${errorElement.html
|
|
19
19
|
.replace(/</g, '<')
|
|
20
20
|
.replace(/>/, '>')}
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
- CSS selector(s) : ${errorElement.selectors.replace(/>/, '>')}
|
|
22
|
+
- HTML Tag Hierarchy : ${errorElement.hierarchy}`;
|
|
23
23
|
if (errorElement.any && errorElement.any.length > 0) {
|
|
24
24
|
errorMessage += `${axeMessages.toSolveAny}${errorElement.any}`;
|
|
25
25
|
if (errorElement.all && errorElement.all.length > 0) {
|
|
@@ -51,8 +51,8 @@ function createA11yRuleViolation(a11yRule, ruleIndex) {
|
|
|
51
51
|
return `(${ruleIndex}) [${a11yRule.id}] ${a11yRule.description}
|
|
52
52
|
* Error element(s) : ${a11yRule.errorElements.length}\n${createA11yErrorElements(a11yRule.errorElements)}
|
|
53
53
|
* Help:
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
• Help URL: ${a11yRule.helpUrl}
|
|
55
|
+
• WCAG Criteria: ${a11yRule.wcagCriteria}`;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Convert any a11y errors from test failures into their own test suite, results
|
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,EAAwB,MAAM,eAAe,CAAC;AACjE,OAAO,EACH,aAAa,EAIhB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAwB,MAAM,eAAe,CAAC;AACjE,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
|
@@ -11,6 +11,7 @@ const matcher_1 = require("./matcher");
|
|
|
11
11
|
const common_1 = require("@sa11y/common");
|
|
12
12
|
const automatic_1 = require("./automatic");
|
|
13
13
|
const globals_1 = require("@jest/globals");
|
|
14
|
+
const preset_rules_1 = require("@sa11y/preset-rules");
|
|
14
15
|
exports.disabledRules = [
|
|
15
16
|
// Descendancy checks that would fail at unit/component level, but pass at page level
|
|
16
17
|
'aria-required-children',
|
|
@@ -37,7 +38,6 @@ const defaultSa11yOpts = {
|
|
|
37
38
|
runAfterEach: false,
|
|
38
39
|
cleanupAfterEach: false,
|
|
39
40
|
consolidateResults: false,
|
|
40
|
-
runDOMMutationObserver: false,
|
|
41
41
|
},
|
|
42
42
|
};
|
|
43
43
|
function registerRemoveChild() {
|
|
@@ -70,6 +70,7 @@ function setup(opts = defaultSa11yOpts) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
registerSa11yMatcher();
|
|
73
|
+
(0, preset_rules_1.registerCustomRules)();
|
|
73
74
|
// Set defaults from env vars
|
|
74
75
|
const autoCheckOpts = opts.autoCheckOpts;
|
|
75
76
|
autoCheckOpts.runAfterEach || (autoCheckOpts.runAfterEach = !!process.env.SA11Y_AUTO);
|
|
@@ -102,9 +103,6 @@ function setup(opts = defaultSa11yOpts) {
|
|
|
102
103
|
'ui-help-components/modules/forceHelp/searchResults/__tests__/searchResults.spec.js',
|
|
103
104
|
'ui-help-components/modules/forceHelp/linkToKnownIssue/__tests__/linkToKnownIssue.spec.js',
|
|
104
105
|
]);
|
|
105
|
-
// TODO: For testing purposes, using SA11Y_CUSTOM_RULES config
|
|
106
|
-
// autoCheckOpts.runDOMMutationObserver ||= !!process.env.SA11Y_ENABLE_DOM_MUTATION_CHECKS;
|
|
107
|
-
autoCheckOpts.runDOMMutationObserver || (autoCheckOpts.runDOMMutationObserver = !!process.env.SA11Y_CUSTOM_RULES);
|
|
108
106
|
(0, automatic_1.registerSa11yAutomaticChecks)(autoCheckOpts);
|
|
109
107
|
}
|
|
110
108
|
exports.setup = setup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sa11y/jest",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.9.0",
|
|
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.
|
|
28
|
-
"@sa11y/format": "6.
|
|
29
|
-
"@sa11y/preset-rules": "6.
|
|
27
|
+
"@sa11y/assert": "6.9.0",
|
|
28
|
+
"@sa11y/format": "6.9.0",
|
|
29
|
+
"@sa11y/preset-rules": "6.9.0",
|
|
30
30
|
"jest-matcher-utils": "^27"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@jest/globals": "28.1.3",
|
|
37
|
-
"@sa11y/common": "6.
|
|
38
|
-
"@sa11y/test-utils": "6.
|
|
37
|
+
"@sa11y/common": "6.9.0",
|
|
38
|
+
"@sa11y/test-utils": "6.9.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"engines": {
|
|
44
|
-
"node": "^16 || ^18"
|
|
44
|
+
"node": "^16 || ^18 || ^20"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "90bd6111dfe1bec4ff98d5e1527a245c3c0a5498"
|
|
47
47
|
}
|