testaro 8.2.0 → 8.4.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/README.md CHANGED
@@ -53,8 +53,8 @@ As of this version, the counts of tests in the packages referenced above were:
53
53
  - WAVE: 110
54
54
  - Nu Html Checker: 147
55
55
  - subtotal: 1206
56
- - Testaro tests: 23
57
- - grand total: 1229
56
+ - Testaro tests: 24
57
+ - grand total: 1230
58
58
 
59
59
  ## Quasi-tests
60
60
 
package/commands.js CHANGED
@@ -152,6 +152,15 @@ exports.commands = {
152
152
  ]
153
153
  },
154
154
  tests: {
155
+ attVal: [
156
+ 'Perform an attVal test',
157
+ {
158
+ attributeName: [true, 'string', 'hasLength', 'name of attribute'],
159
+ areLicit: [true, 'boolean', '', 'whether values are licit'],
160
+ values: [true, 'array', 'areStrings', 'values of attribute'],
161
+ withItems: [true, 'boolean', '', 'itemize']
162
+ }
163
+ ],
155
164
  axe: [
156
165
  'Perform an Axe test',
157
166
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "8.2.0",
3
+ "version": "8.4.0",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/run.js CHANGED
@@ -32,6 +32,7 @@ const moves = {
32
32
  const tests = {
33
33
  alfa: 'alfa',
34
34
  allHidden: 'page that is entirely or mostly hidden',
35
+ attVal: 'elements with attributes having illicit values',
35
36
  axe: 'Axe',
36
37
  bulk: 'count of visible elements',
37
38
  continuum: 'Level Access Continuum, community edition',
@@ -0,0 +1,45 @@
1
+ /*
2
+ attVal
3
+ This test reports attributes with illicit values.
4
+ */
5
+ exports.reporter = async (page, attributeName, areLicit, values, withItems) => {
6
+ // Identify the elements that have the specified attribute with illicit values.
7
+ const badAttributeData = await page.evaluate(
8
+ args => {
9
+ const attributeName = args[0];
10
+ const areLicit = args[1];
11
+ const values = args[2];
12
+ // Returns the text of an element.
13
+ const textOf = async (element, limit) => {
14
+ let text = element.textContent;
15
+ text = text.trim() || element.innerHTML;
16
+ return text.replace(/\s+/sg, ' ').replace(/<>&/g, '').slice(0, limit);
17
+ };
18
+ const attributeElements = Array.from(document.body.querySelectorAll(`[${attributeName}]`));
19
+ const badElements = attributeElements
20
+ .filter(el => {
21
+ const value = el.getAttribute(attributeName);
22
+ if (areLicit) {
23
+ return values.includes(value);
24
+ }
25
+ else {
26
+ return ! values.includes(value);
27
+ }
28
+ });
29
+ const report = badElements.map(el => ({
30
+ tagName: el.tagName,
31
+ textStart: textOf(el, 70),
32
+ attributeValue: el.getAttribute(attributeName)
33
+ }));
34
+ return report;
35
+ },
36
+ [attributeName, areLicit, values]
37
+ );
38
+ const data = {
39
+ total: badAttributeData.length
40
+ };
41
+ if (withItems) {
42
+ data.items = badAttributeData;
43
+ }
44
+ return {result: data};
45
+ };