testaro 59.2.8 → 59.2.10

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.8",
3
+ "version": "59.2.10",
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
@@ -288,7 +288,7 @@ const launch = exports.launch = async (
288
288
  },
289
289
  headless: ! debug,
290
290
  slowMo: waits || 0,
291
- args: ['--disable-dev-shm-usage']
291
+ ...(browserID === 'chromium' && {args: ['--disable-dev-shm-usage']})
292
292
  };
293
293
  try {
294
294
  // Replace the browser with a new one.
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
 
@@ -29,12 +30,16 @@
29
30
 
30
31
  // IMPORTS
31
32
 
33
+ let alfaRules = require('@siteimprove/alfa-rules').default;
32
34
  const {Audit} = require('@siteimprove/alfa-act');
35
+ const path = require('path');
33
36
  const {Playwright} = require('@siteimprove/alfa-playwright');
34
- let alfaRules = require('@siteimprove/alfa-rules').default;
35
37
 
36
38
  // FUNCTIONS
37
39
 
40
+ // Simplifies the spacing of a string.
41
+ const tidy = string => string.replace(/\n/g, ' ').replace(/\s+/g, ' ');
42
+
38
43
  // Conducts and reports the alfa tests.
39
44
  exports.reporter = async (page, report, actIndex) => {
40
45
  const act = report.acts[actIndex];
@@ -44,13 +49,6 @@ exports.reporter = async (page, report, actIndex) => {
44
49
  // Remove the other rules.
45
50
  alfaRules = alfaRules.filter(rule => rules.includes(rule.uri.replace(/^.+-/, '')));
46
51
  }
47
- // Open a page for the summaries of the alfa rules.
48
- const context = page.context();
49
- const rulePage = await context.newPage();
50
- rulePage.on('console', msg => {
51
- const msgText = msg.text();
52
- console.log(msgText);
53
- });
54
52
  // Initialize the act report.
55
53
  const data = {};
56
54
  const result = {
@@ -61,48 +59,28 @@ exports.reporter = async (page, report, actIndex) => {
61
59
  items: []
62
60
  };
63
61
  try {
64
- // Get the Alfa rules.
65
- const response = await rulePage.goto('https://alfa.siteimprove.com/rules', {timeout: 10000});
66
- let ruleData = {};
67
- // If they were obtained:
68
- if (response.status() === 200) {
69
- // Compile data on the rule IDs and summaries.
70
- ruleData = await rulePage.evaluate(() => {
71
- const rulePs = Array.from(document.querySelectorAll('p.h5'));
72
- const ruleData = {};
73
- rulePs.forEach(ruleP => {
74
- const childNodes = Array.from(ruleP.childNodes);
75
- const ruleID = childNodes[0].textContent.slice(4).toLowerCase();
76
- const ruleText = childNodes
77
- .slice(1)
78
- .map(node => node.textContent)
79
- .join(' ')
80
- .trim()
81
- .replace(/"/g, '\'')
82
- .replace(/\s+/g, ' ');
83
- ruleData[ruleID] = ruleText;
84
- });
85
- return ruleData;
86
- });
87
- await rulePage.close();
88
- }
89
62
  // Test the page content with the specified rules.
90
63
  const doc = await page.evaluateHandle('document');
91
64
  const alfaPage = await Playwright.toPage(doc);
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') {