testaro 18.12.0 → 18.13.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/testaro/zIndex.js +21 -57
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "18.12.0",
3
+ "version": "18.13.0",
4
4
  "description": "Run 920 web accessibility tests from 9 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/testaro/zIndex.js CHANGED
@@ -10,68 +10,32 @@
10
10
 
11
11
  // ########## IMPORTS
12
12
 
13
- // Module to get locator data.
14
- const {getLocatorData} = require('../procs/getLocatorData');
13
+ // Module to perform common operations.
14
+ const {init, report} = require('../procs/testaro');
15
15
 
16
16
  // ########## FUNCTIONS
17
17
 
18
+ // Runs the test and returns the result.
18
19
  exports.reporter = async (page, withItems) => {
19
- // Initialize the result.
20
- const data = {};
21
- const totals = [0, 0, 0, 0];
22
- const standardInstances = [];
23
- // Get locators for all eligible elements.
24
- const locAll = page.locator('body *');
25
- const locsAll = await locAll.all();
26
- // For each of them:
27
- for (const loc of locsAll) {
28
- // Get its Z index.
29
- const zIndex = await loc.evaluate(element => {
30
- const styleDec = window.getComputedStyle(element);
31
- return styleDec.zIndex;
20
+ // Initialize the locators and result.
21
+ const all = await init(page, 'body *');
22
+ // For each locator:
23
+ for (const loc of all.allLocs) {
24
+ // Get whether its element violates the rule.
25
+ const badZ = await loc.evaluate(el => {
26
+ const styleDec = window.getComputedStyle(el);
27
+ const {zIndex} = styleDec;
28
+ return zIndex !== 'auto' ? zIndex : null;
32
29
  });
33
- // If it is not auto:
34
- if (zIndex !== 'auto') {
35
- // Add to the totals.
36
- totals[0]++;
37
- // If itemization is required:
38
- if (withItems) {
39
- // Get data on the element.
40
- const elData = await getLocatorData(loc);
41
- // Add an instance to the result.
42
- standardInstances.push({
43
- ruleID: 'zIndex',
44
- what: `Element has a non-default Z index (${zIndex})`,
45
- ordinalSeverity: 0,
46
- tagName: elData.tagName,
47
- id: elData.id,
48
- location: elData.location,
49
- excerpt: elData.excerpt
50
- });
51
- }
30
+ // If it does:
31
+ if (badZ) {
32
+ // Add the locator to the array of violators.
33
+ all.locs.push([loc, badZ]);
52
34
  }
53
35
  }
54
- // If itemization is not required:
55
- if (! withItems) {
56
- // Add a summary instance to the result.
57
- standardInstances.push({
58
- ruleID: 'zIndex',
59
- what: 'Elements have non-default Z indexes',
60
- count: totals[0],
61
- ordinalSeverity: 0,
62
- tagName: '',
63
- id: '',
64
- location: {
65
- doc: '',
66
- type: '',
67
- spec: ''
68
- },
69
- excerpt: ''
70
- });
71
- }
72
- return {
73
- data,
74
- totals,
75
- standardInstances
76
- };
36
+ // Populate and return the result.
37
+ const whats = [
38
+ 'Element has a non-default Z index (__param__)', 'Elements have non-default Z indexes'
39
+ ];
40
+ return await report(withItems, all, 'zIndex', whats, 0);
77
41
  };