testaro 5.7.0 → 5.7.1
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/nuVal.js +51 -33
package/package.json
CHANGED
package/tests/nuVal.js
CHANGED
|
@@ -6,41 +6,59 @@ const https = require('https');
|
|
|
6
6
|
exports.reporter = async page => {
|
|
7
7
|
const pageContent = await page.content();
|
|
8
8
|
// Get the data from a Nu validation.
|
|
9
|
-
const data = await new Promise(resolve => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
response => {
|
|
21
|
-
let report = '';
|
|
22
|
-
response.on('data', chunk => {
|
|
23
|
-
report += chunk;
|
|
24
|
-
});
|
|
25
|
-
// When the data arrive:
|
|
26
|
-
response.on('end', async () => {
|
|
27
|
-
try {
|
|
28
|
-
// Delete unnecessary properties.
|
|
29
|
-
const result = JSON.parse(report);
|
|
30
|
-
return resolve(result);
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
return resolve({
|
|
34
|
-
prevented: true,
|
|
35
|
-
error: error.message,
|
|
36
|
-
report
|
|
37
|
-
});
|
|
9
|
+
const data = await new Promise((resolve, reject) => {
|
|
10
|
+
try {
|
|
11
|
+
const request = https.request(
|
|
12
|
+
{
|
|
13
|
+
// Alternatives: host=validator.w3.org; path=/nu/?parser=html@out=json
|
|
14
|
+
host: 'validator.nu',
|
|
15
|
+
path: '/?parser=html&out=json',
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
'User-Agent': 'Mozilla/5.0',
|
|
19
|
+
'Content-Type': 'text/html; charset=utf-8'
|
|
38
20
|
}
|
|
21
|
+
},
|
|
22
|
+
response => {
|
|
23
|
+
let report = '';
|
|
24
|
+
response.on('data', chunk => {
|
|
25
|
+
report += chunk;
|
|
26
|
+
});
|
|
27
|
+
// When the data arrive:
|
|
28
|
+
response.on('end', async () => {
|
|
29
|
+
try {
|
|
30
|
+
// Delete unnecessary properties.
|
|
31
|
+
const result = JSON.parse(report);
|
|
32
|
+
return resolve(result);
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
console.log(`Validation failed (${error.message})`);
|
|
36
|
+
return resolve({
|
|
37
|
+
prevented: true,
|
|
38
|
+
error: error.message,
|
|
39
|
+
report
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
);
|
|
45
|
+
request.write(pageContent);
|
|
46
|
+
request.end();
|
|
47
|
+
request.on('error', error => {
|
|
48
|
+
console.log(error.message);
|
|
49
|
+
return reject({
|
|
50
|
+
prevented: true,
|
|
51
|
+
error: error.message
|
|
39
52
|
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch(error) {
|
|
56
|
+
console.log(error.message);
|
|
57
|
+
return reject({
|
|
58
|
+
prevented: true,
|
|
59
|
+
error: error.message
|
|
60
|
+
});
|
|
61
|
+
}
|
|
44
62
|
});
|
|
45
63
|
return {result: data};
|
|
46
64
|
};
|