testilo 41.3.0 → 41.5.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/package.json +1 -1
- package/procs/digest/tdp49/index.html +222 -0
- package/procs/digest/tdp49/index.js +240 -0
- package/procs/score/tsp46.js +423 -0
- package/reports/digested/style.css +4 -0
package/package.json
CHANGED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
<!DOCTYPE HTML>
|
|
2
|
+
<html lang="en-US">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<meta name="author" content="Testilo">
|
|
7
|
+
<meta name="creator" content="Testilo">
|
|
8
|
+
<meta name="publisher" name="Testilo">
|
|
9
|
+
<meta name="description" content="report of accessibility testing of a web page">
|
|
10
|
+
<meta name="keywords" content="accessibility a11y web testing">
|
|
11
|
+
<title>Accessibility digest</title>
|
|
12
|
+
<link rel="icon" href="favicon.ico">
|
|
13
|
+
<link rel="stylesheet" href="style.css">
|
|
14
|
+
<script id="script" type="module">
|
|
15
|
+
const sortByA = document.getElementById('sortByA');
|
|
16
|
+
const sortByB = document.getElementById('sortByB');
|
|
17
|
+
const sortBasisSpan = document.getElementById('sortBasis');
|
|
18
|
+
const sortBasisASpan = document.getElementById('sortBasisA');
|
|
19
|
+
const sortBasisBSpan = document.getElementById('sortBasisB');
|
|
20
|
+
const sumBody = document.getElementById('sumBody');
|
|
21
|
+
const rows = Array.from(sumBody.children);
|
|
22
|
+
const sortBases = {
|
|
23
|
+
WCAG: {
|
|
24
|
+
col: 1,
|
|
25
|
+
A: 'weight',
|
|
26
|
+
B: 'score'
|
|
27
|
+
},
|
|
28
|
+
weight: {
|
|
29
|
+
col: 2,
|
|
30
|
+
A: 'WCAG',
|
|
31
|
+
B: 'score'
|
|
32
|
+
},
|
|
33
|
+
score: {
|
|
34
|
+
col: 3,
|
|
35
|
+
A: 'WCAG',
|
|
36
|
+
B: 'weight'
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
// FUNCTION DEFINITION START
|
|
40
|
+
const sortRowsBy = basis => {
|
|
41
|
+
if (basis === 'WCAG') {
|
|
42
|
+
rows.sort((a, b) => {
|
|
43
|
+
const sorters = [a, b].map(row => {
|
|
44
|
+
const wcagParts = row.children[sortBases[basis].col].textContent.split('.');
|
|
45
|
+
const wcagNums = wcagParts.map(part => Number.parseInt(part, 10));
|
|
46
|
+
return 100 * (wcagNums[0] || 0) + 20 * (wcagNums[1] || 0) + (wcagNums[2] || 0);
|
|
47
|
+
});
|
|
48
|
+
return sorters[0] - sorters[1];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if (basis === 'weight') {
|
|
52
|
+
rows.sort((a, b) => {
|
|
53
|
+
const sorters = [a, b].map(row => row.children[sortBases[basis].col].textContent);
|
|
54
|
+
return sorters[1] - sorters[0];
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else if (basis === 'score') {
|
|
58
|
+
rows.sort((a, b) => {
|
|
59
|
+
const sorters = [a, b]
|
|
60
|
+
.map(row => Number.parseInt(row.children[sortBases[basis].col].textContent));
|
|
61
|
+
return sorters[1] - sorters[0];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
sumBody.textContent = '';
|
|
65
|
+
rows.forEach(row => {
|
|
66
|
+
sumBody.appendChild(row);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
// FUNCTION DEFINITION END
|
|
70
|
+
// When a sort button is activated:
|
|
71
|
+
document.getElementById('sortButtons').addEventListener('click', event => {
|
|
72
|
+
const whichButton = event.target.id.slice(-1);
|
|
73
|
+
const oldBasis = sortBasisSpan.textContent;
|
|
74
|
+
const newBasis = sortBases[oldBasis][whichButton];
|
|
75
|
+
// Re-sort the table.
|
|
76
|
+
sortRowsBy(newBasis);
|
|
77
|
+
// Revise the variable texts.
|
|
78
|
+
sortBasisSpan.textContent = newBasis;
|
|
79
|
+
sortBasisASpan.textContent = sortBases[newBasis].A;
|
|
80
|
+
sortBasisBSpan.textContent = sortBases[newBasis].B;
|
|
81
|
+
});
|
|
82
|
+
</script>
|
|
83
|
+
</head>
|
|
84
|
+
<body>
|
|
85
|
+
<main>
|
|
86
|
+
<header>
|
|
87
|
+
<h1>Accessibility digest</h1>
|
|
88
|
+
<h2>Contents</h2>
|
|
89
|
+
<ul>
|
|
90
|
+
<li><a href="#intro">Introduction</a></li>
|
|
91
|
+
<li><a href="#summary">Issue summary</a></li>
|
|
92
|
+
<li><a href="#itemization">Itemized issues</a></li>
|
|
93
|
+
<li><a href="#elements">Elements with issues</a></li>
|
|
94
|
+
</ul>
|
|
95
|
+
<table class="allBorder">
|
|
96
|
+
<caption>Synopsis</caption>
|
|
97
|
+
<tr><th>Page</th><td>__org__</td></tr>
|
|
98
|
+
<tr><th>URL</th><td>__url__</td></tr>
|
|
99
|
+
<tr><th>Test date</th><td>__dateSlash__</td></tr>
|
|
100
|
+
<tr><th>Score</th><td>__total__</td></tr>
|
|
101
|
+
</table>
|
|
102
|
+
<table class="allBorder">
|
|
103
|
+
<caption>Configuration</caption>
|
|
104
|
+
<tr><th>Redirections</th><td>__redirections__</td></tr>
|
|
105
|
+
<tr><th>Tool isolation</th><td>__isolation__</td></tr>
|
|
106
|
+
<tr><th>Report format(s)</th><td>__standard__</td></tr>
|
|
107
|
+
<tr><th>Requester</th><td>__requester__</td></tr>
|
|
108
|
+
<tr><th>Device</th><td>__device__</td></tr>
|
|
109
|
+
<tr><th>Browser type</th><td>__browser__</td></tr>
|
|
110
|
+
<tr><th>Reduced motion</th><td>__motion__</td></tr>
|
|
111
|
+
<tr><th>Tested by</th><td>Testaro__agent__, procedure <code>__ts__</code></td></tr>
|
|
112
|
+
<tr><th>Scored by</th><td>Testilo, procedure <code>__sp__</code></td></tr>
|
|
113
|
+
<tr><th>Digested by</th><td>Testilo, procedure <code>__dp__</code></td></tr>
|
|
114
|
+
<tr>
|
|
115
|
+
<th>Full report</th>
|
|
116
|
+
<td><a href="__reportURL__"><code>__reportURL__</code></a></td>
|
|
117
|
+
</tr>
|
|
118
|
+
</table>
|
|
119
|
+
</header>
|
|
120
|
+
<h2 id="intro">Introduction</h2>
|
|
121
|
+
<p>How <a href="https://www.w3.org/WAI/">accessible</a> is the __org__ web page at <a href="__url__"><code>__url__</code></a>?</p>
|
|
122
|
+
<p>This digest can help answer that question. Ten different tools (Alfa, ASLint, Axe, Editoria11y, Equal Access, HTML CodeSniffer, Nu Html Checker, QualWeb, Testaro, and WAVE) tested the page to check its compliance with their accessibility rules. In all, the tools define about 990 rules, which are classified here into about 310 accessibility issues.</p>
|
|
123
|
+
<p>The results were interpreted to yield a score, with 0 being ideal. The score for this page was __total__, the sum of __issueCount__ for the count of issues, __issue__ for specific issues, __solo__ for unclassified rule violations, __tool__ for tool-by-tool ratings, __element__ for the count of violating elements, __prevention__ for the page preventing tools from running, __log__ for browser warnings, and __latency__ for delayed page responses.</p>
|
|
124
|
+
<details>
|
|
125
|
+
<summary>How the page was scored</summary>
|
|
126
|
+
<h3>Introduction</h3>
|
|
127
|
+
<p>This is an explanation of the scoring of the page.</p>
|
|
128
|
+
<h3>Motivations for scoring</h3>
|
|
129
|
+
<p>Why score? Specifically, why aggregate many facts about a page into a single number?</p>
|
|
130
|
+
<p>One motivation is to simplify comparison and tracking. If you want to compare a page with other pages, or if you want to track changes in a page over time, aggregating many test results for each page into one page score simplifies the task. It becomes possible to say things like <q>Page A is more accessible than page B</q> or <q>Page A is becoming more accessible over time</q>.</p>
|
|
131
|
+
<p>Another motivation is to influence behavior. A score arises from decisions about importance, urgency, and other attributes. People may use scores to award benefits, impose costs, or prioritize work. So, scoring can influence who gets and does what.</p>
|
|
132
|
+
<h3>How to score?</h3>
|
|
133
|
+
<p>Scoring is subjective. Accessibility testing tools use various scoring procedures, based on various ideas.</p>
|
|
134
|
+
<p>The built-in scoring procedures of Testilo are based on the idea that multiple attributes should affect a web-page accessibility score, including:</p>
|
|
135
|
+
<ul>
|
|
136
|
+
<li>conformity to standards</li>
|
|
137
|
+
<li>adherence to best practices</li>
|
|
138
|
+
<li>how many different issues exist</li>
|
|
139
|
+
<li>how many instances of each issue exist</li>
|
|
140
|
+
<li>how many tools report violations of their rules</li>
|
|
141
|
+
<li>how trustworthy each test of each tool is</li>
|
|
142
|
+
<li>how serious each violation of a rule is</li>
|
|
143
|
+
<li>simplicity</li>
|
|
144
|
+
<li>speed of page responses</li>
|
|
145
|
+
<li>testability</li>
|
|
146
|
+
<li>conformity to expectations of browsers</li>
|
|
147
|
+
</ul>
|
|
148
|
+
<p>Some ideas found elsewhere in accessibility scoring are <strong>rejected</strong> by the Testilo procedures:</p>
|
|
149
|
+
<ul>
|
|
150
|
+
<li>density: that an accessibility score should be based on the count of accessibility faults as a fraction of the count of potential accessibility faults (so, the score of a large page with particular faults should be better than the score of a smaller page with exactly those faults)</li>
|
|
151
|
+
<li>applicability: that the score of a page should depend on the types of its content (so, the score of a page with accessible video content should be better than the score of an otherwise identical page without video content)</li>
|
|
152
|
+
</ul>
|
|
153
|
+
<h3>Scoring method summary</h3>
|
|
154
|
+
<p>The scoring method is found in the code of the procedure. The file for any procedure <code>tspnn</code> is in the file <code>procs/score/tspnn.js</code> within the <a href="https://www.npmjs.com/package/testilo?activeTab=code">Testilo package</a>.</p>
|
|
155
|
+
<p>The score computed by this procedure for any page is a non-negative number. The numbers represent accessibility faults, so a higher-scoring page is considered <strong>less</strong> accessible than a lower-scoring page. The best possible score is 0.</p>
|
|
156
|
+
<p>The procedure makes the score of a page the sum of 7 components:</p>
|
|
157
|
+
<ul>
|
|
158
|
+
<li>issue score: how many instances of issues were reported</li>
|
|
159
|
+
<li>solo score: how many violations of rules not yet classified into issues were reported</li>
|
|
160
|
+
<li>tool score: how many violations of their rules did tools report</li>
|
|
161
|
+
<li>element score: how many HTML elements did any tool identify as violating at least one tool rule</li>
|
|
162
|
+
<li>prevention score: how many tools were unable to perform their tests on the page</li>
|
|
163
|
+
<li>log score: how much logging of page errors and other events did the browser do</li>
|
|
164
|
+
<li>latency score: how long did the page take to load and become stable</li>
|
|
165
|
+
</ul>
|
|
166
|
+
<h3>Scoring method details</h3>
|
|
167
|
+
<p>The above component descriptions omit various details.</p>
|
|
168
|
+
<p>About a thousand tool rules are classified into <dfn>issues</dfn> in the <code>tic45.js</code> file used by this procedure. Each of those rules has a <dfn>quality</dfn>, ranging from 0 to 1. When the <strong>issue score</strong> is computed, the count of violations of each rule is multiplied by the quality of that rule. Whichever tool has the largest quality-weighted violation count for an issue, that count is treated as the instance count for the issue. Thus, if 8 tools each report 15 violations within the issue, and their rule qualities are all 1, the instance count is 15, not 120. Moreover, the issue itself has a <dfn>weight</dfn>, ranging from 1 to 4, representing its importance. This instance count is multiplied by that weight. That product is further multiplied by the <code>issueCountWeight</code> value, namely 10. That final product is further adjusted if the issue is inherently limited in instance count. For example, if the issue is that the page <code>html</code> element has no <code>lang</code> attribute, the instance count is limited to 1. If there is such a limit, the <code>maxWeight</code> value, namely 30, is divided by the actual instance count and the quotient is added to 1. That product (or 1 if there is no limit) is multiplied by the instance count, and then the result is treated as the contribution of the issue to the issue score.</p>
|
|
169
|
+
<p>Each <dfn>solo</dfn> (not yet issue-classified) rule violation is multiplied by the sum of 1 and the ordinal severity of the rule, to produce the <strong>solo score</strong>.</p>
|
|
170
|
+
<p>Each rule violation reported by each tool is severity-weighted in the same way as solo rule violations are. Then the sum of those violations is multiplied by the <code>toolWeight</code> value, namely 0.1, to produce the <strong>tool score</strong>.</p>
|
|
171
|
+
<p>The count of elements reported as violators of any rule is multiplied by the <code>elementWeight</code> value, namely 2, to produce the <strong>element score</strong>.</p>
|
|
172
|
+
<p>The count of prevented Testaro rules is multiplied by the <code>testaroRulePreventionWeight</code> quantity, namely 30, and the count of other prevented tools is multiplied by the <code>preventionWeight</code> value, namely 300, to produce the <strong>prevention score</strong>.</p>
|
|
173
|
+
<p>The <strong>log score</strong> is the sum of several components:</p>
|
|
174
|
+
<ul>
|
|
175
|
+
<li>log count: how many times the browser logged a message</li>
|
|
176
|
+
<li>log size: how many characters large the collection of browser log messages was</li>
|
|
177
|
+
<li>error log count: how many browser log messages reported page errors</li>
|
|
178
|
+
<li>error log size: how many characters large the collection of browser log messages reporting page errors was</li>
|
|
179
|
+
<li>prohibition count: how many times the browser logged a prohibited response status (403)</li>
|
|
180
|
+
<li>visit rejection count: how many times the browser logged an abnormal response status</li>
|
|
181
|
+
</ul>
|
|
182
|
+
<p>Each of these components is multiplied by a weight found in the <code>logWeights</code> object.</p>
|
|
183
|
+
<p>Finally, the <strong>latency score</strong> is based on how much longer it took for the page to become loaded and stable than expected. The expected total duration in seconds is the <code>normalLatency</code> value, namely 22 seconds (that is 2 seconds per visit, multiplied by the 11 visits of the 11 tools). This is subtracted from the actual total latency, and that difference is multiplied by the <code>latencyWeight</code> amount, namely 2.</p>
|
|
184
|
+
</details>
|
|
185
|
+
<h2 id="summary">Issue summary</h2>
|
|
186
|
+
<h3>Details about this summary</h3>
|
|
187
|
+
<ul>
|
|
188
|
+
<li>This table shows the numbers of rule violations (<q>instances</q>) reported by one or more tools, classified by issue.</li>
|
|
189
|
+
<li>Tools often disagree on instance counts, because of non-equivalent rules or invalid tests. You can inspect the <a href="__reportURL__">full report</a> to diagnose differences.</li>
|
|
190
|
+
<li>The <q>WCAG</q> value is the principle, guideline, or success criterion of the <a href="https://www.w3.org/TR/WCAG22/">Web Content Accessibility Guidelines</a> most relevant to the issue.</li>
|
|
191
|
+
<li>The <q>Weight</q> value estimates the importance of an instance of the issue, from 1 (minor or advisory) to 4 (serious).</li>
|
|
192
|
+
<li>The <q>Score</q> value is the contribution of the instances of the issue to the page score.</li>
|
|
193
|
+
<li>An instance count of 0 means the tool has a rule belonging to the issue but reported no violations of that rule, although at least one tool reported at least one violation.</li>
|
|
194
|
+
<li>You can sort this table by WCAG, weight, or score.</li>
|
|
195
|
+
</ul>
|
|
196
|
+
<h3>The summary</h3>
|
|
197
|
+
<p role="status">Sorting is by <span id="sortBasis">score</span>.</p>
|
|
198
|
+
<p id="sortButtons">
|
|
199
|
+
<button id="sortButtonA" type="button">Sort by <span id="sortBasisA">WCAG</span></button>
|
|
200
|
+
<button id="sortButtonB" type="button">Sort by <span id="sortBasisB">weight</span></button>
|
|
201
|
+
</p>
|
|
202
|
+
<table class="allBorder thirdCellRight">
|
|
203
|
+
<caption>How many violations each tool reported, by issue</caption>
|
|
204
|
+
<thead>
|
|
205
|
+
<tr><th>Issue</th><th>WCAG</th><th>Weight</th><th>Score</th><th>Instance counts</th></tr>
|
|
206
|
+
</thead>
|
|
207
|
+
<tbody id="sumBody" class="headersLeft">
|
|
208
|
+
__issueRows__
|
|
209
|
+
</tbody>
|
|
210
|
+
</table>
|
|
211
|
+
<h2 id="itemization">Itemized issues</h2>
|
|
212
|
+
<p>The reported rule violations are itemized below, issue by issue. Additional details can be inspected in the <a href="__reportURL__">full report</a>.</p>
|
|
213
|
+
__issueDetailRows__
|
|
214
|
+
<h2 id="elements">Elements with issues</h2>
|
|
215
|
+
<p>Elements exhibiting issues:</p>
|
|
216
|
+
__elementRows__
|
|
217
|
+
<footer>
|
|
218
|
+
<p class="date">Produced <time itemprop="datePublished" datetime="__dateISO__">__dateSlash__</time></p>
|
|
219
|
+
</footer>
|
|
220
|
+
</main>
|
|
221
|
+
</body>
|
|
222
|
+
</html>
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/*
|
|
2
|
+
© 2024 CVS Health and/or one of its affiliates. All rights reserved.
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// index: digester for scoring procedure tsp43.
|
|
24
|
+
|
|
25
|
+
// IMPORTS
|
|
26
|
+
|
|
27
|
+
// Module to keep secrets.
|
|
28
|
+
require('dotenv').config();
|
|
29
|
+
// Module to classify tool rules into issues
|
|
30
|
+
const {issues} = require('../../score/tic45');
|
|
31
|
+
// Module to process files.
|
|
32
|
+
const fs = require('fs/promises');
|
|
33
|
+
// Utility module.
|
|
34
|
+
const {getNowDate, getNowDateSlash} = require('../../util');
|
|
35
|
+
|
|
36
|
+
// CONSTANTS
|
|
37
|
+
|
|
38
|
+
// Digester ID.
|
|
39
|
+
const digesterID = 'tdp48';
|
|
40
|
+
// Newline with indentations.
|
|
41
|
+
const innerJoiner = '\n ';
|
|
42
|
+
const outerJoiner = '\n ';
|
|
43
|
+
// Directory of WCAG links.
|
|
44
|
+
const wcagPhrases = {};
|
|
45
|
+
|
|
46
|
+
// FUNCTIONS
|
|
47
|
+
|
|
48
|
+
// Gets a row of the score-summary table.
|
|
49
|
+
const getScoreRow = (componentName, score) => `<tr><th>${componentName}</th><td>${score}</td></tr>`;
|
|
50
|
+
// Gets a WCAG link or, if not obtainable, a numeric identifier.
|
|
51
|
+
const getWCAGTerm = wcag => {
|
|
52
|
+
const wcagPhrase = wcagPhrases[wcag];
|
|
53
|
+
const wcagTerm = wcagPhrase
|
|
54
|
+
? `<a href="https://www.w3.org/WAI/WCAG22/Understanding/${wcagPhrase}.html">${wcag}</a>`
|
|
55
|
+
: wcag;
|
|
56
|
+
return wcagTerm;
|
|
57
|
+
};
|
|
58
|
+
// Gets a row of the issue-score-summary table.
|
|
59
|
+
const getIssueScoreRow = (issueConstants, issueDetails) => {
|
|
60
|
+
const {summary, wcag, weight} = issueConstants;
|
|
61
|
+
const wcagTerm = getWCAGTerm(wcag);
|
|
62
|
+
const {instanceCounts, score} = issueDetails;
|
|
63
|
+
const toolList = Object
|
|
64
|
+
.keys(instanceCounts)
|
|
65
|
+
.map(tool => `<code>${tool}</code>:${instanceCounts[tool]}`)
|
|
66
|
+
.join(', ');
|
|
67
|
+
return `<tr><th>${summary}</th><td class="center">${wcagTerm}<td class="right num">${weight}</td><td class="right num">${score}</td><td>${toolList}</td></tr>`;
|
|
68
|
+
};
|
|
69
|
+
// Populates the directory of WCAG understanding verbal IDs.
|
|
70
|
+
const getWCAGPhrases = async () => {
|
|
71
|
+
// Get the copy of file https://raw.githubusercontent.com/w3c/wcag/main/guidelines/wcag.json.
|
|
72
|
+
const wcagJSON = await fs.readFile(`${__dirname}/../../../wcag.json`, 'utf8');
|
|
73
|
+
const wcag = JSON.parse(wcagJSON);
|
|
74
|
+
const {principles} = wcag;
|
|
75
|
+
// For each principle in it:
|
|
76
|
+
principles.forEach(principle => {
|
|
77
|
+
// If it is usable:
|
|
78
|
+
if (principle.num && principle.id && principle.id.startsWith('WCAG2:')) {
|
|
79
|
+
// Add it to the directory.
|
|
80
|
+
wcagPhrases[principle.num] = principle.id.slice(6);
|
|
81
|
+
const {guidelines} = principle;
|
|
82
|
+
// For each guideline in the principle:
|
|
83
|
+
guidelines.forEach(guideline => {
|
|
84
|
+
// If it is usable:
|
|
85
|
+
if (guideline.num && guideline.id && guideline.id.startsWith('WCAG2:')) {
|
|
86
|
+
// Add it to the directory.
|
|
87
|
+
wcagPhrases[guideline.num] = guideline.id.slice(6);
|
|
88
|
+
const {successcriteria} = guideline;
|
|
89
|
+
// For each success criterion in the guideline:
|
|
90
|
+
successcriteria.forEach(successCriterion => {
|
|
91
|
+
// If it is usable:
|
|
92
|
+
if (
|
|
93
|
+
successCriterion.num
|
|
94
|
+
&& successCriterion.id
|
|
95
|
+
&& successCriterion.id.startsWith('WCAG2:')
|
|
96
|
+
) {
|
|
97
|
+
// Add it to the directory.
|
|
98
|
+
wcagPhrases[successCriterion.num] = successCriterion.id.slice(6);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
// Adds parameters to a query for a digest.
|
|
107
|
+
const populateQuery = async (report, query) => {
|
|
108
|
+
const {
|
|
109
|
+
browserID, device, id, isolate, lowMotion, score, sources, standard, strict, target
|
|
110
|
+
} = report;
|
|
111
|
+
const {agent, requester, script} = sources;
|
|
112
|
+
const {scoreProcID, summary, details} = score;
|
|
113
|
+
query.ts = script;
|
|
114
|
+
query.sp = scoreProcID;
|
|
115
|
+
query.dp = digesterID;
|
|
116
|
+
// Add the job data to the query.
|
|
117
|
+
query.dateISO = getNowDate();
|
|
118
|
+
query.dateSlash = getNowDateSlash();
|
|
119
|
+
query.org = target.what;
|
|
120
|
+
query.url = target.url;
|
|
121
|
+
query.redirections = strict ? 'prohibited' : 'permitted';
|
|
122
|
+
query.isolation = isolate ? 'yes' : 'no';
|
|
123
|
+
query.standard
|
|
124
|
+
= ['original', 'standard', 'original and standard'][['no', 'only', 'also'].indexOf(standard)];
|
|
125
|
+
query.motion = lowMotion ? 'requested' : 'not requested';
|
|
126
|
+
query.requester = requester;
|
|
127
|
+
query.device = device.id;
|
|
128
|
+
query.browser = browserID;
|
|
129
|
+
query.agent = agent ? ` on agent ${agent}` : '';
|
|
130
|
+
query.reportURL = process.env.SCORED_REPORT_URL.replace('__id__', id);
|
|
131
|
+
// Populate the WCAG phrase directory.
|
|
132
|
+
await getWCAGPhrases();
|
|
133
|
+
// Add values for the score-summary table to the query.
|
|
134
|
+
const rows = {
|
|
135
|
+
summaryRows: [],
|
|
136
|
+
issueRows: []
|
|
137
|
+
};
|
|
138
|
+
['total', 'issueCount', 'issue', 'solo', 'tool', 'element', 'prevention', 'log', 'latency']
|
|
139
|
+
.forEach(sumItem => {
|
|
140
|
+
query[sumItem] = summary[sumItem];
|
|
141
|
+
rows.summaryRows.push(getScoreRow(sumItem, query[sumItem]));
|
|
142
|
+
});
|
|
143
|
+
// Sort the issue IDs in descending score order.
|
|
144
|
+
const issueIDs = Object.keys(details.issue);
|
|
145
|
+
issueIDs.sort((a, b) => details.issue[b].score - details.issue[a].score);
|
|
146
|
+
// Get rows for the issue-score table.
|
|
147
|
+
issueIDs.forEach(issueID => {
|
|
148
|
+
if (issues[issueID]) {
|
|
149
|
+
rows.issueRows.push(getIssueScoreRow(issues[issueID], details.issue[issueID]));
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
console.log(`ERROR: Issue ${issueID} not found`);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
// Add the rows to the query.
|
|
156
|
+
['summaryRows', 'issueRows'].forEach(rowType => {
|
|
157
|
+
query[rowType] = rows[rowType].join(innerJoiner);
|
|
158
|
+
});
|
|
159
|
+
// Add paragraph groups about the issue details to the query.
|
|
160
|
+
const issueDetailRows = [];
|
|
161
|
+
issueIDs.forEach(issueID => {
|
|
162
|
+
const issueSummary = issues[issueID].summary;
|
|
163
|
+
issueDetailRows.push(`<h3 class="bars">Issue: ${issueSummary}</h3>`);
|
|
164
|
+
issueDetailRows.push(`<p>Impact: ${issues[issueID].why || 'N/A'}</p>`);
|
|
165
|
+
const wcag = issues[issueID].wcag;
|
|
166
|
+
const wcagTerm = wcag ? getWCAGTerm(wcag) : 'N/A';
|
|
167
|
+
issueDetailRows.push(`<p>WCAG: ${wcagTerm}</p>`);
|
|
168
|
+
const issueData = details.issue[issueID];
|
|
169
|
+
issueDetailRows.push(`<p>Score: ${issueData.score}</p>`);
|
|
170
|
+
issueDetailRows.push('<h4>Elements</h4>');
|
|
171
|
+
const issuePaths = details.element[issueID];
|
|
172
|
+
if (issuePaths.length) {
|
|
173
|
+
issueDetailRows.push('<ul>');
|
|
174
|
+
issuePaths.forEach(pathID => {
|
|
175
|
+
issueDetailRows.push(` <li>${pathID}</li>`);
|
|
176
|
+
});
|
|
177
|
+
issueDetailRows.push('</ul>');
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
issueDetailRows.push('<p>None identified</p>');
|
|
181
|
+
}
|
|
182
|
+
const toolIDs = Object.keys(issueData.tools);
|
|
183
|
+
toolIDs.forEach(toolID => {
|
|
184
|
+
issueDetailRows.push(`<h4>Violations of <code>${toolID}</code> rules</h4>`);
|
|
185
|
+
const ruleIDs = Object.keys(issueData.tools[toolID]);
|
|
186
|
+
ruleIDs.forEach(ruleID => {
|
|
187
|
+
const ruleData = issueData.tools[toolID][ruleID];
|
|
188
|
+
issueDetailRows.push(`<h5>Rule <code>${ruleID}</code></h5>`);
|
|
189
|
+
issueDetailRows.push(`<p>Description: ${ruleData.what}</p>`);
|
|
190
|
+
issueDetailRows.push(`<p>Count of instances: ${ruleData.complaints.countTotal}</p>`);
|
|
191
|
+
/*
|
|
192
|
+
This fails unless the caller handles such URLs and has compatible scored report URLs.
|
|
193
|
+
const href = `${query.reportURL}?tool=${toolID}&rule=${ruleID}`;
|
|
194
|
+
const detailLabel = `Issue ${issueSummary} tool ${toolID} rule ${ruleID} instance details`;
|
|
195
|
+
issueDetailRows.push(
|
|
196
|
+
`<p><a href="${href}" aria-label="${detailLabel}">Instance details</a></p>`
|
|
197
|
+
);
|
|
198
|
+
*/
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
query.issueDetailRows = issueDetailRows.join(outerJoiner);
|
|
203
|
+
// Add paragraphs about the elements to the query.
|
|
204
|
+
const elementRows = [];
|
|
205
|
+
const issueElements = {};
|
|
206
|
+
Object.keys(details.element).forEach(issueID => {
|
|
207
|
+
const pathIDs = details.element[issueID];
|
|
208
|
+
pathIDs.forEach(pathID => {
|
|
209
|
+
issueElements[pathID] ??= [];
|
|
210
|
+
issueElements[pathID].push(issueID);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
const sortedPathIDs = Object.keys(issueElements).sort();
|
|
214
|
+
sortedPathIDs.forEach(pathID => {
|
|
215
|
+
const elementIssues = issueElements[pathID];
|
|
216
|
+
if (elementIssues) {
|
|
217
|
+
elementRows.push(
|
|
218
|
+
`<h5>Element <code>${pathID}</code></h5>`,
|
|
219
|
+
'<ul>',
|
|
220
|
+
... elementIssues.map(issueID => ` <li>${issues[issueID].summary}</li>`).sort(),
|
|
221
|
+
'</ul>'
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
query.elementRows = elementRows.join(outerJoiner);
|
|
226
|
+
};
|
|
227
|
+
// Returns a digested report.
|
|
228
|
+
exports.digester = async report => {
|
|
229
|
+
// Create a query to replace placeholders.
|
|
230
|
+
const query = {};
|
|
231
|
+
await populateQuery(report, query);
|
|
232
|
+
// Get the template.
|
|
233
|
+
let template = await fs.readFile(`${__dirname}/index.html`, 'utf8');
|
|
234
|
+
// Replace its placeholders.
|
|
235
|
+
Object.keys(query).forEach(param => {
|
|
236
|
+
template = template.replace(new RegExp(`__${param}__`, 'g'), query[param]);
|
|
237
|
+
});
|
|
238
|
+
// Return the digest.
|
|
239
|
+
return template;
|
|
240
|
+
};
|
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
/*
|
|
2
|
+
© 2024 CVS Health and/or one of its affiliates. All rights reserved.
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
tsp46
|
|
25
|
+
Testilo score proc 46
|
|
26
|
+
|
|
27
|
+
Computes target score data and adds them to a Testaro report.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
// IMPORTS
|
|
31
|
+
|
|
32
|
+
const {issues} = require('./tic45');
|
|
33
|
+
|
|
34
|
+
// MISCELLANEOUS CONSTANTS
|
|
35
|
+
|
|
36
|
+
// ID of this proc.
|
|
37
|
+
const scoreProcID = 'tsp46';
|
|
38
|
+
|
|
39
|
+
// WEIGHT CONSTANTS
|
|
40
|
+
// How much is added to the page score by each component.
|
|
41
|
+
|
|
42
|
+
// 1. Issue
|
|
43
|
+
// Each issue.
|
|
44
|
+
const issueCountWeight = 10;
|
|
45
|
+
/*
|
|
46
|
+
Expander of instance counts for issues with inherently limited instance counts. Divide this by
|
|
47
|
+
the maximum possible instance count and add the quotient to 1, then multiply the sum by the actual
|
|
48
|
+
instance count, i.e. the largest rule-quality-weighted instance count among the tools with any
|
|
49
|
+
instances of the issue.
|
|
50
|
+
*/
|
|
51
|
+
const maxWeight = 30;
|
|
52
|
+
|
|
53
|
+
// 2. Solo
|
|
54
|
+
|
|
55
|
+
// 3. Tool
|
|
56
|
+
/*
|
|
57
|
+
Severity: amount added to each raw tool score by each violation of a rule with ordinal severity 0
|
|
58
|
+
through 3.
|
|
59
|
+
*/
|
|
60
|
+
const severityWeights = [1, 2, 3, 4];
|
|
61
|
+
// Final: multiplier of the raw tool score to obtain the final tool score.
|
|
62
|
+
const toolWeight = 0.1;
|
|
63
|
+
|
|
64
|
+
// 4. Element
|
|
65
|
+
// Multiplier of the count of elements with at least 1 rule violation.
|
|
66
|
+
const elementWeight = 2;
|
|
67
|
+
|
|
68
|
+
// 5. Prevention
|
|
69
|
+
// Each tool prevention by the page.
|
|
70
|
+
const preventionWeight = 300;
|
|
71
|
+
// Each prevention of a Testaro rule test by the page.
|
|
72
|
+
const testaroRulePreventionWeight = 30;
|
|
73
|
+
|
|
74
|
+
// 6. Log
|
|
75
|
+
// Multipliers of log values to obtain the log score.
|
|
76
|
+
const logWeights = {
|
|
77
|
+
logCount: 0.1,
|
|
78
|
+
logSize: 0.002,
|
|
79
|
+
errorLogCount: 0.2,
|
|
80
|
+
errorLogSize: 0.004,
|
|
81
|
+
prohibitedCount: 3,
|
|
82
|
+
visitRejectionCount: 2
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// 7. Latency
|
|
86
|
+
// Normal latency (11 visits [1 per tool], with 2 seconds per visit).
|
|
87
|
+
const normalLatency = 22;
|
|
88
|
+
// Total latency exceeding normal, in seconds.
|
|
89
|
+
const latencyWeight = 2;
|
|
90
|
+
|
|
91
|
+
// RULE CONSTANTS
|
|
92
|
+
|
|
93
|
+
// Initialize a table of tool rules.
|
|
94
|
+
const issueIndex = {};
|
|
95
|
+
// Initialize an array of variably named tool rules.
|
|
96
|
+
const issueMatcher = [];
|
|
97
|
+
// For each issue:
|
|
98
|
+
Object.keys(issues).forEach(issueName => {
|
|
99
|
+
// For each tool with rules belonging to that issue:
|
|
100
|
+
Object.keys(issues[issueName].tools).forEach(toolName => {
|
|
101
|
+
// For each of those rules:
|
|
102
|
+
Object.keys(issues[issueName].tools[toolName]).forEach(ruleID => {
|
|
103
|
+
// Add it to the table of tool rules.
|
|
104
|
+
if (! issueIndex[toolName]) {
|
|
105
|
+
issueIndex[toolName] = {};
|
|
106
|
+
}
|
|
107
|
+
issueIndex[toolName][ruleID] = issueName;
|
|
108
|
+
// If it is variably named:
|
|
109
|
+
if (issues[issueName].tools[toolName][ruleID].variable) {
|
|
110
|
+
// Add it to the array of variably named tool rules.
|
|
111
|
+
issueMatcher.push(ruleID);
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// FUNCTIONS
|
|
118
|
+
|
|
119
|
+
// Scores a report.
|
|
120
|
+
exports.scorer = report => {
|
|
121
|
+
// If there are any acts in the report:
|
|
122
|
+
const {acts} = report;
|
|
123
|
+
if (Array.isArray(acts) && acts.length) {
|
|
124
|
+
// If any of them are test acts:
|
|
125
|
+
const testActs = acts.filter(act => act.type === 'test');
|
|
126
|
+
const testTools = new Set(testActs.map(act => act.which));
|
|
127
|
+
if (testActs.length) {
|
|
128
|
+
// Initialize the score data.
|
|
129
|
+
const score = {
|
|
130
|
+
scoreProcID,
|
|
131
|
+
weights: {
|
|
132
|
+
severities: severityWeights,
|
|
133
|
+
tool: toolWeight,
|
|
134
|
+
element: elementWeight,
|
|
135
|
+
log: logWeights,
|
|
136
|
+
latency: latencyWeight,
|
|
137
|
+
prevention: preventionWeight,
|
|
138
|
+
testaroRulePrevention: testaroRulePreventionWeight,
|
|
139
|
+
maxInstanceCount: maxWeight
|
|
140
|
+
},
|
|
141
|
+
normalLatency,
|
|
142
|
+
summary: {
|
|
143
|
+
total: 0,
|
|
144
|
+
issueCount: 0,
|
|
145
|
+
issue: 0,
|
|
146
|
+
solo: 0,
|
|
147
|
+
tool: 0,
|
|
148
|
+
element: 0,
|
|
149
|
+
prevention: 0,
|
|
150
|
+
log: 0,
|
|
151
|
+
latency: 0
|
|
152
|
+
},
|
|
153
|
+
details: {
|
|
154
|
+
severity: {
|
|
155
|
+
total: [0, 0, 0, 0],
|
|
156
|
+
byTool: {}
|
|
157
|
+
},
|
|
158
|
+
prevention: {},
|
|
159
|
+
issue: {},
|
|
160
|
+
solo: {},
|
|
161
|
+
tool: {},
|
|
162
|
+
element: {}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
// Initialize the global and issue-specific sets of path-identified elements.
|
|
166
|
+
const pathIDs = new Set();
|
|
167
|
+
const issuePaths = {};
|
|
168
|
+
const {summary, details} = score;
|
|
169
|
+
// For each test act:
|
|
170
|
+
testActs.forEach(act => {
|
|
171
|
+
const {data, which, standardResult} = act;
|
|
172
|
+
// If the tool is Testaro and the count of rule preventions was reported:
|
|
173
|
+
if (which === 'testaro' && data && data.rulePreventions) {
|
|
174
|
+
// Add their score to the score.
|
|
175
|
+
details.prevention.testaro = testaroRulePreventionWeight * data.rulePreventions.length;
|
|
176
|
+
}
|
|
177
|
+
// If the page prevented the tool from operating:
|
|
178
|
+
if (! standardResult || standardResult.prevented) {
|
|
179
|
+
// Add this to the score.
|
|
180
|
+
details.prevention[which] = preventionWeight;
|
|
181
|
+
}
|
|
182
|
+
// Otherwise, if a valid standard result exists:
|
|
183
|
+
else if (
|
|
184
|
+
standardResult
|
|
185
|
+
&& standardResult.totals
|
|
186
|
+
&& standardResult.totals.length === 4
|
|
187
|
+
&& standardResult.instances
|
|
188
|
+
) {
|
|
189
|
+
// Add the severity totals of the tool to the score.
|
|
190
|
+
const {totals} = standardResult;
|
|
191
|
+
details.severity.byTool[which] = totals;
|
|
192
|
+
// Add the severity-weighted tool totals to the score.
|
|
193
|
+
details.tool[which] = totals.reduce(
|
|
194
|
+
(sum, current, index) => sum + severityWeights[index] * current, 0
|
|
195
|
+
);
|
|
196
|
+
// For each instance of the tool:
|
|
197
|
+
standardResult.instances.forEach(instance => {
|
|
198
|
+
const {count, ordinalSeverity, pathID, ruleID, what} = instance;
|
|
199
|
+
count ??= 1;
|
|
200
|
+
// If the rule ID is not in the table of tool rules:
|
|
201
|
+
let canonicalRuleID = ruleID;
|
|
202
|
+
if (! issueIndex[which][ruleID]) {
|
|
203
|
+
// Convert it to the variably named tool rule that it matches, if any.
|
|
204
|
+
canonicalRuleID = issueMatcher.find(pattern => {
|
|
205
|
+
const patternRE = new RegExp(pattern);
|
|
206
|
+
return patternRE.test(ruleID);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
// If the rule has an ID:
|
|
210
|
+
if (canonicalRuleID) {
|
|
211
|
+
// Get the issue of the rule.
|
|
212
|
+
const issueName = issueIndex[which][canonicalRuleID];
|
|
213
|
+
// If the rule ID belongs to a non-ignorable issue:
|
|
214
|
+
if (issueName !== 'ignorable') {
|
|
215
|
+
// Add the instance to the issue details of the score data.
|
|
216
|
+
if (! details.issue[issueName]) {
|
|
217
|
+
details.issue[issueName] = {
|
|
218
|
+
summary: issues[issueName].summary,
|
|
219
|
+
wcag: issues[issueName].wcag || '',
|
|
220
|
+
score: 0,
|
|
221
|
+
maxCount: 0,
|
|
222
|
+
weight: issues[issueName].weight,
|
|
223
|
+
countLimit: issues[issueName].max,
|
|
224
|
+
instanceCounts: {},
|
|
225
|
+
tools: {}
|
|
226
|
+
};
|
|
227
|
+
if (! details.issue[issueName].countLimit) {
|
|
228
|
+
delete details.issue[issueName].countLimit;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (! details.issue[issueName].tools[which]) {
|
|
232
|
+
details.issue[issueName].tools[which] = {};
|
|
233
|
+
}
|
|
234
|
+
if (! details.issue[issueName].instanceCounts[which]) {
|
|
235
|
+
details.issue[issueName].instanceCounts[which] = 0;
|
|
236
|
+
}
|
|
237
|
+
details.issue[issueName].instanceCounts[which] += count;
|
|
238
|
+
if (! details.issue[issueName].tools[which][canonicalRuleID]) {
|
|
239
|
+
const ruleData = issues[issueName].tools[which][canonicalRuleID];
|
|
240
|
+
details.issue[issueName].tools[which][canonicalRuleID] = {
|
|
241
|
+
quality: ruleData.quality,
|
|
242
|
+
what: ruleData.what,
|
|
243
|
+
complaints: {
|
|
244
|
+
countTotal: 0,
|
|
245
|
+
texts: []
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
details
|
|
250
|
+
.issue[issueName]
|
|
251
|
+
.tools[which][canonicalRuleID]
|
|
252
|
+
.complaints
|
|
253
|
+
.countTotal += count || 1;
|
|
254
|
+
if (
|
|
255
|
+
! details
|
|
256
|
+
.issue[issueName]
|
|
257
|
+
.tools[which][canonicalRuleID]
|
|
258
|
+
.complaints
|
|
259
|
+
.texts
|
|
260
|
+
.includes(what)
|
|
261
|
+
) {
|
|
262
|
+
details
|
|
263
|
+
.issue[issueName]
|
|
264
|
+
.tools[which][canonicalRuleID]
|
|
265
|
+
.complaints
|
|
266
|
+
.texts
|
|
267
|
+
.push(what);
|
|
268
|
+
}
|
|
269
|
+
issuePaths[issueName] ??= new Set();
|
|
270
|
+
// If the element has a path ID:
|
|
271
|
+
if (pathID) {
|
|
272
|
+
// Ensure that it is in the issue-specific set of paths.
|
|
273
|
+
issuePaths[issueName].add(pathID);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// Otherwise, i.e. if the rule ID belongs to no issue:
|
|
278
|
+
else {
|
|
279
|
+
// Add the instance to the solo details of the score data.
|
|
280
|
+
if (! details.solo[which]) {
|
|
281
|
+
details.solo[which] = {};
|
|
282
|
+
}
|
|
283
|
+
if (! details.solo[which][ruleID]) {
|
|
284
|
+
details.solo[which][ruleID] = 0;
|
|
285
|
+
}
|
|
286
|
+
details.solo[which][ruleID] += (count || 1) * (ordinalSeverity + 1);
|
|
287
|
+
// Report this.
|
|
288
|
+
console.log(`ERROR: ${ruleID} of ${which} not found in issues`);
|
|
289
|
+
}
|
|
290
|
+
// Ensure that the element, if path-identified, is in the set of elements.
|
|
291
|
+
if (pathID) {
|
|
292
|
+
pathIDs.add(pathID);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
// Otherwise, i.e. if a failed standard result exists:
|
|
297
|
+
else {
|
|
298
|
+
// Add an inferred prevention to the score.
|
|
299
|
+
details.prevention[which] = preventionWeight;
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
// For each non-ignorable issue with any complaints:
|
|
303
|
+
Object.keys(details.issue).forEach(issueName => {
|
|
304
|
+
const issueData = details.issue[issueName];
|
|
305
|
+
// For each tool with any complaints for the issue:
|
|
306
|
+
Object.keys(issueData.tools).forEach(toolID => {
|
|
307
|
+
// Get the sum of the quality-weighted counts of its issue rules.
|
|
308
|
+
let weightedCount = 0;
|
|
309
|
+
Object.values(issueData.tools[toolID]).forEach(ruleData => {
|
|
310
|
+
weightedCount += ruleData.quality * ruleData.complaints.countTotal;
|
|
311
|
+
});
|
|
312
|
+
// If the sum exceeds the existing maximum weighted count for the issue:
|
|
313
|
+
if (weightedCount > issueData.maxCount) {
|
|
314
|
+
// Change the maximum count for the issue to the sum.
|
|
315
|
+
issueData.maxCount = weightedCount;
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
// Get the score for the issue, including any addition for the instance count limit.
|
|
319
|
+
const maxAddition = issueData.countLimit ? maxWeight / issueData.countLimit : 0;
|
|
320
|
+
issueData.score = Math.round(issueData.weight * issueData.maxCount * (1 + maxAddition));
|
|
321
|
+
// For each tool that has any rule of the issue:
|
|
322
|
+
Object.keys(issues[issueName].tools).forEach(toolName => {
|
|
323
|
+
// If the tool was in the job and has no instances of the issue:
|
|
324
|
+
if (testTools.has(toolName) && ! issueData.instanceCounts[toolName]) {
|
|
325
|
+
// Report its instance count as 0.
|
|
326
|
+
issueData.instanceCounts[toolName] = 0;
|
|
327
|
+
}
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
// Add the severity detail totals to the score.
|
|
331
|
+
details.severity.total = Object
|
|
332
|
+
.keys(details.severity.byTool)
|
|
333
|
+
.reduce((severityTotals, toolID) => {
|
|
334
|
+
details.severity.byTool[toolID].forEach((severityScore, index) => {
|
|
335
|
+
severityTotals[index] += severityScore;
|
|
336
|
+
});
|
|
337
|
+
return severityTotals;
|
|
338
|
+
}, details.severity.total);
|
|
339
|
+
// Add the element details to the score.
|
|
340
|
+
Object.keys(issuePaths).forEach(issueID => {
|
|
341
|
+
details.element[issueID] = Array.from(issuePaths[issueID]);
|
|
342
|
+
});
|
|
343
|
+
// Add the summary issue-count total to the score.
|
|
344
|
+
summary.issueCount = Object.keys(details.issue).length * issueCountWeight;
|
|
345
|
+
// Add the summary issue total to the score.
|
|
346
|
+
summary.issue = Object
|
|
347
|
+
.values(details.issue)
|
|
348
|
+
.reduce((total, current) => total + current.score, 0);
|
|
349
|
+
// Add the summary solo total to the score.
|
|
350
|
+
Object.keys(details.solo).forEach(tool => {
|
|
351
|
+
summary.solo += Object
|
|
352
|
+
.values(details.solo[tool])
|
|
353
|
+
.reduce((total, current) => total + current);
|
|
354
|
+
});
|
|
355
|
+
// Add the summary tool total to the score.
|
|
356
|
+
summary.tool = toolWeight * details.severity.total.reduce(
|
|
357
|
+
(total, current, index) => total + severityWeights[index] * current, 0
|
|
358
|
+
);
|
|
359
|
+
// Get the minimum count of violating elements.
|
|
360
|
+
const actRuleIDs = testActs.filter(act => act.standardResult).map(
|
|
361
|
+
act => act.standardResult.instances.map(instance => `${act.which}:${instance.ruleID}`)
|
|
362
|
+
);
|
|
363
|
+
const allRuleIDs = actRuleIDs.flat();
|
|
364
|
+
const ruleCounts = Array
|
|
365
|
+
.from(new Set(allRuleIDs))
|
|
366
|
+
.map(ruleID => allRuleIDs.filter(id => id === ruleID).length);
|
|
367
|
+
/*
|
|
368
|
+
Add the summary element total to the score, based on the count of identified violating
|
|
369
|
+
elements or the largest count of instances of violations of any rule, whichever is
|
|
370
|
+
greater.
|
|
371
|
+
*/
|
|
372
|
+
summary.element = elementWeight * Math.max(pathIDs.size, ... ruleCounts);
|
|
373
|
+
// Add the summary prevention total to the score.
|
|
374
|
+
summary.prevention = Object.values(details.prevention).reduce(
|
|
375
|
+
(total, current) => total + current, 0
|
|
376
|
+
);
|
|
377
|
+
// Add the summary log score to the score.
|
|
378
|
+
const {jobData} = report;
|
|
379
|
+
if (jobData) {
|
|
380
|
+
summary.log = Math.max(0, Math.round(
|
|
381
|
+
logWeights.logCount * jobData.logCount
|
|
382
|
+
+ logWeights.logSize * jobData.logSize +
|
|
383
|
+
+ logWeights.errorLogCount * jobData.errorLogCount
|
|
384
|
+
+ logWeights.errorLogSize * jobData.errorLogSize
|
|
385
|
+
+ logWeights.prohibitedCount * jobData.prohibitedCount +
|
|
386
|
+
+ logWeights.visitRejectionCount * jobData.visitRejectionCount
|
|
387
|
+
));
|
|
388
|
+
// Add the summary latency score to the score.
|
|
389
|
+
summary.latency = Math.round(
|
|
390
|
+
latencyWeight * (Math.max(0, jobData.visitLatency - normalLatency))
|
|
391
|
+
);
|
|
392
|
+
}
|
|
393
|
+
// Round the unrounded scores.
|
|
394
|
+
Object.keys(summary).forEach(summaryTypeName => {
|
|
395
|
+
summary[summaryTypeName] = Math.round(summary[summaryTypeName]);
|
|
396
|
+
});
|
|
397
|
+
details.severity.total.forEach((severityTotal, index) => {
|
|
398
|
+
details.severity.total[index] = Math.round(severityTotal);
|
|
399
|
+
});
|
|
400
|
+
// Add the summary total score to the score.
|
|
401
|
+
summary.total = summary.issueCount
|
|
402
|
+
+ summary.issue
|
|
403
|
+
+ summary.solo
|
|
404
|
+
+ summary.tool
|
|
405
|
+
+ summary.element
|
|
406
|
+
+ summary.prevention
|
|
407
|
+
+ summary.log
|
|
408
|
+
+ summary.latency;
|
|
409
|
+
// Add the score to the report or replace the existing score of the report.
|
|
410
|
+
report.score = score;
|
|
411
|
+
}
|
|
412
|
+
// Otherwise, i.e. if none of them is a test act:
|
|
413
|
+
else {
|
|
414
|
+
// Report this.
|
|
415
|
+
console.log('ERROR: No test acts');
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
// Otherwise, i.e. if there are no acts in the report:
|
|
419
|
+
else {
|
|
420
|
+
// Report this.
|
|
421
|
+
console.log('ERROR: No acts');
|
|
422
|
+
}
|
|
423
|
+
};
|