testaro 60.6.1 → 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/CONTRIBUTING.md +30 -27
- package/UPGRADES.md +474 -200
- package/package.json +1 -1
- package/procs/testaro.js +6 -6
- package/run.js +51 -0
- package/testaro/lineHeight-slow.js +70 -0
- package/testaro/lineHeight.js +107 -27
- package/validation/jobs/todo/README.md +1 -1
- package/validation/watch/done/README.md +4 -4
- package/validation/watch/todo/README.md +4 -4
package/package.json
CHANGED
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
|
|
101
|
-
id
|
|
102
|
-
location
|
|
103
|
-
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
|
}
|
package/run.js
CHANGED
|
@@ -383,6 +383,57 @@ const launch = exports.launch = async (
|
|
|
383
383
|
get: () => ['en-US', 'en']
|
|
384
384
|
});
|
|
385
385
|
});
|
|
386
|
+
// If the act is a testaro test act:
|
|
387
|
+
if (act.type === 'test' && act.which === 'testaro') {
|
|
388
|
+
// Add a script that defines a window method to get the XPath of an element.
|
|
389
|
+
await page.addInitScript(() => {
|
|
390
|
+
window.getXPath = element => {
|
|
391
|
+
if (!element || element.nodeType !== Node.ELEMENT_NODE) {
|
|
392
|
+
return '';
|
|
393
|
+
}
|
|
394
|
+
const segments = [];
|
|
395
|
+
let el = element;
|
|
396
|
+
// As long as the current node is an element:
|
|
397
|
+
while (el && el.nodeType === Node.ELEMENT_NODE) {
|
|
398
|
+
const tag = el.tagName.toLowerCase();
|
|
399
|
+
// If it is the html element:
|
|
400
|
+
if (el === document.documentElement) {
|
|
401
|
+
// Prepend it to the segment array
|
|
402
|
+
segments.unshift('html');
|
|
403
|
+
// Stop traversing.
|
|
404
|
+
break;
|
|
405
|
+
}
|
|
406
|
+
// Otherwise, get its parent node.
|
|
407
|
+
const parent = el.parentNode;
|
|
408
|
+
// If (abnormally) the parent node is not an element:
|
|
409
|
+
if (!parent || parent.nodeType !== Node.ELEMENT_NODE) {
|
|
410
|
+
// Prepend it to the segment array.
|
|
411
|
+
segments.unshift(tag);
|
|
412
|
+
// Stop traversing, leaving the segment array partial.
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
let subscript = '';
|
|
416
|
+
let sameTagCount = 0;
|
|
417
|
+
// Get the subscript of the element.
|
|
418
|
+
const cohort = Array
|
|
419
|
+
.from(parent.childNodes)
|
|
420
|
+
.filter(
|
|
421
|
+
childNode => childNode.nodeType === Node.ELEMENT_NODE
|
|
422
|
+
&& childNode.tagName === el.tagName
|
|
423
|
+
);
|
|
424
|
+
if (cohort.length > 1) {
|
|
425
|
+
subscript = `[${cohort.indexOf(el) + 1}]`;
|
|
426
|
+
}
|
|
427
|
+
// Prepend the element identifier to the segment array.
|
|
428
|
+
segments.unshift(`${tag}${subscript}`);
|
|
429
|
+
// Continue the traversal with the parent of the current element.
|
|
430
|
+
el = parent;
|
|
431
|
+
}
|
|
432
|
+
// Return the XPath.
|
|
433
|
+
return `/${segments.join('/')}`;
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
}
|
|
386
437
|
// Ensure the report has a jobData property.
|
|
387
438
|
report.jobData ??= {};
|
|
388
439
|
const {jobData} = report;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/*
|
|
2
|
+
© 2023–2024 CVS Health and/or one of its affiliates. All rights reserved.
|
|
3
|
+
© 2025 Jonathan Robert Pool. All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
/*
|
|
27
|
+
lineHeight
|
|
28
|
+
Related to Tenon rule 144.
|
|
29
|
+
This test reports elements whose line heights are less than 1.5 times their font sizes. Even
|
|
30
|
+
such elements with no text create accessibility risk, because any text node added to one of
|
|
31
|
+
them would have a substandard line height. Nonetheless, elements with no non-spacing text in
|
|
32
|
+
their subtrees are excluded.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// IMPORTS
|
|
36
|
+
|
|
37
|
+
// Module to perform common operations.
|
|
38
|
+
const {init, getRuleResult} = require('../procs/testaro');
|
|
39
|
+
|
|
40
|
+
// FUNCTIONS
|
|
41
|
+
|
|
42
|
+
// Runs the test and returns the result.
|
|
43
|
+
exports.reporter = async (page, withItems) => {
|
|
44
|
+
// Initialize the locators and result.
|
|
45
|
+
const all = await init(100, page, 'body *', {hasText: /[^\s]/});
|
|
46
|
+
// For each locator:
|
|
47
|
+
for (const loc of all.allLocs) {
|
|
48
|
+
// Get whether its element violates the rule.
|
|
49
|
+
const data = await loc.evaluate(el => {
|
|
50
|
+
const styleDec = window.getComputedStyle(el);
|
|
51
|
+
const {fontSize, lineHeight} = styleDec;
|
|
52
|
+
return {
|
|
53
|
+
fontSize: Number.parseFloat(fontSize),
|
|
54
|
+
lineHeight: Number.parseFloat(lineHeight)
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
// If it does, after a grace margin for rounding:
|
|
58
|
+
const isBad = data.lineHeight < 1.49 * data.fontSize;
|
|
59
|
+
if (isBad) {
|
|
60
|
+
// Add the locator to the array of violators.
|
|
61
|
+
all.locs.push([loc, `font size ${data.fontSize} px, line height ${data.lineHeight} px`]);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Populate and return the result.
|
|
65
|
+
const whats = [
|
|
66
|
+
'Element line height is less than 1.5 times its font size (__param__)',
|
|
67
|
+
'Elements have line heights less than 1.5 times their font sizes'
|
|
68
|
+
];
|
|
69
|
+
return await getRuleResult(withItems, all, 'lineHeight', whats, 1);
|
|
70
|
+
};
|
package/testaro/lineHeight.js
CHANGED
|
@@ -32,39 +32,119 @@
|
|
|
32
32
|
their subtrees are excluded.
|
|
33
33
|
*/
|
|
34
34
|
|
|
35
|
-
// IMPORTS
|
|
36
|
-
|
|
37
|
-
// Module to perform common operations.
|
|
38
|
-
const {init, getRuleResult} = require('../procs/testaro');
|
|
39
|
-
|
|
40
35
|
// FUNCTIONS
|
|
41
36
|
|
|
42
37
|
// Runs the test and returns the result.
|
|
43
38
|
exports.reporter = async (page, withItems) => {
|
|
44
|
-
//
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// Get
|
|
49
|
-
const
|
|
39
|
+
// Get data on violations of the rule.
|
|
40
|
+
const violationData = await page.evaluate(withItems => {
|
|
41
|
+
// Get all elements.
|
|
42
|
+
const elements = document.body.querySelectorAll('*');
|
|
43
|
+
// Get all elements that have non-empty child text nodes.
|
|
44
|
+
const elementsWithText = Array.from(elements).filter(el =>
|
|
45
|
+
Array.from(el.childNodes).some(child =>
|
|
46
|
+
child.nodeType === Node.TEXT_NODE &&
|
|
47
|
+
child.textContent.trim().length
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
// Initialize a violation count and an array of violation items.
|
|
51
|
+
let violationCount = 0;
|
|
52
|
+
const violationItems = [];
|
|
53
|
+
// For each such element:
|
|
54
|
+
elementsWithText.forEach(el => {
|
|
55
|
+
// Get its relevant style properties.
|
|
50
56
|
const styleDec = window.getComputedStyle(el);
|
|
51
57
|
const {fontSize, lineHeight} = styleDec;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
const fontSizeNum = Number.parseFloat(fontSize);
|
|
59
|
+
const lineHeightNum = Number.parseFloat(lineHeight);
|
|
60
|
+
// If it violates the rule:
|
|
61
|
+
if (lineHeightNum < 1.495 * fontSizeNum) {
|
|
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
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
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({
|
|
112
|
+
ruleID: 'lineHeight',
|
|
113
|
+
what: `Element line height (${lineHeight}px) is less than 1.5 times its font size (${fontSize}px)`,
|
|
114
|
+
ordinalSeverity: 1,
|
|
115
|
+
tagName,
|
|
116
|
+
id,
|
|
117
|
+
location,
|
|
118
|
+
excerpt,
|
|
119
|
+
boxID,
|
|
120
|
+
pathID
|
|
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: ''
|
|
56
143
|
});
|
|
57
|
-
// If it does, after a grace margin for rounding:
|
|
58
|
-
const isBad = data.lineHeight < 1.49 * data.fontSize;
|
|
59
|
-
if (isBad) {
|
|
60
|
-
// Add the locator to the array of violators.
|
|
61
|
-
all.locs.push([loc, `font size ${data.fontSize} px, line height ${data.lineHeight} px`]);
|
|
62
|
-
}
|
|
63
144
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return await getRuleResult(withItems, all, 'lineHeight', whats, 1);
|
|
145
|
+
return {
|
|
146
|
+
data: {},
|
|
147
|
+
totals: [0, violationCount, 0, 0],
|
|
148
|
+
standardInstances
|
|
149
|
+
};
|
|
70
150
|
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# done
|
|
2
|
+
|
|
3
|
+
Directory watched by executor `watchDir`.
|
|
4
|
+
|
|
1
5
|
/*
|
|
2
6
|
© 2023 CVS Health and/or one of its affiliates. All rights reserved.
|
|
3
7
|
|
|
@@ -21,7 +25,3 @@
|
|
|
21
25
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
26
|
SOFTWARE.
|
|
23
27
|
*/
|
|
24
|
-
|
|
25
|
-
# done
|
|
26
|
-
|
|
27
|
-
Directory watched by executor `watchDir`.
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
# todo
|
|
2
|
+
|
|
3
|
+
Directory watched by executor `watchDir`.
|
|
4
|
+
|
|
1
5
|
/*
|
|
2
6
|
© 2023 CVS Health and/or one of its affiliates. All rights reserved.
|
|
3
7
|
|
|
@@ -21,7 +25,3 @@
|
|
|
21
25
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
26
|
SOFTWARE.
|
|
23
27
|
*/
|
|
24
|
-
|
|
25
|
-
# todo
|
|
26
|
-
|
|
27
|
-
Directory watched by executor `watchDir`.
|