testaro 5.5.8 → 5.6.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/create.js +2 -1
- package/package.json +1 -1
- package/run.js +13 -0
- package/runHost.js +22 -1
- package/tests/axe.js +11 -1
- package/tests/menuNav.js +17 -7
package/create.js
CHANGED
|
@@ -112,6 +112,7 @@ const runHosts = async (timeStamp, specs) => {
|
|
|
112
112
|
if (crashHosts.length) {
|
|
113
113
|
console.log(`Hosts crashed:\n${JSON.stringify(crashHosts, null, 2)}`);
|
|
114
114
|
}
|
|
115
|
+
return '';
|
|
115
116
|
}
|
|
116
117
|
};
|
|
117
118
|
// Runs a file-based job and writes a report file for the script or each host.
|
|
@@ -136,7 +137,7 @@ exports.runJob = async (scriptID, batchID) => {
|
|
|
136
137
|
batch = JSON.parse(batchJSON);
|
|
137
138
|
const specs = batchify(script, batch, timeStamp);
|
|
138
139
|
// Recursively run each host script and save the reports.
|
|
139
|
-
runHosts(timeStamp, specs);
|
|
140
|
+
await runHosts(timeStamp, specs);
|
|
140
141
|
}
|
|
141
142
|
// Otherwise, i.e. if there is no batch:
|
|
142
143
|
else {
|
package/package.json
CHANGED
package/run.js
CHANGED
|
@@ -500,6 +500,7 @@ const goto = async (page, url, timeout, waitUntil, isStrict) => {
|
|
|
500
500
|
if (url.startsWith('file://.')) {
|
|
501
501
|
url = url.replace('file://', `file://${__dirname}/`);
|
|
502
502
|
}
|
|
503
|
+
// Visit the URL.
|
|
503
504
|
const response = await page.goto(url, {
|
|
504
505
|
timeout,
|
|
505
506
|
waitUntil
|
|
@@ -509,25 +510,37 @@ const goto = async (page, url, timeout, waitUntil, isStrict) => {
|
|
|
509
510
|
visitTimeoutCount++;
|
|
510
511
|
return 'error';
|
|
511
512
|
});
|
|
513
|
+
// If the visit succeeded:
|
|
512
514
|
if (typeof response !== 'string') {
|
|
513
515
|
const httpStatus = response.status();
|
|
516
|
+
// If the response status was normal:
|
|
514
517
|
if ([200, 304].includes(httpStatus) || url.startsWith('file:')) {
|
|
518
|
+
// If the browser was redirected in violation of a strictness requirement.
|
|
515
519
|
const actualURL = page.url();
|
|
516
520
|
if (isStrict && deSlash(actualURL) !== deSlash(url)) {
|
|
521
|
+
// Return an error.
|
|
517
522
|
console.log(`ERROR: Visit to ${url} redirected to ${actualURL}`);
|
|
518
523
|
return 'redirection';
|
|
519
524
|
}
|
|
525
|
+
// Otherwise, i.e. if no prohibited redirection occurred:
|
|
520
526
|
else {
|
|
527
|
+
// Press the Escape key to dismiss any modal dialog.
|
|
528
|
+
await page.keyboard.press('Escape');
|
|
529
|
+
// Return the response.
|
|
521
530
|
return response;
|
|
522
531
|
}
|
|
523
532
|
}
|
|
533
|
+
// Otherwise, i.e. if the response status was abnormal:
|
|
524
534
|
else {
|
|
535
|
+
// Return an error.
|
|
525
536
|
console.log(`ERROR: Visit to ${url} got status ${httpStatus}`);
|
|
526
537
|
visitRejectionCount++;
|
|
527
538
|
return 'error';
|
|
528
539
|
}
|
|
529
540
|
}
|
|
541
|
+
// Otherwise, i.e. if the visit failed:
|
|
530
542
|
else {
|
|
543
|
+
// Return an error.
|
|
531
544
|
return 'error';
|
|
532
545
|
}
|
|
533
546
|
};
|
package/runHost.js
CHANGED
|
@@ -18,8 +18,29 @@ const runHost = async (id, scriptJSON, hostJSON) => {
|
|
|
18
18
|
script: JSON.parse(scriptJSON),
|
|
19
19
|
acts: []
|
|
20
20
|
};
|
|
21
|
+
let reportJSON = JSON.stringify(report, null, 2);
|
|
21
22
|
await handleRequest(report);
|
|
22
|
-
|
|
23
|
+
report.acts.forEach(act => {
|
|
24
|
+
try {
|
|
25
|
+
JSON.stringify(act);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.log(`ERROR: act of type ${act.type} malformatted`);
|
|
29
|
+
act = {
|
|
30
|
+
type: act.type || 'ERROR',
|
|
31
|
+
which: act.which || 'N/A',
|
|
32
|
+
prevented: true,
|
|
33
|
+
error: error.message
|
|
34
|
+
};
|
|
35
|
+
console.log(`act changed to:\n${JSON.stringify(act, null, 2)}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
try {
|
|
39
|
+
reportJSON = JSON.stringify(report, null, 2);
|
|
40
|
+
}
|
|
41
|
+
catch(error) {
|
|
42
|
+
console.log(`ERROR: report for host ${id} not JSON (${error.message})`);
|
|
43
|
+
}
|
|
23
44
|
process.send(reportJSON, () => {
|
|
24
45
|
process.disconnect();
|
|
25
46
|
process.exit();
|
package/tests/axe.js
CHANGED
|
@@ -24,7 +24,7 @@ const {injectAxe, getAxeResults} = require('axe-playwright');
|
|
|
24
24
|
// Conducts and reports an Axe test.
|
|
25
25
|
exports.reporter = async (page, detailLevel, rules = []) => {
|
|
26
26
|
// Initialize the report.
|
|
27
|
-
|
|
27
|
+
let data = {};
|
|
28
28
|
// Inject axe-core into the page.
|
|
29
29
|
await injectAxe(page)
|
|
30
30
|
.catch(error => {
|
|
@@ -104,5 +104,15 @@ exports.reporter = async (page, detailLevel, rules = []) => {
|
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
// Return the result.
|
|
107
|
+
try {
|
|
108
|
+
JSON.stringify(data);
|
|
109
|
+
}
|
|
110
|
+
catch(error) {
|
|
111
|
+
console.log(`ERROR: axe result cannot be made JSON (${error.message})`);
|
|
112
|
+
data = {
|
|
113
|
+
prevented: true,
|
|
114
|
+
error: `ERROR: axe result cannot be made JSON (${error.message})`
|
|
115
|
+
};
|
|
116
|
+
}
|
|
107
117
|
return {result: data};
|
|
108
118
|
};
|
package/tests/menuNav.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
exports.reporter = async (page, withItems) => {
|
|
8
8
|
// Initialize a report.
|
|
9
|
-
|
|
9
|
+
let data = {
|
|
10
10
|
totals: {
|
|
11
11
|
navigations: {
|
|
12
12
|
all: {
|
|
@@ -238,12 +238,22 @@ exports.reporter = async (page, withItems) => {
|
|
|
238
238
|
// If the menu contains at least 2 direct menu items:
|
|
239
239
|
if (menuItems.length > 1) {
|
|
240
240
|
// Test its menu items.
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
let isCorrect = false;
|
|
242
|
+
try {
|
|
243
|
+
isCorrect = await testMenuItems(firstMenu, menuItems, 0, orientation, true);
|
|
244
|
+
// Increment the data.
|
|
245
|
+
data.totals.menus.total++;
|
|
246
|
+
data.totals.menus[isCorrect ? 'correct' : 'incorrect']++;
|
|
247
|
+
// Process the remaining menus.
|
|
248
|
+
await testMenus(menus.slice(1));
|
|
249
|
+
}
|
|
250
|
+
catch(error) {
|
|
251
|
+
console.log(`ERROR: menuNav could not perform tests (${error.message})`);
|
|
252
|
+
data = {
|
|
253
|
+
prevented: true,
|
|
254
|
+
error: error.message
|
|
255
|
+
};
|
|
256
|
+
}
|
|
247
257
|
}
|
|
248
258
|
}
|
|
249
259
|
};
|