testilo 33.2.3 → 33.3.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 +2 -2
- package/procs/score/tsp41.js +321 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testilo",
|
|
3
|
-
"version": "33.
|
|
4
|
-
"description": "Prepares and processes Testaro reports",
|
|
3
|
+
"version": "33.3.0",
|
|
4
|
+
"description": "Prepares Testaro jobs and processes Testaro reports",
|
|
5
5
|
"main": "call.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
/*
|
|
2
|
+
tsp40
|
|
3
|
+
Testilo score proc 40
|
|
4
|
+
|
|
5
|
+
Computes target score data and adds them to a ts40 report.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// IMPORTS
|
|
9
|
+
|
|
10
|
+
const {issues} = require('./tic40');
|
|
11
|
+
|
|
12
|
+
// CONSTANTS
|
|
13
|
+
|
|
14
|
+
// ID of this proc.
|
|
15
|
+
const scoreProcID = 'tsp41';
|
|
16
|
+
// Latency weight (how much each second of excess latency adds to the score).
|
|
17
|
+
const latencyWeight = 1;
|
|
18
|
+
// Normal latency (6 visits, with 1.5 second per visit).
|
|
19
|
+
const normalLatency = 9;
|
|
20
|
+
// Prevention weights (how much each prevention adds to the score).
|
|
21
|
+
const preventionWeight = 300;
|
|
22
|
+
const testaroRulePreventionWeight = 30;
|
|
23
|
+
// Maximum instance count addition weight (divisor of max).
|
|
24
|
+
const maxWeight = 30;
|
|
25
|
+
// Issue count weight.
|
|
26
|
+
const issueCountWeight = 10;
|
|
27
|
+
// Other weights.
|
|
28
|
+
const severityWeights = [1, 2, 3, 4];
|
|
29
|
+
const toolWeight = 0.1;
|
|
30
|
+
const logWeights = {
|
|
31
|
+
logCount: 0.1,
|
|
32
|
+
logSize: 0.002,
|
|
33
|
+
errorLogCount: 0.2,
|
|
34
|
+
errorLogSize: 0.004,
|
|
35
|
+
prohibitedCount: 3,
|
|
36
|
+
visitRejectionCount: 2
|
|
37
|
+
};
|
|
38
|
+
// Initialize a table of tool rules.
|
|
39
|
+
const issueIndex = {};
|
|
40
|
+
// Initialize an array of variably named tool rules.
|
|
41
|
+
const issueMatcher = [];
|
|
42
|
+
// For each issue:
|
|
43
|
+
Object.keys(issues).forEach(issueName => {
|
|
44
|
+
// For each tool with rules belonging to that issue:
|
|
45
|
+
Object.keys(issues[issueName].tools).forEach(toolName => {
|
|
46
|
+
// For each of those rules:
|
|
47
|
+
Object.keys(issues[issueName].tools[toolName]).forEach(ruleID => {
|
|
48
|
+
// Add it to the table of tool rules.
|
|
49
|
+
if (! issueIndex[toolName]) {
|
|
50
|
+
issueIndex[toolName] = {};
|
|
51
|
+
}
|
|
52
|
+
issueIndex[toolName][ruleID] = issueName;
|
|
53
|
+
// If it is variably named:
|
|
54
|
+
if (issues[issueName].tools[toolName][ruleID].variable) {
|
|
55
|
+
// Add it to the array of variably named tool rules.
|
|
56
|
+
issueMatcher.push(ruleID);
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// FUNCTIONS
|
|
63
|
+
|
|
64
|
+
// Scores a report.
|
|
65
|
+
exports.scorer = report => {
|
|
66
|
+
// If there are any acts in the report:
|
|
67
|
+
const {acts} = report;
|
|
68
|
+
if (Array.isArray(acts) && acts.length) {
|
|
69
|
+
// If any of them are test acts:
|
|
70
|
+
const testActs = acts.filter(act => act.type === 'test');
|
|
71
|
+
if (testActs.length) {
|
|
72
|
+
// Initialize the score data.
|
|
73
|
+
const score = {
|
|
74
|
+
scoreProcID,
|
|
75
|
+
weights: {
|
|
76
|
+
severities: severityWeights,
|
|
77
|
+
tool: toolWeight,
|
|
78
|
+
log: logWeights,
|
|
79
|
+
latency: latencyWeight,
|
|
80
|
+
prevention: preventionWeight,
|
|
81
|
+
testaroRulePrevention: testaroRulePreventionWeight,
|
|
82
|
+
maxInstanceCount: maxWeight
|
|
83
|
+
},
|
|
84
|
+
normalLatency,
|
|
85
|
+
summary: {
|
|
86
|
+
total: 0,
|
|
87
|
+
issueCount: 0,
|
|
88
|
+
issue: 0,
|
|
89
|
+
solo: 0,
|
|
90
|
+
tool: 0,
|
|
91
|
+
prevention: 0,
|
|
92
|
+
log: 0,
|
|
93
|
+
latency: 0
|
|
94
|
+
},
|
|
95
|
+
details: {
|
|
96
|
+
severity: {
|
|
97
|
+
total: [0, 0, 0, 0],
|
|
98
|
+
byTool: {}
|
|
99
|
+
},
|
|
100
|
+
prevention: {},
|
|
101
|
+
issue: {},
|
|
102
|
+
solo: {},
|
|
103
|
+
tool: {}
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const {summary, details} = score;
|
|
107
|
+
// For each test act:
|
|
108
|
+
testActs.forEach(act => {
|
|
109
|
+
const {data, which, standardResult} = act;
|
|
110
|
+
// If the tool is Testaro and the count of rule preventions was reported:
|
|
111
|
+
if (which === 'testaro' && data && data.rulePreventions) {
|
|
112
|
+
// Add their score to the score.
|
|
113
|
+
details.prevention.testaro = testaroRulePreventionWeight * data.rulePreventions.length;
|
|
114
|
+
}
|
|
115
|
+
// If the page prevented the tool from operating:
|
|
116
|
+
if (! standardResult || standardResult.prevented) {
|
|
117
|
+
// Add this to the score.
|
|
118
|
+
details.prevention[which] = preventionWeight;
|
|
119
|
+
}
|
|
120
|
+
// Otherwise, if a valid standard result exists:
|
|
121
|
+
else if (
|
|
122
|
+
standardResult
|
|
123
|
+
&& standardResult.totals
|
|
124
|
+
&& standardResult.totals.length === 4
|
|
125
|
+
&& standardResult.instances
|
|
126
|
+
) {
|
|
127
|
+
// Add the severity totals of the tool to the score.
|
|
128
|
+
const {totals} = standardResult;
|
|
129
|
+
details.severity.byTool[which] = totals;
|
|
130
|
+
// Add the severity-weighted tool totals to the score.
|
|
131
|
+
details.tool[which] = totals.reduce(
|
|
132
|
+
(sum, current, index) => sum + severityWeights[index] * current, 0
|
|
133
|
+
);
|
|
134
|
+
// For each instance of the tool:
|
|
135
|
+
standardResult.instances.forEach(instance => {
|
|
136
|
+
// Get the rule ID.
|
|
137
|
+
const {ruleID, ordinalSeverity, count} = instance;
|
|
138
|
+
// If it is not in the table of tool rules:
|
|
139
|
+
let canonicalRuleID = ruleID;
|
|
140
|
+
if (! issueIndex[which][ruleID]) {
|
|
141
|
+
// Convert it to the variably named tool rule that it matches, if any.
|
|
142
|
+
canonicalRuleID = issueMatcher.find(pattern => {
|
|
143
|
+
const patternRE = new RegExp(pattern);
|
|
144
|
+
return patternRE.test(instance.ruleID);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
// If the rule ID belongs to a non-ignorable issue:
|
|
148
|
+
if (canonicalRuleID) {
|
|
149
|
+
// Get the issue.
|
|
150
|
+
const issueName = issueIndex[which][canonicalRuleID];
|
|
151
|
+
// Add the instance to the issue details of the score data.
|
|
152
|
+
if (issueName !== 'ignorable') {
|
|
153
|
+
if (! details.issue[issueName]) {
|
|
154
|
+
details.issue[issueName] = {
|
|
155
|
+
summary: issues[issueName].summary,
|
|
156
|
+
wcag: issues[issueName].wcag || '',
|
|
157
|
+
score: 0,
|
|
158
|
+
maxCount: 0,
|
|
159
|
+
weight: issues[issueName].weight,
|
|
160
|
+
countLimit: issues[issueName].max,
|
|
161
|
+
instanceCounts: {},
|
|
162
|
+
tools: {}
|
|
163
|
+
};
|
|
164
|
+
if (! details.issue[issueName].countLimit) {
|
|
165
|
+
delete details.issue[issueName].countLimit;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (! details.issue[issueName].tools[which]) {
|
|
169
|
+
details.issue[issueName].tools[which] = {};
|
|
170
|
+
}
|
|
171
|
+
if (! details.issue[issueName].instanceCounts[which]) {
|
|
172
|
+
details.issue[issueName].instanceCounts[which] = 0;
|
|
173
|
+
}
|
|
174
|
+
details.issue[issueName].instanceCounts[which] += instance.count || 1;
|
|
175
|
+
if (! details.issue[issueName].tools[which][canonicalRuleID]) {
|
|
176
|
+
const ruleData = issues[issueName].tools[which][canonicalRuleID];
|
|
177
|
+
details.issue[issueName].tools[which][canonicalRuleID] = {
|
|
178
|
+
quality: ruleData.quality,
|
|
179
|
+
what: ruleData.what,
|
|
180
|
+
complaints: {
|
|
181
|
+
countTotal: 0,
|
|
182
|
+
texts: []
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
details
|
|
187
|
+
.issue[issueName]
|
|
188
|
+
.tools[which][canonicalRuleID]
|
|
189
|
+
.complaints
|
|
190
|
+
.countTotal += instance.count || 1;
|
|
191
|
+
if (
|
|
192
|
+
! details
|
|
193
|
+
.issue[issueName]
|
|
194
|
+
.tools[which][canonicalRuleID]
|
|
195
|
+
.complaints
|
|
196
|
+
.texts
|
|
197
|
+
.includes(instance.what)
|
|
198
|
+
) {
|
|
199
|
+
details
|
|
200
|
+
.issue[issueName]
|
|
201
|
+
.tools[which][canonicalRuleID]
|
|
202
|
+
.complaints
|
|
203
|
+
.texts
|
|
204
|
+
.push(instance.what);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
// Otherwise, i.e. if the rule ID belongs to no issue:
|
|
209
|
+
else {
|
|
210
|
+
// Add the instance to the solo details of the score data.
|
|
211
|
+
if (! details.solo[which]) {
|
|
212
|
+
details.solo[which] = {};
|
|
213
|
+
}
|
|
214
|
+
if (! details.solo[which][ruleID]) {
|
|
215
|
+
details.solo[which][ruleID] = 0;
|
|
216
|
+
}
|
|
217
|
+
details.solo[which][ruleID] += (count || 1) * (ordinalSeverity + 1);
|
|
218
|
+
// Report this.
|
|
219
|
+
console.log(`ERROR: ${instance.ruleID} of ${which} not found in issues`);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// Otherwise, i.e. if a failed standard result exists:
|
|
224
|
+
else {
|
|
225
|
+
// Add an inferred prevention to the score.
|
|
226
|
+
details.prevention[which] = preventionWeight;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
// For each non-ignorable issue with any complaints:
|
|
230
|
+
Object.keys(details.issue).forEach(issueName => {
|
|
231
|
+
const issueData = details.issue[issueName];
|
|
232
|
+
// For each tool with any complaints for the issue:
|
|
233
|
+
Object.keys(issueData.tools).forEach(toolID => {
|
|
234
|
+
// Get the sum of the quality-weighted counts of its issue rules.
|
|
235
|
+
let weightedCount = 0;
|
|
236
|
+
Object.values(issueData.tools[toolID]).forEach(ruleData => {
|
|
237
|
+
weightedCount += ruleData.quality * ruleData.complaints.countTotal;
|
|
238
|
+
});
|
|
239
|
+
// If the sum exceeds the existing maximum weighted count for the issue:
|
|
240
|
+
if (weightedCount > issueData.maxCount) {
|
|
241
|
+
// Change the maximum count for the issue to the sum.
|
|
242
|
+
issueData.maxCount = weightedCount;
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
// Get the score for the issue, including any addition for the instance count limit.
|
|
246
|
+
const maxAddition = issueData.countLimit ? maxWeight / issueData.countLimit : 0;
|
|
247
|
+
issueData.score = Math.round(issueData.weight * issueData.maxCount * (1 + maxAddition));
|
|
248
|
+
});
|
|
249
|
+
// Add the severity detail totals to the score.
|
|
250
|
+
details.severity.total = Object.keys(details.severity.byTool).reduce((severityTotals, toolID) => {
|
|
251
|
+
details.severity.byTool[toolID].forEach((severityScore, index) => {
|
|
252
|
+
severityTotals[index] += severityScore;
|
|
253
|
+
});
|
|
254
|
+
return severityTotals;
|
|
255
|
+
}, details.severity.total);
|
|
256
|
+
// Add the summary issue-count total to the score.
|
|
257
|
+
summary.issueCount = Object.keys(details.issue).length * issueCountWeight;
|
|
258
|
+
// Add the summary issue total to the score.
|
|
259
|
+
summary.issue = Object
|
|
260
|
+
.values(details.issue)
|
|
261
|
+
.reduce((total, current) => total + current.score, 0);
|
|
262
|
+
// Add the summary solo total to the score.
|
|
263
|
+
Object.keys(details.solo).forEach(tool => {
|
|
264
|
+
summary.solo += Object
|
|
265
|
+
.values(details.solo[tool])
|
|
266
|
+
.reduce((total, current) => total + current);
|
|
267
|
+
});
|
|
268
|
+
// Add the summary tool total to the score.
|
|
269
|
+
summary.tool = toolWeight * details.severity.total.reduce(
|
|
270
|
+
(total, current, index) => total + severityWeights[index] * current, 0
|
|
271
|
+
);
|
|
272
|
+
// Add the summary prevention total to the score.
|
|
273
|
+
summary.prevention = Object.values(details.prevention).reduce(
|
|
274
|
+
(total, current) => total + current, 0
|
|
275
|
+
);
|
|
276
|
+
// Add the summary log score to the score.
|
|
277
|
+
const {jobData} = report;
|
|
278
|
+
if (jobData) {
|
|
279
|
+
summary.log = Math.max(0, Math.round(
|
|
280
|
+
logWeights.logCount * jobData.logCount
|
|
281
|
+
+ logWeights.logSize * jobData.logSize +
|
|
282
|
+
+ logWeights.errorLogCount * jobData.errorLogCount
|
|
283
|
+
+ logWeights.errorLogSize * jobData.errorLogSize
|
|
284
|
+
+ logWeights.prohibitedCount * jobData.prohibitedCount +
|
|
285
|
+
+ logWeights.visitRejectionCount * jobData.visitRejectionCount
|
|
286
|
+
));
|
|
287
|
+
// Add the summary latency score to the score.
|
|
288
|
+
summary.latency = Math.round(
|
|
289
|
+
latencyWeight * (Math.max(0, jobData.visitLatency - normalLatency))
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
// Round the unrounded scores.
|
|
293
|
+
Object.keys(summary).forEach(summaryTypeName => {
|
|
294
|
+
summary[summaryTypeName] = Math.round(summary[summaryTypeName]);
|
|
295
|
+
});
|
|
296
|
+
details.severity.total.forEach((severityTotal, index) => {
|
|
297
|
+
details.severity.total[index] = Math.round(severityTotal);
|
|
298
|
+
});
|
|
299
|
+
// Add the summary total score to the score.
|
|
300
|
+
summary.total = summary.issueCount
|
|
301
|
+
+ summary.issue
|
|
302
|
+
+ summary.solo
|
|
303
|
+
+ summary.tool
|
|
304
|
+
+ summary.prevention
|
|
305
|
+
+ summary.log
|
|
306
|
+
+ summary.latency;
|
|
307
|
+
// Add the score to the report or replace the existing score of the report.
|
|
308
|
+
report.score = score;
|
|
309
|
+
}
|
|
310
|
+
// Otherwise, i.e. if none of them is a test act:
|
|
311
|
+
else {
|
|
312
|
+
// Report this.
|
|
313
|
+
console.log('ERROR: No test acts');
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// Otherwise, i.e. if there are no acts in the report:
|
|
317
|
+
else {
|
|
318
|
+
// Report this.
|
|
319
|
+
console.log('ERROR: No acts');
|
|
320
|
+
}
|
|
321
|
+
};
|