@sa11y/jest 6.7.1-alpha.2 → 6.7.1-alpha.4
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 +1 -0
- package/dist/automatic.d.ts.map +1 -1
- package/dist/automatic.js +60 -13
- package/dist/groupViolationResultsProcessor.d.ts.map +1 -1
- package/dist/groupViolationResultsProcessor.js +12 -13
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +4 -0
- package/package.json +7 -7
package/dist/automatic.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type AutoCheckOpts = {
|
|
|
6
6
|
cleanupAfterEach?: boolean;
|
|
7
7
|
consolidateResults?: boolean;
|
|
8
8
|
filesFilter?: string[];
|
|
9
|
+
runDOMMutationObserver?: boolean;
|
|
9
10
|
};
|
|
10
11
|
export declare const setOriginalDocumentBodyHtml: (bodyHtml: string | null) => void;
|
|
11
12
|
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;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAC;CACpC,CAAC;AAgBF,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,CA2E9F;AAoBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAE,aAAoC,GAAG,IAAI,CAmB7F"}
|
package/dist/automatic.js
CHANGED
|
@@ -24,6 +24,7 @@ const defaultAutoCheckOpts = {
|
|
|
24
24
|
filesFilter: [],
|
|
25
25
|
};
|
|
26
26
|
let originalDocumentBodyHtml = null;
|
|
27
|
+
let mutatedNodes = [];
|
|
27
28
|
const setOriginalDocumentBodyHtml = (bodyHtml) => {
|
|
28
29
|
originalDocumentBodyHtml = bodyHtml ?? null;
|
|
29
30
|
};
|
|
@@ -67,22 +68,43 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
67
68
|
let currNode = walker.firstChild();
|
|
68
69
|
const customRules = (0, common_1.useCustomRules)();
|
|
69
70
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
71
|
+
if (!opts.runDOMMutationObserver) {
|
|
72
|
+
while (currNode !== null) {
|
|
73
|
+
// TODO (spike): Use a logger lib with log levels selectable at runtime
|
|
74
|
+
// console.log(
|
|
75
|
+
// `♿ [DEBUG] Automatically checking a11y of ${currNode.nodeName}
|
|
76
|
+
// for test "${expect.getState().currentTestName}"
|
|
77
|
+
// : ${testPath}`
|
|
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
|
+
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
|
+
}
|
|
83
102
|
}
|
|
84
103
|
}
|
|
85
104
|
finally {
|
|
105
|
+
if (opts.runDOMMutationObserver) {
|
|
106
|
+
mutatedNodes = [];
|
|
107
|
+
}
|
|
86
108
|
(0, exports.setOriginalDocumentBodyHtml)(null);
|
|
87
109
|
document.body.innerHTML = currentDocumentHtml;
|
|
88
110
|
if (opts.cleanupAfterEach)
|
|
@@ -97,15 +119,40 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
97
119
|
}
|
|
98
120
|
}
|
|
99
121
|
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
|
+
};
|
|
100
138
|
/**
|
|
101
139
|
* Register accessibility checks to be run automatically after each test
|
|
102
140
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
103
141
|
*/
|
|
104
142
|
function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
|
|
105
143
|
if (opts.runAfterEach) {
|
|
144
|
+
const observer = new MutationObserver(observerCallback);
|
|
106
145
|
// TODO (fix): Make registration idempotent
|
|
107
146
|
(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
|
+
});
|
|
108
152
|
afterEach(async () => {
|
|
153
|
+
if (opts.runDOMMutationObserver) {
|
|
154
|
+
observer.disconnect(); // stop mutation observer
|
|
155
|
+
}
|
|
109
156
|
await automaticCheck(opts);
|
|
110
157
|
});
|
|
111
158
|
}
|
|
@@ -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;AAyJlF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAapF"}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const common_1 = require("@sa11y/common");
|
|
4
4
|
const format_1 = require("@sa11y/format");
|
|
5
|
-
const formatSpacing = '
|
|
6
|
-
const
|
|
5
|
+
const formatSpacing = '\t'.repeat(8);
|
|
6
|
+
const formatForAxeMessage = `\n${formatSpacing}\t\t`;
|
|
7
7
|
const axeMessages = {
|
|
8
|
-
toSolveAny:
|
|
9
|
-
toSolveFirst:
|
|
10
|
-
toSolveSecond:
|
|
8
|
+
toSolveAny: `${formatForAxeMessage}- More Info: To solve the problem, you need to fix at least (1) of the following:\n`,
|
|
9
|
+
toSolveFirst: `${formatForAxeMessage}- More Info: To solve the problem, you need to fix one of the following:\n`,
|
|
10
|
+
toSolveSecond: `${formatForAxeMessage}- And fix the following:\n`,
|
|
11
11
|
};
|
|
12
12
|
/**
|
|
13
13
|
* Create a test failure html elements array grouped by rule violation
|
|
@@ -15,11 +15,11 @@ const axeMessages = {
|
|
|
15
15
|
function createA11yErrorElements(errorElements) {
|
|
16
16
|
const a11yErrorElements = [];
|
|
17
17
|
errorElements.forEach((errorElement, index) => {
|
|
18
|
-
let errorMessage = `${
|
|
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) {
|
|
@@ -49,11 +49,10 @@ function createA11yErrorElements(errorElements) {
|
|
|
49
49
|
*/
|
|
50
50
|
function createA11yRuleViolation(a11yRule, ruleIndex) {
|
|
51
51
|
return `(${ruleIndex}) [${a11yRule.id}] ${a11yRule.description}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
${formatSpacing}${formatSpacing}• WCAG Criteria: ${a11yRule.wcagCriteria}`;
|
|
52
|
+
* Error element(s) : ${a11yRule.errorElements.length}\n${createA11yErrorElements(a11yRule.errorElements)}
|
|
53
|
+
* Help:
|
|
54
|
+
- Help URL: ${a11yRule.helpUrl}
|
|
55
|
+
- WCAG Criteria: ${a11yRule.wcagCriteria}`;
|
|
57
56
|
}
|
|
58
57
|
/**
|
|
59
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;AAGrB,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,EAAwB,MAAM,eAAe,CAAC;AACjE,OAAO,EACH,aAAa,EAIhB,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,aAAa,UAiBzB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,aAAa,EAAE,aAAa,CAAC;CAKhC,CAAC;AAmCF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,SAA4B,GAAG,IAAI,CAiD9D;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
|
@@ -37,6 +37,7 @@ const defaultSa11yOpts = {
|
|
|
37
37
|
runAfterEach: false,
|
|
38
38
|
cleanupAfterEach: false,
|
|
39
39
|
consolidateResults: false,
|
|
40
|
+
runDOMMutationObserver: false,
|
|
40
41
|
},
|
|
41
42
|
};
|
|
42
43
|
function registerRemoveChild() {
|
|
@@ -101,6 +102,9 @@ function setup(opts = defaultSa11yOpts) {
|
|
|
101
102
|
'ui-help-components/modules/forceHelp/searchResults/__tests__/searchResults.spec.js',
|
|
102
103
|
'ui-help-components/modules/forceHelp/linkToKnownIssue/__tests__/linkToKnownIssue.spec.js',
|
|
103
104
|
]);
|
|
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);
|
|
104
108
|
(0, automatic_1.registerSa11yAutomaticChecks)(autoCheckOpts);
|
|
105
109
|
}
|
|
106
110
|
exports.setup = setup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sa11y/jest",
|
|
3
|
-
"version": "6.7.1-alpha.
|
|
3
|
+
"version": "6.7.1-alpha.4",
|
|
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.7.1-alpha.
|
|
28
|
-
"@sa11y/format": "6.7.1-alpha.
|
|
29
|
-
"@sa11y/preset-rules": "6.7.1-alpha.
|
|
27
|
+
"@sa11y/assert": "6.7.1-alpha.4",
|
|
28
|
+
"@sa11y/format": "6.7.1-alpha.4",
|
|
29
|
+
"@sa11y/preset-rules": "6.7.1-alpha.4",
|
|
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.7.1-alpha.
|
|
38
|
-
"@sa11y/test-utils": "6.7.1-alpha.
|
|
37
|
+
"@sa11y/common": "6.7.1-alpha.4",
|
|
38
|
+
"@sa11y/test-utils": "6.7.1-alpha.4"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": "^16 || ^18"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "a44a4a6d189c9d2fc1424891d72a939863a49dd4"
|
|
47
47
|
}
|