testaro 5.3.0 → 5.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/package.json +1 -1
- package/tests/role.js +77 -18
package/package.json
CHANGED
package/tests/role.js
CHANGED
|
@@ -120,6 +120,58 @@ exports.reporter = async page => await page.$eval('body', body => {
|
|
|
120
120
|
'treegrid',
|
|
121
121
|
'treeitem',
|
|
122
122
|
]);
|
|
123
|
+
// Implicit roles
|
|
124
|
+
const implicitRoles = {
|
|
125
|
+
article: 'article',
|
|
126
|
+
aside: 'complementary',
|
|
127
|
+
button: 'button',
|
|
128
|
+
datalist: 'listbox',
|
|
129
|
+
dd: 'definition',
|
|
130
|
+
details: 'group',
|
|
131
|
+
dfn: 'term',
|
|
132
|
+
dialog: 'dialog',
|
|
133
|
+
dt: 'term',
|
|
134
|
+
fieldset: 'group',
|
|
135
|
+
figure: 'figure',
|
|
136
|
+
h1: 'heading',
|
|
137
|
+
h2: 'heading',
|
|
138
|
+
h3: 'heading',
|
|
139
|
+
h4: 'heading',
|
|
140
|
+
h5: 'heading',
|
|
141
|
+
h6: 'heading',
|
|
142
|
+
hr: 'separator',
|
|
143
|
+
html: 'document',
|
|
144
|
+
li: 'listitem',
|
|
145
|
+
main: 'main',
|
|
146
|
+
math: 'math',
|
|
147
|
+
menu: 'list',
|
|
148
|
+
nav: 'navigation',
|
|
149
|
+
ol: 'list',
|
|
150
|
+
output: 'status',
|
|
151
|
+
progress: 'progressbar',
|
|
152
|
+
summary: 'button',
|
|
153
|
+
SVG: 'graphics-document',
|
|
154
|
+
table: 'table',
|
|
155
|
+
tbody: 'rowgroup',
|
|
156
|
+
textarea: 'textbox',
|
|
157
|
+
tfoot: 'rowgroup',
|
|
158
|
+
thead: 'rowgroup',
|
|
159
|
+
tr: 'row',
|
|
160
|
+
ul: 'list'
|
|
161
|
+
};
|
|
162
|
+
// FUNCTIONS
|
|
163
|
+
const dataInit = (data, tagName, role) => {
|
|
164
|
+
if (! data.tagNames[tagName]) {
|
|
165
|
+
data.tagNames[tagName] = {};
|
|
166
|
+
}
|
|
167
|
+
if (! data.tagNames[tagName][role]) {
|
|
168
|
+
data.tagNames[tagName][role] = {
|
|
169
|
+
bad: 0,
|
|
170
|
+
redundant: 0
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
// OPERATION
|
|
123
175
|
// Remove the deprecated roles from the non-abstract roles.
|
|
124
176
|
goodRoles.forEach(role => {
|
|
125
177
|
if (badRoles.has(role)) {
|
|
@@ -128,34 +180,41 @@ exports.reporter = async page => await page.$eval('body', body => {
|
|
|
128
180
|
});
|
|
129
181
|
// Identify all elements with role attributes.
|
|
130
182
|
const roleElements = Array.from(body.querySelectorAll('[role]'));
|
|
131
|
-
// Identify those with roles that are either deprecated or invalid.
|
|
132
|
-
const bads = roleElements.filter(element => {
|
|
133
|
-
const role = element.getAttribute('role');
|
|
134
|
-
return badRoles.has(role) || ! goodRoles.has(role);
|
|
135
|
-
});
|
|
136
183
|
// Initialize the result.
|
|
137
184
|
const data = {
|
|
138
185
|
roleElements: roleElements.length,
|
|
139
|
-
badRoleElements:
|
|
186
|
+
badRoleElements: 0,
|
|
187
|
+
redundantRoleElements: 0,
|
|
140
188
|
tagNames: {}
|
|
141
189
|
};
|
|
142
|
-
//
|
|
143
|
-
|
|
144
|
-
// Identify its facts.
|
|
145
|
-
const tagName = element.tagName;
|
|
190
|
+
// Identify the elements with redundant roles and bad roles.
|
|
191
|
+
roleElements.forEach(element => {
|
|
146
192
|
const role = element.getAttribute('role');
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
193
|
+
const tagName = element.tagName;
|
|
194
|
+
// If the role is not absolutely valid:
|
|
195
|
+
if (! goodRoles.has(role)) {
|
|
196
|
+
// If it is bad or redundant:
|
|
197
|
+
if (badRoles.has(role)) {
|
|
198
|
+
dataInit(data, tagName, role);
|
|
199
|
+
// Add the facts to the result.
|
|
200
|
+
if (role === implicitRoles[tagName.toLowerCase()]) {
|
|
201
|
+
data.redundantRoleElements++;
|
|
202
|
+
data.tagNames[tagName][role].redundant++;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
data.badRoleElements++;
|
|
206
|
+
data.tagNames[tagName][role].bad++;
|
|
207
|
+
}
|
|
151
208
|
}
|
|
209
|
+
// Otherwise, i.e. if it is absolutely invalid:
|
|
152
210
|
else {
|
|
153
|
-
|
|
211
|
+
// Add the facts to the result.
|
|
212
|
+
data.badRoleElements++;
|
|
213
|
+
dataInit(data, tagName, role);
|
|
214
|
+
data.tagNames[tagName][role].bad++;
|
|
154
215
|
}
|
|
155
216
|
}
|
|
156
|
-
else {
|
|
157
|
-
data.tagNames[tagName] = {[role]: 1};
|
|
158
|
-
}
|
|
159
217
|
});
|
|
218
|
+
// Return the result.
|
|
160
219
|
return {result: data};
|
|
161
220
|
});
|