testaro 60.0.0 → 60.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "60.0.0",
3
+ "version": "60.2.0",
4
4
  "description": "Run 1000 web accessibility tests from 11 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/run.js CHANGED
@@ -204,11 +204,20 @@ const goTo = async (report, page, url, timeout, waitUntil) => {
204
204
  }
205
205
  // Otherwise, if the response status was rejection of excessive requests:
206
206
  else if (httpStatus === 429) {
207
+ const retryHeader = response.headers()['retry-after'];
208
+ let waitSeconds = 5;
209
+ if (retryHeader) {
210
+ waitSeconds = Number.isNaN(Number(retryHeader))
211
+ ? Math.ceil((new Date(retryHeader) - new Date()) / 1000)
212
+ : Number(retryHeader);
213
+ }
207
214
  // Return this.
208
- console.log(`ERROR: Visit to ${url} prevented by request frequency limit (status 429)`);
215
+ console.log(
216
+ `ERROR: Visit to ${url} rate-limited (status 429); retry after ${waitSeconds} sec.`
217
+ );
209
218
  return {
210
219
  success: false,
211
- error: 'status429'
220
+ error: `status429/retryAfterSeconds=${waitSeconds}`
212
221
  };
213
222
  }
214
223
  // Otherwise, i.e. if the response status was otherwise abnormal:
@@ -423,11 +432,6 @@ const launch = exports.launch = async (
423
432
  report.jobData.lastScriptNonce = scriptNonce;
424
433
  }
425
434
  }
426
- // Otherwise, i.e. if the navigation was prevented by a request frequency restriction:
427
- else if (navResult.error === 'status429') {
428
- // Report this.
429
- addError(true, false, report, actIndex, 'status429');
430
- }
431
435
  // Otherwise, i.e. if the launch or navigation failed for another reason:
432
436
  else {
433
437
  // Cause another attempt to launch and navigate, if retries remain.
@@ -438,8 +442,21 @@ const launch = exports.launch = async (
438
442
  catch(error) {
439
443
  // If retries remain:
440
444
  if (retries > 0) {
441
- console.log(`WARNING: Retrying launch (${retries} retries left)`);
442
- await wait(2000);
445
+ // Prepare to wait 1 second before a retry.
446
+ let waitSeconds = 1;
447
+ // If the error was a visit failure due to rate limiting:
448
+ if (error.message.includes('status429/retryAfterSeconds=')) {
449
+ // Change the wait to the requested time, if less than 10 seconds.
450
+ const waitSecondsRequest = Number(error.message.replace(/^.+=|\)$/g, ''));
451
+ if (! Number.isNaN(waitSecondsRequest) && waitSecondsRequest < 10) {
452
+ waitSeconds = waitSecondsRequest;
453
+ }
454
+ }
455
+ console.log(
456
+ `WARNING: Waiting ${waitSeconds} sec. before retrying (retries left: ${retries})`
457
+ );
458
+ await wait(1000 * waitSeconds + 100);
459
+ // Then retry the launch and navigation.
443
460
  return launch(report, debug, waits, tempBrowserID, tempURL, retries - 1);
444
461
  }
445
462
  // Otherwise, i.e. if no retries remain:
@@ -804,6 +821,7 @@ const doActs = async (report, opts = {}) => {
804
821
  if (act.data && ! act.data.prevented) {
805
822
  // If standardization is required:
806
823
  if (['also', 'only'].includes(standard)) {
824
+ console.log('>>>>>> Standardizing');
807
825
  // Initialize the standard result.
808
826
  act.standardResult = {
809
827
  totals: [0, 0, 0, 0],
@@ -69,12 +69,20 @@ const linksByType = async page => await page.evaluateHandle(() => {
69
69
  }
70
70
  };
71
71
  // FUNCTION DEFINITIONS END
72
- // Identify the list links in the page.
72
+ // Identify the lists in the page.
73
73
  const lists = Array.from(document.body.querySelectorAll('ul, ol'));
74
+ // Initialize an array of list links.
74
75
  const listLinks = [];
76
+ // For each one:
75
77
  lists.forEach(list => {
78
+ // If it is a list of links:
76
79
  if (isLinkList(list)) {
77
- listLinks.push(... Array.from(list.querySelectorAll('a')));
80
+ // Choose one of the links randomly, assuming they have uniform styles.
81
+ const links = Array.from(list.querySelectorAll('a'));
82
+ const randomIndex = Math.floor(Math.random() * links.length);
83
+ const randomLink = links[randomIndex];
84
+ // Add it to the array.
85
+ listLinks.push(randomLink);
78
86
  }
79
87
  });
80
88
  // Identify the inline links in the page.
@@ -163,6 +171,7 @@ exports.reporter = async (page, withItems) => {
163
171
  // Add its elements to the object.
164
172
  elements.headings[tagName] = Array.from(body.getElementsByTagName(tagName));
165
173
  });
174
+ // FUNCTION DEFINITION START
166
175
  // Tabulates the distribution of style properties for elements of a type.
167
176
  const tallyStyles = (typeName, elements, typeStyles, withItems) => {
168
177
  // If there are any elements:
@@ -226,6 +235,7 @@ exports.reporter = async (page, withItems) => {
226
235
  }
227
236
  }
228
237
  };
238
+ // FUNCTION DEFINITION END
229
239
  // Report the style-property distributions for the element types.
230
240
  tallyStyles('button', elements.buttons, buttonStyles, withItems);
231
241
  tallyStyles('adjacentLink', elements.links.adjacent, [], withItems);