testaro 10.3.0 → 10.4.1

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/actSpecs.js CHANGED
@@ -246,7 +246,8 @@ exports.actSpecs = {
246
246
  withItems: [true, 'boolean', '', 'itemize'],
247
247
  withNewContent: [
248
248
  false, 'boolean', '', 'true: use a URL; false: use page content; omitted: both'
249
- ]
249
+ ],
250
+ rules: [false, 'array', 'areStrings', 'rule names (e.g., RPT_Elem_UniqueId), if not all']
250
251
  }
251
252
  ],
252
253
  labClash: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "10.3.0",
3
+ "version": "10.4.1",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tests/ibm.js CHANGED
@@ -41,15 +41,34 @@ const run = async (content, timeLimit) => {
41
41
  clearTimeout(timeoutID);
42
42
  return result;
43
43
  };
44
+ // Revises report totals for any rule limitation.
45
+ const limitRuleTotals = (report, rules) => {
46
+ if (rules && Array.isArray(rules) && rules.length) {
47
+ const totals = report.report.summary.counts;
48
+ const items = report.report.results;
49
+ totals.violation = totals.recommendation = 0;
50
+ items.forEach(item => {
51
+ if (rules.includes(item.ruleId)) {
52
+ totals[item.level]++;
53
+ }
54
+ });
55
+ }
56
+ };
44
57
  // Trims an IBM report.
45
- const trimReport = (report, withItems) => {
58
+ const trimReport = (report, withItems, rules) => {
46
59
  const data = {};
47
60
  if (report && report.report && report.report.summary) {
61
+ limitRuleTotals(report, rules);
48
62
  const totals = report.report.summary.counts;
49
63
  if (totals) {
50
64
  data.totals = totals;
51
65
  if (withItems) {
52
- data.items = report.report.results;
66
+ if (rules && Array.isArray(rules) && rules.length) {
67
+ data.items = report.report.results.filter(item => rules.includes(item.ruleId));
68
+ }
69
+ else {
70
+ data.items = report.report.results;
71
+ }
53
72
  data.items.forEach(item => {
54
73
  delete item.apiArgs;
55
74
  delete item.category;
@@ -72,8 +91,8 @@ const trimReport = (report, withItems) => {
72
91
  }
73
92
  return data;
74
93
  };
75
- // Performs an IBM test and return the result.
76
- const doTest = async (content, withItems, timeLimit) => {
94
+ // Performs an IBM test and returns the result.
95
+ const doTest = async (content, withItems, timeLimit, rules) => {
77
96
  // Conduct the test and get the result.
78
97
  const report = await run(content, timeLimit);
79
98
  // If the test did not time out:
@@ -89,7 +108,7 @@ const doTest = async (content, withItems, timeLimit) => {
89
108
  console.log('ibm test created no result files.');
90
109
  }
91
110
  // Return the result.
92
- const typeReport = trimReport(report, withItems);
111
+ const typeReport = trimReport(report, withItems, rules);
93
112
  return typeReport;
94
113
  }
95
114
  else {
@@ -100,13 +119,13 @@ const doTest = async (content, withItems, timeLimit) => {
100
119
  }
101
120
  };
102
121
  // Returns results of one or two IBM tests.
103
- exports.reporter = async (page, withItems, withNewContent) => {
122
+ exports.reporter = async (page, withItems, withNewContent, rules) => {
104
123
  // If a test with existing content is to be performed:
105
124
  const result = {};
106
125
  if (! withNewContent) {
107
126
  const timeLimit = 20;
108
127
  const typeContent = await page.content();
109
- result.content = await doTest(typeContent, withItems, timeLimit);
128
+ result.content = await doTest(typeContent, withItems, timeLimit, rules);
110
129
  if (result.content.prevented) {
111
130
  result.prevented = true;
112
131
  console.log(`ERROR: Getting ibm test report from page timed out at ${timeLimit} seconds`);
@@ -116,7 +135,7 @@ exports.reporter = async (page, withItems, withNewContent) => {
116
135
  if ([true, undefined].includes(withNewContent)) {
117
136
  const timeLimit = 20;
118
137
  const typeContent = page.url();
119
- result.url = await doTest(typeContent, withItems, timeLimit);
138
+ result.url = await doTest(typeContent, withItems, timeLimit, rules);
120
139
  if (result.url.prevented) {
121
140
  result.prevented = true;
122
141
  console.log(`ERROR: Getting ibm test report from URL timed out at ${timeLimit} seconds`);