testilo 43.0.1 → 43.0.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": "testilo",
3
- "version": "43.0.1",
3
+ "version": "43.0.2",
4
4
  "description": "Prepares Testaro jobs and processes Testaro reports",
5
5
  "main": "call.js",
6
6
  "scripts": {
@@ -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 gives one answer to that question. Eleven different tools (Alfa, ASLint, Axe, Editoria11y, Equal Access, HTML CodeSniffer, Nu Html Checker, QualWeb, Testaro, WAVE, and WallyAX) tested the page to check its compliance with their accessibility rules. In all, the tools define about a thousand rules, which are classified here into about three hundred 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>tic50.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,241 @@
1
+ /*
2
+ © 2024 CVS Health and/or one of its affiliates. All rights reserved.
3
+ © 2025 Jonathan Robert Pool. All rights reserved.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+ */
23
+
24
+ // index: digester for scoring procedure tsp.
25
+
26
+ // IMPORTS
27
+
28
+ // Module to keep secrets.
29
+ require('dotenv').config();
30
+ // Module to classify tool rules into issues
31
+ const {issues} = require('../../score/tic');
32
+ // Module to process files.
33
+ const fs = require('fs/promises');
34
+ // Utility module.
35
+ const {getNowDate, getNowDateSlash} = require('../../util');
36
+
37
+ // CONSTANTS
38
+
39
+ // Digester ID.
40
+ const digesterID = 'tdp';
41
+ // Newline with indentations.
42
+ const innerJoiner = '\n ';
43
+ const outerJoiner = '\n ';
44
+ // Directory of WCAG links.
45
+ const wcagPhrases = {};
46
+
47
+ // FUNCTIONS
48
+
49
+ // Gets a row of the score-summary table.
50
+ const getScoreRow = (componentName, score) => `<tr><th>${componentName}</th><td>${score}</td></tr>`;
51
+ // Gets a WCAG link or, if not obtainable, a numeric identifier.
52
+ const getWCAGTerm = wcag => {
53
+ const wcagPhrase = wcagPhrases[wcag];
54
+ const wcagTerm = wcagPhrase
55
+ ? `<a href="https://www.w3.org/WAI/WCAG22/Understanding/${wcagPhrase}.html">${wcag}</a>`
56
+ : wcag;
57
+ return wcagTerm;
58
+ };
59
+ // Gets a row of the issue-score-summary table.
60
+ const getIssueScoreRow = (issueConstants, issueDetails) => {
61
+ const {summary, wcag, weight} = issueConstants;
62
+ const wcagTerm = getWCAGTerm(wcag);
63
+ const {instanceCounts, score} = issueDetails;
64
+ const toolList = Object
65
+ .keys(instanceCounts)
66
+ .map(tool => `<code>${tool}</code>:${instanceCounts[tool]}`)
67
+ .join(', ');
68
+ 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>`;
69
+ };
70
+ // Populates the directory of WCAG understanding verbal IDs.
71
+ const getWCAGPhrases = async () => {
72
+ // Get the copy of file https://raw.githubusercontent.com/w3c/wcag/main/guidelines/wcag.json.
73
+ const wcagJSON = await fs.readFile(`${__dirname}/../../../wcag.json`, 'utf8');
74
+ const wcag = JSON.parse(wcagJSON);
75
+ const {principles} = wcag;
76
+ // For each principle in it:
77
+ principles.forEach(principle => {
78
+ // If it is usable:
79
+ if (principle.num && principle.id && principle.id.startsWith('WCAG2:')) {
80
+ // Add it to the directory.
81
+ wcagPhrases[principle.num] = principle.id.slice(6);
82
+ const {guidelines} = principle;
83
+ // For each guideline in the principle:
84
+ guidelines.forEach(guideline => {
85
+ // If it is usable:
86
+ if (guideline.num && guideline.id && guideline.id.startsWith('WCAG2:')) {
87
+ // Add it to the directory.
88
+ wcagPhrases[guideline.num] = guideline.id.slice(6);
89
+ const {successcriteria} = guideline;
90
+ // For each success criterion in the guideline:
91
+ successcriteria.forEach(successCriterion => {
92
+ // If it is usable:
93
+ if (
94
+ successCriterion.num
95
+ && successCriterion.id
96
+ && successCriterion.id.startsWith('WCAG2:')
97
+ ) {
98
+ // Add it to the directory.
99
+ wcagPhrases[successCriterion.num] = successCriterion.id.slice(6);
100
+ }
101
+ });
102
+ }
103
+ });
104
+ }
105
+ });
106
+ };
107
+ // Adds parameters to a query for a digest.
108
+ const populateQuery = async (report, query) => {
109
+ const {
110
+ browserID, device, id, isolate, lowMotion, score, sources, standard, strict, target
111
+ } = report;
112
+ const {agent, requester, script} = sources;
113
+ const {scoreProcID, summary, details} = score;
114
+ query.ts = script;
115
+ query.sp = scoreProcID;
116
+ query.dp = digesterID;
117
+ // Add the job data to the query.
118
+ query.dateISO = getNowDate();
119
+ query.dateSlash = getNowDateSlash();
120
+ query.org = target.what;
121
+ query.url = target.url;
122
+ query.redirections = strict ? 'prohibited' : 'permitted';
123
+ query.isolation = isolate ? 'yes' : 'no';
124
+ query.standard
125
+ = ['original', 'standard', 'original and standard'][['no', 'only', 'also'].indexOf(standard)];
126
+ query.motion = lowMotion ? 'requested' : 'not requested';
127
+ query.requester = requester;
128
+ query.device = device.id;
129
+ query.browser = browserID;
130
+ query.agent = agent ? ` on agent ${agent}` : '';
131
+ query.reportURL = process.env.SCORED_REPORT_URL.replace('__id__', id);
132
+ // Populate the WCAG phrase directory.
133
+ await getWCAGPhrases();
134
+ // Add values for the score-summary table to the query.
135
+ const rows = {
136
+ summaryRows: [],
137
+ issueRows: []
138
+ };
139
+ ['total', 'issueCount', 'issue', 'solo', 'tool', 'element', 'prevention', 'log', 'latency']
140
+ .forEach(sumItem => {
141
+ query[sumItem] = summary[sumItem];
142
+ rows.summaryRows.push(getScoreRow(sumItem, query[sumItem]));
143
+ });
144
+ // Sort the issue IDs in descending score order.
145
+ const issueIDs = Object.keys(details.issue);
146
+ issueIDs.sort((a, b) => details.issue[b].score - details.issue[a].score);
147
+ // Get rows for the issue-score table.
148
+ issueIDs.forEach(issueID => {
149
+ if (issues[issueID]) {
150
+ rows.issueRows.push(getIssueScoreRow(issues[issueID], details.issue[issueID]));
151
+ }
152
+ else {
153
+ console.log(`ERROR: Issue ${issueID} not found`);
154
+ }
155
+ });
156
+ // Add the rows to the query.
157
+ ['summaryRows', 'issueRows'].forEach(rowType => {
158
+ query[rowType] = rows[rowType].join(innerJoiner);
159
+ });
160
+ // Add paragraph groups about the issue details to the query.
161
+ const issueDetailRows = [];
162
+ issueIDs.forEach(issueID => {
163
+ const issueSummary = issues[issueID].summary;
164
+ issueDetailRows.push(`<h3 class="bars">Issue: ${issueSummary}</h3>`);
165
+ issueDetailRows.push(`<p>Impact: ${issues[issueID].why || 'N/A'}</p>`);
166
+ const wcag = issues[issueID].wcag;
167
+ const wcagTerm = wcag ? getWCAGTerm(wcag) : 'N/A';
168
+ issueDetailRows.push(`<p>WCAG: ${wcagTerm}</p>`);
169
+ const issueData = details.issue[issueID];
170
+ issueDetailRows.push(`<p>Score: ${issueData.score}</p>`);
171
+ issueDetailRows.push('<h4>Elements</h4>');
172
+ const issuePaths = details.element[issueID];
173
+ if (issuePaths.length) {
174
+ issueDetailRows.push('<ul>');
175
+ issuePaths.forEach(pathID => {
176
+ issueDetailRows.push(` <li>${pathID}</li>`);
177
+ });
178
+ issueDetailRows.push('</ul>');
179
+ }
180
+ else {
181
+ issueDetailRows.push('<p>None identified</p>');
182
+ }
183
+ const toolIDs = Object.keys(issueData.tools);
184
+ toolIDs.forEach(toolID => {
185
+ issueDetailRows.push(`<h4>Violations of <code>${toolID}</code> rules</h4>`);
186
+ const ruleIDs = Object.keys(issueData.tools[toolID]);
187
+ ruleIDs.forEach(ruleID => {
188
+ const ruleData = issueData.tools[toolID][ruleID];
189
+ issueDetailRows.push(`<h5>Rule <code>${ruleID}</code></h5>`);
190
+ issueDetailRows.push(`<p>Description: ${ruleData.what}</p>`);
191
+ issueDetailRows.push(`<p>Count of instances: ${ruleData.complaints.countTotal}</p>`);
192
+ /*
193
+ This fails unless the caller handles such URLs and has compatible scored report URLs.
194
+ const href = `${query.reportURL}?tool=${toolID}&rule=${ruleID}`;
195
+ const detailLabel = `Issue ${issueSummary} tool ${toolID} rule ${ruleID} instance details`;
196
+ issueDetailRows.push(
197
+ `<p><a href="${href}" aria-label="${detailLabel}">Instance details</a></p>`
198
+ );
199
+ */
200
+ });
201
+ });
202
+ });
203
+ query.issueDetailRows = issueDetailRows.join(outerJoiner);
204
+ // Add paragraphs about the elements to the query.
205
+ const elementRows = [];
206
+ const issueElements = {};
207
+ Object.keys(details.element).forEach(issueID => {
208
+ const pathIDs = details.element[issueID];
209
+ pathIDs.forEach(pathID => {
210
+ issueElements[pathID] ??= [];
211
+ issueElements[pathID].push(issueID);
212
+ });
213
+ });
214
+ const sortedPathIDs = Object.keys(issueElements).sort();
215
+ sortedPathIDs.forEach(pathID => {
216
+ const elementIssues = issueElements[pathID];
217
+ if (elementIssues) {
218
+ elementRows.push(
219
+ `<h5>Element <code>${pathID}</code></h5>`,
220
+ '<ul>',
221
+ ... elementIssues.map(issueID => ` <li>${issues[issueID].summary}</li>`).sort(),
222
+ '</ul>'
223
+ );
224
+ }
225
+ });
226
+ query.elementRows = elementRows.join(outerJoiner);
227
+ };
228
+ // Returns a digested report.
229
+ exports.digester = async report => {
230
+ // Create a query to replace placeholders.
231
+ const query = {};
232
+ await populateQuery(report, query);
233
+ // Get the template.
234
+ let template = await fs.readFile(`${__dirname}/index.html`, 'utf8');
235
+ // Replace its placeholders.
236
+ Object.keys(query).forEach(param => {
237
+ template = template.replace(new RegExp(`__${param}__`, 'g'), query[param]);
238
+ });
239
+ // Return the digest.
240
+ return template;
241
+ };