testilo 41.0.5 → 41.2.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.
@@ -1,158 +0,0 @@
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/tic43');
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 = 'tdp43';
40
- // Newline with indentations.
41
- const innerJoiner = '\n ';
42
-
43
- // FUNCTIONS
44
-
45
- // Gets a row of the score-summary table.
46
- const getScoreRow = (componentName, score) => `<tr><th>${componentName}</th><td>${score}</td></tr>`;
47
- // Gets a row of the issue-score-summary table.
48
- const getIssueScoreRow = (issueConstants, issueDetails) => {
49
- const {summary, wcag} = issueConstants;
50
- const {instanceCounts, score} = issueDetails;
51
- const toolList = Object
52
- .keys(instanceCounts)
53
- .map(tool => `<code>${tool}</code>:${instanceCounts[tool]}`)
54
- .join(', ');
55
- return `<tr><th>${summary}</th><td class="center">${wcag}<td class="right num">${score}</td><td>${toolList}</td></tr>`;
56
- };
57
- // Adds parameters to a query for a digest.
58
- const populateQuery = (report, query) => {
59
- const {acts, id, sources, score} = report;
60
- const {script, target, requester} = sources;
61
- const {scoreProcID, summary, details} = score;
62
- query.ts = script;
63
- query.sp = scoreProcID;
64
- query.dp = digesterID;
65
- // Add the job data to the query.
66
- query.dateISO = getNowDate();
67
- query.dateSlash = getNowDateSlash();
68
- query.org = target.what;
69
- query.url = target.which;
70
- query.requester = requester;
71
- const firstLaunch = acts.find(act => act.type === 'launch');
72
- if (firstLaunch) {
73
- query.device = firstLaunch.deviceID || 'unknown';
74
- }
75
- else {
76
- query.device = 'unknown';
77
- }
78
- query.reportURL = process.env.SCORED_REPORT_URL.replace('__id__', id);
79
- // Add values for the score-summary table to the query.
80
- const rows = {
81
- summaryRows: [],
82
- issueRows: []
83
- };
84
- ['total', 'issueCount', 'issue', 'solo', 'tool', 'element', 'prevention', 'log', 'latency']
85
- .forEach(sumItem => {
86
- query[sumItem] = summary[sumItem];
87
- rows.summaryRows.push(getScoreRow(sumItem, query[sumItem]));
88
- });
89
- // Sort the issue IDs in descending score order.
90
- const issueIDs = Object.keys(details.issue);
91
- issueIDs.sort((a, b) => details.issue[b].score - details.issue[a].score);
92
- // Get rows for the issue-score table.
93
- issueIDs.forEach(issueID => {
94
- if (issues[issueID]) {
95
- rows.issueRows.push(getIssueScoreRow(issues[issueID], details.issue[issueID]));
96
- }
97
- else {
98
- console.log(`ERROR: Issue ${issueID} not found`);
99
- }
100
- });
101
- // Add the rows to the query.
102
- ['summaryRows', 'issueRows'].forEach(rowType => {
103
- query[rowType] = rows[rowType].join(innerJoiner);
104
- });
105
- // Add paragraph groups about the issue details to the query.
106
- const issueDetailRows = [];
107
- issueIDs.forEach(issueID => {
108
- const issueSummary = issues[issueID].summary;
109
- issueDetailRows.push(`<h3 class="bars">Issue: ${issueSummary}</h3>`);
110
- issueDetailRows.push(`<p>Impact: ${issues[issueID].why || 'N/A'}</p>`);
111
- issueDetailRows.push(`<p>WCAG: ${issues[issueID].wcag || 'N/A'}</p>`);
112
- const issueData = details.issue[issueID];
113
- issueDetailRows.push(`<p>Score: ${issueData.score}</p>`);
114
- issueDetailRows.push('<h4>Elements</h4>');
115
- const issuePaths = details.element[issueID];
116
- if (issuePaths.length) {
117
- issueDetailRows.push('<ul>');
118
- issuePaths.forEach(pathID => {
119
- issueDetailRows.push(`<li>${pathID}</li>`);
120
- });
121
- issueDetailRows.push('</ul>');
122
- }
123
- else {
124
- issueDetailRows.push('<p>None identified</p>');
125
- }
126
- const toolIDs = Object.keys(issueData.tools);
127
- toolIDs.forEach(toolID => {
128
- issueDetailRows.push(`<h4>Violations of <code>${toolID}</code> rules</h4>`);
129
- const ruleIDs = Object.keys(issueData.tools[toolID]);
130
- ruleIDs.forEach(ruleID => {
131
- const ruleData = issueData.tools[toolID][ruleID];
132
- issueDetailRows.push(`<h5>Rule <code>${ruleID}</code></h5>`);
133
- issueDetailRows.push(`<p>Description: ${ruleData.what}</p>`);
134
- issueDetailRows.push(`<p>Count of instances: ${ruleData.complaints.countTotal}</p>`);
135
- const href = `${query.reportURL}?tool=${toolID}&rule=${ruleID}`;
136
- const detailLabel = `Issue ${issueSummary} tool ${toolID} rule ${ruleID} instance details`;
137
- issueDetailRows.push(
138
- `<p><a href="${href}" aria-label="${detailLabel}">Instance details</a></p>`
139
- );
140
- });
141
- });
142
- });
143
- query.issueDetailRows = issueDetailRows.join(innerJoiner);
144
- };
145
- // Returns a digested report.
146
- exports.digester = async report => {
147
- // Create a query to replace placeholders.
148
- const query = {};
149
- populateQuery(report, query);
150
- // Get the template.
151
- let template = await fs.readFile(`${__dirname}/index.html`, 'utf8');
152
- // Replace its placeholders.
153
- Object.keys(query).forEach(param => {
154
- template = template.replace(new RegExp(`__${param}__`, 'g'), query[param]);
155
- });
156
- // Return the digest.
157
- return template;
158
- };