testaro 69.0.1 → 69.0.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/package.json +1 -1
- package/procs/getSource.js +8 -3
- package/testaro/headingAmb.js +5 -0
- package/tests/nuVal.js +6 -4
- package/tests/testaro.js +15 -9
package/package.json
CHANGED
package/procs/getSource.js
CHANGED
|
@@ -23,23 +23,28 @@ const fs = require('fs/promises');
|
|
|
23
23
|
exports.getSource = async page => {
|
|
24
24
|
const url = page.url();
|
|
25
25
|
const scheme = url.replace(/:.+/, '');
|
|
26
|
+
// Initialize the test data.
|
|
26
27
|
const data = {
|
|
27
28
|
prevented: false,
|
|
28
29
|
source: ''
|
|
29
30
|
};
|
|
31
|
+
// If the page is a local file:
|
|
30
32
|
if (scheme === 'file') {
|
|
31
33
|
const filePath = url.slice(7);
|
|
34
|
+
// Get the source from it.
|
|
32
35
|
const rawPage = await fs.readFile(filePath, 'utf8');
|
|
36
|
+
// Add the source to the test data.
|
|
33
37
|
data.source = rawPage;
|
|
34
38
|
}
|
|
39
|
+
// Otherwise, i.e. if the page is not a local file:
|
|
35
40
|
else {
|
|
36
41
|
try {
|
|
37
|
-
const
|
|
38
|
-
const rawPage = await
|
|
42
|
+
const response = await page.goto(url);
|
|
43
|
+
const rawPage = await response.text();
|
|
39
44
|
data.source = rawPage;
|
|
40
45
|
}
|
|
41
46
|
catch(error) {
|
|
42
|
-
console.log(`ERROR getting source of ${url}
|
|
47
|
+
console.log(`ERROR (${error.message}) getting source of ${url}; cause: ${error.cause}`);
|
|
43
48
|
data.prevented = true;
|
|
44
49
|
data.error = `ERROR getting source of ${url}`;
|
|
45
50
|
}
|
package/testaro/headingAmb.js
CHANGED
|
@@ -47,6 +47,11 @@ exports.reporter = async (page, catalog, withItems) => {
|
|
|
47
47
|
// Return a violation description.
|
|
48
48
|
return 'Heading has the same text as the prior same-level sibling heading';
|
|
49
49
|
}
|
|
50
|
+
// Otherwise, i.e. if they do not have identical text contents:
|
|
51
|
+
else {
|
|
52
|
+
// Stop inspecting.
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
50
55
|
}
|
|
51
56
|
// Otherwise, i.e. if it is superior to the element:
|
|
52
57
|
else {
|
package/tests/nuVal.js
CHANGED
|
@@ -56,12 +56,14 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
56
56
|
body: testTarget
|
|
57
57
|
};
|
|
58
58
|
const nuURL = 'https://validator.w3.org/nu/?parser=html&out=json';
|
|
59
|
-
let nuData;
|
|
59
|
+
let nuData = {};
|
|
60
|
+
let nuResponse = new Response();
|
|
60
61
|
try {
|
|
61
62
|
// Get a Nu Html Checker report from the W3C validator service.
|
|
62
63
|
nuResponse = await fetch(nuURL, fetchOptions);
|
|
64
|
+
const {ok, status, statusText} = nuResponse;
|
|
63
65
|
// If the acquisition succeeded:
|
|
64
|
-
if (
|
|
66
|
+
if (ok) {
|
|
65
67
|
// Get the response body as an object.
|
|
66
68
|
nuData = await nuResponse.json();
|
|
67
69
|
}
|
|
@@ -71,13 +73,13 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
71
73
|
const nuResponseText = await nuResponse.text();
|
|
72
74
|
// Add a failure report to the data.
|
|
73
75
|
data.prevented = true;
|
|
74
|
-
data.error = `HTTP ${
|
|
76
|
+
data.error = `HTTP ${status}: ${statusText} (${nuResponseText?.slice(0, 200)})`;
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
79
|
// If an error occurred:
|
|
78
80
|
catch (error) {
|
|
79
81
|
// Report it.
|
|
80
|
-
const message = `ERROR getting results (${error.message}; status ${
|
|
82
|
+
const message = `ERROR getting results (${error.message}; status ${nuResponse.status || 'none'} (${JSON.stringify(nuData?.body || 'no body', null, 2)})`;
|
|
81
83
|
console.log(message);
|
|
82
84
|
data.prevented = true;
|
|
83
85
|
data.error = message;
|
package/tests/testaro.js
CHANGED
|
@@ -118,14 +118,6 @@ const allRules = [
|
|
|
118
118
|
timeOut: 5,
|
|
119
119
|
defaultOn: true
|
|
120
120
|
},
|
|
121
|
-
{
|
|
122
|
-
id: 'dupAtt',
|
|
123
|
-
what: 'duplicate attribute values',
|
|
124
|
-
contaminates: false,
|
|
125
|
-
needsAccessibleName: false,
|
|
126
|
-
timeOut: 5,
|
|
127
|
-
defaultOn: true
|
|
128
|
-
},
|
|
129
121
|
{
|
|
130
122
|
id: 'embAc',
|
|
131
123
|
what: 'active elements embedded in links or buttons',
|
|
@@ -350,6 +342,14 @@ const allRules = [
|
|
|
350
342
|
timeOut: 5,
|
|
351
343
|
defaultOn: true
|
|
352
344
|
},
|
|
345
|
+
{
|
|
346
|
+
id: 'dupAtt',
|
|
347
|
+
what: 'duplicate attribute values',
|
|
348
|
+
contaminates: false,
|
|
349
|
+
needsAccessibleName: false,
|
|
350
|
+
timeOut: 5,
|
|
351
|
+
defaultOn: true
|
|
352
|
+
},
|
|
353
353
|
{
|
|
354
354
|
id: 'autocomplete',
|
|
355
355
|
what: 'name and email inputs without autocomplete attributes',
|
|
@@ -508,6 +508,7 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
508
508
|
? ruleSpec.slice(1)
|
|
509
509
|
: allRules.filter(rule => rule.defaultOn && ! allRuleIDs.includes(rule.id));
|
|
510
510
|
const jobRules = allRules.filter(rule => jobRuleIDs.includes(rule.id));
|
|
511
|
+
let justPrevented = false;
|
|
511
512
|
// For each rule to be tested for:
|
|
512
513
|
for (let ruleIndex = 0; ruleIndex < jobRules.length; ruleIndex++) {
|
|
513
514
|
const rule = jobRules[ruleIndex];
|
|
@@ -526,6 +527,7 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
526
527
|
const headEmulation = ruleResult.id.startsWith('shoot') ? 'high' : 'high';
|
|
527
528
|
// Get whether the rule needs a new browser launched.
|
|
528
529
|
const needsLaunch = ruleIndex === 0
|
|
530
|
+
|| justPrevented
|
|
529
531
|
|| jobRules[ruleIndex - 1].contaminates
|
|
530
532
|
|| jobRules[ruleIndex].needsAccessibleName && ! jobRules[ruleIndex - 1].needsAccessibleName;
|
|
531
533
|
const pageClosed = page && page.isClosed();
|
|
@@ -542,6 +544,7 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
542
544
|
actIndex,
|
|
543
545
|
tempBrowserID: browserID,
|
|
544
546
|
tempURL: url,
|
|
547
|
+
headEmulation,
|
|
545
548
|
xPathNeed: 'script',
|
|
546
549
|
needsAccessibleName: jobRules[ruleIndex].needsAccessibleName,
|
|
547
550
|
retries: 2
|
|
@@ -580,6 +583,7 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
580
583
|
timer = new Promise(resolve => {
|
|
581
584
|
timeout = setTimeout(() => {
|
|
582
585
|
// Add data about the timeout to the rule result.
|
|
586
|
+
justPrevented = true;
|
|
583
587
|
ruleResult.prevented = true;
|
|
584
588
|
ruleResult.error = 'Timeout';
|
|
585
589
|
console.log(`ERROR: Test of testaro rule ${ruleResult.id} timed out`);
|
|
@@ -609,6 +613,7 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
609
613
|
if (ruleResult.instances) {
|
|
610
614
|
standardResult.instances.push(... ruleResult.instances);
|
|
611
615
|
}
|
|
616
|
+
justPrevented = false;
|
|
612
617
|
// If testing is to stop after a failure and the page failed the test:
|
|
613
618
|
if (stopOnFail && ruleReport.totals?.some(total => total)) {
|
|
614
619
|
// Test for no more rules.
|
|
@@ -618,6 +623,8 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
618
623
|
}
|
|
619
624
|
// If an error is thrown by the test:
|
|
620
625
|
catch(error) {
|
|
626
|
+
ruleResult.prevented = true;
|
|
627
|
+
justPrevented = true;
|
|
621
628
|
const isPageClosed = ['closed', 'Protocol error', 'Target page'].some(phrase =>
|
|
622
629
|
error.message.includes(phrase)
|
|
623
630
|
);
|
|
@@ -629,7 +636,6 @@ exports.reporter = async (page, report, actIndex) => {
|
|
|
629
636
|
// Otherwise, i.e. if the page is open:
|
|
630
637
|
else {
|
|
631
638
|
// Add this to the rule result.
|
|
632
|
-
ruleResult.prevented = true;
|
|
633
639
|
ruleResult.error = error.message;
|
|
634
640
|
console.log(
|
|
635
641
|
`ERROR: Test of testaro rule ${ruleResult.id} prevented (${error.message})`
|