@sa11y/jest 5.3.2 → 6.1.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 +0 -5
- package/dist/automatic.d.ts +1 -0
- package/dist/automatic.d.ts.map +1 -1
- package/dist/automatic.js +8 -2
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +16 -11
- package/package.json +7 -9
package/README.md
CHANGED
|
@@ -19,7 +19,6 @@ 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)
|
|
23
22
|
|
|
24
23
|
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
25
24
|
|
|
@@ -279,7 +278,3 @@ Automatic checks currently has the following limitations.
|
|
|
279
278
|
### Disabled Checks
|
|
280
279
|
|
|
281
280
|
- @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
|
@@ -8,6 +8,7 @@ export type AutoCheckOpts = {
|
|
|
8
8
|
filesFilter?: string[];
|
|
9
9
|
};
|
|
10
10
|
export declare const setOriginalDocumentBodyHtml: (bodyHtml: string | null) => void;
|
|
11
|
+
export declare const getOriginalDocumentBodyHtml: () => string | null;
|
|
11
12
|
/**
|
|
12
13
|
* Check if current test file needs to be skipped based on any provided filter
|
|
13
14
|
*/
|
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;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,
|
|
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,CAoC9F;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAE,aAAoC,GAAG,IAAI,CAQ7F"}
|
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 = exports.setOriginalDocumentBodyHtml = void 0;
|
|
9
|
+
exports.registerSa11yAutomaticChecks = exports.automaticCheck = exports.skipTest = exports.getOriginalDocumentBodyHtml = 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");
|
|
@@ -28,6 +28,10 @@ const setOriginalDocumentBodyHtml = (bodyHtml) => {
|
|
|
28
28
|
originalDocumentBodyHtml = bodyHtml ?? null;
|
|
29
29
|
};
|
|
30
30
|
exports.setOriginalDocumentBodyHtml = setOriginalDocumentBodyHtml;
|
|
31
|
+
const getOriginalDocumentBodyHtml = () => {
|
|
32
|
+
return originalDocumentBodyHtml;
|
|
33
|
+
};
|
|
34
|
+
exports.getOriginalDocumentBodyHtml = getOriginalDocumentBodyHtml;
|
|
31
35
|
/**
|
|
32
36
|
* Check if current test file needs to be skipped based on any provided filter
|
|
33
37
|
*/
|
|
@@ -92,7 +96,9 @@ function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
|
|
|
92
96
|
if (opts.runAfterEach) {
|
|
93
97
|
// TODO (fix): Make registration idempotent
|
|
94
98
|
(0, common_1.log)('Registering sa11y checks to be run automatically after each test');
|
|
95
|
-
afterEach(async () =>
|
|
99
|
+
afterEach(async () => {
|
|
100
|
+
await automaticCheck(opts);
|
|
101
|
+
});
|
|
96
102
|
}
|
|
97
103
|
}
|
|
98
104
|
exports.registerSa11yAutomaticChecks = registerSa11yAutomaticChecks;
|
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,
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../src/setup.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,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;AA8BF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,GAAE,SAA4B,GAAG,IAAI,CAY9D;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAU3C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,WAAgB,GAAG,UAAU,CAK3F"}
|
package/dist/setup.js
CHANGED
|
@@ -10,7 +10,6 @@ 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");
|
|
14
13
|
exports.disabledRules = [
|
|
15
14
|
// Descendancy checks that would fail at unit/component level, but pass at page level
|
|
16
15
|
'aria-required-children',
|
|
@@ -29,14 +28,6 @@ exports.disabledRules = [
|
|
|
29
28
|
'audio-caption',
|
|
30
29
|
'video-caption',
|
|
31
30
|
];
|
|
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
|
-
}
|
|
40
31
|
/**
|
|
41
32
|
* Default options for sa11y jest matcher
|
|
42
33
|
*/
|
|
@@ -47,11 +38,26 @@ const defaultSa11yOpts = {
|
|
|
47
38
|
consolidateResults: false,
|
|
48
39
|
},
|
|
49
40
|
};
|
|
41
|
+
function registerRemoveChild() {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
43
|
+
const originalRemoveChild = Element.prototype.removeChild;
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
45
|
+
Element.prototype.removeChild = function (oldChild) {
|
|
46
|
+
if (oldChild.parentNode === this) {
|
|
47
|
+
// Your custom implementation here
|
|
48
|
+
if (!(0, automatic_1.getOriginalDocumentBodyHtml)()) {
|
|
49
|
+
(0, automatic_1.setOriginalDocumentBodyHtml)(document?.body?.innerHTML ?? '');
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return originalRemoveChild.call(this, oldChild);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
50
55
|
/**
|
|
51
56
|
* Register Sa11y Jest API and automatic checks depending on {@link Sa11yOpts}
|
|
52
57
|
* @param opts - {@link Sa11yOpts} to opt-in to automatic checks
|
|
53
58
|
*/
|
|
54
59
|
function setup(opts = defaultSa11yOpts) {
|
|
60
|
+
registerRemoveChild();
|
|
55
61
|
registerSa11yMatcher();
|
|
56
62
|
// Set defaults from env vars
|
|
57
63
|
const autoCheckOpts = opts.autoCheckOpts;
|
|
@@ -68,9 +74,8 @@ exports.setup = setup;
|
|
|
68
74
|
* Register accessibility helpers toBeAccessible as jest matchers
|
|
69
75
|
*/
|
|
70
76
|
function registerSa11yMatcher() {
|
|
71
|
-
const wrapper = wrapperSnapshotMatcher(jest_snapshot_1.toMatchSnapshot);
|
|
72
77
|
if (globals_1.expect !== undefined) {
|
|
73
|
-
globals_1.expect.extend({ toBeAccessible: matcher_1.toBeAccessible
|
|
78
|
+
globals_1.expect.extend({ toBeAccessible: matcher_1.toBeAccessible });
|
|
74
79
|
}
|
|
75
80
|
else {
|
|
76
81
|
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": "
|
|
3
|
+
"version": "6.1.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": "
|
|
28
|
-
"@sa11y/format": "
|
|
29
|
-
"@sa11y/preset-rules": "
|
|
27
|
+
"@sa11y/assert": "6.1.0",
|
|
28
|
+
"@sa11y/format": "6.1.0",
|
|
29
|
+
"@sa11y/preset-rules": "6.1.0",
|
|
30
30
|
"jest-matcher-utils": "^27"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
@@ -34,10 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@jest/globals": "28.1.3",
|
|
37
|
-
"@sa11y/common": "
|
|
38
|
-
"@sa11y/test-utils": "
|
|
39
|
-
"expect": "28.1.3",
|
|
40
|
-
"jest-snapshot": "28.1.3"
|
|
37
|
+
"@sa11y/common": "6.1.0",
|
|
38
|
+
"@sa11y/test-utils": "6.1.0"
|
|
41
39
|
},
|
|
42
40
|
"publishConfig": {
|
|
43
41
|
"access": "public"
|
|
@@ -45,5 +43,5 @@
|
|
|
45
43
|
"engines": {
|
|
46
44
|
"node": "^16 || ^18"
|
|
47
45
|
},
|
|
48
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "a19cfe75abfad15cdef9919ed753d1479e6af69b"
|
|
49
47
|
}
|