@sa11y/jest 3.0.2 → 4.0.0-alpha.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 +1 -5
- package/dist/automatic.d.ts +4 -0
- package/dist/automatic.d.ts.map +1 -1
- package/dist/automatic.js +18 -17
- package/dist/resultsProcessor.js +1 -2
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +4 -4
- package/package.json +11 -10
package/README.md
CHANGED
|
@@ -180,11 +180,7 @@ SA11Y_AUTO=1 SA11Y_CLEANUP=1 jest
|
|
|
180
180
|
- Invoking `jest` with environment variables as above will enable automatic checks with no changes required to `setup()`
|
|
181
181
|
- The environment variables can be used to set up parallel builds e.g., in a CI environment without code changes to `setup()` to opt-in to automatic checks
|
|
182
182
|
- Setting `SA11Y_DEBUG=1` will output verbose logging
|
|
183
|
-
- `SA11Y_AUTO_FILTER` can be used to specify a comma seperated list of test file paths to filter
|
|
184
|
-
- When specified, automatic checks will be run only on given files
|
|
185
|
-
- A file can be excluded from automatic checks by prefixing the filename with `!`
|
|
186
|
-
- e.g. `SA11Y_AUTO_FILTER='!exclude.test.js'`
|
|
187
|
-
- The file paths can be also be expressed as [regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet) if necessary
|
|
183
|
+
- `SA11Y_AUTO_FILTER` can be used to specify a comma seperated list of test file paths to filter out from automatic checks. When specified automatic checks are skipped for given files.
|
|
188
184
|
|
|
189
185
|
### Sa11y results processor
|
|
190
186
|
|
package/dist/automatic.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export declare type AutoCheckOpts = {
|
|
|
7
7
|
consolidateResults?: boolean;
|
|
8
8
|
filesFilter?: string[];
|
|
9
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Check if current test file needs to be skipped based on any provided filter
|
|
12
|
+
*/
|
|
13
|
+
export declare function skipTest(testPath: string | undefined, filesFilter?: string[]): boolean;
|
|
10
14
|
/**
|
|
11
15
|
* Run accessibility check on each element node in the body using {@link toBeAccessible}
|
|
12
16
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
package/dist/automatic.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automatic.d.ts","sourceRoot":"","sources":["../src/automatic.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"automatic.d.ts","sourceRoot":"","sources":["../src/automatic.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,oBAAY,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;AAYF;;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,CA+B9F;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,GAAE,aAAoC,GAAG,IAAI,CAM7F"}
|
package/dist/automatic.js
CHANGED
|
@@ -6,11 +6,12 @@
|
|
|
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 = void 0;
|
|
9
|
+
exports.registerSa11yAutomaticChecks = exports.automaticCheck = exports.skipTest = 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");
|
|
13
13
|
const matcher_1 = require("./matcher");
|
|
14
|
+
const globals_1 = require("@jest/globals");
|
|
14
15
|
/**
|
|
15
16
|
* Default options when {@link registerSa11yAutomaticChecks} is invoked
|
|
16
17
|
*/
|
|
@@ -20,30 +21,32 @@ const defaultAutoCheckOpts = {
|
|
|
20
21
|
consolidateResults: true,
|
|
21
22
|
filesFilter: [],
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Check if current test file needs to be skipped based on any provided filter
|
|
26
|
+
*/
|
|
27
|
+
function skipTest(testPath, filesFilter) {
|
|
28
|
+
if (!testPath || !filesFilter || !(filesFilter?.length > 0))
|
|
29
|
+
return false;
|
|
30
|
+
const skipTest = filesFilter.some((fileName) => testPath.toLowerCase().includes(fileName.toLowerCase()));
|
|
31
|
+
if (skipTest) {
|
|
32
|
+
(0, common_1.log)(`Skipping automatic accessibility check on ${testPath} as it matches given files filter: ${filesFilter.toString()}`);
|
|
33
|
+
}
|
|
34
|
+
return skipTest;
|
|
35
|
+
}
|
|
36
|
+
exports.skipTest = skipTest;
|
|
23
37
|
/**
|
|
24
38
|
* Run accessibility check on each element node in the body using {@link toBeAccessible}
|
|
25
39
|
* @param opts - Options for automatic checks {@link AutoCheckOpts}
|
|
26
40
|
*/
|
|
27
41
|
async function automaticCheck(opts = defaultAutoCheckOpts) {
|
|
28
|
-
|
|
29
|
-
const violations = [];
|
|
30
|
-
const testPath = expect.getState().testPath;
|
|
31
|
-
// If option to run only on selected files is specified, then current path should
|
|
32
|
-
// match against at least one file
|
|
33
|
-
if (((_a = opts.filesFilter) === null || _a === void 0 ? void 0 : _a.length) &&
|
|
34
|
-
!opts.filesFilter
|
|
35
|
-
// Convenience shortcut converting '!' prefix to filename
|
|
36
|
-
// as negative lookahead assertion regex
|
|
37
|
-
.map((filename) => (filename.startsWith('!') ? `/(?!${filename})$` : filename))
|
|
38
|
-
.some((fileName) => RegExp(fileName).test(testPath))) {
|
|
39
|
-
(0, common_1.log)(`Skipping automatic accessibility check on ${testPath} as it does not match selected files provided: ${opts.filesFilter.toString()}`);
|
|
42
|
+
if (skipTest(globals_1.expect.getState().testPath, opts.filesFilter))
|
|
40
43
|
return;
|
|
41
|
-
}
|
|
42
44
|
// Skip automatic check if test is using fake timer as it would result in timeout
|
|
43
45
|
if ((0, matcher_1.isTestUsingFakeTimer)()) {
|
|
44
46
|
(0, common_1.log)('Skipping automatic accessibility check as Jest fake timer is in use.');
|
|
45
47
|
return;
|
|
46
48
|
}
|
|
49
|
+
const violations = [];
|
|
47
50
|
// Create a DOM walker filtering only elements (skipping text, comment nodes etc)
|
|
48
51
|
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT);
|
|
49
52
|
let currNode = walker.firstChild();
|
|
@@ -77,9 +80,7 @@ function registerSa11yAutomaticChecks(opts = defaultAutoCheckOpts) {
|
|
|
77
80
|
if (opts.runAfterEach) {
|
|
78
81
|
// TODO (fix): Make registration idempotent
|
|
79
82
|
(0, common_1.log)('Registering sa11y checks to be run automatically after each test');
|
|
80
|
-
afterEach(
|
|
81
|
-
await automaticCheck(opts);
|
|
82
|
-
});
|
|
83
|
+
afterEach(() => automaticCheck(opts));
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
exports.registerSa11yAutomaticChecks = registerSa11yAutomaticChecks;
|
package/dist/resultsProcessor.js
CHANGED
|
@@ -54,13 +54,12 @@ function processA11yErrors(testSuite, testResult) {
|
|
|
54
54
|
// TODO (spike) : What happens if there are ever multiple failureDetails?
|
|
55
55
|
// Ideally there shouldn't be as test execution should be stopped on failure
|
|
56
56
|
format_1.A11yResults.add(error.a11yResults, suiteName).forEach((a11yResult) => {
|
|
57
|
-
var _a;
|
|
58
57
|
const className = `${suiteName}${metadataSeparator}${a11yResult.wcag}`;
|
|
59
58
|
// TODO (code cov): Fix - should be covered by existing tests
|
|
60
59
|
/* istanbul ignore next */
|
|
61
60
|
if (!Array.isArray(consolidatedErrors.get(className)))
|
|
62
61
|
consolidatedErrors.set(className, []);
|
|
63
|
-
|
|
62
|
+
consolidatedErrors.get(className)?.push(createA11yTestResult(testResult, a11yResult));
|
|
64
63
|
});
|
|
65
64
|
}
|
|
66
65
|
});
|
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,EAAgC,MAAM,aAAa,CAAC;
|
|
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,EAAgC,MAAM,aAAa,CAAC;AAG1E,eAAO,MAAM,aAAa,UAiBzB,CAAC;AAEF;;GAEG;AACH,oBAAY,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,CAU3C;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,WAAW,WAAgB,GAAG,UAAU,CAK3F"}
|
package/dist/setup.js
CHANGED
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.adaptA11yConfig = exports.registerSa11yMatcher = exports.setup = exports.disabledRules = void 0;
|
|
10
10
|
const matcher_1 = require("./matcher");
|
|
11
11
|
const automatic_1 = require("./automatic");
|
|
12
|
+
const globals_1 = require("@jest/globals");
|
|
12
13
|
exports.disabledRules = [
|
|
13
14
|
// Descendancy checks that would fail at unit/component level, but pass at page level
|
|
14
15
|
'aria-required-children',
|
|
@@ -42,7 +43,6 @@ const defaultSa11yOpts = {
|
|
|
42
43
|
* @param opts - {@link Sa11yOpts} to opt-in to automatic checks
|
|
43
44
|
*/
|
|
44
45
|
function setup(opts = defaultSa11yOpts) {
|
|
45
|
-
var _a;
|
|
46
46
|
registerSa11yMatcher();
|
|
47
47
|
// Set defaults from env vars
|
|
48
48
|
const autoCheckOpts = opts.autoCheckOpts;
|
|
@@ -50,7 +50,7 @@ function setup(opts = defaultSa11yOpts) {
|
|
|
50
50
|
// Consolidate results if automatic checks is enabled
|
|
51
51
|
autoCheckOpts.consolidateResults || (autoCheckOpts.consolidateResults = autoCheckOpts.runAfterEach);
|
|
52
52
|
autoCheckOpts.cleanupAfterEach || (autoCheckOpts.cleanupAfterEach = !!process.env.SA11Y_CLEANUP);
|
|
53
|
-
if (
|
|
53
|
+
if (process.env.SA11Y_AUTO_FILTER?.trim().length)
|
|
54
54
|
autoCheckOpts.filesFilter || (autoCheckOpts.filesFilter = process.env.SA11Y_AUTO_FILTER.split(','));
|
|
55
55
|
(0, automatic_1.registerSa11yAutomaticChecks)(autoCheckOpts);
|
|
56
56
|
}
|
|
@@ -59,8 +59,8 @@ exports.setup = setup;
|
|
|
59
59
|
* Register accessibility helpers toBeAccessible as jest matchers
|
|
60
60
|
*/
|
|
61
61
|
function registerSa11yMatcher() {
|
|
62
|
-
if (expect !== undefined) {
|
|
63
|
-
expect.extend({ toBeAccessible: matcher_1.toBeAccessible });
|
|
62
|
+
if (globals_1.expect !== undefined) {
|
|
63
|
+
globals_1.expect.extend({ toBeAccessible: matcher_1.toBeAccessible });
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
66
|
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": "4.0.0-alpha.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",
|
|
@@ -23,21 +23,22 @@
|
|
|
23
23
|
"dist/**/*.d.ts*"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@jest/test-result": "
|
|
27
|
-
"@sa11y/assert": "
|
|
28
|
-
"@sa11y/format": "
|
|
29
|
-
"@sa11y/preset-rules": "
|
|
30
|
-
"jest-matcher-utils": "
|
|
26
|
+
"@jest/test-result": "^27",
|
|
27
|
+
"@sa11y/assert": "4.0.0-alpha.0",
|
|
28
|
+
"@sa11y/format": "4.0.0-alpha.0",
|
|
29
|
+
"@sa11y/preset-rules": "4.0.0-alpha.0",
|
|
30
|
+
"jest-matcher-utils": "^27"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"jest": ">=
|
|
33
|
+
"jest": ">=27.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@
|
|
37
|
-
"@sa11y/
|
|
36
|
+
"@jest/globals": "28.1.3",
|
|
37
|
+
"@sa11y/common": "4.0.0-alpha.0",
|
|
38
|
+
"@sa11y/test-utils": "4.0.0-alpha.0"
|
|
38
39
|
},
|
|
39
40
|
"publishConfig": {
|
|
40
41
|
"access": "public"
|
|
41
42
|
},
|
|
42
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "aeb87b6b27bfd56cf9f3de201456dd821e57b408"
|
|
43
44
|
}
|