testaro 60.6.1 → 60.7.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.
- package/CONTRIBUTING.md +30 -27
- package/UPGRADES.md +474 -200
- package/package.json +1 -1
- package/run.js +51 -0
- package/testaro/lineHeight-slow.js +70 -0
- package/testaro/lineHeight.js +59 -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/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,71 @@
|
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
const violators = await page.evaluate(() => {
|
|
40
|
+
const elements = document.body.querySelectorAll('*');
|
|
41
|
+
const elementsWithText = Array.from(elements).filter(el =>
|
|
42
|
+
Array.from(el.childNodes).some(child =>
|
|
43
|
+
child.nodeType === Node.TEXT_NODE &&
|
|
44
|
+
child.textContent.trim().length
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
const violatorData = [];
|
|
48
|
+
elementsWithText.forEach(el => {
|
|
50
49
|
const styleDec = window.getComputedStyle(el);
|
|
51
50
|
const {fontSize, lineHeight} = styleDec;
|
|
51
|
+
const fontSizeNum = Number.parseFloat(fontSize);
|
|
52
|
+
const lineHeightNum = Number.parseFloat(lineHeight);
|
|
53
|
+
const fontSizeTrunc = fontSizeNum.toFixed(1);
|
|
54
|
+
const lineHeightTrunc = lineHeightNum.toFixed(1);
|
|
55
|
+
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
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
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;
|
|
52
89
|
return {
|
|
53
|
-
|
|
54
|
-
|
|
90
|
+
ruleID: 'lineHeight',
|
|
91
|
+
what: `Element line height (${lineHeight}px) is less than 1.5 times its font size (${fontSize}px)`,
|
|
92
|
+
ordinalSeverity: 1,
|
|
93
|
+
tagName,
|
|
94
|
+
id,
|
|
95
|
+
location,
|
|
96
|
+
excerpt,
|
|
97
|
+
boxID,
|
|
98
|
+
pathID
|
|
55
99
|
};
|
|
56
|
-
})
|
|
57
|
-
|
|
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);
|
|
100
|
+
})
|
|
101
|
+
};
|
|
70
102
|
};
|
|
@@ -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`.
|