testaro 64.8.1 → 64.8.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.
- package/package.json +1 -1
- package/procs/standardize.js +26 -12
- package/tests/wave.js +23 -20
- package/procs/wavedoc.json +0 -1617
package/package.json
CHANGED
package/procs/standardize.js
CHANGED
|
@@ -321,29 +321,42 @@ const doQualWeb = (result, standardResult, ruleClassName) => {
|
|
|
321
321
|
};
|
|
322
322
|
// Converts instances of a wave rule category.
|
|
323
323
|
const doWAVE = (result, standardResult, categoryName) => {
|
|
324
|
+
// If results for the category are reported:
|
|
324
325
|
if (result.categories && result.categories[categoryName]) {
|
|
325
326
|
const category = result.categories[categoryName];
|
|
326
327
|
const ordinalSeverity = categoryName === 'alert' ? 0 : 3;
|
|
327
328
|
const {items} = category;
|
|
329
|
+
// If any violations in the category are reported:
|
|
328
330
|
if (items) {
|
|
331
|
+
// For each rule violated:
|
|
329
332
|
Object.keys(items).forEach(ruleID => {
|
|
330
|
-
items[ruleID]
|
|
333
|
+
const item = items[ruleID];
|
|
334
|
+
// For each violation:
|
|
335
|
+
item.selectors.forEach(violationFacts => {
|
|
331
336
|
let tagName = '';
|
|
332
337
|
let id = '';
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
338
|
+
const finalTerm = violationFacts[0].replace(/^.+\s/, '');
|
|
339
|
+
// If the selector is an element ID:
|
|
340
|
+
if (finalTerm.includes('#')) {
|
|
341
|
+
const finalArray = finalTerm.split('#');
|
|
342
|
+
// Use it to get the element tagname and ID
|
|
343
|
+
tagName = finalArray[0].replace(/:.*/, '');
|
|
344
|
+
id = isBadID(finalArray[1]) ? '' : finalArray[1];
|
|
345
|
+
}
|
|
346
|
+
// Otherwise, i.e. if the selector is not an element ID:
|
|
347
|
+
else {
|
|
348
|
+
// Get the element tagname from it.
|
|
349
|
+
tagName = finalTerm.replace(/:.*/, '');
|
|
343
350
|
}
|
|
351
|
+
const {wcag} = item;
|
|
352
|
+
// Get a violation description suffix from the WCAG data of the rule.
|
|
353
|
+
const wcagSuffix = wcag.length
|
|
354
|
+
? ` (${wcag.map(wcagItem => wcagItem.name).join('; ')})`
|
|
355
|
+
: '';
|
|
356
|
+
// Get a standard instance.
|
|
344
357
|
const instance = {
|
|
345
358
|
ruleID,
|
|
346
|
-
what:
|
|
359
|
+
what: `${item.description}${wcagSuffix}`,
|
|
347
360
|
ordinalSeverity,
|
|
348
361
|
tagName,
|
|
349
362
|
id,
|
|
@@ -354,6 +367,7 @@ const doWAVE = (result, standardResult, categoryName) => {
|
|
|
354
367
|
},
|
|
355
368
|
excerpt: violationFacts[1]
|
|
356
369
|
};
|
|
370
|
+
// Add it to the standard result.
|
|
357
371
|
standardResult.instances.push(instance);
|
|
358
372
|
});
|
|
359
373
|
});
|
package/tests/wave.js
CHANGED
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
|
|
16
16
|
// CONSTANTS
|
|
17
17
|
|
|
18
|
-
const fs = require('fs/promises');
|
|
19
18
|
const https = require('https');
|
|
20
19
|
|
|
21
20
|
// FUNCTIONS
|
|
@@ -93,9 +92,9 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
93
92
|
}
|
|
94
93
|
});
|
|
95
94
|
}
|
|
96
|
-
//
|
|
97
|
-
const
|
|
98
|
-
const waveDoc =
|
|
95
|
+
// Get the WAVE WCAG documentation.
|
|
96
|
+
const waveDocResponse = await fetch('https://wave.webaim.org/api/docs');
|
|
97
|
+
const waveDoc = waveDocResponse.ok ? await waveDocResponse.json() : [];
|
|
99
98
|
// For each rule category:
|
|
100
99
|
for (const categoryName of Object.keys(categories)) {
|
|
101
100
|
const category = categories[categoryName];
|
|
@@ -112,24 +111,28 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
112
111
|
const {guidelines} = ruleDoc;
|
|
113
112
|
const rule = items[ruleName];
|
|
114
113
|
// Add WCAG information to the rule data.
|
|
115
|
-
rule.wcag = guidelines;
|
|
114
|
+
rule.wcag = guidelines || [];
|
|
116
115
|
// For each violation:
|
|
117
116
|
for (const index in rule.selectors) {
|
|
118
|
-
const selector = rule.selectors[index];
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
117
|
+
const selector = rule.selectors[index] || '';
|
|
118
|
+
let excerpt = '';
|
|
119
|
+
// If a selector is provided:
|
|
120
|
+
if (selector) {
|
|
121
|
+
// Get an excerpt of the element.
|
|
122
|
+
excerpt = await page.evaluate(selector => {
|
|
123
|
+
const element = document.querySelector(selector);
|
|
124
|
+
// If the selector matches an element:
|
|
125
|
+
if (element) {
|
|
126
|
+
// Get an excerpt of the element.
|
|
127
|
+
const rawExcerpt = element.textContent.trim() || element.outerHTML.trim();
|
|
128
|
+
const normalizedExcerpt = rawExcerpt.replace(/\s+/g, ' ');
|
|
129
|
+
return normalizedExcerpt.slice(0, 300);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
return '';
|
|
133
|
+
}
|
|
134
|
+
}, selector);
|
|
135
|
+
}
|
|
133
136
|
// Convert the violation selector to a selector-excerpt pair.
|
|
134
137
|
rule.selectors[index] = [selector, excerpt];
|
|
135
138
|
}
|