testaro 72.1.1 → 72.1.3
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/testaro/allCaps.js +9 -8
- package/tests/wave.js +92 -83
package/package.json
CHANGED
package/testaro/allCaps.js
CHANGED
|
@@ -90,13 +90,13 @@ const classifyWithAI = entries => new Promise((resolve, reject) => {
|
|
|
90
90
|
return;
|
|
91
91
|
}
|
|
92
92
|
const text = parsed.content[0].text;
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
.
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
);
|
|
93
|
+
const classifications = [...text.matchAll(/\{"index":\s*\d+,\s*"confidence":\s*[01]\.\d{1,2}\}/g)]
|
|
94
|
+
.map(m => {
|
|
95
|
+
const {index, confidence} = JSON.parse(m[0]);
|
|
96
|
+
return {index, confidence: Math.round(confidence * 10) / 10};
|
|
97
|
+
});
|
|
98
|
+
const {input_tokens, output_tokens} = parsed.usage;
|
|
99
|
+
resolve({classifications, aiModelUsage: {inputTokens: input_tokens, outputTokens: output_tokens}});
|
|
100
100
|
}
|
|
101
101
|
catch(error) {
|
|
102
102
|
reject(new Error(`Haiku response error: ${error.message}`));
|
|
@@ -141,7 +141,8 @@ exports.reporter = async (_, catalog, withItems) => {
|
|
|
141
141
|
let violations;
|
|
142
142
|
try {
|
|
143
143
|
// Get AI estimates of the probabilities of their violating the rule.
|
|
144
|
-
const classifications = await classifyWithAI(sample);
|
|
144
|
+
const {classifications, aiModelUsage} = await classifyWithAI(sample);
|
|
145
|
+
data.aiModelUsage = aiModelUsage;
|
|
145
146
|
// Treat the entries with above-minimum violation confidence levels as violations.
|
|
146
147
|
violations = classifications
|
|
147
148
|
.filter(({confidence}) => confidence >= MIN_CONFIDENCE)
|
package/tests/wave.js
CHANGED
|
@@ -89,96 +89,105 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
89
89
|
}
|
|
90
90
|
// If the response was parsed:
|
|
91
91
|
if (! data.prevented) {
|
|
92
|
-
const {categories} = result.nativeResult;
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
// If standard results are to be reported:
|
|
121
|
-
if (standard) {
|
|
122
|
-
const {standardResult} = result;
|
|
123
|
-
const {totals, instances} = standardResult;
|
|
124
|
-
// Add the category violation count to the standard-result totals.
|
|
125
|
-
totals[ordinalSeverity] += category.count;
|
|
126
|
-
const annotatedItems = await page.evaluate(items => {
|
|
127
|
-
const ruleIDs = Object.keys(items);
|
|
128
|
-
// For each rule of the category with any violations:
|
|
129
|
-
ruleIDs.forEach(ruleID => {
|
|
130
|
-
const {selectors} = items[ruleID];
|
|
131
|
-
// For each of those violations:
|
|
132
|
-
for (const index in selectors) {
|
|
133
|
-
const selector = selectors[index];
|
|
134
|
-
// Get the violator.
|
|
135
|
-
let violator;
|
|
136
|
-
try {
|
|
137
|
-
violator = document.querySelector(selector);
|
|
138
|
-
// Concatenate its selector with its XPath in the native result.
|
|
139
|
-
selectors[index] = [selector, window.getXPath(violator) ?? ''];
|
|
140
|
-
} catch (error) {
|
|
141
|
-
console.error(`ERROR: Invalid selector: ${selector} (${error.message})`);
|
|
142
|
-
}
|
|
92
|
+
const {categories, status} = result.nativeResult;
|
|
93
|
+
// If the request succeeded and produced categories:
|
|
94
|
+
if(status.success && categories) {
|
|
95
|
+
// Delete the unnecessary properties of the categories.
|
|
96
|
+
delete categories.feature;
|
|
97
|
+
delete categories.structure;
|
|
98
|
+
delete categories.aria;
|
|
99
|
+
// For each WAVE rule category:
|
|
100
|
+
for (const categoryName of ['error', 'contrast', 'alert']) {
|
|
101
|
+
const category = categories[categoryName];
|
|
102
|
+
const ordinalSeverity = categoryName === 'alert' ? 0 : 3;
|
|
103
|
+
// If any violated rules (named items by WAVE) were reported:
|
|
104
|
+
if (
|
|
105
|
+
category?.items
|
|
106
|
+
&& Object.keys(category.items).length
|
|
107
|
+
) {
|
|
108
|
+
const {items} = category;
|
|
109
|
+
// If rules to be tested for were specified:
|
|
110
|
+
if (rules && rules.length) {
|
|
111
|
+
// For each rule violated:
|
|
112
|
+
Object.keys(items).forEach(ruleID => {
|
|
113
|
+
// If it was not a specified rule:
|
|
114
|
+
if (! rules.includes(ruleID)) {
|
|
115
|
+
// Decrease the category violation count by the count of its violations.
|
|
116
|
+
category.count -= items[ruleID].count;
|
|
117
|
+
// Remove its violations from the native result.
|
|
118
|
+
delete items[ruleID];
|
|
143
119
|
}
|
|
144
120
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
121
|
+
}
|
|
122
|
+
// If standard results are to be reported:
|
|
123
|
+
if (standard) {
|
|
124
|
+
const {standardResult} = result;
|
|
125
|
+
const {totals, instances} = standardResult;
|
|
126
|
+
// Add the category violation count to the standard-result totals.
|
|
127
|
+
totals[ordinalSeverity] += category.count;
|
|
128
|
+
const annotatedItems = await page.evaluate(items => {
|
|
129
|
+
const ruleIDs = Object.keys(items);
|
|
130
|
+
// For each rule of the category with any violations:
|
|
131
|
+
ruleIDs.forEach(ruleID => {
|
|
132
|
+
const {selectors} = items[ruleID];
|
|
133
|
+
// For each of those violations:
|
|
134
|
+
for (const index in selectors) {
|
|
135
|
+
const selector = selectors[index];
|
|
136
|
+
// Get the violator.
|
|
137
|
+
let violator;
|
|
138
|
+
try {
|
|
139
|
+
violator = document.querySelector(selector);
|
|
140
|
+
// Concatenate its selector with its XPath in the native result.
|
|
141
|
+
selectors[index] = [selector, window.getXPath(violator) ?? ''];
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.error(`ERROR: Invalid selector: ${selector} (${error.message})`);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return items;
|
|
148
|
+
}, items);
|
|
149
|
+
const ruleIDs = Object.keys(annotatedItems);
|
|
150
|
+
// For each rule of the category with any violations:
|
|
151
|
+
for (const ruleID of ruleIDs) {
|
|
152
|
+
const {description, selectors} = annotatedItems[ruleID];
|
|
153
|
+
// For each violation of the rule:
|
|
154
|
+
for (const violation of selectors) {
|
|
155
|
+
// Initialize a standard instance.
|
|
156
|
+
const instance = {
|
|
157
|
+
ruleID,
|
|
158
|
+
what: description,
|
|
159
|
+
ordinalSeverity,
|
|
160
|
+
count: 1
|
|
161
|
+
};
|
|
162
|
+
const xPath = violation[1];
|
|
163
|
+
// Add the catalog index to the instance.
|
|
164
|
+
instance.catalogIndex = getXPathCatalogIndex(report.catalog, xPath);
|
|
165
|
+
// Add the instance to the standard result.
|
|
166
|
+
instances.push(instance);
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
}
|
|
167
170
|
}
|
|
168
171
|
}
|
|
169
172
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
173
|
+
// Otherwise, if the request failed:
|
|
174
|
+
else if (! status.success) {
|
|
175
|
+
// Report this.
|
|
176
|
+
data.prevented = true;
|
|
177
|
+
data.error = status.error || 'Unknown error';
|
|
178
|
+
}
|
|
179
|
+
const {statistics} = result.nativeResult;
|
|
180
|
+
if (statistics) {
|
|
181
|
+
// Copy important data from the native result to the result.
|
|
182
|
+
data.pageTitle = statistics.pagetitle || '';
|
|
183
|
+
data.pageURL = statistics.pageurl || '';
|
|
184
|
+
data.elapsedSeconds = statistics.time || null;
|
|
185
|
+
data.creditsRemaining = statistics.creditsremaining || null;
|
|
186
|
+
console.log(`WAVE credits remaining: ${data.creditsRemaining}`);
|
|
187
|
+
data.allItemCount = statistics.allitemcount || null;
|
|
188
|
+
data.totalElements = statistics.totalelements || null;
|
|
189
|
+
data.waveURL = statistics.waveurl || '';
|
|
190
|
+
}
|
|
182
191
|
}
|
|
183
192
|
// Return the result.
|
|
184
193
|
resolve({
|