testaro 60.1.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/run.js +27 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "60.1.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],