@sa11y/jest 4.1.2 → 4.1.3
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.
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AggregatedResult } from '@jest/test-result';
|
|
2
|
+
/**
|
|
3
|
+
* Custom results processor for a11y results grouping the violations. Only affects JSON results file output.
|
|
4
|
+
* To be used with jest cli options --json --outputFile
|
|
5
|
+
* e.g. jest --json --outputFile jestResults.json --testResultsProcessor `node_modules/@sa11y/jest/dist/groupViolationResultsProcessor.js`
|
|
6
|
+
* Ref: https://jestjs.io/docs/configuration#testresultsprocessor-string
|
|
7
|
+
* - Mapping of AggregatedResult to JSON format to https://github.com/facebook/jest/blob/master/packages/jest-test-result/src/formatTestResults.ts
|
|
8
|
+
*/
|
|
9
|
+
export default function resultsProcessor(results: AggregatedResult): AggregatedResult;
|
|
10
|
+
//# sourceMappingURL=groupViolationResultsProcessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groupViolationResultsProcessor.d.ts","sourceRoot":"","sources":["../src/groupViolationResultsProcessor.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAA+B,MAAM,mBAAmB,CAAC;AAkHlF;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAapF"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const common_1 = require("@sa11y/common");
|
|
4
|
+
const format_1 = require("@sa11y/format");
|
|
5
|
+
/**
|
|
6
|
+
* Create a test failure html elements array grouped by rule violation
|
|
7
|
+
*/
|
|
8
|
+
function createA11yErrorElements(errorElements) {
|
|
9
|
+
const a11yErrorElements = [];
|
|
10
|
+
errorElements.forEach((errorElement, index) => {
|
|
11
|
+
a11yErrorElements.push(`- (${index + 1}) HTML element : ${errorElement.html.replace(/</g, '<').replace(/>/, '>')}
|
|
12
|
+
- CSS selector(s) : ${errorElement.selectors.replace(/>/, '>')}
|
|
13
|
+
- HTML Tag Hierarchy : ${errorElement.hierarchy}`);
|
|
14
|
+
});
|
|
15
|
+
return a11yErrorElements.join('\n');
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a test failure violation error message grouped by rule violation
|
|
19
|
+
*/
|
|
20
|
+
function createA11yRuleViolation(a11yRule, ruleIndex) {
|
|
21
|
+
return `(${ruleIndex}) [${a11yRule.id}] ${a11yRule.description}
|
|
22
|
+
* Help URL: ${a11yRule.helpUrl}
|
|
23
|
+
* More info: ${a11yRule.summary}
|
|
24
|
+
* Error element(s) : ${a11yRule.errorElements.length}
|
|
25
|
+
${createA11yErrorElements(a11yRule.errorElements)}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Convert any a11y errors from test failures into their own test suite, results
|
|
29
|
+
*/
|
|
30
|
+
function processA11yErrors(results, testSuite, testResult) {
|
|
31
|
+
const a11yFailureDetails = [];
|
|
32
|
+
const a11yFailureMessages = [];
|
|
33
|
+
let a11yErrorsExist = false;
|
|
34
|
+
testResult.failureDetails.forEach((failure) => {
|
|
35
|
+
let error = failure.error;
|
|
36
|
+
// If using circus test runner https://github.com/facebook/jest/issues/11405#issuecomment-843549606
|
|
37
|
+
// TODO (code cov): Add test data covering the case for circus test runner
|
|
38
|
+
/* istanbul ignore next */
|
|
39
|
+
if (error === undefined)
|
|
40
|
+
error = failure;
|
|
41
|
+
if (error.name === format_1.A11yError.name) {
|
|
42
|
+
a11yErrorsExist = true;
|
|
43
|
+
a11yFailureDetails.push({ ...failure });
|
|
44
|
+
const a11yRuleViolations = {};
|
|
45
|
+
let a11yRuleViolationsCount = 0;
|
|
46
|
+
let a11yErrorElementsCount = 0;
|
|
47
|
+
error.a11yResults.forEach((a11yResult) => {
|
|
48
|
+
a11yErrorElementsCount++;
|
|
49
|
+
if (!a11yRuleViolations[a11yResult.wcag]) {
|
|
50
|
+
a11yRuleViolationsCount++;
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
52
|
+
a11yRuleViolations[a11yResult.wcag] = {
|
|
53
|
+
id: a11yResult.id,
|
|
54
|
+
description: a11yResult.description,
|
|
55
|
+
helpUrl: a11yResult.helpUrl,
|
|
56
|
+
summary: a11yResult.summary,
|
|
57
|
+
errorElements: [],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
a11yRuleViolations[a11yResult.wcag].errorElements.push({
|
|
61
|
+
html: a11yResult.html,
|
|
62
|
+
selectors: a11yResult.selectors,
|
|
63
|
+
hierarchy: a11yResult.key,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
const a11yFailureMessage = `
|
|
67
|
+
The test has failed the accessibility check. Accessibility Stacktrace/Issues:
|
|
68
|
+
${a11yErrorElementsCount} HTML elements have accessibility issue(s). ${a11yRuleViolationsCount} rules failed.
|
|
69
|
+
|
|
70
|
+
${Object.values(a11yRuleViolations)
|
|
71
|
+
.map((a11yRuleViolation, index) => createA11yRuleViolation(a11yRuleViolation, index + 1))
|
|
72
|
+
.join('\n')}
|
|
73
|
+
For more info about automated accessibility testing: https://sfdc.co/a11y-test
|
|
74
|
+
For tips on fixing accessibility bugs: https://sfdc.co/a11y
|
|
75
|
+
Questions? Post on Accessibility Team Chatter: https://sfdc.co/a11y-gus
|
|
76
|
+
`;
|
|
77
|
+
a11yFailureMessages.push(a11yFailureMessage);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (!a11yErrorsExist) {
|
|
81
|
+
testSuite.numFailingTests -= 1;
|
|
82
|
+
results.numFailedTests -= 1;
|
|
83
|
+
if (testSuite.numFailingTests === 0)
|
|
84
|
+
results.numFailedTestSuites -= 1;
|
|
85
|
+
}
|
|
86
|
+
testResult.failureDetails = [...a11yFailureDetails];
|
|
87
|
+
testResult.failureMessages = [...a11yFailureMessages];
|
|
88
|
+
testResult.status = a11yFailureDetails.length === 0 ? 'passed' : testResult.status;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Custom results processor for a11y results grouping the violations. Only affects JSON results file output.
|
|
92
|
+
* To be used with jest cli options --json --outputFile
|
|
93
|
+
* e.g. jest --json --outputFile jestResults.json --testResultsProcessor `node_modules/@sa11y/jest/dist/groupViolationResultsProcessor.js`
|
|
94
|
+
* Ref: https://jestjs.io/docs/configuration#testresultsprocessor-string
|
|
95
|
+
* - Mapping of AggregatedResult to JSON format to https://github.com/facebook/jest/blob/master/packages/jest-test-result/src/formatTestResults.ts
|
|
96
|
+
*/
|
|
97
|
+
function resultsProcessor(results) {
|
|
98
|
+
(0, common_1.log)(`Processing ${results.numTotalTests} tests ..`);
|
|
99
|
+
results.testResults // suite results
|
|
100
|
+
.filter((testSuite) => testSuite.numFailingTests > 0)
|
|
101
|
+
.forEach((testSuite) => {
|
|
102
|
+
testSuite.testResults // individual test results
|
|
103
|
+
.filter((testResult) => testResult.status === 'failed')
|
|
104
|
+
.forEach((testResult) => {
|
|
105
|
+
processA11yErrors(results, testSuite, testResult);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
return results;
|
|
109
|
+
}
|
|
110
|
+
exports.default = resultsProcessor;
|
|
111
|
+
// The processor must be a node module that exports a function
|
|
112
|
+
module.exports = resultsProcessor;
|
|
113
|
+
//# sourceMappingURL=groupViolationResultsProcessor.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sa11y/jest",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3",
|
|
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": "4.1.
|
|
28
|
-
"@sa11y/format": "4.1.
|
|
29
|
-
"@sa11y/preset-rules": "4.1.
|
|
27
|
+
"@sa11y/assert": "4.1.3",
|
|
28
|
+
"@sa11y/format": "4.1.3",
|
|
29
|
+
"@sa11y/preset-rules": "4.1.3",
|
|
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": "4.1.
|
|
38
|
-
"@sa11y/test-utils": "4.1.
|
|
37
|
+
"@sa11y/common": "4.1.3",
|
|
38
|
+
"@sa11y/test-utils": "4.1.3"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"engines": {
|
|
44
44
|
"node": "^14 || ^16"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "0dd89aeb585291616b64ccd8026f2f18f84c8b4b"
|
|
47
47
|
}
|