@jrpool/kilotest 24.0.8 → 24.1.1

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.
@@ -0,0 +1,141 @@
1
+ /*
2
+ util.js
3
+ Shared utilities.
4
+ */
5
+
6
+ // IMPORTS
7
+
8
+ const {getPageData, getReport, isValidReport, objectSort, tools} = require('../util');
9
+ const issuesClassification = require('testilo/procs/score/tic').issues;
10
+
11
+ // FUNCTIONS
12
+
13
+ // Converts tool IDs to tool data sorted by tool name.
14
+ const getToolData = toolIDs => objectSort(
15
+ Array.from(toolIDs).map(toolID => {
16
+ const toolData = tools[toolID];
17
+ return {
18
+ toolID,
19
+ toolName: toolData[0],
20
+ toolMaker: toolData[1]
21
+ }
22
+ }),
23
+ 'toolName',
24
+ 'alpha'
25
+ );
26
+ // Returns a +-delimited list of sorted tool names.
27
+ const getToolList = toolIDs => Array.from(toolIDs)
28
+ .map(toolID => tools[toolID][0])
29
+ .sort((a, b) => a.localeCompare(b, 'en', {sensitivity: 'base'}))
30
+ .join(' + ');
31
+ // Returns data on the issues reported by a report.
32
+ const getIssuesData = async (timeStamp, jobID) => {
33
+ // Get the report.
34
+ const report = await getReport(timeStamp, jobID);
35
+ // If it is valid:
36
+ if (isValidReport(report)) {
37
+ // Initialize the temporary data.
38
+ const temp = {
39
+ issues: {},
40
+ reporters: new Set(),
41
+ violators: new Set()
42
+ };
43
+ // Initialize the final data.
44
+ const final = {
45
+ reporters: [],
46
+ reporterList: '',
47
+ reporterCount: 0,
48
+ violatorCount: 0,
49
+ preventions: report.jobData.preventions,
50
+ priorityNames: {
51
+ 4: 'highest',
52
+ 3: 'high',
53
+ 2: 'low',
54
+ 1: 'lowest'
55
+ },
56
+ issues: {
57
+ 4: [],
58
+ 3: [],
59
+ 2: [],
60
+ 1: []
61
+ },
62
+ issueCount: 0
63
+ };
64
+ // For each act in the report:
65
+ report.acts.forEach(act => {
66
+ // If it is a test act:
67
+ if (act.type === 'test') {
68
+ const {result, which} = act;
69
+ const instances = result?.standardResult?.instances ?? [];
70
+ // For each of its standard instances:
71
+ instances.forEach(instance => {
72
+ const {catalogIndex, issueID} = instance;
73
+ // If the instance identifies its rule as belonging to a non-ignorable issue:
74
+ if (issueID && issueID !== 'ignorable') {
75
+ const issueClassification = issuesClassification[issueID];
76
+ // If the issue has a current weighted classification:
77
+ if (issueClassification && [1, 2, 3, 4].includes(issueClassification.weight)) {
78
+ const {summary, wcag, weight, why} = issueClassification;
79
+ // Initialize the temporary data on the issue if necessary.
80
+ temp.issues[issueID] ??= {
81
+ issueID,
82
+ summary,
83
+ wcag,
84
+ why,
85
+ weight,
86
+ reporters: new Set(),
87
+ reporterList: '',
88
+ violators: new Set()
89
+ };
90
+ // Ensure the tool is in the temporary data.
91
+ temp.issues[issueID].reporters.add(which);
92
+ temp.reporters.add(which);
93
+ // If the instance has a catalog index:
94
+ if (catalogIndex) {
95
+ // Ensure the violator is in the temporary data.
96
+ temp.issues[issueID].violators.add(catalogIndex);
97
+ temp.violators.add(catalogIndex);
98
+ }
99
+ }
100
+ }
101
+ });
102
+ }
103
+ });
104
+ // Finish populating the final data.
105
+ final.reporters = getToolData(temp.reporters);
106
+ final.reporterList = getToolList(temp.reporters);
107
+ final.reporterCount = final.reporters.length;
108
+ final.violatorCount = temp.violators.size;
109
+ Object.values(temp.issues).forEach(issue => {
110
+ const {issueID, summary, wcag, why, weight} = issue;
111
+ const finalIssue = {
112
+ issueID,
113
+ summary,
114
+ wcag,
115
+ why,
116
+ weight
117
+ };
118
+ finalIssue.reporters = getToolData(issue.reporters);
119
+ finalIssue.reporterList = getToolList(issue.reporters);
120
+ finalIssue.reporterCount = finalIssue.reporters.length;
121
+ finalIssue.violatorCount = issue.violators.size;
122
+ final.issues[issue.weight].push(finalIssue);
123
+ });
124
+ final.issueCount = Object.keys(temp.issues).length;
125
+ // For each weight:
126
+ [4, 3, 2, 1].forEach(weight => {
127
+ // Sort its issues in the final data alphabetically by reporter names.
128
+ objectSort(final.issues[weight], 'reporterList', 'alpha');
129
+ // Sort the issues again in descending reporter-count order, making this the primary order.
130
+ objectSort(final.issues[weight], 'reporterCount', 'numericDown');
131
+ });
132
+ // Return the data.
133
+ return final;
134
+ }
135
+ // Otherwise, i.e. if it is invalid, return this.
136
+ return 'ERROR: Report missing or invalid.';
137
+ };
138
+ exports.getData = async (timeStamp, jobID) => ({
139
+ pageData: await getPageData(timeStamp, jobID),
140
+ issuesData: await getIssuesData(timeStamp, jobID)
141
+ });