testaro 60.8.3 → 60.8.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/testaro/attVal.js +34 -25
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "60.8.3",
3
+ "version": "60.8.4",
4
4
  "description": "Run 1000 web accessibility tests from 11 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/testaro/attVal.js CHANGED
@@ -24,35 +24,44 @@
24
24
 
25
25
  /*
26
26
  attVal
27
- This test reports attributes with illicit values.
27
+ This test reports elements with illicit values of an attribute.
28
28
  */
29
29
 
30
- // ########## IMPORTS
31
-
32
- // Module to perform common operations.
33
- const {init, getRuleResult} = require('../procs/testaro');
34
-
35
- // ########## FUNCTIONS
30
+ // FUNCTIONS
36
31
 
37
32
  // Runs the test and returns the result.
38
33
  exports.reporter = async (page, withItems, attributeName, areLicit, values) => {
39
- // Initialize the locators and result.
40
- const all = await init(100, page, `[${attributeName}]`);
41
- // For each locator:
42
- for (const loc of all.allLocs) {
43
- // Get whether its element violates the rule.
44
- const value = await loc.getAttribute(attributeName);
45
- const isBad = areLicit !== values.includes(value);
46
- // If it does:
47
- if (isBad) {
48
- // Add the locator to the array of violators.
49
- all.locs.push([loc, value]);
34
+ // Return totals and standard instances for the rule.
35
+ return await page.evaluate(args => {
36
+ const [withItems, attributeName, areLicit, values] = args;
37
+ // Get all candidates, i.e. elements with the attribute.
38
+ const candidates = document.body.querySelectorAll(`[${attributeName}]`);
39
+ let violationCount = 0;
40
+ const instances = [];
41
+ // For each candidate:
42
+ candidates.forEach(element => {
43
+ const value = element.getAttribute(attributeName);
44
+ // If it violates the rule:
45
+ if (areLicit !== values.includes(value)) {
46
+ // Increment the violation count.
47
+ violationCount++;
48
+ // If itemization is required:
49
+ if (withItems) {
50
+ const what = `Element has attribute ${attributeName} with illicit value ${value}`;
51
+ instances.push(window.getInstance(element, 'attVal', what, 1, 2));
52
+ }
53
+ }
54
+ });
55
+ // If there were any violations and itemization is not required:
56
+ if (violationCount && ! withItems) {
57
+ const what = `Elements have attribute ${attributeName} with illicit values`;
58
+ // Add a summary instance to the instances.
59
+ instances.push(window.getInstance(null, 'attVal', what, violationCount, 2));
50
60
  }
51
- }
52
- // Populate and return the result.
53
- const whats = [
54
- `Element has attribute ${attributeName} with illicit value “__param__”`,
55
- `Elements have attribute ${attributeName} with illicit values`
56
- ];
57
- return await getRuleResult(withItems, all, 'attVal', whats, 2);
61
+ return {
62
+ data: {},
63
+ totals: [0, 0, violationCount, 0],
64
+ standardInstances: instances
65
+ };
66
+ }, [withItems, attributeName, areLicit, values]);
58
67
  };