testaro 10.0.0 → 10.2.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/actSpecs.js +12 -0
- package/package.json +1 -1
- package/run.js +5 -0
- package/tests/alfa.js +13 -3
- package/tests/continuum.js +15 -4
package/actSpecs.js
CHANGED
|
@@ -153,6 +153,12 @@ exports.actSpecs = {
|
|
|
153
153
|
]
|
|
154
154
|
},
|
|
155
155
|
tests: {
|
|
156
|
+
alfa: [
|
|
157
|
+
'Perform an alfa test',
|
|
158
|
+
{
|
|
159
|
+
rules: [false, 'array', 'areStrings', 'rule names (e.g., r25), if not all']
|
|
160
|
+
}
|
|
161
|
+
],
|
|
156
162
|
attVal: [
|
|
157
163
|
'Perform an attVal test',
|
|
158
164
|
{
|
|
@@ -169,6 +175,12 @@ exports.actSpecs = {
|
|
|
169
175
|
rules: [true, 'array', 'areStrings', 'rule names, or empty if all']
|
|
170
176
|
}
|
|
171
177
|
],
|
|
178
|
+
continuum: [
|
|
179
|
+
'Perform a continuum test',
|
|
180
|
+
{
|
|
181
|
+
rules: [false, 'array', 'areNumbers', 'rule numbers (e.g., 25), if not all']
|
|
182
|
+
}
|
|
183
|
+
],
|
|
172
184
|
elements: [
|
|
173
185
|
'Perform an elements test',
|
|
174
186
|
{
|
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -119,6 +119,8 @@ const isState = string => ['loaded', 'idle'].includes(string);
|
|
|
119
119
|
const isURL = string => /^(?:https?|file):\/\/[^\s]+$/.test(string);
|
|
120
120
|
// Validates a focusable tag name.
|
|
121
121
|
const isFocusable = string => ['a', 'button', 'input', 'select'].includes(string);
|
|
122
|
+
// Returns whether all elements of an array are numbers.
|
|
123
|
+
const areNumbers = array => array.every(element => typeof element === 'number');
|
|
122
124
|
// Returns whether all elements of an array are strings.
|
|
123
125
|
const areStrings = array => array.every(element => typeof element === 'string');
|
|
124
126
|
// Returns whether a variable has a specified type.
|
|
@@ -160,6 +162,9 @@ const hasSubtype = (variable, subtype) => {
|
|
|
160
162
|
else if (subtype === 'isWaitable') {
|
|
161
163
|
return waitables.includes(variable);
|
|
162
164
|
}
|
|
165
|
+
else if (subtype === 'areNumbers') {
|
|
166
|
+
return areNumbers(variable);
|
|
167
|
+
}
|
|
163
168
|
else if (subtype === 'areStrings') {
|
|
164
169
|
return areStrings(variable);
|
|
165
170
|
}
|
package/tests/alfa.js
CHANGED
|
@@ -7,12 +7,17 @@
|
|
|
7
7
|
|
|
8
8
|
const {Audit} = require('@siteimprove/alfa-act');
|
|
9
9
|
const {Scraper} = require('@siteimprove/alfa-scraper');
|
|
10
|
-
|
|
10
|
+
let alfaRules = require('@siteimprove/alfa-rules').default;
|
|
11
11
|
|
|
12
12
|
// FUNCTIONS
|
|
13
13
|
|
|
14
14
|
// Conducts and reports an alfa test.
|
|
15
|
-
exports.reporter = async page => {
|
|
15
|
+
exports.reporter = async (page, rules) => {
|
|
16
|
+
// If only some rules are to be employed:
|
|
17
|
+
if (rules && rules.length) {
|
|
18
|
+
// Remove the other rules.
|
|
19
|
+
alfaRules = alfaRules.filter(rule => rules.includes(rule.uri.replace(/^.+-/, '')));
|
|
20
|
+
}
|
|
16
21
|
// Get the document containing the summaries of the alfa rules.
|
|
17
22
|
const context = page.context();
|
|
18
23
|
const rulePage = await context.newPage();
|
|
@@ -44,6 +49,7 @@ exports.reporter = async page => {
|
|
|
44
49
|
});
|
|
45
50
|
await rulePage.close();
|
|
46
51
|
}
|
|
52
|
+
// Initialize the result.
|
|
47
53
|
const data = {
|
|
48
54
|
totals: {
|
|
49
55
|
failures: 0,
|
|
@@ -52,15 +58,19 @@ exports.reporter = async page => {
|
|
|
52
58
|
items: []
|
|
53
59
|
};
|
|
54
60
|
await Scraper.with(async scraper => {
|
|
61
|
+
// Get the page content.
|
|
55
62
|
for (const input of await scraper.scrape(page.url())) {
|
|
56
|
-
|
|
63
|
+
// Test it with the specified rules.
|
|
64
|
+
const audit = Audit.of(input, alfaRules);
|
|
57
65
|
const outcomes = Array.from(await audit.evaluate());
|
|
66
|
+
// For each failure or warning:
|
|
58
67
|
outcomes.forEach((outcome, index) => {
|
|
59
68
|
const {target} = outcome;
|
|
60
69
|
if (target && ! target._members) {
|
|
61
70
|
const outcomeJ = outcome.toJSON();
|
|
62
71
|
const verdict = outcomeJ.outcome;
|
|
63
72
|
if (verdict !== 'passed') {
|
|
73
|
+
// Add to the result.
|
|
64
74
|
const {rule} = outcomeJ;
|
|
65
75
|
const {tags, uri, requirements} = rule;
|
|
66
76
|
const ruleID = uri.replace(/^.+-/, '');
|
package/tests/continuum.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
// FUNCTIONS
|
|
8
8
|
// Runs Continuum on the page.
|
|
9
|
-
exports.reporter = async page => {
|
|
9
|
+
exports.reporter = async (page, rules) => {
|
|
10
10
|
let result = {};
|
|
11
11
|
// Inject the continuum scripts into the page, exposing the continuum object.
|
|
12
12
|
for (const fileName of ['continuum.conf', 'AccessEngine.community', 'Continuum.community']) {
|
|
@@ -23,9 +23,20 @@ exports.reporter = async page => {
|
|
|
23
23
|
}
|
|
24
24
|
if (! result.prevented) {
|
|
25
25
|
// Run the Continuum ruleset and get the result, failing if none within 20 seconds.
|
|
26
|
-
result = await page.evaluate(async
|
|
26
|
+
result = await page.evaluate(async rules => {
|
|
27
27
|
continuum.setUp(null, null, window);
|
|
28
|
-
|
|
28
|
+
// If a set of rules to be employed was specified:
|
|
29
|
+
let bigResultPromise;
|
|
30
|
+
if (rules && Array.isArray(rules) && rules.length && rules.every(rule => typeof rule === 'number')) {
|
|
31
|
+
// Run the tests for them.
|
|
32
|
+
bigResultPromise = continuum.runTests(rules);
|
|
33
|
+
}
|
|
34
|
+
// Otherwise, i.e. if no rules were specified:
|
|
35
|
+
else {
|
|
36
|
+
// Run all the tests.
|
|
37
|
+
bigResultPromise = continuum.runAllTests();
|
|
38
|
+
}
|
|
39
|
+
// Allow 20 seconds for the result compilation.
|
|
29
40
|
const deadlinePromise = new Promise(resolve => {
|
|
30
41
|
setTimeout(() => {
|
|
31
42
|
resolve('timeout');
|
|
@@ -54,7 +65,7 @@ exports.reporter = async page => {
|
|
|
54
65
|
error: 'ERROR: Invalid result'
|
|
55
66
|
};
|
|
56
67
|
}
|
|
57
|
-
});
|
|
68
|
+
}, rules);
|
|
58
69
|
}
|
|
59
70
|
return {result};
|
|
60
71
|
};
|