testaro 59.2.7 → 59.2.9

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": "59.2.7",
3
+ "version": "59.2.9",
4
4
  "description": "Run 1000 web accessibility tests from 11 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -34,6 +34,7 @@
34
34
 
35
35
  // IMPORTS
36
36
 
37
+ const pixelmatch = require('pixelmatch').default;
37
38
  const {PNG} = require('pngjs');
38
39
 
39
40
  // FUNCTIONS
@@ -103,8 +104,6 @@ exports.visChange = async (page, options = {}) => {
103
104
  // Get their dimensions.
104
105
  const {width, height} = pngs[0];
105
106
  // Get the count of differing pixels between the shots.
106
- const pixelmatchModule = await import('pixelmatch');
107
- const pixelmatch = pixelmatchModule.default;
108
107
  const pixelChanges = pixelmatch(pngs[0].data, pngs[1].data, null, width, height);
109
108
  // Get the ratio of differing to all pixels as a percentage.
110
109
  const changePercent = 100 * pixelChanges / (width * height);
package/tests/alfa.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  © 2021–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
 
@@ -27,26 +28,27 @@
27
28
  This test implements the alfa ruleset for accessibility.
28
29
  */
29
30
 
31
+ // IMPORTS
32
+
33
+ let alfaRules = require('@siteimprove/alfa-rules').default;
34
+ const {Audit} = require('@siteimprove/alfa-act');
35
+ const path = require('path');
36
+ const {Playwright} = require('@siteimprove/alfa-playwright');
37
+
30
38
  // FUNCTIONS
31
39
 
40
+ // Simplifies the spacing of a string.
41
+ const tidy = string => string.replace(/\n/g, ' ').replace(/\s+/g, ' ');
42
+
32
43
  // Conducts and reports the alfa tests.
33
- exports.reporter = async (page, report, actIndex, timeLimit) => {
44
+ exports.reporter = async (page, report, actIndex) => {
34
45
  const act = report.acts[actIndex];
35
46
  const {rules} = act;
36
- const alfaRulesModule = await import('@siteimprove/alfa-rules');
37
- const alfaRules = alfaRulesModule.default;
38
47
  // If only some rules are to be employed:
39
48
  if (rules && rules.length) {
40
49
  // Remove the other rules.
41
50
  alfaRules = alfaRules.filter(rule => rules.includes(rule.uri.replace(/^.+-/, '')));
42
51
  }
43
- // Open a page for the summaries of the alfa rules.
44
- const context = page.context();
45
- const rulePage = await context.newPage();
46
- rulePage.on('console', msg => {
47
- const msgText = msg.text();
48
- console.log(msgText);
49
- });
50
52
  // Initialize the act report.
51
53
  const data = {};
52
54
  const result = {
@@ -57,52 +59,28 @@ exports.reporter = async (page, report, actIndex, timeLimit) => {
57
59
  items: []
58
60
  };
59
61
  try {
60
- // Get the Alfa rules.
61
- const response = await rulePage.goto('https://alfa.siteimprove.com/rules', {timeout: 10000});
62
- let ruleData = {};
63
- // If they were obtained:
64
- if (response.status() === 200) {
65
- // Compile data on the rule IDs and summaries.
66
- ruleData = await rulePage.evaluate(() => {
67
- const rulePs = Array.from(document.querySelectorAll('p.h5'));
68
- const ruleData = {};
69
- rulePs.forEach(ruleP => {
70
- const childNodes = Array.from(ruleP.childNodes);
71
- const ruleID = childNodes[0].textContent.slice(4).toLowerCase();
72
- const ruleText = childNodes
73
- .slice(1)
74
- .map(node => node.textContent)
75
- .join(' ')
76
- .trim()
77
- .replace(/"/g, '\'')
78
- .replace(/\s+/g, ' ');
79
- ruleData[ruleID] = ruleText;
80
- });
81
- return ruleData;
82
- });
83
- await rulePage.close();
84
- }
85
62
  // Test the page content with the specified rules.
86
63
  const doc = await page.evaluateHandle('document');
87
- const alfaPlaywrightModule = await import('@siteimprove/alfa-playwright');
88
- const {Playwright} = alfaPlaywrightModule;
89
64
  const alfaPage = await Playwright.toPage(doc);
90
- const alfaActModule = await import('@siteimprove/alfa-act');
91
- const {Audit} = alfaActModule;
92
65
  const audit = Audit.of(alfaPage, alfaRules);
66
+ // Get the test outcomes.
93
67
  const outcomes = Array.from(await audit.evaluate());
94
- // For each failure or warning:
68
+ // For each outcome:
95
69
  outcomes.forEach((outcome, index) => {
96
70
  const {target} = outcome;
71
+ // If the target exists and is not a collection:
97
72
  if (target && ! target._members) {
73
+ // Convert the outcome to an object.
98
74
  const outcomeJ = outcome.toJSON();
75
+ // Get the verdict.
99
76
  const verdict = outcomeJ.outcome;
77
+ // If the verdict is a failure or warning:
100
78
  if (verdict !== 'passed') {
101
79
  // Add to the result.
102
- const {rule} = outcomeJ;
80
+ const {expectations, rule} = outcomeJ;
103
81
  const {tags, uri, requirements} = rule;
104
82
  const ruleID = uri.replace(/^.+-/, '');
105
- const ruleSummary = ruleData[ruleID] || '';
83
+ let ruleSummary = tidy(expectations?.[0]?.[1]?.error?.message || '');
106
84
  const targetJ = outcomeJ.target;
107
85
  const codeLines = target.toString().split('\n');
108
86
  if (codeLines[0] === '#document') {
@@ -161,7 +139,7 @@ exports.reporter = async (page, report, actIndex, timeLimit) => {
161
139
  });
162
140
  }
163
141
  catch(error) {
164
- console.log(`ERROR: navigation to URL timed out (${error})`);
142
+ console.log(`ERROR: Navigation to URL timed out (${error})`);
165
143
  data.prevented = true;
166
144
  data.error = 'ERROR: Act failed';
167
145
  }