testaro 5.1.0 → 5.1.3

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/htmlcs/HTMLCS.js CHANGED
@@ -6321,10 +6321,8 @@
6321
6321
  self.output(messages[i]);
6322
6322
  msgCount[messages[i].type]++;
6323
6323
  }
6324
- console.log("done");
6325
6324
  }, function () {
6326
6325
  console.log("Something in HTML_CodeSniffer failed to parse. Cannot run.");
6327
- console.log("done");
6328
6326
  }, "en");
6329
6327
  return Array.from(messageStrings);
6330
6328
  };
@@ -7968,4 +7966,4 @@
7968
7966
  };
7969
7967
  }(); // Expose globals.
7970
7968
  return _global;
7971
- }));
7969
+ }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "5.1.0",
3
+ "version": "5.1.3",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/run.js CHANGED
@@ -37,7 +37,7 @@ const tests = {
37
37
  focInd: 'focus indicators',
38
38
  focOp: 'focusability and operability',
39
39
  hover: 'hover-caused content additions',
40
- htmlcs: 'HTML CodeSniffer WCAG 2.1 A, AA, and AAA rulesets',
40
+ htmlcs: 'HTML CodeSniffer WCAG 2.1 AA ruleset',
41
41
  ibm: 'IBM Accessibility Checker',
42
42
  labClash: 'labeling inconsistencies',
43
43
  linkUl: 'adjacent-link underlining',
@@ -257,6 +257,7 @@ const closeBrowsers = async () => {
257
257
  await browser.close();
258
258
  }
259
259
  }
260
+ browsers = [];
260
261
  };
261
262
  // Launches a browser.
262
263
  const launch = async typeName => {
@@ -560,7 +561,7 @@ const visit = async (act, page, isStrict) => {
560
561
  // If the visit fails:
561
562
  if (response === 'error') {
562
563
  // Give up.
563
- const errorMsg = `ERROR: Attemts to visit ${requestedURL} failed`;
564
+ const errorMsg = `ERROR: Attempts to visit ${requestedURL} failed`;
564
565
  console.log(errorMsg);
565
566
  act.result = errorMsg;
566
567
  await page.goto('about:blank')
package/tests/htmlcs.js CHANGED
@@ -6,51 +6,75 @@
6
6
  // FUNCTIONS
7
7
  // Runs HTML CodeSniffer on the page.
8
8
  exports.reporter = async page => {
9
+ const result = {};
9
10
  await page.addScriptTag({
10
11
  path: `${__dirname}/../htmlcs/HTMLCS.js`
12
+ })
13
+ .catch(error => {
14
+ console.log(`ERROR adding the htmlcs script to the page (${error.message})`);
15
+ result.prevented = true;
16
+ result.error = 'ERROR adding the htmlcs script to the page';
11
17
  });
12
- let messageStrings = [];
13
- for (const standard of ['WCAG2AA']) {
14
- const nextIssues = await page.evaluate(standard => HTMLCS_RUNNER.run(standard), standard);
15
- messageStrings.push(... nextIssues);
16
- }
17
- // Sort the issues by class and standard.
18
- messageStrings.sort();
19
- // Remove any duplicate issues.
20
- messageStrings = [... new Set(messageStrings)];
21
- // Initialize the result.
22
- const result = {
23
- Error: {},
24
- Warning: {}
25
- };
26
- // For each issue:
27
- messageStrings.forEach(string => {
28
- const parts = string.split(/\|/g);
29
- const partCount = parts.length;
30
- if (partCount !== 6) {
31
- console.log(`ERROR: Issue string ${string} has too few or too many parts`);
32
- }
33
- // If it is an error or a warning (not a notice):
34
- else if (['Error', 'Warning'].includes(parts[0])) {
35
- /*
36
- Add the issue to an issueClass.issueCode.description array in the result.
37
- This saves space, because, although some descriptions are issue-specific, such as
38
- descriptions that state the contrast ratio of an element, most descriptions are
39
- generic, so typically many issues share a description.
40
- */
41
- const issueCode = parts[1].replace(/^WCAG2|\.Principle\d\.Guideline[\d_]+/g, '');
42
- if (! result[parts[0]][issueCode]) {
43
- result[parts[0]][issueCode] = {};
18
+ if (! result.prevented) {
19
+ let messageStrings = [];
20
+ for (const standard of ['WCAG2AA']) {
21
+ const nextIssues = await page.evaluate(standard => {
22
+ let issues = null;
23
+ try {
24
+ issues = HTMLCS_RUNNER.run(standard);
25
+ }
26
+ catch(error) {
27
+ console.log(`ERROR executing HTMLCS_RUNNER on ${document.URL} (${error.message})`);
28
+ };
29
+ return issues;
30
+ }, standard);
31
+ if (nextIssues) {
32
+ messageStrings.push(... nextIssues);
44
33
  }
45
- if (! result[parts[0]][issueCode][parts[4]]) {
46
- result[parts[0]][issueCode][parts[4]] = [];
34
+ else {
35
+ result.prevented = true;
36
+ result.error = 'ERROR executing HTMLCS_RUNNER in the page';
37
+ break;
47
38
  }
48
- result[parts[0]][issueCode][parts[4]].push({
49
- tagName: parts[2],
50
- id: parts[3],
51
- code: parts[5]
39
+ };
40
+ if (! result.prevented) {
41
+ // Sort the issues by class and standard.
42
+ messageStrings.sort();
43
+ // Remove any duplicate issues.
44
+ messageStrings = [... new Set(messageStrings)];
45
+ // Initialize the result.
46
+ result.Error = {};
47
+ result.Warning = {};
48
+ // For each issue:
49
+ messageStrings.forEach(string => {
50
+ const parts = string.split(/\|/, 6);
51
+ const partCount = parts.length;
52
+ if (partCount < 6) {
53
+ console.log(`ERROR: Issue string ${string} has too few parts`);
54
+ }
55
+ // If it is an error or a warning (not a notice):
56
+ else if (['Error', 'Warning'].includes(parts[0])) {
57
+ /*
58
+ Add the issue to an issueClass.issueCode.description array in the result.
59
+ This saves space, because, although some descriptions are issue-specific, such as
60
+ descriptions that state the contrast ratio of an element, most descriptions are
61
+ generic, so typically many issues share a description.
62
+ */
63
+ const issueCode = parts[1].replace(/^WCAG2|\.Principle\d\.Guideline[\d_]+/g, '');
64
+ if (! result[parts[0]][issueCode]) {
65
+ result[parts[0]][issueCode] = {};
66
+ }
67
+ if (! result[parts[0]][issueCode][parts[4]]) {
68
+ result[parts[0]][issueCode][parts[4]] = [];
69
+ }
70
+ result[parts[0]][issueCode][parts[4]].push({
71
+ tagName: parts[2],
72
+ id: parts[3],
73
+ code: parts[5]
74
+ });
75
+ }
52
76
  });
53
77
  }
54
- });
78
+ }
55
79
  return {result};
56
80
  };