testaro 1.0.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.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +502 -0
  3. package/aceconfig.js +7 -0
  4. package/commands.js +249 -0
  5. package/index.js +1248 -0
  6. package/package.json +39 -0
  7. package/procs/score/asp09.js +555 -0
  8. package/procs/test/allText.js +76 -0
  9. package/procs/test/allVis.js +17 -0
  10. package/procs/test/linksByType.js +90 -0
  11. package/procs/test/textOf.txt +73 -0
  12. package/scoring/correlation.js +74 -0
  13. package/scoring/correlations.json +327 -0
  14. package/scoring/data.json +26021 -0
  15. package/scoring/dupCounts.js +39 -0
  16. package/scoring/dupCounts.json +112 -0
  17. package/scoring/duplications.json +253 -0
  18. package/scoring/issues.json +304 -0
  19. package/scoring/packageData.js +171 -0
  20. package/scoring/packageIssues.js +34 -0
  21. package/scoring/rulesetData.json +15 -0
  22. package/tests/aatt.js +64 -0
  23. package/tests/alfa.js +107 -0
  24. package/tests/axe.js +109 -0
  25. package/tests/bulk.js +21 -0
  26. package/tests/embAc.js +36 -0
  27. package/tests/focAll.js +62 -0
  28. package/tests/focInd.js +99 -0
  29. package/tests/focOp.js +132 -0
  30. package/tests/hover.js +195 -0
  31. package/tests/ibm.js +89 -0
  32. package/tests/labClash.js +157 -0
  33. package/tests/linkUl.js +65 -0
  34. package/tests/menuNav.js +254 -0
  35. package/tests/motion.js +115 -0
  36. package/tests/radioSet.js +87 -0
  37. package/tests/role.js +164 -0
  38. package/tests/styleDiff.js +146 -0
  39. package/tests/tabNav.js +282 -0
  40. package/tests/wave.js +44 -0
  41. package/tests/zIndex.js +49 -0
  42. package/validation/batches/sample.json +13 -0
  43. package/validation/executors/sample.js +11 -0
  44. package/validation/scripts/app/sample.json +21 -0
  45. package/validation/scripts/test/bulk.json +39 -0
  46. package/validation/scripts/test/embAc.json +45 -0
  47. package/validation/scripts/test/focAll.json +59 -0
  48. package/validation/scripts/test/focInd.json +55 -0
  49. package/validation/scripts/test/focOp.json +53 -0
  50. package/validation/scripts/test/hover.json +47 -0
  51. package/validation/scripts/test/labClash.json +43 -0
  52. package/validation/scripts/test/linkUl.json +62 -0
  53. package/validation/scripts/test/menuNav.json +97 -0
  54. package/validation/scripts/test/motion.json +53 -0
  55. package/validation/scripts/test/radioSet.json +43 -0
  56. package/validation/scripts/test/role.json +42 -0
  57. package/validation/scripts/test/styleDiff.json +61 -0
  58. package/validation/scripts/test/tabNav.json +97 -0
  59. package/validation/scripts/test/zIndex.json +40 -0
  60. package/validation/targets/bulk/bad.html +48 -0
  61. package/validation/targets/bulk/good.html +15 -0
  62. package/validation/targets/embAc/bad.html +21 -0
  63. package/validation/targets/embAc/good.html +15 -0
  64. package/validation/targets/focAll/good.html +15 -0
  65. package/validation/targets/focAll/less.html +15 -0
  66. package/validation/targets/focAll/more.html +16 -0
  67. package/validation/targets/focInd/bad.html +31 -0
  68. package/validation/targets/focInd/good.html +22 -0
  69. package/validation/targets/focOp/bad.html +18 -0
  70. package/validation/targets/focOp/good.html +15 -0
  71. package/validation/targets/hover/bad.html +19 -0
  72. package/validation/targets/hover/good.html +15 -0
  73. package/validation/targets/labClash/bad.html +20 -0
  74. package/validation/targets/labClash/good.html +18 -0
  75. package/validation/targets/linkUl/bad.html +16 -0
  76. package/validation/targets/linkUl/good.html +30 -0
  77. package/validation/targets/linkUl/na.html +20 -0
  78. package/validation/targets/menuNav/bad.html +106 -0
  79. package/validation/targets/menuNav/bad.js +348 -0
  80. package/validation/targets/menuNav/good.html +106 -0
  81. package/validation/targets/menuNav/good.js +365 -0
  82. package/validation/targets/menuNav/style.css +22 -0
  83. package/validation/targets/motion/bad.css +15 -0
  84. package/validation/targets/motion/bad.html +16 -0
  85. package/validation/targets/motion/good.html +15 -0
  86. package/validation/targets/radioSet/bad.html +34 -0
  87. package/validation/targets/radioSet/good.html +27 -0
  88. package/validation/targets/role/bad.html +26 -0
  89. package/validation/targets/role/good.html +22 -0
  90. package/validation/targets/styleDiff/bad.html +35 -0
  91. package/validation/targets/styleDiff/good.html +36 -0
  92. package/validation/targets/tabNav/bad.html +51 -0
  93. package/validation/targets/tabNav/bad.js +35 -0
  94. package/validation/targets/tabNav/good.html +53 -0
  95. package/validation/targets/tabNav/good.js +83 -0
  96. package/validation/targets/tabNav/goodMoz.js +206 -0
  97. package/validation/targets/tabNav/style.css +34 -0
  98. package/validation/targets/zIndex/bad.html +17 -0
  99. package/validation/targets/zIndex/good.html +15 -0
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "testaro",
3
+ "version": "1.0.0",
4
+ "description": "Automation of accessibility testing",
5
+ "main": "index.html",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/jrpool/testaro.git"
12
+ },
13
+ "keywords": [
14
+ "accessibility",
15
+ "a11y",
16
+ "testing",
17
+ "automation"
18
+ ],
19
+ "author": "Jonathan Pool <pool@jpdev.pro>",
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/jrpool/testaro/issues"
23
+ },
24
+ "homepage": "https://github.com/jrpool/testaro#readme",
25
+ "dependencies": {
26
+ "@siteimprove/alfa-act": "*",
27
+ "@siteimprove/alfa-playwright": "*",
28
+ "@siteimprove/alfa-rules": "*",
29
+ "@siteimprove/alfa-scraper": "*",
30
+ "aatt": "*",
31
+ "accessibility-checker": "*",
32
+ "axe-playwright": "*",
33
+ "pixelmatch": "*",
34
+ "playwright": "*"
35
+ },
36
+ "devDependencies": {
37
+ "eslint": "*"
38
+ }
39
+ }
@@ -0,0 +1,555 @@
1
+ /*
2
+ asp09
3
+ Autotest score proc 9
4
+ Computes and reports a score from 5 packages and 16 custom tests, with discounts.
5
+ */
6
+ exports.scorer = acts => {
7
+ // CONSTANTS
8
+ // Define the configuration disclosures.
9
+ const logWeights = {
10
+ count: 0.5,
11
+ size: 0.01,
12
+ prohibited: 15,
13
+ visitTimeout: 10,
14
+ visitRejection: 10
15
+ };
16
+ const rules = {
17
+ aatt: '',
18
+ alfa:'',
19
+ axe: '',
20
+ bulk: '',
21
+ embAc: '',
22
+ focAll: '',
23
+ focInd: '',
24
+ focOp: '',
25
+ hover: '',
26
+ ibm: '',
27
+ labClash: '',
28
+ linkUl: '',
29
+ log: 'multiply log items by respective logWeights; sum',
30
+ menuNav: '',
31
+ motion: '',
32
+ radioSet: '',
33
+ role: '',
34
+ styleDiff: '',
35
+ tabNav: '',
36
+ wave: '',
37
+ zIndex: ''
38
+ };
39
+ let duplications = {};
40
+ const diffStyles = [
41
+ 'borderStyle',
42
+ 'borderWidth',
43
+ 'fontStyle',
44
+ 'fontWeight',
45
+ 'lineHeight',
46
+ 'maxHeight',
47
+ 'maxWidth',
48
+ 'minHeight',
49
+ 'minWidth',
50
+ 'opacity',
51
+ 'outlineOffset',
52
+ 'outlineStyle',
53
+ 'outlineWidth',
54
+ 'textDecorationLine',
55
+ 'textDecorationStyle',
56
+ 'textDecorationThickness'
57
+ ];
58
+ // Initialize the score.
59
+ const inferences = {};
60
+ let deficit = {
61
+ total: 0,
62
+ aatt: null,
63
+ alfa: null,
64
+ axe: null,
65
+ bulk: null,
66
+ embAc: null,
67
+ focAll: null,
68
+ focInd: null,
69
+ focOp: null,
70
+ hover: null,
71
+ ibm: null,
72
+ labClash: null,
73
+ linkUl: null,
74
+ log: null,
75
+ menuNav: null,
76
+ motion: null,
77
+ radioSet: null,
78
+ role: null,
79
+ styleDiff: null,
80
+ tabNav: null,
81
+ wave: null,
82
+ zIndex: null
83
+ };
84
+ // VARIABLES
85
+ let facts;
86
+ // If there are any acts:
87
+ if (Array.isArray(acts)) {
88
+ // If any of them are tests:
89
+ const tests = acts.filter(act => act.type === 'test');
90
+ if (tests.length) {
91
+ // CONSTANTS
92
+ // Empirically derived counts of duplications of package rules.
93
+ duplications = {
94
+ 'aatt': {
95
+ 'e:F77': 1,
96
+ 'e:H36': 4,
97
+ 'e:H37': 2,
98
+ 'e:H57': 3,
99
+ 'e:H58': 2,
100
+ 'w:G141': 3,
101
+ 'w:H98': 1,
102
+ 'e:ARIA6+H53': 1,
103
+ 'e:H24': 2,
104
+ 'e:G1+G123+G124': 1,
105
+ 'w:G90': 1,
106
+ 'w:H44': 1
107
+ },
108
+ 'alfa': {
109
+ 'r3': 2,
110
+ 'r28': 4,
111
+ 'r2': 2,
112
+ 'r4': 3,
113
+ 'r7': 2,
114
+ 'r53': 3,
115
+ 'r10': 1,
116
+ 'r11': 1,
117
+ 'r12': 2,
118
+ 'r20': 1,
119
+ 'r42': 1,
120
+ 'r43': 1,
121
+ 'r47': 1,
122
+ 'r5': 2,
123
+ 'r68': 1,
124
+ 'r93': 1,
125
+ 'r13': 1
126
+ },
127
+ 'axe': {
128
+ 'input-image-alt': 4,
129
+ 'html-has-lang': 3,
130
+ 'valid-lang': 2,
131
+ 'heading-order': 3,
132
+ 'link-name': 2,
133
+ 'aria-command-name': 2,
134
+ 'dlitem': 1,
135
+ 'image-alt': 2,
136
+ 'duplicate-id': 1,
137
+ 'aria-required-parent': 1,
138
+ 'svg-img-alt': 1,
139
+ 'meta-viewport': 1,
140
+ 'html-lang-valid': 2,
141
+ 'aria-required-children': 1,
142
+ 'avoid-inline-spacing': 1,
143
+ 'area-alt': 2,
144
+ 'aria-allowed-role': 1,
145
+ 'aria-required-attr': 1,
146
+ 'aria-valid-attr': 1,
147
+ 'autocomplete-valid': 1,
148
+ 'color-contrast': 1,
149
+ 'empty-heading': 2,
150
+ 'frame-title': 1,
151
+ 'image-redundant-alt': 1,
152
+ 'landmark-complementary-is-top-level': 2,
153
+ 'landmark-no-duplicate-banner': 1,
154
+ 'landmark-no-duplicate-main': 2,
155
+ 'document-title': 1,
156
+ 'object-alt': 1,
157
+ 'page-has-heading-one': 1,
158
+ 'select-name': 1
159
+ },
160
+ 'ibm': {
161
+ 'v:WCAG20_Object_HasText': 1,
162
+ 'v:WCAG20_Area_HasAlt': 2,
163
+ 'v:WCAG20_Input_ExplicitLabelImage': 4,
164
+ 'v:WCAG20_Frame_HasTitle': 2,
165
+ 'v:WCAG20_Elem_Lang_Valid': 2,
166
+ 'v:HAAC_Img_UsemapAlt': 1,
167
+ 'v:aria_semantics_role': 1,
168
+ 'v:Rpt_Aria_RequiredProperties': 1,
169
+ 'v:Rpt_Aria_ValidProperty': 1,
170
+ 'v:WCAG21_Input_Autocomplete': 1,
171
+ 'v:IBMA_Color_Contrast_WCAG2AA': 2,
172
+ 'v:RPT_Header_HasContent': 2,
173
+ 'v:WCAG20_Img_HasAlt': 2,
174
+ 'v:WCAG20_Img_LinkTextNotRedundant': 1,
175
+ 'v:Rpt_Aria_ComplementaryRequiredLabel_Implicit': 1,
176
+ 'v:Rpt_Aria_MultipleComplementaryLandmarks_Implicit': 1,
177
+ 'v:Rpt_Aria_MultipleBannerLandmarks_Implicit': 1,
178
+ 'r:Rpt_Aria_MultipleMainsVisibleLabel_Implicit': 1,
179
+ 'v:Rpt_Aria_MultipleMainsRequireLabel_Implicit_2': 1,
180
+ 'v:WCAG20_A_HasText': 1,
181
+ 'v:Rpt_Aria_ValidIdRef': 1,
182
+ 'v:WCAG20_Elem_UniqueAccessKey': 1,
183
+ 'v:WCAG20_Input_RadioChkInFieldSet': 1
184
+ },
185
+ 'wave': {
186
+ 'a:link_internal_broken': 1,
187
+ 'e:alt_area_missing': 3,
188
+ 'e:alt_input_missing': 4,
189
+ 'e:alt_missing': 2,
190
+ 'e:language_missing': 3,
191
+ 'a:heading_skipped': 3,
192
+ 'a:event_handler': 1,
193
+ 'a:label_orphaned': 1,
194
+ 'e:title_invalid': 1,
195
+ 'e:heading_empty': 2,
196
+ 'a:plugin': 1,
197
+ 'a:h1_missing': 1,
198
+ 'a:select_missing_label': 1,
199
+ 'c:contrast': 1,
200
+ 'e:aria_reference_broken': 1,
201
+ 'a:accesskey': 1,
202
+ 'a:fieldset_missing': 1
203
+ }
204
+ };
205
+ // FUNCTIONS
206
+ // Adds the actual or inferred score of a test to the total score.
207
+ const increment = test => {
208
+ deficit.total += typeof deficit[test] === 'number' ? deficit[test] : inferences[test];
209
+ };
210
+ // OPERATION
211
+ // For each test:
212
+ tests.forEach(test => {
213
+ const {which} = test;
214
+ // Compute its score.
215
+ if (which === 'alfa') {
216
+ facts = test.result;
217
+ if (facts && Array.isArray(facts)) {
218
+ rules.alfa = 'multiply cantTell by 2*, failed by 4* (*discounted); sum';
219
+ deficit.alfa = Math.round(facts.reduce((total, issue) => {
220
+ const rawScore = [4, 2][['failed', 'cantTell'].indexOf(issue.verdict)] || 0;
221
+ const divisor = duplications.alfa[issue.rule.ruleID] + 1 || 1;
222
+ return total + rawScore / divisor;
223
+ }, 0));
224
+ deficit.total += deficit.alfa;
225
+ }
226
+ }
227
+ else if (which === 'aatt') {
228
+ facts = test.result;
229
+ if (facts && Array.isArray(facts)) {
230
+ rules.aatt = 'multiply warning by 2*, error by 4* (*discounted); sum';
231
+ const issues = facts.filter(fact => fact.type);
232
+ deficit.aatt = Math.round(issues.reduce((total, issue) => {
233
+ const rawScore = [4, 2][['error', 'warning'].indexOf(issue.type)] || 0;
234
+ const divisor = duplications.aatt[`${issue.type.slice(0, 1)}:${issue.id}`] + 1 || 1;
235
+ return total + rawScore / divisor;
236
+ }, 0));
237
+ deficit.total += deficit.aatt;
238
+ }
239
+ }
240
+ else if (which === 'axe') {
241
+ facts = test.result && test.result.items;
242
+ if (facts) {
243
+ rules.axe = 'multiply minor by 2*, moderate by 3*, serious by 4*, critical by 5* (*discounted); sum';
244
+ deficit.axe = Math.round(facts.reduce((total, item) => {
245
+ const rawScore = item.elements.length * (
246
+ [5, 4, 3, 2][['critical', 'serious', 'moderate', 'minor'].indexOf(item.impact)] || 0
247
+ );
248
+ const divisor = duplications.axe[item.rule] + 1 || 1;
249
+ return total + rawScore / divisor;
250
+ }, 0));
251
+ deficit.total += deficit.axe;
252
+ }
253
+ }
254
+ else if (which === 'ibm') {
255
+ facts = test.result;
256
+ if (facts && facts.content && facts.url && (facts.content.totals || facts.url.totals)) {
257
+ rules.ibm = 'multiply violations by 4*, recommendations by 2* (*discounted); sum';
258
+ const scores = {
259
+ content: null,
260
+ url: null
261
+ };
262
+ ['content', 'url'].forEach(type => {
263
+ const totals = facts[type].totals;
264
+ if (totals) {
265
+ const items = facts[type].items || [];
266
+ scores[type] = Math.round(items.reduce((total, item) => {
267
+ const {ruleId, level} = item;
268
+ const rawScore = [4, 2][['violation', 'recommendation'].indexOf(level)] || 0;
269
+ const divisor = duplications.ibm[`${level.slice(0, 1)}:${ruleId}`] + 1 || 1;
270
+ return total + rawScore / divisor;
271
+ }, 0));
272
+ }
273
+ });
274
+ if (scores.content !== null || scores.url !== null) {
275
+ deficit.ibm = Math.max(scores.content || 0, scores.url || 0);
276
+ deficit.total += deficit.ibm;
277
+ }
278
+ }
279
+ }
280
+ else if (which === 'wave') {
281
+ facts = test.result && test.result.categories;
282
+ if (facts) {
283
+ rules.wave
284
+ = 'multiply alerts by 2*, contrast errors by 3*, errors by 4* (*discounted); sum';
285
+ const weights = {
286
+ error: 4,
287
+ contrast: 3,
288
+ alert: 2
289
+ };
290
+ const scores = {
291
+ error: 0,
292
+ contrast: 0,
293
+ alert: 0
294
+ };
295
+ ['error', 'contrast', 'alert'].forEach(level => {
296
+ const {items} = facts[level];
297
+ scores[level] = Math.round(Object.keys(items).reduce((total, ruleID) => {
298
+ const rawScore = items[ruleID].count * weights[level];
299
+ const divisor = duplications.wave[`${level.slice(0, 1)}:${ruleID}`] + 1 || 1;
300
+ return total + rawScore / divisor;
301
+ }, 0));
302
+ });
303
+ deficit.wave = scores.error + scores.contrast + scores.alert;
304
+ deficit.total += deficit.wave;
305
+ }
306
+ }
307
+ else if (which === 'bulk') {
308
+ facts = test.result && test.result.visibleElements;
309
+ if (typeof facts === 'number') {
310
+ rules.bulk = 'subtract 250 from visible elements; make 0 if negative; raise to 0.9th power; multiply by 0.15';
311
+ // Deficit: 15% of the excess, to the 0.9th power, of the element count over 250.
312
+ deficit.bulk = Math.floor(0.15 * Math.pow(Math.max(0, facts - 250), 0.9));
313
+ }
314
+ else {
315
+ inferences.bulk = 100;
316
+ }
317
+ increment('bulk');
318
+ }
319
+ else if (which === 'embAc') {
320
+ facts = test.result && test.result.totals;
321
+ if (facts) {
322
+ rules.embAc = 'multiply link- or button-contained links, buttons, inputs, and selects by 3 (discounted)';
323
+ deficit.embAc = 3 * (facts.links + facts.buttons + facts.inputs + facts.selects);
324
+ }
325
+ else {
326
+ inferences.embAc = 150;
327
+ }
328
+ increment('embAc');
329
+ }
330
+ else if (which === 'focAll') {
331
+ facts = test.result;
332
+ if (facts && typeof facts === 'object') {
333
+ rules.focAll= 'multiply discrepancy between focusable and focused element counts by 3';
334
+ deficit.focAll = 3 * Math.abs(facts.discrepancy);
335
+ }
336
+ else {
337
+ inferences.focAll = 150;
338
+ }
339
+ increment('focAll');
340
+ }
341
+ else if (which === 'focInd') {
342
+ facts = test.result && test.result.totals;
343
+ facts = facts ? facts.types : null;
344
+ if (facts) {
345
+ rules.focInd = 'multiply indicatorless-when-focused elements by 5';
346
+ deficit.focInd = 5 * facts.indicatorMissing.total + 3 * facts.nonOutlinePresent.total;
347
+ }
348
+ else {
349
+ inferences.focInd = 150;
350
+ }
351
+ increment('focInd');
352
+ }
353
+ else if (which === 'focOl') {
354
+ facts = test.result && test.result.totals;
355
+ facts = facts ? facts.types : null;
356
+ facts = facts ? facts.outlineMissing : null;
357
+ if (facts) {
358
+ rules.focOl = 'multiply non-outline focus indicators by 3, missing focus indicators by 5; sum';
359
+ deficit.focOl = 3 * facts.total;
360
+ }
361
+ else {
362
+ inferences.focOl = 100;
363
+ }
364
+ increment('focOl');
365
+ }
366
+ else if (which === 'focOp') {
367
+ facts = test.result && test.result.totals;
368
+ if (facts) {
369
+ rules.focOp = 'multiply nonfocusable operable elements by 4, nonoperable focusable by 1; sum';
370
+ deficit.focOp
371
+ = 4 * facts.types.onlyOperable.total + 1 * facts.types.onlyFocusable.total;
372
+ }
373
+ else {
374
+ inferences.focOp = 150;
375
+ }
376
+ increment('focOp');
377
+ }
378
+ else if (which === 'hover') {
379
+ facts = test.result && test.result.totals;
380
+ if (facts) {
381
+ rules.hover = 'multiply elements changing page on hover by 4, made visible by 2, with directly changed opacity by 0.1, with indirectly changed opacity by 0.2, unhoverable by 2; sum';
382
+ deficit.hover
383
+ = 4 * facts.triggers
384
+ + 2 * facts.madeVisible
385
+ + Math.floor(0.1 * facts.opacityChanged)
386
+ + Math.floor(0.2 * facts.opacityAffected)
387
+ + 2 * facts.unhoverables;
388
+ }
389
+ else {
390
+ inferences.hover = 150;
391
+ }
392
+ increment('hover');
393
+ }
394
+ else if (which === 'labClash') {
395
+ facts = test.result && test.result.totals;
396
+ if (facts) {
397
+ rules.labClash = 'multiply conflictually labeled elements by 2, unlabeled elements by 2; sum';
398
+ // Unlabeled elements discounted.
399
+ deficit.labClash = 2 * facts.mislabeled + 2 * facts.unlabeled;
400
+ }
401
+ else {
402
+ inferences.labClash = 100;
403
+ }
404
+ increment('labClash');
405
+ }
406
+ else if (which === 'linkUl') {
407
+ facts = test.result && test.result.totals;
408
+ facts = facts ? facts.inline : null;
409
+ if (facts) {
410
+ rules.linkUl = 'multiply nonunderlined inline links by 3';
411
+ deficit.linkUl = 3 * (facts.total - facts.underlined);
412
+ }
413
+ else {
414
+ inferences.linkUl = 150;
415
+ }
416
+ increment('linkUl');
417
+ }
418
+ else if (which === 'menuNav') {
419
+ facts = test.result && test.result.totals && test.result.totals.navigations;
420
+ if (facts) {
421
+ rules.menuNav = 'multiply Home and End errors by 1 and other key-navigation errors by 3; sum';
422
+ deficit.menuNav
423
+ = 3 * facts.all.incorrect
424
+ - 2 * (facts.specific.home.incorrect + facts.specific.end.incorrect);
425
+ }
426
+ else {
427
+ inferences.menuNav = 150;
428
+ }
429
+ increment('menuNav');
430
+ }
431
+ else if (which === 'motion') {
432
+ facts = test.result;
433
+ if (facts && facts.bytes) {
434
+ rules.motion = 'get PNG screenshot sizes (sss); get differing-pixel counts between adjacent PNG screenshots (pd); “sssd” = sss difference ÷ smaller sss - 1; multiply mean adjacent sssd by 5, maximum adjacent sssd by 2, maximum over-all ssd by 1; divide mean pd by 10,000, maximum pd by 25,000; multiply count of non-0 pd by 30; sum';
435
+ deficit.motion = Math.floor(
436
+ 5 * (facts.meanLocalRatio - 1)
437
+ + 2 * (facts.maxLocalRatio - 1)
438
+ + facts.globalRatio - 1
439
+ + facts.meanPixelChange / 10000
440
+ + facts.maxPixelChange / 25000
441
+ + 30 * facts.changeFrequency
442
+ );
443
+ }
444
+ else {
445
+ inferences.motion = 150;
446
+ }
447
+ increment('motion');
448
+ }
449
+ else if (which === 'radioSet') {
450
+ facts = test.result && test.result.totals;
451
+ if (facts) {
452
+ rules.radioSet = 'multiply radio buttons not in fieldsets with legends and no other-name radio buttons by 2';
453
+ // Defects discounted.
454
+ deficit.radioSet = 2 * (facts.total - facts.inSet);
455
+ }
456
+ else {
457
+ inferences.radioSet = 100;
458
+ }
459
+ increment('radioSet');
460
+ }
461
+ else if (which === 'role') {
462
+ facts = test.result && test.result.badRoleElements;
463
+ if (typeof facts === 'number') {
464
+ rules.role = 'multiple role attributes with invalid or native-HTML-equivalent values by 2';
465
+ // Defects discounted.
466
+ deficit.role = 2 * facts;
467
+ }
468
+ else {
469
+ inferences.role = 100;
470
+ }
471
+ increment('role');
472
+ }
473
+ else if (which === 'styleDiff') {
474
+ facts = test.result && test.result.totals;
475
+ if (facts) {
476
+ rules.styleDiff = 'for each of element classes block a, inline a, button, h1, h2, h3, h4, h5, and h6, get diffStyles-distinct styles; multiply their count minus 1 by 2; multiply count of elements with non-plurality styles by 0.2; sum';
477
+ // Identify objects having the tag-name totals and style distributions as properties.
478
+ const tagNameCounts = Object.values(facts);
479
+ // Identify an array of pairs of counts of excess styles and nonplurality elements.
480
+ const deficits = tagNameCounts.map(
481
+ item => {
482
+ const subtotals = item.subtotals ? item.subtotals : [item.total];
483
+ return [subtotals.length - 1, item.total - subtotals[0]];
484
+ }
485
+ );
486
+ // Deficit: 2 per excess style + 0.2 per nonplurality element.
487
+ deficit.styleDiff = Math.floor(deficits.reduce(
488
+ (total, currentPair) => total + 2 * currentPair[0] + 0.2 * currentPair[1], 0
489
+ ));
490
+ }
491
+ else {
492
+ inferences.styleDiff = 100;
493
+ }
494
+ increment('styleDiff');
495
+ }
496
+ else if (which === 'tabNav') {
497
+ facts = test.result && test.result.totals && test.result.totals.navigations;
498
+ if (facts) {
499
+ rules.tabNav = 'multiply Home and End errors by 1 and other key-navigation errors by 3; sum';
500
+ deficit.tabNav
501
+ = 3 * facts.all.incorrect
502
+ - 2 * (facts.specific.home.incorrect + facts.specific.end.incorrect);
503
+ }
504
+ else {
505
+ inferences.tabNav = 150;
506
+ }
507
+ increment('tabNav');
508
+ }
509
+ else if (which === 'zIndex') {
510
+ facts = test.result && test.result.totals;
511
+ if (facts) {
512
+ rules.zIndex = 'multiply non-auto z indexes by 3';
513
+ deficit.zIndex = 3 * facts.total;
514
+ }
515
+ else {
516
+ inferences.zIndex = 100;
517
+ }
518
+ increment('zIndex');
519
+ }
520
+ });
521
+ // Compute the inferred scores of package tests that failed and adjust the total score.
522
+ const estimate = (tests, penalty) => {
523
+ const packageScores = tests.map(test => deficit[test]).filter(score => score !== null);
524
+ const scoreCount = packageScores.length;
525
+ let meanScore;
526
+ if (scoreCount) {
527
+ meanScore = Math.floor(
528
+ packageScores.reduce((sum, current) => sum + current) / packageScores.length
529
+ );
530
+ }
531
+ else {
532
+ meanScore = 100;
533
+ }
534
+ tests.forEach(test => {
535
+ if (deficit[test] === null) {
536
+ inferences[test] = meanScore + penalty;
537
+ deficit.total += inferences[test];
538
+ }
539
+ });
540
+ };
541
+ estimate(['aatt', 'axe', 'ibm', 'wave'], 100);
542
+ }
543
+ }
544
+ // Return the score facts, except for the log test.
545
+ return {
546
+ scoreProc: 'asp',
547
+ version: '9',
548
+ duplications,
549
+ rules,
550
+ diffStyles,
551
+ logWeights,
552
+ inferences,
553
+ deficit
554
+ };
555
+ };
@@ -0,0 +1,76 @@
1
+ // Returns the text associated with an element.
2
+ exports.allText = async (page, elementHandle) => await page.evaluate(element => {
3
+ // Identify the element, if specified, or else the focused element.
4
+ const el = element || document.activeElement;
5
+ // Initialize an array of its texts.
6
+ const texts = [];
7
+ // FUNCTION DEFINITION START
8
+ // Removes excess spacing from a string.
9
+ const debloat = text => text.trim().replace(/\s+/g, ' ');
10
+ // FUNCTION DEFINITION END
11
+ // Add any attribute label to the array.
12
+ const ariaLabel = el.getAttribute('aria-label');
13
+ if (ariaLabel) {
14
+ const trimmedLabel = debloat(ariaLabel);
15
+ if (trimmedLabel) {
16
+ texts.push(trimmedLabel);
17
+ }
18
+ }
19
+ // Add any explicit and implicit labels to the array.
20
+ const labelNodeList = el.labels;
21
+ if (labelNodeList && labelNodeList.length) {
22
+ const labels = Array.from(labelNodeList);
23
+ const labelTexts = labels
24
+ .map(label => label.textContent && debloat(label.textContent))
25
+ .filter(text => text);
26
+ if (labelTexts.length) {
27
+ texts.push(...labelTexts);
28
+ }
29
+ }
30
+ // Add any referenced labels to the array.
31
+ if (el.hasAttribute('aria-labelledby')) {
32
+ const labelerIDs = el.getAttribute('aria-labelledby').split(/\s+/);
33
+ labelerIDs.forEach(id => {
34
+ const labeler = document.getElementById(id);
35
+ if (labeler) {
36
+ const labelerText = debloat(labeler.textContent);
37
+ if (labelerText) {
38
+ texts.push(labelerText);
39
+ }
40
+ }
41
+ });
42
+ }
43
+ // Add any image text alternatives to the array.
44
+ const altTexts = Array
45
+ .from(element.querySelectorAll('img[alt]:not([alt=""])'))
46
+ .map(img => debloat(img.alt))
47
+ .join('; ');
48
+ if (altTexts.length) {
49
+ texts.push(altTexts);
50
+ }
51
+ // Add the first 100 characters of any text content of the element to the array.
52
+ const ownText = element.textContent;
53
+ if (ownText) {
54
+ const minText = debloat(ownText);
55
+ if (minText) {
56
+ texts.push(minText.slice(0, 100));
57
+ }
58
+ }
59
+ // Add any ID of the element to the array.
60
+ const id = element.id;
61
+ if (id) {
62
+ texts.push(`#${id}`);
63
+ }
64
+ // Identify a concatenation of the texts.
65
+ let textChain = texts.join('; ');
66
+ // If it is empty:
67
+ if (! textChain) {
68
+ // Substitute the HTML of the element.
69
+ textChain = `{${debloat(element.outerHTML)}}`;
70
+ if (textChain === '{}') {
71
+ textChain = '';
72
+ }
73
+ }
74
+ // Return a concatenation of the texts in the array.
75
+ return textChain;
76
+ }, elementHandle);
@@ -0,0 +1,17 @@
1
+ // Makes all elements in a page visible.
2
+ exports.allVis = async page => {
3
+ await page.$$eval('body *', elements => {
4
+ elements.forEach(element => {
5
+ const styleDec = window.getComputedStyle(element);
6
+ if (styleDec.display === 'none') {
7
+ element.style.display = 'initial';
8
+ }
9
+ if (['hidden', 'collapse'].includes(styleDec.visibility)) {
10
+ element.style.visibility = 'inherit';
11
+ }
12
+ });
13
+ })
14
+ .catch(error => {
15
+ console.log(`ERROR making all elements visible (${error.message})`);
16
+ });
17
+ };