testaro 62.0.3 → 62.0.4

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 (2) hide show
  1. package/package.json +1 -1
  2. package/tests/ibm.js +40 -89
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "62.0.3",
3
+ "version": "62.0.4",
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/tests/ibm.js CHANGED
@@ -22,7 +22,6 @@
22
22
 
23
23
  // IMPORTS
24
24
 
25
- const fs = require('fs').promises;
26
25
  // Scanner. Importing and executing 'close' crashed the Node process.
27
26
  const accessibilityChecker = require('accessibility-checker');
28
27
  const {getCompliance} = accessibilityChecker;
@@ -30,7 +29,7 @@ const {getCompliance} = accessibilityChecker;
30
29
  // FUNCTIONS
31
30
 
32
31
  // Runs the IBM test and returns the result.
33
- const run = async (content, timeLimit) => {
32
+ const run = async content => {
34
33
  const nowLabel = (new Date()).toISOString().slice(0, 19);
35
34
  try {
36
35
  const ibmReport = await getCompliance(content, nowLabel);
@@ -66,13 +65,13 @@ const limitRuleTotals = (actReport, rules) => {
66
65
  }
67
66
  };
68
67
  // Trims an IBM report.
69
- const trimActReport = (data, actReport, withItems, rules) => {
68
+ const trimActReport = (actReport, withItems, rules) => {
70
69
  // If the act report includes a summary:
71
70
  if (actReport && actReport.summary) {
72
71
  // Remove excluded rules from the act report.
73
72
  limitRuleTotals(actReport, rules);
74
- // If the act report includes totals:
75
73
  const totals = actReport.summary.counts;
74
+ // If the act report includes totals:
76
75
  if (totals) {
77
76
  // If itemization is required:
78
77
  if (withItems) {
@@ -101,115 +100,67 @@ const trimActReport = (data, actReport, withItems, rules) => {
101
100
  }
102
101
  // Otherwise, i.e. if it excludes totals:
103
102
  else {
104
- // Report this.
105
- const error = 'ERROR: No totals reported';
106
- console.log(error);
107
- data.prevented = true;
108
- data.error = error;
109
- // Return an empty act report.
103
+ // Return an act report with this error.
110
104
  return {
111
- totals: {},
112
- items: []
105
+ totals: null,
106
+ items: [],
107
+ error: 'No totals reported'
113
108
  };
114
109
  }
115
110
  }
116
111
  // Otherwise, i.e. if it excludes a summary:
117
112
  else {
118
- // Report this.
119
- const error = 'ERROR: No summary reported';
120
- console.log(error);
121
- data.prevented = true;
122
- data.error = error;
123
- // Return an empty act report.
113
+ // Return an act report with this error.
124
114
  return {
125
- totals: {},
126
- items: []
127
- };
128
- }
129
- };
130
- // Performs the IBM tests and returns an act report.
131
- const doTest = async (content, withItems, timeLimit, rules) => {
132
- // Conduct the tests.
133
- const data = {};
134
- try {
135
- const runReport = await run(content, timeLimit);
136
- // If there were results:
137
- if (runReport.report) {
138
- // Return a trimmed act report.
139
- const {report} = runReport;
140
- const trimmedReport = trimActReport(data, report, withItems, rules);
141
- return {
142
- data,
143
- result: trimmedReport
144
- };
145
- }
146
- // Otherwise, i.e. if there were no results:
147
- else {
148
- // Return this.
149
- return {
150
- data: runReport,
151
- result: {}
152
- }
153
- }
154
- }
155
- catch(error) {
156
- const message = `Act failed (${error.message.slice(0, 200)})`;
157
- console.log(message);
158
- data.prevented = true;
159
- data.error = message;
160
- return {
161
- data,
162
- result: {}
115
+ totals: null,
116
+ items: [],
117
+ error: 'No summary reported'
163
118
  };
164
119
  }
165
120
  };
166
121
  // Conducts and reports the IBM Equal Access tests.
167
- exports.reporter = async (page, report, actIndex, timeLimit) => {
122
+ exports.reporter = async (page, report, actIndex) => {
168
123
  const act = report.acts[actIndex];
169
124
  const {withItems, withNewContent, rules} = act;
170
125
  const contentType = withNewContent ? 'new' : 'existing';
171
126
  try {
172
127
  const typeContent = contentType === 'existing' ? await page.content() : page.url();
173
- // Perform the tests.
174
- const actReport = await doTest(typeContent, withItems, timeLimit, rules);
175
- // If the testing was finished on time:
176
- if (actReport !== 'timedOut') {
177
- const {data, result} = actReport;
178
- // If the act was prevented:
179
- if (data && data.prevented) {
180
- // Report this.
181
- const message = 'ERROR: Act was prevented';
182
- data.error ??= message;
183
- // Return the failure.
128
+ // Conduct the tests.
129
+ const runReport = await run(typeContent);
130
+ const {report} = runReport;
131
+ // If there were results:
132
+ if (report) {
133
+ // Trim them.
134
+ const trimmedReport = trimActReport(report, withItems, rules);
135
+ const {error} = trimmedReport;
136
+ // If the report was not trimmable:
137
+ if (error) {
138
+ // Return an act report with this error.
184
139
  return {
185
- data,
140
+ data: {
141
+ prevented: true,
142
+ error
143
+ },
186
144
  result: {}
187
- };
188
- }
189
- // Otherwise, i.e. if the act was not prevented:
190
- else {
191
- // Return the result.
192
- return {
193
- data,
194
- result
195
- };
145
+ }
196
146
  }
197
- }
198
- // Otherwise, i.e. if the testing timed out:
199
- else {
200
- // Report this.
147
+ // Otherwise, i.e. if the report was trimmable, return it.
201
148
  return {
202
- data: {
203
- prevented: true,
204
- error: message
205
- },
206
- result: {}
149
+ data: {},
150
+ result: trimmedReport
207
151
  };
208
152
  }
153
+ // Otherwise, i.e. if there was only an error, return it in an act report.
154
+ return {
155
+ data: runReport,
156
+ result: {}
157
+ }
209
158
  }
159
+ // If an error occurred:
210
160
  catch(error) {
211
- const message = `Act crashed (${error.message.slice(0, 200)})`;
212
- console.log(`ERROR: ${message}`);
161
+ const message = `Act failed (${error.message.slice(0, 200)})`;
162
+ console.log(message);
163
+ // Return it in an act report.
213
164
  return {
214
165
  data: {
215
166
  prevented: true,