testaro 32.2.0 → 32.2.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/tests/qualWeb.js +111 -105
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "32.2.0",
3
+ "version": "32.2.1",
4
4
  "description": "Run 960 web accessibility tests from 9 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tests/qualWeb.js CHANGED
@@ -61,143 +61,149 @@ exports.reporter = async (page, options) => {
61
61
  }
62
62
  };
63
63
  // Specify a URL or provide the content.
64
- if (withNewContent) {
65
- qualWebOptions.url = page.url();
66
- }
67
- else {
68
- qualWebOptions.html = await page.content();
69
- }
70
- // Specify which rules to test for.
71
- const actSpec = rules ? rules.find(typeRules => typeRules.startsWith('act:')) : null;
72
- const wcagSpec = rules ? rules.find(typeRules => typeRules.startsWith('wcag:')) : null;
73
- const bestSpec = rules ? rules.find(typeRules => typeRules.startsWith('best:')) : null;
74
- if (actSpec) {
75
- if (actSpec === 'act:') {
76
- qualWebOptions.execute.act = false;
64
+ try {
65
+ if (withNewContent) {
66
+ qualWebOptions.url = page.url();
77
67
  }
78
68
  else {
79
- const actRules = actSpec.slice(4).split(',').map(num => `QW-ACT-R${num}`);
80
- qualWebOptions['act-rules'] = {rules: actRules};
69
+ qualWebOptions.html = await page.content();
70
+ }
71
+ // Specify which rules to test for.
72
+ const actSpec = rules ? rules.find(typeRules => typeRules.startsWith('act:')) : null;
73
+ const wcagSpec = rules ? rules.find(typeRules => typeRules.startsWith('wcag:')) : null;
74
+ const bestSpec = rules ? rules.find(typeRules => typeRules.startsWith('best:')) : null;
75
+ if (actSpec) {
76
+ if (actSpec === 'act:') {
77
+ qualWebOptions.execute.act = false;
78
+ }
79
+ else {
80
+ const actRules = actSpec.slice(4).split(',').map(num => `QW-ACT-R${num}`);
81
+ qualWebOptions['act-rules'] = {rules: actRules};
82
+ qualWebOptions.execute.act = true;
83
+ }
84
+ }
85
+ else {
86
+ qualWebOptions['act-rules'] = {
87
+ levels: ['A', 'AA', 'AAA'],
88
+ principles: ['Perceivable', 'Operable', 'Understandable', 'Robust']
89
+ };
81
90
  qualWebOptions.execute.act = true;
82
91
  }
83
- }
84
- else {
85
- qualWebOptions['act-rules'] = {
86
- levels: ['A', 'AA', 'AAA'],
87
- principles: ['Perceivable', 'Operable', 'Understandable', 'Robust']
88
- };
89
- qualWebOptions.execute.act = true;
90
- }
91
- if (wcagSpec) {
92
- if (wcagSpec === 'wcag:') {
93
- qualWebOptions.execute.wcag = false;
92
+ if (wcagSpec) {
93
+ if (wcagSpec === 'wcag:') {
94
+ qualWebOptions.execute.wcag = false;
95
+ }
96
+ else {
97
+ const wcagTechniques = wcagSpec.slice(5).split(',').map(num => `QW-WCAG-T${num}`);
98
+ qualWebOptions['wcag-techniques'] = {techniques: wcagTechniques};
99
+ qualWebOptions.execute.wcag = true;
100
+ }
94
101
  }
95
102
  else {
96
- const wcagTechniques = wcagSpec.slice(5).split(',').map(num => `QW-WCAG-T${num}`);
97
- qualWebOptions['wcag-techniques'] = {techniques: wcagTechniques};
103
+ qualWebOptions['wcag-techniques'] = {
104
+ levels: ['A', 'AA', 'AAA'],
105
+ principles: ['Perceivable', 'Operable', 'Understandable', 'Robust']
106
+ };
98
107
  qualWebOptions.execute.wcag = true;
99
108
  }
100
- }
101
- else {
102
- qualWebOptions['wcag-techniques'] = {
103
- levels: ['A', 'AA', 'AAA'],
104
- principles: ['Perceivable', 'Operable', 'Understandable', 'Robust']
105
- };
106
- qualWebOptions.execute.wcag = true;
107
- }
108
- if (bestSpec) {
109
- if (bestSpec === 'best:') {
110
- qualWebOptions.execute.bp = false;
109
+ if (bestSpec) {
110
+ if (bestSpec === 'best:') {
111
+ qualWebOptions.execute.bp = false;
112
+ }
113
+ else {
114
+ const bestPractices = bestSpec.slice(5).split(',').map(num => `QW-BP${num}`);
115
+ qualWebOptions['best-practices'] = {bestPractices};
116
+ // qualWebOptions.execute.bp = true;
117
+ // Temporarily disable best practices, because they crash QualWeb.
118
+ qualWebOptions.execute.bp = false;
119
+ }
111
120
  }
112
121
  else {
113
- const bestPractices = bestSpec.slice(5).split(',').map(num => `QW-BP${num}`);
114
- qualWebOptions['best-practices'] = {bestPractices};
115
122
  // qualWebOptions.execute.bp = true;
116
123
  // Temporarily disable best practices, because they crash QualWeb.
117
124
  qualWebOptions.execute.bp = false;
118
125
  }
119
- }
120
- else {
121
- // qualWebOptions.execute.bp = true;
122
- // Temporarily disable best practices, because they crash QualWeb.
123
- qualWebOptions.execute.bp = false;
124
- }
125
- // Get the report.
126
- let actReports = await qualWeb.evaluate(qualWebOptions);
127
- // Remove the copy of the DOM from it.
128
- const result = actReports[withNewContent ? qualWebOptions.url : 'customHtml'];
129
- if (result && result.system && result.system.page && result.system.page.dom) {
130
- delete result.system.page.dom;
131
- // For each test section of the act report:
132
- const {modules} = result;
133
- if (modules) {
134
- for (const section of ['act-rules', 'wcag-techniques', 'best-practices']) {
135
- if (qualWebOptions[section]) {
136
- if (modules[section]) {
137
- const {assertions} = modules[section];
138
- if (assertions) {
139
- const ruleIDs = Object.keys(assertions);
140
- ruleIDs.forEach(ruleID => {
141
- // Remove passing results.
142
- const ruleAssertions = assertions[ruleID];
143
- const {metadata} = ruleAssertions;
144
- if (metadata) {
145
- if (metadata.warning === 0 && metadata.failed === 0) {
146
- delete assertions[ruleID];
147
- }
148
- else {
149
- if (ruleAssertions.results) {
150
- ruleAssertions.results = ruleAssertions.results.filter(
151
- raResult => raResult.verdict !== 'passed'
152
- );
126
+ // Get the report.
127
+ let actReports = await qualWeb.evaluate(qualWebOptions);
128
+ // Remove the copy of the DOM from it.
129
+ const result = actReports[withNewContent ? qualWebOptions.url : 'customHtml'];
130
+ if (result && result.system && result.system.page && result.system.page.dom) {
131
+ delete result.system.page.dom;
132
+ // For each test section of the act report:
133
+ const {modules} = result;
134
+ if (modules) {
135
+ for (const section of ['act-rules', 'wcag-techniques', 'best-practices']) {
136
+ if (qualWebOptions[section]) {
137
+ if (modules[section]) {
138
+ const {assertions} = modules[section];
139
+ if (assertions) {
140
+ const ruleIDs = Object.keys(assertions);
141
+ ruleIDs.forEach(ruleID => {
142
+ // Remove passing results.
143
+ const ruleAssertions = assertions[ruleID];
144
+ const {metadata} = ruleAssertions;
145
+ if (metadata) {
146
+ if (metadata.warning === 0 && metadata.failed === 0) {
147
+ delete assertions[ruleID];
153
148
  }
154
- }
155
- }
156
- // Shorten long HTML codes of elements.
157
- const {results} = ruleAssertions;
158
- results.forEach(raResult => {
159
- const {elements} = raResult;
160
- if (elements && elements.length) {
161
- elements.forEach(element => {
162
- if (element.htmlCode && element.htmlCode.length > 700) {
163
- element.htmlCode = `${element.htmlCode.slice(0, 700)} …`;
149
+ else {
150
+ if (ruleAssertions.results) {
151
+ ruleAssertions.results = ruleAssertions.results.filter(
152
+ raResult => raResult.verdict !== 'passed'
153
+ );
164
154
  }
165
- });
155
+ }
166
156
  }
157
+ // Shorten long HTML codes of elements.
158
+ const {results} = ruleAssertions;
159
+ results.forEach(raResult => {
160
+ const {elements} = raResult;
161
+ if (elements && elements.length) {
162
+ elements.forEach(element => {
163
+ if (element.htmlCode && element.htmlCode.length > 700) {
164
+ element.htmlCode = `${element.htmlCode.slice(0, 700)} …`;
165
+ }
166
+ });
167
+ }
168
+ });
167
169
  });
168
- });
170
+ }
171
+ else {
172
+ data.prevented = true;
173
+ data.error = 'ERROR: No assertions';
174
+ }
169
175
  }
170
176
  else {
171
177
  data.prevented = true;
172
- data.error = 'ERROR: No assertions';
178
+ data.error = `ERROR: No ${section} section`;
173
179
  }
174
180
  }
175
- else {
176
- data.prevented = true;
177
- data.error = `ERROR: No ${section} section`;
178
- }
179
181
  }
180
182
  }
183
+ else {
184
+ data.prevented = true;
185
+ data.error = 'ERROR: No modules';
186
+ }
181
187
  }
182
188
  else {
183
189
  data.prevented = true;
184
- data.error = 'ERROR: No modules';
190
+ data.error = 'ERROR: No DOM';
185
191
  }
186
- }
187
- else {
188
- data.prevented = true;
189
- data.error = 'ERROR: No DOM';
190
- }
191
- // Stop the QualWeb core engine.
192
- await qualWeb.stop();
193
- // Return the result.
194
- try {
195
- JSON.stringify(result);
192
+ // Stop the QualWeb core engine.
193
+ await qualWeb.stop();
194
+ // Return the result.
195
+ try {
196
+ JSON.stringify(result);
197
+ }
198
+ catch(error) {
199
+ const message = `ERROR: qualWeb result cannot be made JSON (${error.message})`;
200
+ data.prevented = true;
201
+ data.error = message;
202
+ };
196
203
  }
197
204
  catch(error) {
198
- const message = `ERROR: qualWeb result cannot be made JSON (${error.message})`;
199
205
  data.prevented = true;
200
- data.error = message;
206
+ data.error = error.message.slice(0, 200);
201
207
  };
202
208
  return {
203
209
  data,