testaro 4.5.3 → 4.6.0

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/commands.js CHANGED
@@ -179,6 +179,7 @@ exports.commands = {
179
179
  hover: [
180
180
  'Perform a hover test',
181
181
  {
182
+ sampleSize: [false, 'number', '', 'number of triggers to sample, if fewer than all'],
182
183
  withItems: [true, 'boolean']
183
184
  }
184
185
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "4.5.3",
3
+ "version": "4.6.0",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/tests/hover.js CHANGED
@@ -9,9 +9,9 @@
9
9
  has the tag name 'A' or 'BUTTON' or otherwise the descendants of the element. The only
10
10
  elements counted as being made visible by hovering are those with tag names 'A', 'BUTTON',
11
11
  'INPUT', and 'SPAN', and those with 'role="menuitem"' attributes. The test waits 700 ms after
12
- each hover in case of delayed effects. Despite this delay, the test makes the execution time
13
- practical by randomly sampling targets instead of hovering over all of them. Therefore, the
14
- results may vary from one execution to another.
12
+ each hover in case of delayed effects. Despite this delay, the test can make the execution time
13
+ practical by randomly sampling targets instead of hovering over all of them. When sampling is
14
+ performed, the results may vary from one execution to another.
15
15
  */
16
16
 
17
17
  // CONSTANTS
@@ -53,14 +53,14 @@ const getSample = (population, sampleSize) => {
53
53
  return [];
54
54
  }
55
55
  };
56
+ // Returns the text of an element.
57
+ const textOf = async (element, limit) => {
58
+ let text = await element.textContent();
59
+ text = text.trim() || await element.innerHTML();
60
+ return text.trim().replace(/\s*/sg, '').slice(0, limit);
61
+ };
56
62
  // Recursively finds and reports triggers and targets.
57
63
  const find = async (withItems, page, triggers) => {
58
- if (withItems) {
59
- data.items = {
60
- triggers: [],
61
- unhoverables: []
62
- };
63
- }
64
64
  // If any potential disclosure triggers remain:
65
65
  if (triggers.length) {
66
66
  // Identify the first of them.
@@ -181,12 +181,6 @@ const find = async (withItems, page, triggers) => {
181
181
  }
182
182
  catch (error) {
183
183
  console.log('ERROR hovering');
184
- // Returns the text of an element.
185
- const textOf = async (element, limit) => {
186
- let text = await element.textContent();
187
- text = text.trim() || await element.innerHTML();
188
- return text.trim().replace(/\s*/sg, '').slice(0, limit);
189
- };
190
184
  data.totals.unhoverables++;
191
185
  if (withItems) {
192
186
  data.items.unhoverables.push({
@@ -201,7 +195,16 @@ const find = async (withItems, page, triggers) => {
201
195
  await find(withItems, page, triggers.slice(1));
202
196
  }
203
197
  };
204
- exports.reporter = async (page, withItems) => {
198
+ // Performs hover test and reports results.
199
+ exports.reporter = async (page, sampleSize = Infinity, withItems) => {
200
+ // If details are to be reported:
201
+ if (withItems) {
202
+ // Add properties for details to the initialized result.
203
+ data.items = {
204
+ triggers: [],
205
+ unhoverables: []
206
+ };
207
+ }
205
208
  // Identify the triggers.
206
209
  const selectors = [
207
210
  'body a:visible',
@@ -217,8 +220,7 @@ exports.reporter = async (page, withItems) => {
217
220
  });
218
221
  // If they number more than the sample size limit, sample them.
219
222
  const triggerCount = triggers.length;
220
- const sampleSize = 15;
221
- const triggerSample = triggerCount > sampleSize ? getSample(triggers, 15) : triggers;
223
+ const triggerSample = triggerCount > sampleSize ? getSample(triggers, sampleSize) : triggers;
222
224
  // Find and document the hover-triggered disclosures.
223
225
  await find(withItems, page, triggerSample);
224
226
  // If the triggers were sampled: