testaro 60.10.2 → 60.10.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "60.10.2",
3
+ "version": "60.10.3",
4
4
  "description": "Run 1000 web accessibility tests from 11 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -28,21 +28,40 @@
28
28
  Report caption elements that are not the first child of their table element.
29
29
  */
30
30
 
31
- const {init, getRuleResult} = require('../procs/testaro');
31
+ // FUNCTIONS
32
32
 
33
33
  exports.reporter = async (page, withItems) => {
34
- const all = await init(100, page, 'caption');
35
- for (const loc of all.allLocs) {
36
- const isBad = await loc.evaluate(el => {
37
- const parent = el.parentElement;
38
- if (!parent || parent.tagName !== 'TABLE') return false;
39
- return parent.firstElementChild !== el;
34
+ // Return totals and standard instances for the rule.
35
+ return await page.evaluate(withItems => {
36
+ // Get all candidates, i.e. caption elements.
37
+ const candidates = document.body.querySelectorAll('caption');
38
+ let violationCount = 0;
39
+ const instances = [];
40
+ // For each candidate:
41
+ candidates.forEach(element => {
42
+ const parent = element.parentElement;
43
+ // If the element is not the first child of a table element:
44
+ if (! parent || parent.tagName !== 'TABLE' || parent.firstElementChild !== el) {
45
+ // Increment the violation count.
46
+ violationCount++;
47
+ // If itemization is required:
48
+ if (withItems) {
49
+ const what = 'caption element is not the first child of a table element';
50
+ // Add an instance to the instances.
51
+ instances.push(window.getInstance(element, 'captionLoc', what, 1, 3));
52
+ }
53
+ }
40
54
  });
41
- if (isBad) all.locs.push(loc);
42
- }
43
- const whats = [
44
- 'Element is not the first child of a table element',
45
- 'caption elements are not the first children of table elements'
46
- ];
47
- return await getRuleResult(withItems, all, 'captionLoc', whats, 3, 'CAPTION');
55
+ // If there are any violations and itemization is not required:
56
+ if (violationCount && ! withItems) {
57
+ const what = 'caption elements are not the first children of table elements';
58
+ // Add a summary instance to the instances.
59
+ instances.push(window.getInstance(null, 'captionLoc', what, violationCount, 3, 'caption'));
60
+ }
61
+ return {
62
+ data: {},
63
+ totals: [0, 0, 0, violationCount],
64
+ standardInstances: instances
65
+ }
66
+ }, withItems);
48
67
  };