@sa11y/jest 6.9.5 → 6.10.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 +1 -0
- package/dist/automatic.d.ts.map +1 -1
- package/dist/automatic.js +63 -11
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +3 -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;AAiBF,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,CAiF9F;AAsBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAE,aAAoC,GAAG,IAAI,CAmB7F"}
|
package/dist/automatic.js
CHANGED
|
@@ -22,8 +22,10 @@ const defaultAutoCheckOpts = {
|
|
|
22
22
|
cleanupAfterEach: true,
|
|
23
23
|
consolidateResults: true,
|
|
24
24
|
filesFilter: [],
|
|
25
|
+
runDOMMutationObserver: false,
|
|
25
26
|
};
|
|
26
27
|
let originalDocumentBodyHtml = null;
|
|
28
|
+
let mutatedNodes = [];
|
|
27
29
|
const setOriginalDocumentBodyHtml = (bodyHtml) => {
|
|
28
30
|
originalDocumentBodyHtml = bodyHtml ?? null;
|
|
29
31
|
};
|
|
@@ -67,22 +69,44 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
67
69
|
let currNode = walker.firstChild();
|
|
68
70
|
const customRules = (0, common_1.useCustomRules)();
|
|
69
71
|
try {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
if (!opts.runDOMMutationObserver) {
|
|
73
|
+
while (currNode !== null) {
|
|
74
|
+
// TODO (spike): Use a logger lib with log levels selectable at runtime
|
|
75
|
+
// console.log(
|
|
76
|
+
// `♿ [DEBUG] Automatically checking a11y of ${currNode.nodeName}
|
|
77
|
+
// for test "${expect.getState().currentTestName}"
|
|
78
|
+
// : ${testPath}`
|
|
79
|
+
// );
|
|
80
|
+
// W-10004832 - Exclude descendancy based rules from automatic checks
|
|
81
|
+
if (customRules.length === 0)
|
|
82
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
|
|
83
|
+
else
|
|
84
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(currNode, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
|
|
85
|
+
currNode = walker.nextSibling();
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
78
89
|
if (customRules.length === 0)
|
|
79
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(
|
|
90
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(document.body, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
|
|
80
91
|
else
|
|
81
|
-
violations.push(...(await (0, assert_1.getViolationsJSDOM)(
|
|
82
|
-
|
|
92
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(document.body, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
|
|
93
|
+
document.body.innerHTML = '';
|
|
94
|
+
// loop mutated nodes
|
|
95
|
+
for await (const mutatedNode of mutatedNodes) {
|
|
96
|
+
if (mutatedNode) {
|
|
97
|
+
document.body.innerHTML = mutatedNode;
|
|
98
|
+
if (customRules.length === 0)
|
|
99
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(document.body, (0, setup_1.adaptA11yConfig)(preset_rules_1.defaultRuleset))));
|
|
100
|
+
else
|
|
101
|
+
violations.push(...(await (0, assert_1.getViolationsJSDOM)(document.body, (0, setup_1.adaptA11yConfigCustomRules)(preset_rules_1.defaultRuleset, customRules))));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
83
104
|
}
|
|
84
105
|
}
|
|
85
106
|
finally {
|
|
107
|
+
if (opts.runDOMMutationObserver) {
|
|
108
|
+
mutatedNodes = [];
|
|
109
|
+
}
|
|
86
110
|
(0, exports.setOriginalDocumentBodyHtml)(null);
|
|
87
111
|
document.body.innerHTML = currentDocumentHtml;
|
|
88
112
|
if (opts.cleanupAfterEach)
|
|
@@ -97,15 +121,43 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
97
121
|
}
|
|
98
122
|
}
|
|
99
123
|
exports.automaticCheck = automaticCheck;
|
|
124
|
+
function observerCallback(mutations, _observer) {
|
|
125
|
+
for (const mutation of mutations) {
|
|
126
|
+
mutation.addedNodes.forEach((node) => {
|
|
127
|
+
if (node?.parentElement?.innerHTML) {
|
|
128
|
+
mutatedNodes.push(node.parentElement.innerHTML);
|
|
129
|
+
}
|
|
130
|
+
else if (node?.outerHTML) {
|
|
131
|
+
mutatedNodes.push(node?.outerHTML);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserverInit
|
|
137
|
+
const observerOptions = {
|
|
138
|
+
subtree: true,
|
|
139
|
+
childList: true,
|
|
140
|
+
attributes: true,
|
|
141
|
+
characterData: true, // monitor changes to the character data contained within nodes
|
|
142
|
+
};
|
|
100
143
|
/**
|
|
101
144
|
* Register accessibility checks to be run automatically after each test
|
|
102
145
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
103
146
|
*/
|
|
104
147
|
function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
|
|
105
148
|
if (opts.runAfterEach) {
|
|
149
|
+
const observer = new MutationObserver(observerCallback);
|
|
106
150
|
// TODO (fix): Make registration idempotent
|
|
107
151
|
(0, common_1.log)('Registering sa11y checks to be run automatically after each test');
|
|
152
|
+
beforeEach(() => {
|
|
153
|
+
if (opts.runDOMMutationObserver) {
|
|
154
|
+
observer.observe(document.body, observerOptions);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
108
157
|
afterEach(async () => {
|
|
158
|
+
if (opts.runDOMMutationObserver) {
|
|
159
|
+
observer.disconnect(); // stop mutation observer
|
|
160
|
+
}
|
|
109
161
|
await automaticCheck(opts);
|
|
110
162
|
});
|
|
111
163
|
}
|
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;AAmCF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,SAA4B,GAAG,IAAI,CAgD9D;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,6 +38,7 @@ const defaultSa11yOpts = {
|
|
|
38
38
|
runAfterEach: false,
|
|
39
39
|
cleanupAfterEach: false,
|
|
40
40
|
consolidateResults: false,
|
|
41
|
+
runDOMMutationObserver: false,
|
|
41
42
|
},
|
|
42
43
|
};
|
|
43
44
|
function registerRemoveChild() {
|
|
@@ -103,6 +104,8 @@ function setup(opts = defaultSa11yOpts) {
|
|
|
103
104
|
'ui-help-components/modules/forceHelp/searchResults/__tests__/searchResults.spec.js',
|
|
104
105
|
'ui-help-components/modules/forceHelp/linkToKnownIssue/__tests__/linkToKnownIssue.spec.js',
|
|
105
106
|
]);
|
|
107
|
+
// set the flag to true to run sa11y in DOM Mutation Observer mode
|
|
108
|
+
autoCheckOpts.runDOMMutationObserver || (autoCheckOpts.runDOMMutationObserver = !!process.env.SA11Y_ENABLE_DOM_MUTATION_OBSERVER);
|
|
106
109
|
(0, automatic_1.registerSa11yAutomaticChecks)(autoCheckOpts);
|
|
107
110
|
}
|
|
108
111
|
exports.setup = setup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sa11y/jest",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.10.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.10.0",
|
|
28
|
+
"@sa11y/format": "6.10.0",
|
|
29
|
+
"@sa11y/preset-rules": "6.10.0",
|
|
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.
|
|
38
|
-
"@sa11y/test-utils": "6.
|
|
37
|
+
"@sa11y/common": "6.10.0",
|
|
38
|
+
"@sa11y/test-utils": "6.10.0"
|
|
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": "1f5d3dc24b26e096686cc22436998661705b490a"
|
|
47
47
|
}
|