testaro 4.5.1 → 4.5.2
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/commands.js +2 -1
- package/package.json +1 -1
- package/run.js +1 -1
- package/tests/aatt.js +66 -29
package/commands.js
CHANGED
|
@@ -146,7 +146,8 @@ exports.commands = {
|
|
|
146
146
|
aatt: [
|
|
147
147
|
'Perform an AATT test with HTML CodeSniffer',
|
|
148
148
|
{
|
|
149
|
-
waitLong: [false, 'boolean', '', 'whether to wait
|
|
149
|
+
waitLong: [false, 'boolean', '', 'whether to wait 12 instead of 6 seconds for a result'],
|
|
150
|
+
tryLimit: [false, 'number', '', 'times to try the test before giving up; default 4']
|
|
150
151
|
}
|
|
151
152
|
],
|
|
152
153
|
axe: [
|
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -900,7 +900,7 @@ const doActs = async (report, actIndex, page) => {
|
|
|
900
900
|
// Otherwise, if the act is a move:
|
|
901
901
|
else if (moves[act.type]) {
|
|
902
902
|
const selector = typeof moves[act.type] === 'string' ? moves[act.type] : act.what;
|
|
903
|
-
//
|
|
903
|
+
// Try up to 5 times, every 2 seconds, to identify the element to perform the move on.
|
|
904
904
|
let matchResult = {success: false};
|
|
905
905
|
let tries = 0;
|
|
906
906
|
while (tries++ < 5 && ! matchResult.success) {
|
package/tests/aatt.js
CHANGED
|
@@ -7,31 +7,59 @@
|
|
|
7
7
|
const {evaluate} = require('aatt');
|
|
8
8
|
|
|
9
9
|
// FUNCTIONS
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
source
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
|
|
10
|
+
// Recursively test a page with HTML CodeSniffer for WCAC 2.1 AAA.
|
|
11
|
+
const retest = async (page, waitLong, triesLeft) => {
|
|
12
|
+
// If the limit on tries has not been exhausted:
|
|
13
|
+
if (triesLeft) {
|
|
14
|
+
// Set the limit in seconds on the wait for the result.
|
|
15
|
+
const timeLimit = waitLong ? 12 : 6;
|
|
16
|
+
// Get the HTML of the document body.
|
|
17
|
+
const source = await page.content();
|
|
18
|
+
// Return the result of a test with the HTML CodeSniffer WCAG 2.1 AA ruleset as a string.
|
|
19
|
+
const report = evaluate({
|
|
20
|
+
source,
|
|
21
|
+
output: 'json',
|
|
22
|
+
engine: 'htmlcs',
|
|
23
|
+
level: 'WCAG2AAA'
|
|
24
|
+
});
|
|
25
|
+
// Wait for it until the time limit expires.
|
|
26
|
+
let timeoutID;
|
|
27
|
+
const wait = new Promise(resolve => {
|
|
28
|
+
timeoutID = setTimeout(() => {
|
|
29
|
+
resolve('');
|
|
30
|
+
}, 1000 * timeLimit);
|
|
31
|
+
});
|
|
32
|
+
const result = await Promise.race([report, wait]);
|
|
33
|
+
// If it arrived within the time limit:
|
|
34
|
+
if (result) {
|
|
35
|
+
clearTimeout(timeoutID);
|
|
36
|
+
// Return the result as JSON.
|
|
37
|
+
const reportJSON = result.replace(/^.+?Object.?\s+|\s+done\s*$/sg, '');
|
|
38
|
+
return {
|
|
39
|
+
triesLeft,
|
|
40
|
+
reportJSON
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
console.log(`ERROR: Test aatt timed out at ${timeLimit} seconds; tries left: ${triesLeft - 1}`);
|
|
45
|
+
return retest(page, waitLong, --triesLeft);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Otherwise, i.e. if the limit on tries has been exhausted:
|
|
49
|
+
else {
|
|
50
|
+
// Return this.
|
|
51
|
+
return {
|
|
52
|
+
triesLeft,
|
|
53
|
+
reportJSON: ''
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.reporter = async (page, waitLong, tryLimit = 4) => {
|
|
58
|
+
// Try the test up to the limit on tries.
|
|
59
|
+
const result = await retest(page, waitLong, tryLimit);
|
|
60
|
+
const {triesLeft, reportJSON} = result;
|
|
61
|
+
// If any try succeeded:
|
|
62
|
+
if (reportJSON) {
|
|
35
63
|
try {
|
|
36
64
|
// Convert the JSON string to an array.
|
|
37
65
|
const issueArray = JSON.parse(reportJSON);
|
|
@@ -49,10 +77,18 @@ exports.reporter = async (page, waitLong) => {
|
|
|
49
77
|
.join('+');
|
|
50
78
|
}
|
|
51
79
|
});
|
|
52
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
result: {
|
|
82
|
+
report: nonNotices,
|
|
83
|
+
triesLeft
|
|
84
|
+
}
|
|
85
|
+
};
|
|
53
86
|
}
|
|
54
87
|
catch (error) {
|
|
55
88
|
console.log(`ERROR processing AATT report (${error.message})`);
|
|
89
|
+
console.log(
|
|
90
|
+
`JSON report starts with ${reportJSON.slice(0, 50)} and ends with ${reportJSON.slice(-50)}`
|
|
91
|
+
);
|
|
56
92
|
return {
|
|
57
93
|
result: {
|
|
58
94
|
prevented: true,
|
|
@@ -61,14 +97,15 @@ exports.reporter = async (page, waitLong) => {
|
|
|
61
97
|
};
|
|
62
98
|
}
|
|
63
99
|
}
|
|
64
|
-
// Otherwise, i.e. if the
|
|
100
|
+
// Otherwise, i.e. if the limit on tries was exhausted:
|
|
65
101
|
else {
|
|
66
102
|
// Report the failure.
|
|
67
|
-
|
|
103
|
+
const error = 'ERROR: Getting AATT report took too long';
|
|
104
|
+
console.log(error);
|
|
68
105
|
return {
|
|
69
106
|
result: {
|
|
70
107
|
prevented: true,
|
|
71
|
-
error
|
|
108
|
+
error
|
|
72
109
|
}
|
|
73
110
|
};
|
|
74
111
|
}
|