testaro 10.2.0 → 10.4.1
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/actSpecs.js +13 -1
- package/package.json +1 -1
- package/tests/htmlcs.js +15 -5
- package/tests/ibm.js +27 -8
package/actSpecs.js
CHANGED
|
@@ -229,13 +229,25 @@ exports.actSpecs = {
|
|
|
229
229
|
withItems: [true, 'boolean', '', 'itemize']
|
|
230
230
|
}
|
|
231
231
|
],
|
|
232
|
+
htmlcs: [
|
|
233
|
+
'Perform an htmlcs test',
|
|
234
|
+
{
|
|
235
|
+
rules: [
|
|
236
|
+
false,
|
|
237
|
+
'array',
|
|
238
|
+
'areStrings',
|
|
239
|
+
'rule names (e.g., Principle1.Guideline1_4.1_4_9), if not all'
|
|
240
|
+
]
|
|
241
|
+
}
|
|
242
|
+
],
|
|
232
243
|
ibm: [
|
|
233
244
|
'Perform an IBM Equal Access test',
|
|
234
245
|
{
|
|
235
246
|
withItems: [true, 'boolean', '', 'itemize'],
|
|
236
247
|
withNewContent: [
|
|
237
248
|
false, 'boolean', '', 'true: use a URL; false: use page content; omitted: both'
|
|
238
|
-
]
|
|
249
|
+
],
|
|
250
|
+
rules: [false, 'array', 'areStrings', 'rule names (e.g., RPT_Elem_UniqueId), if not all']
|
|
239
251
|
}
|
|
240
252
|
],
|
|
241
253
|
labClash: [
|
package/package.json
CHANGED
package/tests/htmlcs.js
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
// FUNCTIONS
|
|
7
7
|
// Runs HTML CodeSniffer on the page.
|
|
8
|
-
exports.reporter = async page => {
|
|
8
|
+
exports.reporter = async (page, rules) => {
|
|
9
9
|
const result = {};
|
|
10
|
+
// Add the HTMLCS script to the page.
|
|
10
11
|
await page.addScriptTag({
|
|
11
12
|
path: `${__dirname}/../htmlcs/HTMLCS.js`
|
|
12
13
|
})
|
|
@@ -17,17 +18,26 @@ exports.reporter = async page => {
|
|
|
17
18
|
});
|
|
18
19
|
if (! result.prevented) {
|
|
19
20
|
let messageStrings = [];
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
// Define the rules to be employed as those of WCAG 2 level AAA.
|
|
22
|
+
for (const standard of ['WCAG2AAA']) {
|
|
23
|
+
const nextIssues = await page.evaluate(args => {
|
|
24
|
+
const standard = args[0];
|
|
25
|
+
const rules = args[1];
|
|
26
|
+
// If only some rules are to be employed:
|
|
27
|
+
if (rules && Array.isArray(rules) && rules.length) {
|
|
28
|
+
// Redefine WCAG 2 AAA as including only them.
|
|
29
|
+
window.HTMLCS_WCAG2AAA.sniffs = rules;
|
|
30
|
+
}
|
|
31
|
+
// Run the tests.
|
|
22
32
|
let issues = null;
|
|
23
33
|
try {
|
|
24
|
-
issues = window
|
|
34
|
+
issues = window.HTMLCS_RUNNER.run(standard);
|
|
25
35
|
}
|
|
26
36
|
catch(error) {
|
|
27
37
|
console.log(`ERROR executing HTMLCS_RUNNER on ${document.URL} (${error.message})`);
|
|
28
38
|
}
|
|
29
39
|
return issues;
|
|
30
|
-
}, standard);
|
|
40
|
+
}, [standard, rules]);
|
|
31
41
|
if (nextIssues && nextIssues.every(issue => typeof issue === 'string')) {
|
|
32
42
|
messageStrings.push(... nextIssues);
|
|
33
43
|
}
|
package/tests/ibm.js
CHANGED
|
@@ -41,15 +41,34 @@ const run = async (content, timeLimit) => {
|
|
|
41
41
|
clearTimeout(timeoutID);
|
|
42
42
|
return result;
|
|
43
43
|
};
|
|
44
|
+
// Revises report totals for any rule limitation.
|
|
45
|
+
const limitRuleTotals = (report, rules) => {
|
|
46
|
+
if (rules && Array.isArray(rules) && rules.length) {
|
|
47
|
+
const totals = report.report.summary.counts;
|
|
48
|
+
const items = report.report.results;
|
|
49
|
+
totals.violation = totals.recommendation = 0;
|
|
50
|
+
items.forEach(item => {
|
|
51
|
+
if (rules.includes(item.ruleId)) {
|
|
52
|
+
totals[item.level]++;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
44
57
|
// Trims an IBM report.
|
|
45
|
-
const trimReport = (report, withItems) => {
|
|
58
|
+
const trimReport = (report, withItems, rules) => {
|
|
46
59
|
const data = {};
|
|
47
60
|
if (report && report.report && report.report.summary) {
|
|
61
|
+
limitRuleTotals(report, rules);
|
|
48
62
|
const totals = report.report.summary.counts;
|
|
49
63
|
if (totals) {
|
|
50
64
|
data.totals = totals;
|
|
51
65
|
if (withItems) {
|
|
52
|
-
|
|
66
|
+
if (rules && Array.isArray(rules) && rules.length) {
|
|
67
|
+
data.items = report.report.results.filter(item => rules.includes(item.ruleId));
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
data.items = report.report.results;
|
|
71
|
+
}
|
|
53
72
|
data.items.forEach(item => {
|
|
54
73
|
delete item.apiArgs;
|
|
55
74
|
delete item.category;
|
|
@@ -72,8 +91,8 @@ const trimReport = (report, withItems) => {
|
|
|
72
91
|
}
|
|
73
92
|
return data;
|
|
74
93
|
};
|
|
75
|
-
// Performs an IBM test and
|
|
76
|
-
const doTest = async (content, withItems, timeLimit) => {
|
|
94
|
+
// Performs an IBM test and returns the result.
|
|
95
|
+
const doTest = async (content, withItems, timeLimit, rules) => {
|
|
77
96
|
// Conduct the test and get the result.
|
|
78
97
|
const report = await run(content, timeLimit);
|
|
79
98
|
// If the test did not time out:
|
|
@@ -89,7 +108,7 @@ const doTest = async (content, withItems, timeLimit) => {
|
|
|
89
108
|
console.log('ibm test created no result files.');
|
|
90
109
|
}
|
|
91
110
|
// Return the result.
|
|
92
|
-
const typeReport = trimReport(report, withItems);
|
|
111
|
+
const typeReport = trimReport(report, withItems, rules);
|
|
93
112
|
return typeReport;
|
|
94
113
|
}
|
|
95
114
|
else {
|
|
@@ -100,13 +119,13 @@ const doTest = async (content, withItems, timeLimit) => {
|
|
|
100
119
|
}
|
|
101
120
|
};
|
|
102
121
|
// Returns results of one or two IBM tests.
|
|
103
|
-
exports.reporter = async (page, withItems, withNewContent) => {
|
|
122
|
+
exports.reporter = async (page, withItems, withNewContent, rules) => {
|
|
104
123
|
// If a test with existing content is to be performed:
|
|
105
124
|
const result = {};
|
|
106
125
|
if (! withNewContent) {
|
|
107
126
|
const timeLimit = 20;
|
|
108
127
|
const typeContent = await page.content();
|
|
109
|
-
result.content = await doTest(typeContent, withItems, timeLimit);
|
|
128
|
+
result.content = await doTest(typeContent, withItems, timeLimit, rules);
|
|
110
129
|
if (result.content.prevented) {
|
|
111
130
|
result.prevented = true;
|
|
112
131
|
console.log(`ERROR: Getting ibm test report from page timed out at ${timeLimit} seconds`);
|
|
@@ -116,7 +135,7 @@ exports.reporter = async (page, withItems, withNewContent) => {
|
|
|
116
135
|
if ([true, undefined].includes(withNewContent)) {
|
|
117
136
|
const timeLimit = 20;
|
|
118
137
|
const typeContent = page.url();
|
|
119
|
-
result.url = await doTest(typeContent, withItems, timeLimit);
|
|
138
|
+
result.url = await doTest(typeContent, withItems, timeLimit, rules);
|
|
120
139
|
if (result.url.prevented) {
|
|
121
140
|
result.prevented = true;
|
|
122
141
|
console.log(`ERROR: Getting ibm test report from URL timed out at ${timeLimit} seconds`);
|