@sa11y/jest 7.0.1 → 7.1.0-alpha.2
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/README.md +1 -1
- package/dist/automatic.d.ts +9 -2
- package/dist/automatic.d.ts.map +1 -1
- package/dist/automatic.js +31 -5
- package/dist/groupViolationResultsProcessor.d.ts.map +1 -1
- package/dist/groupViolationResultsProcessor.js +1 -0
- package/dist/setup.d.ts +2 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +5 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -108,7 +108,7 @@ it('should be accessible', async () => {
|
|
|
108
108
|
// Setup DOM to be tested for accessibility
|
|
109
109
|
//...
|
|
110
110
|
|
|
111
|
-
// assert that DOM is accessible (using base preset-rule)
|
|
111
|
+
// assert that whole DOM is accessible (using base preset-rule)
|
|
112
112
|
await expect(document).toBeAccessible();
|
|
113
113
|
|
|
114
114
|
// Can be used to test accessibility of a specific HTML element
|
package/dist/automatic.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ export type AutoCheckOpts = {
|
|
|
9
9
|
runDOMMutationObserver?: boolean;
|
|
10
10
|
enableIncompleteResults?: boolean;
|
|
11
11
|
};
|
|
12
|
+
export type RenderedDOMSaveOpts = {
|
|
13
|
+
renderedDOMDumpDirPath?: string;
|
|
14
|
+
generateRenderedDOMFileSaveLocation?: (testFilePath: string, testName: string) => {
|
|
15
|
+
fileName: string;
|
|
16
|
+
fileUrl: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
12
19
|
export declare const setOriginalDocumentBodyHtml: (bodyHtml: string | null) => void;
|
|
13
20
|
export declare const getOriginalDocumentBodyHtml: () => string | null;
|
|
14
21
|
/**
|
|
@@ -19,10 +26,10 @@ export declare function skipTest(testPath: string | undefined, filesFilter?: str
|
|
|
19
26
|
* Run accessibility check on each element node in the body using {@link toBeAccessible}
|
|
20
27
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
21
28
|
*/
|
|
22
|
-
export declare function automaticCheck(opts?: AutoCheckOpts): Promise<void>;
|
|
29
|
+
export declare function automaticCheck(opts?: AutoCheckOpts, renderedDOMSaveOpts?: RenderedDOMSaveOpts): Promise<void>;
|
|
23
30
|
/**
|
|
24
31
|
* Register accessibility checks to be run automatically after each test
|
|
25
32
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
26
33
|
*/
|
|
27
|
-
export declare function registerSa11yAutomaticChecks(opts?: AutoCheckOpts): void;
|
|
34
|
+
export declare function registerSa11yAutomaticChecks(opts?: AutoCheckOpts, renderedDOMSaveOpts?: RenderedDOMSaveOpts): void;
|
|
28
35
|
//# sourceMappingURL=automatic.d.ts.map
|
package/dist/automatic.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automatic.d.ts","sourceRoot":"","sources":["../src/automatic.ts"],"names":[],"mappings":"AAmBA;;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;IACjC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;
|
|
1
|
+
{"version":3,"file":"automatic.d.ts","sourceRoot":"","sources":["../src/automatic.ts"],"names":[],"mappings":"AAmBA;;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;IACjC,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAC9B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,mCAAmC,CAAC,EAAE,CAClC,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,KACf;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC9C,CAAC;AAsBF,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,CAChC,IAAI,GAAE,aAAoC,EAC1C,mBAAmB,GAAE,mBAAgD,GACtE,OAAO,CAAC,IAAI,CAAC,CAmGf;AAsBD;;;GAGG;AACH,wBAAgB,4BAA4B,CACxC,IAAI,GAAE,aAAoC,EAC1C,mBAAmB,GAAE,mBAAgD,GACtE,IAAI,CAmBN"}
|
package/dist/automatic.js
CHANGED
|
@@ -24,6 +24,9 @@ const defaultAutoCheckOpts = {
|
|
|
24
24
|
runDOMMutationObserver: false,
|
|
25
25
|
enableIncompleteResults: false,
|
|
26
26
|
};
|
|
27
|
+
const defaultRenderedDOMSaveOpts = {
|
|
28
|
+
renderedDOMDumpDirPath: '',
|
|
29
|
+
};
|
|
27
30
|
let originalDocumentBodyHtml = null;
|
|
28
31
|
let mutatedNodes = [];
|
|
29
32
|
const setOriginalDocumentBodyHtml = (bodyHtml) => {
|
|
@@ -51,7 +54,7 @@ exports.skipTest = skipTest;
|
|
|
51
54
|
* Run accessibility check on each element node in the body using {@link toBeAccessible}
|
|
52
55
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
53
56
|
*/
|
|
54
|
-
async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
57
|
+
async function automaticCheck(opts = defaultAutoCheckOpts, renderedDOMSaveOpts = defaultRenderedDOMSaveOpts) {
|
|
55
58
|
if (skipTest(globals_1.expect.getState().testPath, opts.filesFilter))
|
|
56
59
|
return;
|
|
57
60
|
// Skip automatic check if test is using fake timer as it would result in timeout
|
|
@@ -73,6 +76,7 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
73
76
|
// Create a DOM walker filtering only elements (skipping text, comment nodes etc)
|
|
74
77
|
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
|
|
75
78
|
let currNode = walker.firstChild();
|
|
79
|
+
let renderedDOMSavedFileName = '';
|
|
76
80
|
try {
|
|
77
81
|
if (!opts.runDOMMutationObserver) {
|
|
78
82
|
while (currNode !== null) {
|
|
@@ -88,7 +92,29 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
else {
|
|
91
|
-
|
|
95
|
+
const a11yResultsJSDOM = await (0, assert_1.getA11yResultsJSDOM)(document.body, config, opts.enableIncompleteResults);
|
|
96
|
+
if (a11yResultsJSDOM?.length > 0) {
|
|
97
|
+
if (!!renderedDOMSaveOpts.renderedDOMDumpDirPath &&
|
|
98
|
+
!!renderedDOMSaveOpts.generateRenderedDOMFileSaveLocation) {
|
|
99
|
+
try {
|
|
100
|
+
// save the document body HTML
|
|
101
|
+
const testFilePath = globals_1.expect.getState().testPath ?? '';
|
|
102
|
+
const testName = globals_1.expect.getState().currentTestName ?? '';
|
|
103
|
+
if (!testFilePath || !testName) {
|
|
104
|
+
console.log(`Skipping saving rendered DOM HTML as one or both of test file path and test name are empty`);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const { fileName, fileUrl } = renderedDOMSaveOpts.generateRenderedDOMFileSaveLocation(testFilePath, testName);
|
|
108
|
+
renderedDOMSavedFileName = fileUrl;
|
|
109
|
+
(0, common_1.writeHtmlFileInPath)(renderedDOMSaveOpts.renderedDOMDumpDirPath, fileName, document.body.innerHTML);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
console.log(`ran into an error while saving rendered DOM - ${e.message}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
a11yResults.push(...a11yResultsJSDOM);
|
|
92
118
|
document.body.innerHTML = '';
|
|
93
119
|
// loop mutated nodes
|
|
94
120
|
for await (const mutatedNode of mutatedNodes) {
|
|
@@ -113,7 +139,7 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
113
139
|
if (process.env.SELECTOR_FILTER_KEYWORDS) {
|
|
114
140
|
a11yResults = (0, format_1.exceptionListFilterSelectorKeywords)(a11yResults, process.env.SELECTOR_FILTER_KEYWORDS.split(','));
|
|
115
141
|
}
|
|
116
|
-
format_1.A11yError.checkAndThrow(a11yResults, { deduplicate: opts.consolidateResults });
|
|
142
|
+
format_1.A11yError.checkAndThrow(a11yResults, { deduplicate: opts.consolidateResults, renderedDOMSavedFileName });
|
|
117
143
|
}
|
|
118
144
|
}
|
|
119
145
|
exports.automaticCheck = automaticCheck;
|
|
@@ -140,7 +166,7 @@ const observerOptions = {
|
|
|
140
166
|
* Register accessibility checks to be run automatically after each test
|
|
141
167
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
142
168
|
*/
|
|
143
|
-
function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
|
|
169
|
+
function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts, renderedDOMSaveOpts = defaultRenderedDOMSaveOpts) {
|
|
144
170
|
if (opts.runAfterEach) {
|
|
145
171
|
const observer = new MutationObserver(observerCallback);
|
|
146
172
|
// TODO (fix): Make registration idempotent
|
|
@@ -154,7 +180,7 @@ function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
|
|
|
154
180
|
if (opts.runDOMMutationObserver) {
|
|
155
181
|
observer.disconnect(); // stop mutation observer
|
|
156
182
|
}
|
|
157
|
-
await automaticCheck(opts);
|
|
183
|
+
await automaticCheck(opts, renderedDOMSaveOpts);
|
|
158
184
|
});
|
|
159
185
|
}
|
|
160
186
|
}
|
|
@@ -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;AAelF,MAAM,MAAM,YAAY,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAoBF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,YAAY,EAAE,UAqDpE;
|
|
1
|
+
{"version":3,"file":"groupViolationResultsProcessor.d.ts","sourceRoot":"","sources":["../src/groupViolationResultsProcessor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAA+B,MAAM,mBAAmB,CAAC;AAelF,MAAM,MAAM,YAAY,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAoBF;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,aAAa,EAAE,YAAY,EAAE,UAqDpE;AA4GD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAa5E;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAaxF"}
|
|
@@ -113,6 +113,7 @@ function processA11yDetailsAndMessages(error, a11yFailureMessages) {
|
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
const a11yFailureMessage = `
|
|
116
|
+
${error.renderedDOMSavedFileName ? `HTML Source: ${error.renderedDOMSavedFileName}\n` : ''}
|
|
116
117
|
The test has failed the accessibility check. Accessibility Stacktrace/Issues:
|
|
117
118
|
${a11yErrorElementsCount} HTML elements have accessibility issue(s). ${a11yRuleViolationsCount} rules failed.
|
|
118
119
|
|
package/dist/setup.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { AutoCheckOpts } from './automatic';
|
|
1
|
+
import { AutoCheckOpts, RenderedDOMSaveOpts } from './automatic';
|
|
2
2
|
/**
|
|
3
3
|
* Options to be passed on to {@link setup}
|
|
4
4
|
*/
|
|
5
5
|
export type Sa11yOpts = {
|
|
6
6
|
autoCheckOpts: AutoCheckOpts;
|
|
7
|
+
renderedDOMSaveOpts: RenderedDOMSaveOpts;
|
|
7
8
|
};
|
|
8
9
|
/**
|
|
9
10
|
* Register Sa11y Jest API and automatic checks depending on {@link Sa11yOpts}
|
package/dist/setup.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AASA,OAAO,EACH,aAAa,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AASA,OAAO,EACH,aAAa,EAIb,mBAAmB,EACtB,MAAM,aAAa,CAAC;AAIrB;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,mBAAmB,EAAE,mBAAmB,CAAC;CAK5C,CAAC;AAuCF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,SAA4B,GAAG,IAAI,CAmD9D;AACD;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAU3C"}
|
package/dist/setup.js
CHANGED
|
@@ -23,6 +23,9 @@ const defaultSa11yOpts = {
|
|
|
23
23
|
runDOMMutationObserver: false,
|
|
24
24
|
enableIncompleteResults: false,
|
|
25
25
|
},
|
|
26
|
+
renderedDOMSaveOpts: {
|
|
27
|
+
renderedDOMDumpDirPath: '',
|
|
28
|
+
},
|
|
26
29
|
};
|
|
27
30
|
function registerRemoveChild() {
|
|
28
31
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
@@ -90,7 +93,8 @@ function setup(opts = defaultSa11yOpts) {
|
|
|
90
93
|
// set the flag to true to run sa11y in DOM Mutation Observer mode
|
|
91
94
|
autoCheckOpts.runDOMMutationObserver || (autoCheckOpts.runDOMMutationObserver = !!process.env.SA11Y_ENABLE_DOM_MUTATION_OBSERVER);
|
|
92
95
|
autoCheckOpts.enableIncompleteResults || (autoCheckOpts.enableIncompleteResults = !!process.env.SA11Y_ENABLE_INCOMPLETE_RESULTS);
|
|
93
|
-
|
|
96
|
+
const renderedDOMSaveOpts = opts.renderedDOMSaveOpts;
|
|
97
|
+
(0, automatic_1.registerSa11yAutomaticChecks)(autoCheckOpts, renderedDOMSaveOpts);
|
|
94
98
|
}
|
|
95
99
|
exports.setup = setup;
|
|
96
100
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sa11y/jest",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.1.0-alpha.2",
|
|
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": "7.0.
|
|
28
|
-
"@sa11y/format": "7.0.
|
|
29
|
-
"@sa11y/preset-rules": "7.0.
|
|
27
|
+
"@sa11y/assert": "7.1.0-alpha.2",
|
|
28
|
+
"@sa11y/format": "7.1.0-alpha.2",
|
|
29
|
+
"@sa11y/preset-rules": "7.1.0-alpha.2",
|
|
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": "7.0.
|
|
38
|
-
"@sa11y/test-utils": "7.0.
|
|
37
|
+
"@sa11y/common": "7.1.0-alpha.2",
|
|
38
|
+
"@sa11y/test-utils": "7.1.0-alpha.2"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": "^18 || ^20"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "108d459f5c12828a7071769bef8812be898df56b"
|
|
47
47
|
}
|