testilo 6.1.3 → 6.1.4

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/digest.js CHANGED
@@ -21,6 +21,7 @@ const fs = require('fs/promises');
21
21
 
22
22
  const reportDirScored = process.env.REPORTDIR_SCORED || 'reports/scored';
23
23
  const reportDirDigested = process.env.REPORTDIR_DIGESTED || 'reports/digested';
24
+ const digestProcDir = process.env.DIGESTPROCDIR || `${__dirname}/procs/digest`;
24
25
 
25
26
  // ########## FUNCTIONS
26
27
 
@@ -46,7 +47,7 @@ exports.digest = async (digesterID, reportIDStart) => {
46
47
  .readFile(`${__dirname}/procs/digest/${digesterID}/index.html`, 'utf8');
47
48
  const digest = replaceHolders(template, query);
48
49
  const fileNameBase = fileName.slice(0, -5);
49
- await fs.writeFile(`${__dirname}/${reportDirDigested}/${fileNameBase}.html`, digest);
50
+ await fs.writeFile(`${digestProcDir}/${fileNameBase}.html`, digest);
50
51
  console.log(`Report ${fileNameBase} digested and saved`);
51
52
  };
52
53
  return reportFileNames.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "6.1.3",
3
+ "version": "6.1.4",
4
4
  "description": "Client that scores and digests Testaro reports",
5
5
  "main": "aim.js",
6
6
  "scripts": {
@@ -0,0 +1,55 @@
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
+ <meta name="author" content="Testilo">
7
+ <meta name="creator" content="Testilo">
8
+ <meta name="publisher" name="Testilo">
9
+ <meta name="description" content="report of accessibility testing of a web page">
10
+ <meta name="keywords" content="accessibility a11y web testing">
11
+ <title>Accessibility test digest</title>
12
+ <link rel="icon" href="favicon.png">
13
+ <link rel="stylesheet" href="style.css">
14
+ </head>
15
+ <body>
16
+ <main>
17
+ <header>
18
+ <h1>Accessibility test digest</h1>
19
+ <h2>Synopsis</h2>
20
+ <div id="synopsis">
21
+ <p><strong>Page</strong>: __org__</p>
22
+ <p><strong>URL</strong>: __url__</p>
23
+ <p><strong>Score</strong>: __totalScore__</p>
24
+ <p><strong>Tested by</strong>: Testaro, procedure <code>__tp__</code></p>
25
+ <p><strong>Scored by</strong>: Testilo, procedure <code>__sp__</code></p>
26
+ <p><strong>Digested by</strong>: Testilo, procedure <code>__dp__</code></p>
27
+ </div>
28
+ </header>
29
+ <h2>Introduction</h2>
30
+ <p>The <a href="https://www.npmjs.com/package/testaro">Testaro</a> application used its <code>__tp__</code> testing procedure to test the <a href="https://www.w3.org/WAI/fundamentals/accessibility-intro/"><dfn>accessibility</dfn></a> (barrier-free design and coding) of the __org__ web page at <a href="__url__">__url__</a> on __dateSlash__. The procedure performed 1230 tests. Of these, 24 are custom tests or <q>quasi-tests</q> by Testaro, and the others belong to these eight other packages (programs that perform collections of tests):</p>
31
+ <ul>
32
+ <li><a href="https://github.com/Siteimprove/alfa">Alfa</a> by Siteimprove</li>
33
+ <li><a href="https://www.npmjs.com/package/axe-core">Axe-core</a> by Deque</li>
34
+ <li><a href="https://www.webaccessibility.com/tools/">Continuum</a> by Level Access</li>
35
+ <li>
36
+ <a href="https://www.npmjs.com/package/html_codesniffer">HTML CodeSniffer</a> by Squiz Labs
37
+ </li>
38
+ <li><a href="https://github.com/IBMa/equal-access">Equal Access</a> by IBM</li>
39
+ <li><a href="https://github.com/validator/validator">Nu Html Checker</a></li>
40
+ <li><a href="https://tenon.io/documentation/apiv2.php">Tenon</a> by Level Access</li>
41
+ <li><a href="https://wave.webaim.org/api/">WAVE</a> by WebAIM</li>
42
+ </ul>
43
+ <p>Testaro produced a report enumerating the test results.</p>
44
+ <p><a href="https://www.npmjs.com/package/testilo">Testilo</a> processed the report and used the <code>__sp__</code> scoring procedure to compute partial and total scores for the page. The total score is __totalScore__ (where 0 is the best possible score). The scored report is appended below.</p>
45
+ <p>Finally, Testilo used procedure <code>__dp__</code> to produce this digest, briefly explaining how <code>__sp__</code> computed the scores.</p>
46
+ <h2>Score summary</h2>
47
+ <p>Total score: __totalScore__</p>
48
+ <h2>Report</h2>
49
+ <pre>__report__</pre>
50
+ <footer>
51
+ <p class="date">Produced <time itemprop="datePublished" datetime="__dateISO__">__dateSlash__</time></p>
52
+ </footer>
53
+ </main>
54
+ </body>
55
+ </html>
@@ -0,0 +1,46 @@
1
+ /*
2
+ index: digester for scoring procedure sp19a.
3
+ Creator of parameters for substitution into index.html.
4
+ Usage example for selected files in REPORTDIR_SCORED: node digest dp18a 35k1r
5
+ Usage example for all files in REPORTDIR_SCORED: node digest dp18a
6
+ */
7
+
8
+ // FUNCTIONS
9
+
10
+ // Makes strings HTML-safe.
11
+ const htmlEscape = textOrNumber => textOrNumber
12
+ .toString()
13
+ .replace(/&/g, '&amp;')
14
+ .replace(/</g, '&lt;');
15
+ // Gets a row of the score-summary table.
16
+ const getScoreRow = (component, score) => `<tr><th>${component}</th><td>${score}</td></tr>`;
17
+ // Adds parameters to a query for a digest.
18
+ exports.makeQuery = (report, query) => {
19
+ // Add an HTML-safe copy of the host report to the query to be appended to the digest.
20
+ const {script, host, score} = report;
21
+ const reportJSON = JSON.stringify(report, null, 2);
22
+ const reportJSONSafe = htmlEscape(reportJSON);
23
+ query.report = reportJSONSafe;
24
+ query.tp = 'tp19';
25
+ query.sp = 'sp19a';
26
+ query.dp = 'dp19a';
27
+ // Add the job data to the query.
28
+ query.dateISO = report.endTime.slice(0, 10);
29
+ query.dateSlash = query.dateISO.replace(/-/g, '/');
30
+ if (host && host.what && host.which) {
31
+ query.org = host.what;
32
+ query.url = host.which;
33
+ }
34
+ else {
35
+ const firstURLCommand = script.commands.find(command => command.type === 'url');
36
+ if (firstURLCommand && firstURLCommand.what && firstURLCommand.which) {
37
+ query.org = firstURLCommand.what;
38
+ query.url = firstURLCommand.which;
39
+ }
40
+ else {
41
+ console.log('ERROR: host missing or invalid');
42
+ return;
43
+ }
44
+ }
45
+ query.totalScore = score;
46
+ };
@@ -0,0 +1,34 @@
1
+ /*
2
+ sp18a
3
+ Testilo score proc 19a
4
+
5
+ Computes scores from Testaro script tp19 and adds them to a report.
6
+ Usage examples:
7
+ node score sp19a 35k1r
8
+ node score sp19a
9
+ */
10
+
11
+ // Scores a report.
12
+ exports.scorer = async report => {
13
+ // If there are any acts in the report:
14
+ const {acts} = report;
15
+ if (Array.isArray(acts)) {
16
+ // If any of them are test acts:
17
+ const testActs = acts.filter(act => act.type === 'test');
18
+ if (testActs.length) {
19
+ report.scoreProcID = 'sp19a';
20
+ report.score = 0;
21
+ // For each test act:
22
+ testActs.forEach(test => {
23
+ const {which} = test;
24
+ if (which === 'bulk') {
25
+ const count = test.result && test.result.visibleElements;
26
+ if (typeof count === 'number') {
27
+ // Add 1 to the score per 300 visible elements beyond 300.
28
+ report.score += Math.max(0, count / 300 - 1);
29
+ }
30
+ }
31
+ });
32
+ }
33
+ }
34
+ };
package/score.js CHANGED
@@ -21,6 +21,7 @@ const fs = require('fs/promises');
21
21
 
22
22
  const reportDirRaw = process.env.REPORTDIR_RAW || 'reports/raw';
23
23
  const reportDirScored = process.env.REPORTDIR_SCORED || 'reports/scored';
24
+ const scoreProcDir = process.env.SCOREPROCDIR || `${__dirname}/procs/score`;
24
25
 
25
26
  // ########## FUNCTIONS
26
27
 
@@ -33,7 +34,7 @@ exports.score = async (scoreProcID, reportIDStart) => {
33
34
  reportFileNames = reportFileNames.filter(fileName => fileName.startsWith(reportIDStart));
34
35
  }
35
36
  // For each of them:
36
- const {scorer} = require(`./procs/score/${scoreProcID}`);
37
+ const {scorer} = require(`${scoreProcDir}/${scoreProcID}`);
37
38
  for (const fileName of reportFileNames) {
38
39
  // Score it.
39
40
  const reportJSON = await fs.readFile(`${reportDirRaw}/${fileName}`, 'utf8');