testilo 7.1.1 → 9.0.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.
@@ -0,0 +1,69 @@
1
+ /*
2
+ cp20sqrt.js
3
+ Returns a query for replacing placeholders in the associated template.
4
+ Makes the bar widths the square roots of their proportional widths, for cases of extreme
5
+ score disparity.
6
+ */
7
+
8
+ // ########## IMPORTS
9
+
10
+ // Module to keep secrets local.
11
+ require('dotenv').config();
12
+ // Module to access files.
13
+ const fs = require('fs/promises');
14
+
15
+ // ########## CONSTANTS
16
+
17
+ const reportDirScored = process.env.REPORTDIR_SCORED || 'reports/scored';
18
+ const query = {};
19
+
20
+ // ########## FUNCTIONS
21
+
22
+ // Returns data on the targets.
23
+ const getData = async scoredReports => {
24
+ const reportCount = scoredReports.length;
25
+ const bodyData = [];
26
+ for (const report of scoredReports) {
27
+ const {id, host, score} = report;
28
+ bodyData.push({
29
+ id,
30
+ org: host.what,
31
+ url: host.which,
32
+ score: score.summary.total
33
+ });
34
+ };
35
+ return {
36
+ pageCount,
37
+ bodyData
38
+ }
39
+ };
40
+ // Returns the maximum score.
41
+ const getMaxScore = tableData => tableData.reduce((max, item) => Math.max(max, item.score), 0);
42
+ // Converts report data to a table body.
43
+ const getTableBody = async bodyData => {
44
+ const maxScore = getMaxScore(bodyData);
45
+ const rows = bodyData
46
+ .sort((a, b) => a.score - b.score)
47
+ .map(item => {
48
+ const {id, org, url, score} = item;
49
+ const pageCell = `<th scope="row"><a href="${url}">${org}</a></th>`;
50
+ const numCell = `<td><a href="digests/${id}.html">${score}</a></td>`;
51
+ // Make the bar width proportional.
52
+ const barWidth = 100 * score / maxScore;
53
+ const bar = `<rect height="100%" width="${barWidth}%" fill="red"></rect>`;
54
+ const barCell = `<td aria-hidden="true"><svg width="100%" height="0.7em">${bar}</svg></td>`;
55
+ const row = `<tr>${pageCell}${numCell}${barCell}</tr>`;
56
+ return row;
57
+ });
58
+ return rows.join('\n ');
59
+ };
60
+ // Returns a query for a comparative table.
61
+ exports.getQuery = async () => {
62
+ const data = await getData();
63
+ query.pageCount = data.pageCount;
64
+ query.tableBody = await getTableBody(data.bodyData);
65
+ const date = new Date();
66
+ query.dateISO = date.toISOString().slice(0, 10);
67
+ query.dateSlash = query.dateISO.replace(/-/g, '/');
68
+ return query;
69
+ };
@@ -6014,7 +6014,7 @@ const addDetail = (actWhich, testID, addition = 1) => {
6014
6014
  }
6015
6015
  };
6016
6016
  // Scores a report.
6017
- exports.scorer = async report => {
6017
+ exports.scorer = report => {
6018
6018
  // Initialize the variables.
6019
6019
  init();
6020
6020
  // If there are any acts in the report:
package/score.js CHANGED
@@ -1,19 +1,26 @@
1
1
  /*
2
2
  score.js
3
- Scores a Testaro report.
3
+ Scores Testaro reports.
4
4
  Arguments:
5
- 0. Score proc.
6
- 1. Raw report.
5
+ 0. Scoring function.
6
+ 1. Array of reports.
7
7
  */
8
8
 
9
9
  // ########## FUNCTIONS
10
10
 
11
- // Score the specified raw report and return it, scored.
12
- exports.score = async (scorer, rawReport) => {
13
- // Initialize a scored report.
14
- const scoredReport = JSON.parse(JSON.stringify(rawReport));
15
- // Score it.
16
- await scorer(scoredReport);
17
- console.log(`Report ${rawReport.job.id} scored`);
18
- return scoredReport;
11
+ // Scores the specified raw reports and returns them, scored.
12
+ exports.score = (scorer, reports) => {
13
+ const scoredReports = [];
14
+ // For each report:
15
+ for (const report of reports) {
16
+ // Score it.
17
+ const scoredReport = JSON.parse(JSON.stringify(report));
18
+ scorer(scoredReport);
19
+ // Append it to the array of scored reports.
20
+ scoredReports.push(scoredReport);
21
+ console.log(`Report ${report.id} scored`);
22
+ }
23
+ // Return the array of scored reports.
24
+ console.log(`Scoring complete; report count ${reports.length}`);
25
+ return scoredReports;
19
26
  };
@@ -0,0 +1,57 @@
1
+ {
2
+ "id": "8oqso-script-accordion",
3
+ "what": "call validation",
4
+ "strict": false,
5
+ "timeLimit": 30,
6
+ "acts": [
7
+ {
8
+ "type": "launch",
9
+ "which": "chromium"
10
+ },
11
+ {
12
+ "type": "url",
13
+ "which": "https://www.w3.org/WAI/ARIA/apg/example-index/accordion/accordion",
14
+ "what": "Accordion Example"
15
+ },
16
+ {
17
+ "type": "button",
18
+ "which": "Billing Address",
19
+ "what": "expand accordion"
20
+ },
21
+ {
22
+ "type": "test",
23
+ "which": "focAll",
24
+ "what": "Tab-focusability"
25
+ },
26
+ {
27
+ "type": "launch",
28
+ "which": "chromium"
29
+ },
30
+ {
31
+ "type": "url",
32
+ "which": "https://www.w3.org/WAI/ARIA/apg/example-index/accordion/accordion",
33
+ "what": "Accordion Example"
34
+ },
35
+ {
36
+ "type": "button",
37
+ "which": "Billing Address",
38
+ "what": "expand accordion"
39
+ },
40
+ {
41
+ "type": "test",
42
+ "which": "bulk",
43
+ "what": "count of visible elements"
44
+ }
45
+ ],
46
+ "sources": {
47
+ "script": "script",
48
+ "batch": "batch",
49
+ "target": {
50
+ "id": "accordion",
51
+ "what": "Example of expanded accordion"
52
+ },
53
+ "requester": "jonathan.pool@cvshealth.com"
54
+ },
55
+ "creationTime": "2023-01-04T18:20:01",
56
+ "timeStamp": "8oqso"
57
+ }
@@ -0,0 +1,47 @@
1
+ {
2
+ "id": "8oqso-script-example",
3
+ "what": "call validation",
4
+ "strict": false,
5
+ "timeLimit": 30,
6
+ "acts": [
7
+ {
8
+ "type": "launch",
9
+ "which": "chromium"
10
+ },
11
+ {
12
+ "type": "url",
13
+ "which": "https://example.com",
14
+ "what": "example"
15
+ },
16
+ {
17
+ "type": "test",
18
+ "which": "focAll",
19
+ "what": "Tab-focusability"
20
+ },
21
+ {
22
+ "type": "launch",
23
+ "which": "chromium"
24
+ },
25
+ {
26
+ "type": "url",
27
+ "which": "https://example.com",
28
+ "what": "example"
29
+ },
30
+ {
31
+ "type": "test",
32
+ "which": "bulk",
33
+ "what": "count of visible elements"
34
+ }
35
+ ],
36
+ "sources": {
37
+ "script": "script",
38
+ "batch": "batch",
39
+ "target": {
40
+ "id": "example",
41
+ "what": "Example"
42
+ },
43
+ "requester": "jonathan.pool@cvshealth.com"
44
+ },
45
+ "creationTime": "2023-01-04T18:20:01",
46
+ "timeStamp": "8oqso"
47
+ }
@@ -0,0 +1,43 @@
1
+ {
2
+ "id": "batch",
3
+ "what": "call validation",
4
+ "targets": [
5
+ {
6
+ "id": "example",
7
+ "what": "Example",
8
+ "acts": {
9
+ "main": [
10
+ {
11
+ "type": "launch"
12
+ },
13
+ {
14
+ "type": "url",
15
+ "which": "https://example.com",
16
+ "what": "example"
17
+ }
18
+ ]
19
+ }
20
+ },
21
+ {
22
+ "id": "accordion",
23
+ "what": "Example of expanded accordion",
24
+ "acts": {
25
+ "main": [
26
+ {
27
+ "type": "launch"
28
+ },
29
+ {
30
+ "type": "url",
31
+ "which": "https://www.w3.org/WAI/ARIA/apg/example-index/accordion/accordion",
32
+ "what": "Accordion Example"
33
+ },
34
+ {
35
+ "type": "button",
36
+ "which": "Billing Address",
37
+ "what": "expand accordion"
38
+ }
39
+ ]
40
+ }
41
+ }
42
+ ]
43
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "id": "script",
3
+ "what": "call validation",
4
+ "strict": false,
5
+ "timeLimit": 30,
6
+ "acts": [
7
+ {
8
+ "type": "placeholder",
9
+ "which": "main",
10
+ "launch": "chromium"
11
+ },
12
+ {
13
+ "type": "test",
14
+ "which": "focAll",
15
+ "what": "Tab-focusability"
16
+ },
17
+ {
18
+ "type": "test",
19
+ "which": "bulk",
20
+ "what": "count of visible elements"
21
+ }
22
+ ]
23
+ }
@@ -0,0 +1,18 @@
1
+ /*
2
+ comparer.
3
+ Creator of parameters for substitution into comparison.html.
4
+ */
5
+
6
+ // FUNCTIONS
7
+
8
+ // Adds parameters to a query for a comparison.
9
+ exports.comparer = (reports, query) => {
10
+ const entries = reports.map(report => ({
11
+ target: report.sources.target.what,
12
+ score: report.score.total
13
+ }));
14
+ const entriesHTML = entries
15
+ .map(entry => `<li>Page of ${entry.target} got score ${entry.score}.</li>`)
16
+ .join('\n ');
17
+ query.list = `<ul>\n ${entriesHTML}\n </ul>`;
18
+ };
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE HTML>
2
+ <html lang="en-US">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Comparison</title>
7
+ </head>
8
+ <body>
9
+ <main>
10
+ <header>
11
+ <h1>Comparison</h1>
12
+ </header>
13
+ <h2>Introduction</h2>
14
+ <p>This is a comparison of web pages.</p>
15
+ <h2>Score tabulation</h2>
16
+ __list__
17
+ </main>
18
+ </body>
19
+ </html>
@@ -0,0 +1,78 @@
1
+ {
2
+ "id": "report",
3
+ "what": "Report for scoring validation",
4
+ "strict": true,
5
+ "timeLimit": 10,
6
+ "acts": [
7
+ {
8
+ "type": "launch",
9
+ "which": "chromium",
10
+ "what": "Chromium browser",
11
+ "startTime": 1662474496075,
12
+ "endTime": 1662474496453
13
+ },
14
+ {
15
+ "type": "url",
16
+ "which": "https://example.com",
17
+ "what": "Example0",
18
+ "startTime": 1662474496453,
19
+ "result": "https://example.com",
20
+ "endTime": 1662474501684
21
+ },
22
+ {
23
+ "type": "test",
24
+ "which": "bulk",
25
+ "what": "count of visible elements",
26
+ "startTime": 1662474501684,
27
+ "url": "https://example.com",
28
+ "result": {
29
+ "visibleElements": 100,
30
+ "success": true
31
+ },
32
+ "endTime": 1662474501866
33
+ }
34
+ ],
35
+ "sources": {
36
+ "script": "script",
37
+ "batch": "batch",
38
+ "target": {
39
+ "id": "example",
40
+ "what": "Example0"
41
+ },
42
+ "requester": "user@domain.tld"
43
+ },
44
+ "creationTime": "2023-11-20T15:50:27",
45
+ "timeStamp": "cc3pl",
46
+ "jobData": {
47
+ "log": [
48
+ {
49
+ "event": "startTime",
50
+ "value": "2022-09-06T14:27:55"
51
+ },
52
+ {
53
+ "event": "endTime",
54
+ "value": "2022-09-06T14:30:47"
55
+ }
56
+ ],
57
+ "timeStamp": "5lezg",
58
+ "testTimes": [
59
+ [
60
+ "bulk",
61
+ 0
62
+ ]
63
+ ],
64
+ "logCount": 10,
65
+ "logSize": 100,
66
+ "errorLogCount": 1,
67
+ "errorLogSize": 10,
68
+ "prohibitedCount": 0,
69
+ "visitTimeoutCount": 0,
70
+ "visitRejectionCount": 0,
71
+ "visitLatency": 3,
72
+ "endTime": "2022-09-06T14:30:47",
73
+ "elapsedSeconds": 5
74
+ },
75
+ "score": {
76
+ "total": 100
77
+ }
78
+ }
@@ -0,0 +1,78 @@
1
+ {
2
+ "id": "report",
3
+ "what": "Report for scoring validation",
4
+ "strict": true,
5
+ "timeLimit": 10,
6
+ "acts": [
7
+ {
8
+ "type": "launch",
9
+ "which": "chromium",
10
+ "what": "Chromium browser",
11
+ "startTime": 1662474496075,
12
+ "endTime": 1662474496453
13
+ },
14
+ {
15
+ "type": "url",
16
+ "which": "https://example.com",
17
+ "what": "Example1",
18
+ "startTime": 1662474496453,
19
+ "result": "https://example.com",
20
+ "endTime": 1662474501684
21
+ },
22
+ {
23
+ "type": "test",
24
+ "which": "bulk",
25
+ "what": "count of visible elements",
26
+ "startTime": 1662474501684,
27
+ "url": "https://example.com",
28
+ "result": {
29
+ "visibleElements": 101,
30
+ "success": true
31
+ },
32
+ "endTime": 1662474501866
33
+ }
34
+ ],
35
+ "sources": {
36
+ "script": "script",
37
+ "batch": "batch",
38
+ "target": {
39
+ "id": "example",
40
+ "what": "Example1"
41
+ },
42
+ "requester": "user@domain.tld"
43
+ },
44
+ "creationTime": "2023-11-20T15:50:27",
45
+ "timeStamp": "cc3pl",
46
+ "jobData": {
47
+ "log": [
48
+ {
49
+ "event": "startTime",
50
+ "value": "2022-09-06T14:27:55"
51
+ },
52
+ {
53
+ "event": "endTime",
54
+ "value": "2022-09-06T14:30:47"
55
+ }
56
+ ],
57
+ "timeStamp": "5lezg",
58
+ "testTimes": [
59
+ [
60
+ "bulk",
61
+ 0
62
+ ]
63
+ ],
64
+ "logCount": 10,
65
+ "logSize": 100,
66
+ "errorLogCount": 1,
67
+ "errorLogSize": 10,
68
+ "prohibitedCount": 0,
69
+ "visitTimeoutCount": 0,
70
+ "visitRejectionCount": 0,
71
+ "visitLatency": 3,
72
+ "endTime": "2022-09-06T14:30:47",
73
+ "elapsedSeconds": 5
74
+ },
75
+ "score": {
76
+ "total": 101
77
+ }
78
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ validate.js
3
+ Validates compare module.
4
+ */
5
+
6
+ // ########## IMPORTS
7
+
8
+ // Function to process files.
9
+ const fs = require('fs/promises');
10
+ // Function to digest reports.
11
+ const {compare} = require('../../compare');
12
+ // Digesting function.
13
+ const {comparer} = require('./comparer');
14
+
15
+ // ########## FUNCTIONS
16
+
17
+ // Validates the digest module.
18
+ const validate = async () => {
19
+ // Get the reports.
20
+ const report0JSON = await fs.readFile(`${__dirname}/report0.json`, 'utf8');
21
+ const scoredReport0 = JSON.parse(report0JSON);
22
+ const report1JSON = await fs.readFile(`${__dirname}/report1.json`, 'utf8');
23
+ const scoredReport1 = JSON.parse(report1JSON);
24
+ // Get the comparison template.
25
+ const comparisonTemplate = await fs.readFile(`${__dirname}/comparison.html`, 'utf8');
26
+ // Perform the comparison.
27
+ const comparison = compare(comparisonTemplate, comparer, [scoredReport0, scoredReport1]);
28
+ // Validate the comparison.
29
+ if (typeof comparison === 'string') {
30
+ console.log('Success: Comparing left the comparison a string');
31
+ }
32
+ else {
33
+ console.log('ERROR: Comparing changed the comparison type');
34
+ return;
35
+ }
36
+ if (comparison.includes('<h2>Introduction</h2>')) {
37
+ console.log('Success: Comparing left the static template content unchanged');
38
+ }
39
+ else {
40
+ console.log('ERROR: Comparing changed the static template content');
41
+ return;
42
+ }
43
+ if (comparison.includes('Page of Example0 got score 100')) {
44
+ console.log('Success: Comparing interpolated the data correctly');
45
+ }
46
+ else {
47
+ console.log('ERROR: Comparing did not interpolate the data correctly');
48
+ return;
49
+ }
50
+ };
51
+ validate();
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE HTML>
2
+ <html lang="en-US">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Digest</title>
7
+ </head>
8
+ <body>
9
+ <main>
10
+ <header>
11
+ <h1>Digest</h1>
12
+ </header>
13
+ <h2>Introduction</h2>
14
+ <p>This is a digest of the web page of __target__.</p>
15
+ <h2>Score summary</h2>
16
+ <p>The count of tests was __testCount__.</p>
17
+ </main>
18
+ </body>
19
+ </html>
@@ -0,0 +1,12 @@
1
+ /*
2
+ digester.
3
+ Creator of parameters for substitution into digest.html.
4
+ */
5
+
6
+ // FUNCTIONS
7
+
8
+ // Adds parameters to a query for a digest.
9
+ exports.digester = (report, query) => {
10
+ query.target = report.sources.target.what;
11
+ query.testCount = report.score.testCount;
12
+ };
@@ -0,0 +1,78 @@
1
+ {
2
+ "id": "report",
3
+ "what": "Report for scoring validation",
4
+ "strict": true,
5
+ "timeLimit": 10,
6
+ "acts": [
7
+ {
8
+ "type": "launch",
9
+ "which": "chromium",
10
+ "what": "Chromium browser",
11
+ "startTime": 1662474496075,
12
+ "endTime": 1662474496453
13
+ },
14
+ {
15
+ "type": "url",
16
+ "which": "https://example.com",
17
+ "what": "Example",
18
+ "startTime": 1662474496453,
19
+ "result": "https://example.com",
20
+ "endTime": 1662474501684
21
+ },
22
+ {
23
+ "type": "test",
24
+ "which": "bulk",
25
+ "what": "count of visible elements",
26
+ "startTime": 1662474501684,
27
+ "url": "https://example.com",
28
+ "result": {
29
+ "visibleElements": 100,
30
+ "success": true
31
+ },
32
+ "endTime": 1662474501866
33
+ }
34
+ ],
35
+ "sources": {
36
+ "script": "script",
37
+ "batch": "batch",
38
+ "target": {
39
+ "id": "example",
40
+ "what": "Example"
41
+ },
42
+ "requester": "user@domain.tld"
43
+ },
44
+ "creationTime": "2023-11-20T15:50:27",
45
+ "timeStamp": "cc3pl",
46
+ "jobData": {
47
+ "log": [
48
+ {
49
+ "event": "startTime",
50
+ "value": "2022-09-06T14:27:55"
51
+ },
52
+ {
53
+ "event": "endTime",
54
+ "value": "2022-09-06T14:30:47"
55
+ }
56
+ ],
57
+ "timeStamp": "5lezg",
58
+ "testTimes": [
59
+ [
60
+ "bulk",
61
+ 0
62
+ ]
63
+ ],
64
+ "logCount": 10,
65
+ "logSize": 100,
66
+ "errorLogCount": 1,
67
+ "errorLogSize": 10,
68
+ "prohibitedCount": 0,
69
+ "visitTimeoutCount": 0,
70
+ "visitRejectionCount": 0,
71
+ "visitLatency": 3,
72
+ "endTime": "2022-09-06T14:30:47",
73
+ "elapsedSeconds": 5
74
+ },
75
+ "score": {
76
+ "testCount": 1
77
+ }
78
+ }