testaro 12.4.3 → 12.5.3
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 +2 -0
- package/package.json +1 -1
- package/run.js +3 -1
- package/tests/nuVal.js +66 -74
package/README.md
CHANGED
|
@@ -57,6 +57,8 @@ As of this version, the counts of tests of the tools referenced above were:
|
|
|
57
57
|
- Testaro: 29
|
|
58
58
|
- total: 1356
|
|
59
59
|
|
|
60
|
+
Of the 29 Testaro tests, 26 are evaluative (they discover accessibility issues), and the other 3 (`elements`, `textNodes`, and `title`) are informative (they report conditions specified by the user).
|
|
61
|
+
|
|
60
62
|
## Quasi-tests
|
|
61
63
|
|
|
62
64
|
Reports produced by Testaro contain data in addition to the results of these tests. Such data can be used like tests. In particular, the data include:
|
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -83,7 +83,7 @@ const tenonData = {
|
|
|
83
83
|
accessToken: '',
|
|
84
84
|
requestIDs: {}
|
|
85
85
|
};
|
|
86
|
-
//
|
|
86
|
+
// Strings in log messages indicating errors.
|
|
87
87
|
const errorWords = [
|
|
88
88
|
'but not used',
|
|
89
89
|
'content security policy',
|
|
@@ -95,8 +95,10 @@ const errorWords = [
|
|
|
95
95
|
'invalid',
|
|
96
96
|
'missing',
|
|
97
97
|
'non-standard',
|
|
98
|
+
'not supported',
|
|
98
99
|
'refused',
|
|
99
100
|
'requires',
|
|
101
|
+
'sorry',
|
|
100
102
|
'suspicious',
|
|
101
103
|
'unrecognized',
|
|
102
104
|
'violates',
|
package/tests/nuVal.js
CHANGED
|
@@ -1,92 +1,84 @@
|
|
|
1
1
|
/*
|
|
2
2
|
nuVal
|
|
3
|
-
This test subjects a page to the Nu Html Checker
|
|
4
|
-
|
|
3
|
+
This test subjects a page and its source to the Nu Html Checker, thereby testing scripted
|
|
4
|
+
content found only in the loaded page and erroneous content before the browser corrects it.
|
|
5
|
+
The API erratically replaces left and right double quotation marks with invalid UTF-8, which
|
|
5
6
|
appears as 2 or 3 successive instances of the replacement character (U+fffd). Therefore, this
|
|
6
7
|
test removes all such quotation marks and the replacement character. That causes
|
|
7
8
|
'Bad value “” for' to become 'Bad value for'. Since the corruption of quotation marks is
|
|
8
9
|
erratic, no better solution is known.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
|
|
12
|
+
// ########## IMPORTS
|
|
13
|
+
|
|
14
|
+
// Module to make HTTP requests.
|
|
15
|
+
const fetch = require('node-fetch');
|
|
16
|
+
// Module to process files.
|
|
17
|
+
const fs = require('fs/promises');
|
|
18
|
+
|
|
19
|
+
// ########## FUNCTIONS
|
|
20
|
+
|
|
11
21
|
exports.reporter = async (page, messages) => {
|
|
22
|
+
// Get the browser-parsed page.
|
|
12
23
|
const pageContent = await page.content();
|
|
13
|
-
// Get the
|
|
14
|
-
const
|
|
24
|
+
// Get the page source.
|
|
25
|
+
const url = page.url();
|
|
26
|
+
const scheme = url.replace(/:.+/, '');
|
|
27
|
+
let rawPage;
|
|
28
|
+
if (scheme === 'file') {
|
|
29
|
+
const filePath = url.slice(7);
|
|
30
|
+
rawPage = await fs.readFile(filePath, 'utf8');
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
15
33
|
try {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
/*
|
|
19
|
-
Alternatives (more timeout-prone): host=validator.nu; path=/?parser=html@out=json
|
|
20
|
-
That host crashes instead of ending with a fatal error.
|
|
21
|
-
*/
|
|
22
|
-
host: 'validator.w3.org',
|
|
23
|
-
path: '/nu/?parser=html&out=json',
|
|
24
|
-
method: 'POST',
|
|
25
|
-
headers: {
|
|
26
|
-
'User-Agent': 'Mozilla/5.0',
|
|
27
|
-
'Content-Type': 'text/html; charset=utf-8'
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
response => {
|
|
31
|
-
let report = '';
|
|
32
|
-
response.on('data', chunk => {
|
|
33
|
-
report += chunk;
|
|
34
|
-
});
|
|
35
|
-
// When the data arrive:
|
|
36
|
-
response.on('end', async () => {
|
|
37
|
-
try {
|
|
38
|
-
// Delete left and right quotation marks and their erratic invalid replacements.
|
|
39
|
-
const result = JSON.parse(report.replace(/[\u{fffd}“”]/ug, ''));
|
|
40
|
-
return resolve(result);
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
console.log(`ERROR: Validation failed (${error.message})`);
|
|
44
|
-
return resolve({
|
|
45
|
-
prevented: true,
|
|
46
|
-
error: error.message,
|
|
47
|
-
report
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
);
|
|
53
|
-
request.write(pageContent);
|
|
54
|
-
request.end();
|
|
55
|
-
request.on('error', error => {
|
|
56
|
-
console.log(error.message);
|
|
57
|
-
return resolve({
|
|
58
|
-
prevented: true,
|
|
59
|
-
error: error.message
|
|
60
|
-
});
|
|
61
|
-
});
|
|
34
|
+
const rawPageResponse = await fetch(url);
|
|
35
|
+
rawPage = await rawPageResponse.text();
|
|
62
36
|
}
|
|
63
37
|
catch(error) {
|
|
64
|
-
console.log(error.message);
|
|
65
|
-
return
|
|
38
|
+
console.log(`ERROR getting page for nuVal test (${error.message})`);
|
|
39
|
+
return {result: {
|
|
66
40
|
prevented: true,
|
|
67
|
-
error:
|
|
68
|
-
}
|
|
41
|
+
error: 'ERROR getting page for nuVal test'
|
|
42
|
+
}};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// Get the data from validator.w3.org, a more reliable service than validator.nu.
|
|
46
|
+
const fetchOptions = {
|
|
47
|
+
method: 'post',
|
|
48
|
+
headers: {
|
|
49
|
+
'User-Agent': 'Mozilla/5.0',
|
|
50
|
+
'Content-Type': 'text/html; charset=utf-8'
|
|
69
51
|
}
|
|
70
|
-
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
};
|
|
53
|
+
const nuURL = 'https://validator.w3.org/nu/?parser=html&out=json';
|
|
54
|
+
const data = {};
|
|
55
|
+
// For each page type:
|
|
56
|
+
for (const page of [['pageContent', pageContent], ['rawPage', rawPage]]) {
|
|
57
|
+
try {
|
|
58
|
+
// Get a Nu Html Checker report on it.
|
|
59
|
+
fetchOptions.body = page[1];
|
|
60
|
+
const nuResult = await fetch(nuURL, fetchOptions);
|
|
61
|
+
const nuData = await nuResult.json();
|
|
62
|
+
const nuDataClean = JSON.parse(JSON.stringify(nuData).replace(/[\u{fffd}“”]/ug, ''));
|
|
63
|
+
// Delete left and right quotation marks and their erratic invalid replacements.
|
|
64
|
+
data[page[0]] = nuDataClean;
|
|
65
|
+
// If there is a report and restrictions on the report messages were specified:
|
|
66
|
+
if (! data[page[0]].error && messages && Array.isArray(messages) && messages.length) {
|
|
67
|
+
// Remove all messages except those specified.
|
|
68
|
+
const messageSpecs = messages.map(messageSpec => messageSpec.split(':', 2));
|
|
69
|
+
data[page[0]].messages = data[page[0]].messages.filter(message => messageSpecs.some(
|
|
70
|
+
messageSpec => message.type === messageSpec[0]
|
|
71
|
+
&& message.message.startsWith(messageSpec[1])
|
|
72
|
+
));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.log(`ERROR: nuVal report validation failed (${error.message})`);
|
|
77
|
+
return {result: {
|
|
75
78
|
prevented: true,
|
|
76
|
-
error:
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
}, 1000 * timeLimit);
|
|
80
|
-
});
|
|
81
|
-
// Get the result, or an error report if nuVal timed out after 12 seconds.
|
|
82
|
-
const data = await Promise.race([dataPromise, timeoutPromise]);
|
|
83
|
-
// If there is a report and restrictions on the report messages were specified:
|
|
84
|
-
if (! data.error && messages && Array.isArray(messages) && messages.length) {
|
|
85
|
-
// Remove all messages except those specified.
|
|
86
|
-
const messageSpecs = messages.map(messageSpec => messageSpec.split(':', 2));
|
|
87
|
-
data.messages = data.messages.filter(message => messageSpecs.some(
|
|
88
|
-
messageSpec => message.type === messageSpec[0] && message.message.startsWith(messageSpec[1])
|
|
89
|
-
));
|
|
79
|
+
error: 'nuVal report validation failed',
|
|
80
|
+
}};
|
|
81
|
+
}
|
|
90
82
|
}
|
|
91
83
|
return {result: data};
|
|
92
84
|
};
|