testaro 5.0.1 → 5.1.2

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 (3) hide show
  1. package/package.json +1 -1
  2. package/run.js +2 -2
  3. package/tests/htmlcs.js +63 -38
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "5.0.1",
3
+ "version": "5.1.2",
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',
@@ -560,7 +560,7 @@ const visit = async (act, page, isStrict) => {
560
560
  // If the visit fails:
561
561
  if (response === 'error') {
562
562
  // Give up.
563
- const errorMsg = `ERROR: Attemts to visit ${requestedURL} failed`;
563
+ const errorMsg = `ERROR: Attempts to visit ${requestedURL} failed`;
564
564
  console.log(errorMsg);
565
565
  act.result = errorMsg;
566
566
  await page.goto('about:blank')
package/tests/htmlcs.js CHANGED
@@ -6,50 +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 ['WCAG2A', 'WCAG2AA', 'WCAG2AAA']) {
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
- if (! result[parts[0]][parts[1]]) {
42
- result[parts[0]][parts[1]] = {};
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);
43
33
  }
44
- if (! result[parts[0]][parts[1]][parts[4]]) {
45
- result[parts[0]][parts[1]][parts[4]] = [];
34
+ else {
35
+ result.prevented = true;
36
+ result.error = 'ERROR executing HTMLCS_RUNNER in the page';
37
+ break;
46
38
  }
47
- result[parts[0]][parts[1]][parts[4]].push({
48
- tagName: parts[2],
49
- id: parts[3],
50
- 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
+ }
51
76
  });
52
77
  }
53
- });
78
+ }
54
79
  return {result};
55
80
  };