@sa11y/jest 5.1.0 → 5.2.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/README.md +5 -0
- package/dist/automatic.d.ts +1 -0
- package/dist/automatic.d.ts.map +1 -1
- package/dist/automatic.js +10 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +11 -1
- package/package.json +9 -7
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ Accessibility matcher for [Jest](https://jestjs.io)
|
|
|
19
19
|
- [JSON result transformation](#json-result-transformation)
|
|
20
20
|
- [Limitations](#limitations)
|
|
21
21
|
- [Disabled Checks](#disabled-checks)
|
|
22
|
+
- [Jest toMatchSnapshot() API Wrapper](#jest-tomatchsnapshot-api-wrapper)
|
|
22
23
|
|
|
23
24
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
24
25
|
|
|
@@ -278,3 +279,7 @@ Automatic checks currently has the following limitations.
|
|
|
278
279
|
### Disabled Checks
|
|
279
280
|
|
|
280
281
|
- @sa11y/jest automatic checks also disabled rules which were disabled in `toBeAccessible` Jest API ([disabled-checks](https://github.com/salesforce/sa11y/tree/master/packages/jest#disabled-checks))
|
|
282
|
+
|
|
283
|
+
### Jest toMatchSnapshot() API Wrapper
|
|
284
|
+
|
|
285
|
+
- When Snapshot testing is done, jest's `toMatchSnapshot()` API is altering the document.body element attributes as needed to generate snapshots thereby the a11y checks which happen later on `document.body` isn't running on actual elements. To solve this, a wrapper has been introduced to restore the document.body DOM before jest's `toMatchSnapshot` is invoked and use the restored version of document.body for a11y checks.
|
package/dist/automatic.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export type AutoCheckOpts = {
|
|
|
7
7
|
consolidateResults?: boolean;
|
|
8
8
|
filesFilter?: string[];
|
|
9
9
|
};
|
|
10
|
+
export declare const setOriginalDocumentBodyHtml: (bodyHtml: string | null) => void;
|
|
10
11
|
/**
|
|
11
12
|
* Check if current test file needs to be skipped based on any provided filter
|
|
12
13
|
*/
|
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;CAC1B,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;;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,CAoC9F;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAE,aAAoC,GAAG,IAAI,CAM7F"}
|
package/dist/automatic.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.registerSa11yAutomaticChecks = exports.automaticCheck = exports.skipTest = void 0;
|
|
9
|
+
exports.registerSa11yAutomaticChecks = exports.automaticCheck = exports.skipTest = exports.setOriginalDocumentBodyHtml = void 0;
|
|
10
10
|
const common_1 = require("@sa11y/common");
|
|
11
11
|
const assert_1 = require("@sa11y/assert");
|
|
12
12
|
const format_1 = require("@sa11y/format");
|
|
@@ -23,6 +23,11 @@ const defaultAutoCheckOpts = {
|
|
|
23
23
|
consolidateResults: true,
|
|
24
24
|
filesFilter: [],
|
|
25
25
|
};
|
|
26
|
+
let originalDocumentBodyHtml = null;
|
|
27
|
+
const setOriginalDocumentBodyHtml = (bodyHtml) => {
|
|
28
|
+
originalDocumentBodyHtml = bodyHtml ?? null;
|
|
29
|
+
};
|
|
30
|
+
exports.setOriginalDocumentBodyHtml = setOriginalDocumentBodyHtml;
|
|
26
31
|
/**
|
|
27
32
|
* Check if current test file needs to be skipped based on any provided filter
|
|
28
33
|
*/
|
|
@@ -49,6 +54,9 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
49
54
|
return;
|
|
50
55
|
}
|
|
51
56
|
const violations = [];
|
|
57
|
+
if (originalDocumentBodyHtml) {
|
|
58
|
+
document.body.innerHTML = originalDocumentBodyHtml;
|
|
59
|
+
}
|
|
52
60
|
// Create a DOM walker filtering only elements (skipping text, comment nodes etc)
|
|
53
61
|
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
|
|
54
62
|
let currNode = walker.firstChild();
|
|
@@ -66,6 +74,7 @@ async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
|
66
74
|
}
|
|
67
75
|
}
|
|
68
76
|
finally {
|
|
77
|
+
(0, exports.setOriginalDocumentBodyHtml)(null);
|
|
69
78
|
if (opts.cleanupAfterEach)
|
|
70
79
|
document.body.innerHTML = ''; // remove non-element nodes
|
|
71
80
|
// TODO (spike): Disable stack trace for automatic checks.
|
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,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,aAAa,EAA6D,MAAM,aAAa,CAAC;AASvG,eAAO,MAAM,aAAa,UAiBzB,CAAC;AAWF;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACpB,aAAa,EAAE,aAAa,CAAC;CAKhC,CAAC;AAaF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,SAA4B,GAAG,IAAI,CAW9D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAW3C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,WAAgB,GAAG,UAAU,CAK3F"}
|
package/dist/setup.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.adaptA11yConfig = exports.registerSa11yMatcher = exports.setup = exports
|
|
|
10
10
|
const matcher_1 = require("./matcher");
|
|
11
11
|
const automatic_1 = require("./automatic");
|
|
12
12
|
const globals_1 = require("@jest/globals");
|
|
13
|
+
const jest_snapshot_1 = require("jest-snapshot");
|
|
13
14
|
exports.disabledRules = [
|
|
14
15
|
// Descendancy checks that would fail at unit/component level, but pass at page level
|
|
15
16
|
'aria-required-children',
|
|
@@ -28,6 +29,14 @@ exports.disabledRules = [
|
|
|
28
29
|
'audio-caption',
|
|
29
30
|
'video-caption',
|
|
30
31
|
];
|
|
32
|
+
function wrapperSnapshotMatcher(originalMatcher) {
|
|
33
|
+
return function (...args) {
|
|
34
|
+
(0, automatic_1.setOriginalDocumentBodyHtml)(document?.body?.innerHTML ?? '');
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
return originalMatcher.call(globals_1.expect.getState(), ...args);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
31
40
|
/**
|
|
32
41
|
* Default options for sa11y jest matcher
|
|
33
42
|
*/
|
|
@@ -59,8 +68,9 @@ exports.setup = setup;
|
|
|
59
68
|
* Register accessibility helpers toBeAccessible as jest matchers
|
|
60
69
|
*/
|
|
61
70
|
function registerSa11yMatcher() {
|
|
71
|
+
const wrapper = wrapperSnapshotMatcher(jest_snapshot_1.toMatchSnapshot);
|
|
62
72
|
if (globals_1.expect !== undefined) {
|
|
63
|
-
globals_1.expect.extend({ toBeAccessible: matcher_1.toBeAccessible });
|
|
73
|
+
globals_1.expect.extend({ toBeAccessible: matcher_1.toBeAccessible, toMatchSnapshot: wrapper });
|
|
64
74
|
}
|
|
65
75
|
else {
|
|
66
76
|
throw new Error("Unable to find Jest's expect function." +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sa11y/jest",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.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": "5.
|
|
28
|
-
"@sa11y/format": "5.
|
|
29
|
-
"@sa11y/preset-rules": "5.
|
|
27
|
+
"@sa11y/assert": "5.2.0",
|
|
28
|
+
"@sa11y/format": "5.2.0",
|
|
29
|
+
"@sa11y/preset-rules": "5.2.0",
|
|
30
30
|
"jest-matcher-utils": "^27"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -34,8 +34,10 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@jest/globals": "28.1.3",
|
|
37
|
-
"@sa11y/common": "5.
|
|
38
|
-
"@sa11y/test-utils": "5.
|
|
37
|
+
"@sa11y/common": "5.2.0",
|
|
38
|
+
"@sa11y/test-utils": "5.2.0",
|
|
39
|
+
"expect": "28.1.3",
|
|
40
|
+
"jest-snapshot": "28.1.3"
|
|
39
41
|
},
|
|
40
42
|
"publishConfig": {
|
|
41
43
|
"access": "public"
|
|
@@ -43,5 +45,5 @@
|
|
|
43
45
|
"engines": {
|
|
44
46
|
"node": "^16 || ^18"
|
|
45
47
|
},
|
|
46
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "440bbb4f9d9fc3e2263e75af8e2235008eafe789"
|
|
47
49
|
}
|