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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "72.1.1",
3
+ "version": "72.1.3",
4
4
  "description": "Run 1000 web accessibility tests from 11 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- resolve(
94
- [...text.matchAll(/\{"index":\s*\d+,\s*"confidence":\s*[01]\.\d{1,2}\}/g)]
95
- .map(m => {
96
- const {index, confidence} = JSON.parse(m[0]);
97
- return {index, confidence: Math.round(confidence * 10) / 10};
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
- // Delete its unnecessary properties.
94
- delete categories.feature;
95
- delete categories.structure;
96
- delete categories.aria;
97
- // For each WAVE rule category:
98
- for (const categoryName of ['error', 'contrast', 'alert']) {
99
- const category = categories[categoryName];
100
- const ordinalSeverity = categoryName === 'alert' ? 0 : 3;
101
- // If any violated rules (named items by WAVE) were reported:
102
- if (
103
- category?.items
104
- && Object.keys(category.items).length
105
- ) {
106
- const {items} = category;
107
- // If rules to be tested for were specified:
108
- if (rules && rules.length) {
109
- // For each rule violated:
110
- Object.keys(items).forEach(ruleID => {
111
- // If it was not a specified rule:
112
- if (! rules.includes(ruleID)) {
113
- // Decrease the category violation count by the count of its violations.
114
- category.count -= items[ruleID].count;
115
- // Remove its violations from the native result.
116
- delete items[ruleID];
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
- return items;
146
- }, items);
147
- const ruleIDs = Object.keys(annotatedItems);
148
- // For each rule of the category with any violations:
149
- for (const ruleID of ruleIDs) {
150
- const {description, selectors} = annotatedItems[ruleID];
151
- // For each violation of the rule:
152
- for (const violation of selectors) {
153
- // Initialize a standard instance.
154
- const instance = {
155
- ruleID,
156
- what: description,
157
- ordinalSeverity,
158
- count: 1
159
- };
160
- const xPath = violation[1];
161
- // Add the catalog index to the instance.
162
- instance.catalogIndex = getXPathCatalogIndex(report.catalog, xPath);
163
- // Add the instance to the standard result.
164
- instances.push(instance);
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
- const {statistics} = result.nativeResult;
172
- if (statistics) {
173
- // Copy important data from the native result to the result.
174
- data.pageTitle = statistics.pagetitle || '';
175
- data.pageURL = statistics.pageurl || '';
176
- data.elapsedSeconds = statistics.time || null;
177
- data.creditsRemaining = statistics.creditsremaining || null;
178
- console.log(`WAVE credits remaining: ${data.creditsRemaining}`);
179
- data.allItemCount = statistics.allitemcount || null;
180
- data.totalElements = statistics.totalelements || null;
181
- data.waveURL = statistics.waveurl || '';
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({