testaro 64.3.0 → 64.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/nuVnu.js +54 -37
package/package.json
CHANGED
package/tests/nuVnu.js
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
|
|
11
11
|
/*
|
|
12
12
|
This tool subjects a page and its source to the Nu Html Checker, thereby testing scripted content found only in the loaded page and erroneous content before the browser corrects it. The API erratically replaces left and right double quotation marks with invalid UTF-8, which appears as 2 or 3 successive instances of the replacement character (U+fffd). Therefore, this test removes all such quotation marks and the replacement character. That causes 'Bad value “” for' to become 'Bad value for'. Since the corruption of quotation marks is erratic, no better solution is known.
|
|
13
|
-
This tool is the installed version of the Nu Html Checker. It is an alternative to the nuVal tool, which uses the same validator as a web service of the World Wide Web Consortium (W3C). Each tool has advantages and disadvantages. The main advantage of the nuVnu tool is that it can evaluate pages larger than about 80,000 bytes and pages reachable from the host that Testaro runs on even if not reachable from the public Internet. The main
|
|
13
|
+
This tool is the installed version of the Nu Html Checker. It is an alternative to the nuVal tool, which uses the same validator as a web service of the World Wide Web Consortium (W3C). Each tool has advantages and disadvantages. The main advantage of the nuVnu tool is that it can evaluate pages larger than about 80,000 bytes and pages reachable from the host that Testaro runs on even if not reachable from the public Internet. The main advantages of nuVal are that it usually runs faster than nuVnu and it does not require the Testaro host to provide a Java virtual machine.
|
|
14
|
+
When both nuVal and nuVnu are included in a job, nuVal should precede nuVnu. If nuVal succeeds, nuVnu aborts. So, only one of the two tools contributes instances to the job report.
|
|
14
15
|
*/
|
|
15
16
|
|
|
16
17
|
// IMPORTS
|
|
@@ -32,48 +33,64 @@ const tmpDir = os.tmpdir();
|
|
|
32
33
|
|
|
33
34
|
// Conducts and reports the Nu Html Checker tests.
|
|
34
35
|
exports.reporter = async (page, report, actIndex) => {
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// If any error was thrown:
|
|
51
|
-
catch (error) {
|
|
52
|
-
const errorMessage = error.message;
|
|
36
|
+
// Get the vuVal act, if it exists.
|
|
37
|
+
const nuValAct = report.acts.find(act => act.type === 'test' && act.which === 'nuVal');
|
|
38
|
+
// If it does not exist or it exists but was prevented:
|
|
39
|
+
if (! nuValAct || nuValAct.data?.prevented) {
|
|
40
|
+
const act = report.acts[actIndex];
|
|
41
|
+
const {rules, withSource} = act;
|
|
42
|
+
// Get the content.
|
|
43
|
+
const data = await getContent(page, withSource);
|
|
44
|
+
let result;
|
|
45
|
+
// If it was obtained:
|
|
46
|
+
if (data.testTarget) {
|
|
47
|
+
const pagePath = `${tmpDir}/nuVnu-page-${report.id}.html`;
|
|
48
|
+
// Save it in a temporary file.
|
|
49
|
+
await fs.writeFile(pagePath, data.testTarget);
|
|
50
|
+
let nuData;
|
|
53
51
|
try {
|
|
54
|
-
|
|
55
|
-
nuData =
|
|
52
|
+
// Get Nu Html Checker output on it.
|
|
53
|
+
nuData = await vnu.check(['--format', 'json', '--stdout', pagePath]);
|
|
56
54
|
}
|
|
57
|
-
// If
|
|
55
|
+
// If any error was thrown:
|
|
58
56
|
catch (error) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
const errorMessage = error.message;
|
|
58
|
+
try {
|
|
59
|
+
// Parse it as JSON, i.e. a benign nuVnu result with at least 1 violation.
|
|
60
|
+
nuData = JSON.parse(error.message);
|
|
61
|
+
}
|
|
62
|
+
// If parsing it as JSON fails:
|
|
63
|
+
catch (error) {
|
|
64
|
+
// Report a genuine error.
|
|
65
|
+
data.prevented = true;
|
|
66
|
+
data.error = errorMessage;
|
|
67
|
+
}
|
|
62
68
|
}
|
|
69
|
+
// Delete the temporary file.
|
|
70
|
+
await fs.unlink(pagePath);
|
|
71
|
+
// Postprocess the result.
|
|
72
|
+
result = curate(data, nuData, rules);
|
|
73
|
+
}
|
|
74
|
+
// Otherwise, i.e. if the content was not obtained:
|
|
75
|
+
else {
|
|
76
|
+
// Report this.
|
|
77
|
+
data.prevented = true;
|
|
78
|
+
data.error = 'Content not obtained';
|
|
63
79
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
return {
|
|
81
|
+
data,
|
|
82
|
+
result
|
|
83
|
+
};
|
|
68
84
|
}
|
|
69
|
-
// Otherwise, i.e. if the
|
|
85
|
+
// Otherwise, i.e. if the nuVal act exists and succeeded:
|
|
70
86
|
else {
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
// Abort this act and report this.
|
|
88
|
+
return {
|
|
89
|
+
data: {
|
|
90
|
+
skipped: true,
|
|
91
|
+
reason: 'nuVal succeeded'
|
|
92
|
+
},
|
|
93
|
+
result: {}
|
|
94
|
+
};
|
|
74
95
|
}
|
|
75
|
-
return {
|
|
76
|
-
data,
|
|
77
|
-
result
|
|
78
|
-
};
|
|
79
96
|
};
|