testaro 60.7.0 → 60.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "60.7.0",
3
+ "version": "60.7.1",
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/procs/testaro.js CHANGED
@@ -90,19 +90,19 @@ const getRuleResult = exports.getRuleResult = async (
90
90
  // If itemization is required:
91
91
  if (withItems) {
92
92
  // Get the bounding box of the element.
93
- const {location} = elData;
93
+ const {tagName,id, location, excerpt} = elData;
94
94
  const box = location.type === 'box' ? location.spec : await boxOf(loc);
95
95
  // Add a standard instance to the result.
96
96
  standardInstances.push({
97
97
  ruleID,
98
98
  what: whatParam ? whats[0].replace('__param__', whatParam) : whats[0],
99
99
  ordinalSeverity,
100
- tagName: elData.tagName,
101
- id: elData.id,
102
- location: elData.location,
103
- excerpt: elData.excerpt,
100
+ tagName,
101
+ id,
102
+ location,
103
+ excerpt,
104
104
  boxID: boxToString(box),
105
- pathID: await xPath(loc)
105
+ pathID: tagName === 'HTML' ? '/html' : await xPath(loc)
106
106
  });
107
107
  }
108
108
  }
@@ -36,57 +36,79 @@
36
36
 
37
37
  // Runs the test and returns the result.
38
38
  exports.reporter = async (page, withItems) => {
39
- const violators = await page.evaluate(() => {
39
+ // Get data on violations of the rule.
40
+ const violationData = await page.evaluate(withItems => {
41
+ // Get all elements.
40
42
  const elements = document.body.querySelectorAll('*');
43
+ // Get all elements that have non-empty child text nodes.
41
44
  const elementsWithText = Array.from(elements).filter(el =>
42
45
  Array.from(el.childNodes).some(child =>
43
46
  child.nodeType === Node.TEXT_NODE &&
44
47
  child.textContent.trim().length
45
48
  )
46
49
  );
47
- const violatorData = [];
50
+ // Initialize a violation count and an array of violation items.
51
+ let violationCount = 0;
52
+ const violationItems = [];
53
+ // For each such element:
48
54
  elementsWithText.forEach(el => {
55
+ // Get its relevant style properties.
49
56
  const styleDec = window.getComputedStyle(el);
50
57
  const {fontSize, lineHeight} = styleDec;
51
58
  const fontSizeNum = Number.parseFloat(fontSize);
52
59
  const lineHeightNum = Number.parseFloat(lineHeight);
53
- const fontSizeTrunc = fontSizeNum.toFixed(1);
54
- const lineHeightTrunc = lineHeightNum.toFixed(1);
60
+ // If it violates the rule:
55
61
  if (lineHeightNum < 1.495 * fontSizeNum) {
56
- const boxData = el.getBoundingClientRect();
57
- ['x', 'y', 'width', 'height'].forEach(dimension => {
58
- boxData[dimension] = Math.round(boxData[dimension]);
59
- });
60
- const {x, y, width, height} = boxData;
61
- violatorData.push({
62
- tagName: el.tagName,
63
- id: el.id,
64
- location: {
65
- doc: 'dom',
66
- type: 'box',
67
- spec: {
68
- x,
69
- y,
70
- width,
71
- height
72
- }
73
- },
74
- excerpt: el.textContent.trim(),
75
- boxID: [x, y, width, height].join(':'),
76
- pathID: window.getXPath(el),
77
- fontSize: fontSizeTrunc,
78
- lineHeight: lineHeightTrunc
79
- });
62
+ // Increment the violation count.
63
+ violationCount++;
64
+ // If itemization is required:
65
+ if (withItems) {
66
+ // Get its bounding box.
67
+ const boxData = el.getBoundingClientRect();
68
+ ['x', 'y', 'width', 'height'].forEach(dimension => {
69
+ boxData[dimension] = Math.round(boxData[dimension]);
70
+ });
71
+ const {x, y, width, height} = boxData;
72
+ const fontSizeTrunc = fontSizeNum.toFixed(1);
73
+ const lineHeightTrunc = lineHeightNum.toFixed(1);
74
+ // Add data on the element to the violation items.
75
+ violationItems.push({
76
+ tagName: el.tagName,
77
+ id: el.id,
78
+ location: {
79
+ doc: 'dom',
80
+ type: 'box',
81
+ spec: {
82
+ x,
83
+ y,
84
+ width,
85
+ height
86
+ }
87
+ },
88
+ excerpt: el.textContent.trim(),
89
+ boxID: [x, y, width, height].join(':'),
90
+ pathID: window.getXPath(el),
91
+ fontSize: fontSizeTrunc,
92
+ lineHeight: lineHeightTrunc
93
+ });
94
+ }
80
95
  }
81
96
  });
82
- return violatorData;
83
- });
84
- return {
85
- data: {},
86
- totals: [0, violators.length, 0, 0],
87
- standardInstances: violators.map(violator => {
88
- const {tagName, id, location, excerpt, boxID, pathID, fontSize, lineHeight} = violator;
89
- return {
97
+ return {
98
+ violationCount,
99
+ violationItems
100
+ };
101
+ }, withItems);
102
+ const {violationCount, violationItems} = violationData;
103
+ // Initialize the standard instances.
104
+ const standardInstances = [];
105
+ // If itemization is required:
106
+ if (withItems) {
107
+ // For each violation item:
108
+ violationItems.forEach(violationItem => {
109
+ // Add a standard instance.
110
+ const {tagName, id, location, excerpt, boxID, pathID, fontSize, lineHeight} = violationItem;
111
+ standardInstances.push({
90
112
  ruleID: 'lineHeight',
91
113
  what: `Element line height (${lineHeight}px) is less than 1.5 times its font size (${fontSize}px)`,
92
114
  ordinalSeverity: 1,
@@ -96,7 +118,33 @@ exports.reporter = async (page, withItems) => {
96
118
  excerpt,
97
119
  boxID,
98
120
  pathID
99
- };
100
- })
121
+ });
122
+ });
123
+ }
124
+ // Otherwise, i.e. if itemization is not required:
125
+ else {
126
+ const {violationCount} = violationData;
127
+ // Summarize the violations.
128
+ standardInstances.push({
129
+ ruleID: 'lineHeight',
130
+ what: `Element line heights are less than 1.5 times their font sizes`,
131
+ ordinalSeverity: 1,
132
+ count: violationCount,
133
+ tagName: '',
134
+ id: '',
135
+ location: {
136
+ doc: '',
137
+ type: '',
138
+ spec: ''
139
+ },
140
+ excerpt: '',
141
+ boxID: '',
142
+ pathID: ''
143
+ });
144
+ }
145
+ return {
146
+ data: {},
147
+ totals: [0, violationCount, 0, 0],
148
+ standardInstances
101
149
  };
102
150
  };