testaro 60.2.1 → 60.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "60.2.1",
3
+ "version": "60.3.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": {
@@ -50,9 +50,10 @@ const actIndex = Number.parseInt(process.argv[2]);
50
50
 
51
51
  // FUNCTIONS
52
52
 
53
+ // Performs the tests of the act specified by the caller.
53
54
  const doTestAct = async () => {
54
55
  const reportPath = `${tmpDir}/report.json`;
55
- // Get the saved report.
56
+ // Get the report from the temporary directory.
56
57
  const reportJSON = await fs.readFile(reportPath, 'utf8');
57
58
  const report = JSON.parse(reportJSON);
58
59
  // Get a reference to the act in the report.
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  © 2023–2024 CVS Health and/or one of its affiliates. All rights reserved.
3
+ © 2025 Jonathan Robert Pool. All rights reserved.
3
4
 
4
5
  MIT License
5
6
 
@@ -705,7 +706,7 @@ const convert = (toolName, data, result, standardResult) => {
705
706
  // Round the totals of the standard result.
706
707
  standardResult.totals = standardResult.totals.map(total => Math.round(total));
707
708
  };
708
- // Converts the results.
709
+ // Converts the results of a test act.
709
710
  exports.standardize = act => {
710
711
  const {which, data, result, standardResult} = act;
711
712
  if (which && result && standardResult) {
package/run.js CHANGED
@@ -668,6 +668,11 @@ const abortActs = (report, actIndex) => {
668
668
  // Report that the job is aborted.
669
669
  console.log(`ERROR: Job aborted on act ${actIndex}`);
670
670
  };
671
+ // Returns the combination of browser ID and target URL of an act.
672
+ const launchSpecs = (act, report) => [
673
+ act.browserID || report.browserID || '',
674
+ act.target && act.target.url || report.target && report.target.url || ''
675
+ ];
671
676
  // Performs the acts in a report and adds the results to the report.
672
677
  const doActs = async (report, opts = {}) => {
673
678
  const {acts} = report;
@@ -752,13 +757,14 @@ const doActs = async (report, opts = {}) => {
752
757
  }
753
758
  // Otherwise, if the act is a launch:
754
759
  else if (type === 'launch') {
760
+ const actLaunchSpecs = launchSpecs(act, report);
755
761
  // Launch a browser, navigate to a page, and add the result to the act.
756
762
  await launch(
757
763
  report,
758
764
  debug,
759
765
  waits,
760
- act.browserID || report.browserID || '',
761
- act.target && act.target.url || report.target && report.target.url || ''
766
+ actLaunchSpecs[0],
767
+ actLaunchSpecs[1]
762
768
  );
763
769
  // If this failed:
764
770
  if (page.prevented) {
@@ -819,50 +825,6 @@ const doActs = async (report, opts = {}) => {
819
825
  toolTimes[act.which] += time;
820
826
  // If the act was not prevented:
821
827
  if (act.data && ! act.data.prevented) {
822
- // If standardization is required:
823
- if (['also', 'only'].includes(standard)) {
824
- console.log('>>>>>> Standardizing');
825
- // Initialize the standard result.
826
- act.standardResult = {
827
- totals: [0, 0, 0, 0],
828
- instances: []
829
- };
830
- // Populate it.
831
- standardize(act);
832
- // Launch a browser and navigate to the page.
833
- await launch(
834
- report,
835
- debug,
836
- waits,
837
- act.browserID || report.browserID || '',
838
- act.target && act.target.url || report.target && report.target.url || ''
839
- );
840
- // If this failed:
841
- if (page.prevented) {
842
- // Add this to the act.
843
- act.data ??= {};
844
- act.data.prevented = true;
845
- act.data.error = page.error || '';
846
- }
847
- // Otherwise, i.e. if it succeeded:
848
- else {
849
- // Add a box ID and a path ID to each of its standard instances if missing.
850
- for (const instance of act.standardResult.instances) {
851
- const elementID = await identify(instance, page);
852
- if (! instance.boxID) {
853
- instance.boxID = elementID ? elementID.boxID : '';
854
- }
855
- if (! instance.pathID) {
856
- instance.pathID = elementID ? elementID.pathID : '';
857
- }
858
- };
859
- }
860
- // If the original-format result is not to be included in the report:
861
- if (standard === 'only') {
862
- // Remove it.
863
- delete act.result;
864
- }
865
- }
866
828
  // If the act has expectations:
867
829
  const expectations = act.expect;
868
830
  if (expectations) {
@@ -1501,7 +1463,71 @@ const doActs = async (report, opts = {}) => {
1501
1463
  }
1502
1464
  }
1503
1465
  console.log('Acts completed');
1466
+ // If standardization is required:
1467
+ if (['also', 'only'].includes(standard)) {
1468
+ console.log('>>>> Standardizing results of test acts');
1469
+ const launchSpecActs = {};
1470
+ // For each act:
1471
+ report.acts.forEach((act, index) => {
1472
+ // If it is a test act:
1473
+ if (act.type === 'test') {
1474
+ // Classify it by its browser ID and target URL.
1475
+ const specs = launchSpecs(act, report);
1476
+ const specString = `${specs[0]}>${specs[1]}`;
1477
+ if (launchSpecActs[specString]) {
1478
+ launchSpecActs[specString].push(index);
1479
+ }
1480
+ else {
1481
+ launchSpecActs[specString] = [index];
1482
+ }
1483
+ }
1484
+ });
1485
+ // For each browser ID/target URL class:
1486
+ for (const specString of Object.keys(launchSpecActs)) {
1487
+ const specs = specString.split('>');
1488
+ // Launch a browser and navigate to the page.
1489
+ await launch(
1490
+ report,
1491
+ debug,
1492
+ waits,
1493
+ specs[0],
1494
+ specs[1]
1495
+ );
1496
+ // For each test act with the class:
1497
+ for (const specActIndex of launchSpecActs[specString]) {
1498
+ const act = report.acts[specActIndex];
1499
+ // Initialize the standard result.
1500
+ act.standardResult = {
1501
+ totals: [0, 0, 0, 0],
1502
+ instances: []
1503
+ };
1504
+ // Populate it.
1505
+ standardize(act);
1506
+ // If the launch and navigation succeeded:
1507
+ if (! page.prevented) {
1508
+ // Add a box ID and a path ID to each of its standard instances if missing.
1509
+ for (const instance of act.standardResult.instances) {
1510
+ const elementID = await identify(instance, page);
1511
+ if (! instance.boxID) {
1512
+ instance.boxID = elementID ? elementID.boxID : '';
1513
+ }
1514
+ if (! instance.pathID) {
1515
+ instance.pathID = elementID ? elementID.pathID : '';
1516
+ }
1517
+ };
1518
+ }
1519
+ // If the original-format result is not to be included in the report:
1520
+ if (standard === 'only') {
1521
+ // Remove it.
1522
+ delete act.result;
1523
+ }
1524
+ };
1525
+ };
1526
+ console.log('>>>> Standardization completed');
1527
+ }
1528
+ // Close the browser.
1504
1529
  await browserClose();
1530
+ // Delete the temporary report file.
1505
1531
  await fs.rm(reportPath, {force: true});
1506
1532
  return report;
1507
1533
  };