testaro 60.8.1 → 60.8.2

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.8.1",
3
+ "version": "60.8.2",
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/run.js CHANGED
@@ -462,6 +462,8 @@ const launch = exports.launch = async (
462
462
  });
463
463
  const {x, y, width, height} = boxData;
464
464
  const {tagName, id = ''} = element;
465
+ const rawExcerpt = element.textContent.trim() || element.outerHTML.trim();
466
+ const excerpt = rawExcerpt.replace(/\s+/g, ' ').slice(0, 200);
465
467
  // Return an itemized instance.
466
468
  return {
467
469
  ruleID,
@@ -480,7 +482,7 @@ const launch = exports.launch = async (
480
482
  height
481
483
  }
482
484
  },
483
- excerpt: element.textContent.trim().replace(/\s+/g, ' ').slice(0, 100),
485
+ excerpt,
484
486
  boxID: [x, y, width, height].join(':'),
485
487
  pathID: window.getXPath(element)
486
488
  };
@@ -1,6 +1,7 @@
1
1
  /*
2
2
  © 2025 CVS Health and/or one of its affiliates. All rights reserved.
3
3
  © 2025 Juan S. Casado. All rights reserved.
4
+ © 2025 Jonathan Robert Pool. All rights reserved.
4
5
 
5
6
  MIT License
6
7
 
@@ -25,34 +26,52 @@
25
26
 
26
27
  /*
27
28
  altScheme
28
- Identify img elements whose alt attribute is an entire URL or clearly a file name (favicon).
29
+ Identify img elements whose alt attribute is a URL or file name.
29
30
  */
30
31
 
31
- const {init, getRuleResult} = require('../procs/testaro');
32
+ // FUNCTIONS
32
33
 
34
+ // Runs the test and returns the result.
33
35
  exports.reporter = async (page, withItems) => {
34
- // Candidate images: any img with an alt attribute (including empty)
35
- const all = await init(100, page, 'img[alt]');
36
- for (const loc of all.allLocs) {
37
- const isBad = await loc.evaluate(el => {
38
- const alt = (el.getAttribute('alt') || '').trim();
39
- if (!alt) return false;
40
- // full-string URL (http(s) or file or ftp) — must be the entire alt value
41
- if (/^\s*(?:https?:|file:|ftp:)\S+\s*$/i.test(alt)) return true;
42
- // favicon or typical file names
43
- if (/favicon/i.test(alt)) return true;
44
- // common image file extensions that occupy the entire alt or are the base filename
45
- if (/^\s*\S+\.(?:png|jpe?g|gif|svg|webp|ico)\s*$/i.test(alt)) return true;
46
- // match exact equality with src or href attributes
47
- const href = (el.getAttribute('href') || el.getAttribute('src') || '').trim();
48
- if (href && alt === href) return true;
49
- return false;
36
+ // Return totals and standard instances for the rule.
37
+ return await page.evaluate(withItems => {
38
+ // Get all candidates, i.e. img elements with alt attributes.
39
+ const candidates = document.body.querySelectorAll('img[alt]');
40
+ let violationCount = 0;
41
+ const instances = [];
42
+ // For each candidate:
43
+ candidates.forEach(element => {
44
+ const alt = (element.getAttribute('alt') || '').trim();
45
+ // If it is non-empty:
46
+ if (alt) {
47
+ const isURL = /^(?:https?:|file:|ftp:)\S+$/i.test(alt);
48
+ const isFileName = /favicon|^\S+\.(?:png|jpe?g|gif|svg|webp|ico)$/i.test(alt);
49
+ // If it is a URL or file name:
50
+ if (isURL || isFileName) {
51
+ // Increment the violation count.
52
+ violationCount++;
53
+ // If itemization is required:
54
+ if (withItems) {
55
+ const valueType = isURL && isFileName
56
+ ? 'the URL of an image file'
57
+ : (isURL ? 'a URL' : 'a file name');
58
+ const what = `img element has an alt attribute with ${valueType} as its value`;
59
+ // Add an instance to the instances.
60
+ instances.push(window.getInstance(element, 'altScheme', what, 1, 2));
61
+ }
62
+ }
63
+ }
50
64
  });
51
- if (isBad) all.locs.push(loc);
52
- }
53
- const whats = [
54
- 'Element has an alt attribute with a URL as its entire value',
55
- 'img elements have alt attributes with URLs as their entire values'
56
- ];
57
- return await getRuleResult(withItems, all, 'altScheme', whats, 2);
65
+ // If there were any violations and itemization is not required:
66
+ if (violationCount && ! withItems) {
67
+ const what = 'img elements have alt attributes with URL or filename values';
68
+ // Add a summary instance to the instances.
69
+ instances.push(window.getInstance(null, 'altScheme', what, violationCount, 2, 'IMG'));
70
+ }
71
+ return {
72
+ data: {},
73
+ totals: [0, violationCount, 0, 0],
74
+ standardInstances: instances
75
+ };
76
+ }, withItems);
58
77
  };
@@ -37,8 +37,8 @@
37
37
  <p><img id="mapGIF" href="https://urbaninstitute.github.io/r-at-urban/mapping/www/images/yay_maps.gif" alt="animated map of the USA"></p>
38
38
  <p>Defect 1: Look at this other map:</p>
39
39
  <p><img id="mapPNG" href="https://upload.wikimedia.org/wikipedia/commons/f/f7/Blank_map_of_states.png" alt="https://upload.wikimedia.org/wikipedia/commons/f/f7/Blank_map_of_states.png"></p>
40
- <p>Defect 2: Look at this pattern:</p>
41
- <p><img href="http://httpforever.com/css/images/header-major-on-light.svg" alt="http://httpforever.com/css/images/header-major-on-light.svg"></p>
40
+ <p>Defect 2: This image has a file name as a text alternative:</p>
41
+ <p><img href="http://httpforever.com/css/images/header-major-on-light.svg" alt="header-major-on-light.svg"></p>
42
42
  <p>Defect 3: Look at this icon:</p>
43
43
  <p><img href="file://favicon.png" alt="file://favicon.png"></p>
44
44
  <p>This map has an empty text alternative, but that does not violate the altScheme rule:</p>
@@ -1,98 +0,0 @@
1
- /*
2
- © 2023 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
- allHidden
28
- This test reports a page that is entirely or mainly hidden.
29
- */
30
-
31
- // FUNCTIONS
32
-
33
- // Runs the test and returns the result.
34
- exports.reporter = async page => {
35
- // Get data on violations of the rule.
36
- const violationData = await page.evaluate(() => {
37
- // Get all candidates, i.e. the regions that should never be hidden.
38
- const regions = {
39
- html: {
40
- element: document.documentElement,
41
- severity: 3
42
- },
43
- body: {
44
- element: document.body,
45
- severity: 2
46
- },
47
- main: {
48
- element: document.querySelector('main, [role=main]'),
49
- severity: 1
50
- }
51
- };
52
- let violationCounts = [0, 0, 0, 0];
53
- const instances = [];
54
- // For each candidate:
55
- Object.keys(regions).forEach(regionName => {
56
- const region = regions[regionName];
57
- const {element, severity} = region;
58
- console.log(`XXX ${regionName}`);
59
- const tagName = regionName.toUpperCase();
60
- // If it is not main and does not exist:
61
- if (! element && regionName !== 'main') {
62
- console.log(`XXX ${regionName} is not main anddoes not exist`);
63
- // Increment the violation count.
64
- violationCounts[3]++;
65
- // Add an instance to the instances.
66
- const what = `The ${regionName} region does not exist`;
67
- // Add a summary instance to the instances.
68
- instances.push(window.getInstance(null, 'allHidden', what, 1, 3, tagName));
69
- }
70
- // Otherwise, if it exists:
71
- else if (element) {
72
- console.log(`XXX ${regionName} exists`);
73
- const styleDec = window.getComputedStyle(element);
74
- const {display, visibility} = styleDec;
75
- // If it is hidden:
76
- if (display === 'none' || visibility === 'hidden' || element.ariaHidden === 'true') {
77
- // Increment the violation count.
78
- violationCounts[severity]++;
79
- // Add an instance to the instances.
80
- const what = `The ${regionName} region is hidden`;
81
- // Add an instance to the instances.
82
- instances.push(window.getInstance(element, 'allHidden', what, 1, severity, tagName));
83
- }
84
- }
85
- });
86
- return {
87
- violationCounts,
88
- instances
89
- };
90
- });
91
- const {violationCounts, instances} = violationData;
92
- // Return the result.
93
- return {
94
- data: {},
95
- totals: violationCounts,
96
- standardInstances: instances
97
- };
98
- };