testaro 34.1.2 → 35.0.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 -2
- package/package.json +1 -1
- package/tests/ed11y.js +32 -27
package/README.md
CHANGED
|
@@ -424,8 +424,6 @@ When you include a `rules` property, you limit the tests of the tool that are pe
|
|
|
424
424
|
|
|
425
425
|
The `nuVal`, `qualWeb`, and `testaro` tools require specific formats for the `rules` property. Those formats are described below in the sections about those tools.
|
|
426
426
|
|
|
427
|
-
The `ed11y` tool does not yet allow rule specification.
|
|
428
|
-
|
|
429
427
|
###### Examples
|
|
430
428
|
|
|
431
429
|
An example of a `test` act is:
|
package/package.json
CHANGED
package/tests/ed11y.js
CHANGED
|
@@ -35,13 +35,13 @@ const fs = require('fs/promises');
|
|
|
35
35
|
// Conducts and reports the Editoria11y tests.
|
|
36
36
|
exports.reporter = async (page, options) => {
|
|
37
37
|
// Get the nonce, if any.
|
|
38
|
-
const {report} = options;
|
|
38
|
+
const {act, report} = options;
|
|
39
39
|
const {jobData} = report;
|
|
40
40
|
const scriptNonce = jobData && jobData.lastScriptNonce;
|
|
41
41
|
// Get the test script.
|
|
42
42
|
const script = await fs.readFile(`${__dirname}/../ed11y/editoria11y.min.js`, 'utf8');
|
|
43
43
|
const rawResultJSON = await page.evaluate(args => new Promise(async resolve => {
|
|
44
|
-
const {scriptNonce, script} = args;
|
|
44
|
+
const {scriptNonce, script, rulesToTest} = args;
|
|
45
45
|
// When the script is executed:
|
|
46
46
|
document.addEventListener('ed11yResults', () => {
|
|
47
47
|
// Get the result.
|
|
@@ -74,34 +74,39 @@ exports.reporter = async (page, options) => {
|
|
|
74
74
|
delete resultObj.options.lightTheme;
|
|
75
75
|
// Initialize the element results.
|
|
76
76
|
const results = resultObj.results = [];
|
|
77
|
-
//
|
|
77
|
+
// For each rule violation:
|
|
78
78
|
Ed11y.results.forEach(elResult => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
result
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
result.tagName = element.tagName || '';
|
|
87
|
-
result.id = element.id || '';
|
|
88
|
-
result.loc = {};
|
|
89
|
-
const locRect = element.getBoundingClientRect();
|
|
90
|
-
if (locRect) {
|
|
91
|
-
['x', 'y', 'width', 'height'].forEach(dim => {
|
|
92
|
-
result.loc[dim] = Math.round(locRect[dim]);
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
let elText = element.textContent.replace(/\s+/g, ' ').trim();
|
|
96
|
-
if (! elText) {
|
|
97
|
-
elText = element.outerHTML;
|
|
79
|
+
// If rules were not selected or they were and include this one:
|
|
80
|
+
if (! rulesToTest || rulesToTest.includes(elResult.test)) {
|
|
81
|
+
// Create a violation record.
|
|
82
|
+
const result = {};
|
|
83
|
+
result.test = elResult.test || '';
|
|
84
|
+
if (elResult.content) {
|
|
85
|
+
result.content = elResult.content.replace(/\s+/g, ' ');
|
|
98
86
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
87
|
+
if (elResult.element) {
|
|
88
|
+
const{element} = elResult;
|
|
89
|
+
result.tagName = element.tagName || '';
|
|
90
|
+
result.id = element.id || '';
|
|
91
|
+
result.loc = {};
|
|
92
|
+
const locRect = element.getBoundingClientRect();
|
|
93
|
+
if (locRect) {
|
|
94
|
+
['x', 'y', 'width', 'height'].forEach(dim => {
|
|
95
|
+
result.loc[dim] = Math.round(locRect[dim]);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
let elText = element.textContent.replace(/\s+/g, ' ').trim();
|
|
99
|
+
if (! elText) {
|
|
100
|
+
elText = element.outerHTML;
|
|
101
|
+
}
|
|
102
|
+
if (elText.length > 400) {
|
|
103
|
+
elText = `${elText.slice(0, 200)}…${elText.slice(-200)}`;
|
|
104
|
+
}
|
|
105
|
+
result.excerpt = elText.replace(/\s+/g, ' ');
|
|
101
106
|
}
|
|
102
|
-
|
|
107
|
+
// Add it to the result.
|
|
108
|
+
results.push(result);
|
|
103
109
|
}
|
|
104
|
-
results.push(result);
|
|
105
110
|
});
|
|
106
111
|
// Return the result.
|
|
107
112
|
try {
|
|
@@ -131,7 +136,7 @@ exports.reporter = async (page, options) => {
|
|
|
131
136
|
console.log(`ERROR creating Ed11y (${error.message})`);
|
|
132
137
|
resolve(JSON.stringify({error: error.message}));
|
|
133
138
|
};
|
|
134
|
-
}), {scriptNonce, script});
|
|
139
|
+
}), {scriptNonce, script, rulesToTest: act.rules});
|
|
135
140
|
const result = JSON.parse(rawResultJSON);
|
|
136
141
|
let data = {};
|
|
137
142
|
// Return the act report.
|