testilo 30.0.0 → 31.0.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/README.md CHANGED
@@ -745,24 +745,25 @@ const {track} = require('testilo/track');
745
745
  const trackerDir = `${process.env.FUNCTIONDIR}/track/ttp99a`;
746
746
  const {tracker} = require(`${trackerDir}/index`);
747
747
  const summaryReport = …;
748
- const [reportID, trackReport] = track(tracker, summaryReport);
748
+ const [reportID, 'main competitors', trackReport] = track(tracker, summaryReport);
749
749
  ```
750
750
 
751
- The `track()` function returns an ID and an HTML tracking report that shows data for all of the results in the summary report. The invoking module can further dispose of the tracking report as needed.
751
+ The `track()` function returns an ID and an HTML tracking report that shows data for all of the results in the summary report and identifies “main competitors” as its subject. The invoking module can further dispose of the tracking report as needed.
752
752
 
753
753
  ##### By a user
754
754
 
755
755
  A user can invoke `track()` in one of these ways:
756
756
 
757
757
  ```javaScript
758
- node call track ttp99a 241016
759
- node call track ttp99a 241016 'ABC Foundation'
758
+ node call track ttp99a 'main competitors'
759
+ node call track ttp99a 'main competitors' 241016
760
+ node call track ttp99a 'main competitors' 241016 'ABC Foundation'
760
761
  ```
761
762
 
762
763
  When a user invokes `track()` in this example, the `call` module:
763
- - gets the summary report from the first file in the `summarized` subdirectory of the `REPORTDIR` directory whose name begins with `'241016'`.
764
+ - gets the summary report from the last file in the `summarized` subdirectory of the `REPORTDIR` directory, or if the third argument to `call()` exists the last one whose name begins with `'241016'`.
764
765
  - selects the summarized data for all results in the summary report, or if the fourth argument to `call()` exists from all results whose `target.what` property has the value `'ABC Foundation'`.
765
- - uses tracker `ttp99a` to create a tracking report.
766
+ - uses tracker `ttp99a` to create a tracking report that identifies “main competitors” as its subject.
766
767
  - assigns an ID to the tracking report.
767
768
  - writes the tracking report to the `tracking` subdirectory of the `REPORTDIR` directory, with the ID as the base of its file name.
768
769
 
package/call.js CHANGED
@@ -52,11 +52,17 @@ const fnArgs = process.argv.slice(3);
52
52
 
53
53
  // ########## FUNCTIONS
54
54
 
55
- // Gets a summary report.
55
+ // Gets the last matching summary report.
56
56
  const getSummaryReport = async selector => {
57
57
  const summaryDir = `${reportDir}/summarized`;
58
58
  const summaryReportNames = await fs.readdir(summaryDir);
59
- const summaryReportName = summaryReportNames.find(reportName => reportName.startsWith(selector));
59
+ let summaryReportName;
60
+ if (summaryReportNames && summaryReportNames.length) {
61
+ summaryReportName = summaryReportNames.findLast(reportName => reportName.startsWith(selector));
62
+ }
63
+ else {
64
+ summaryReportName = summaryReportNames.pop();
65
+ }
60
66
  if (summaryReportName) {
61
67
  const summaryReportJSON = await fs.readFile(`${summaryDir}/${summaryReportName}`, 'utf8');
62
68
  const summaryReport = JSON.parse(summaryReportJSON);
@@ -255,7 +261,7 @@ const callSummarize = async (what, selector = '') => {
255
261
  const summaryReport = {
256
262
  id: getFileID(2),
257
263
  what,
258
- data: []
264
+ summaries: []
259
265
  };
260
266
  // For each report to be summarized:
261
267
  for (const reportID of reportIDs) {
@@ -263,7 +269,7 @@ const callSummarize = async (what, selector = '') => {
263
269
  const report = await getReport('scored', reportID);
264
270
  // Add a summary of it to the summary report.
265
271
  const summary = summarize(report);
266
- summaryReport.data.push(summary);
272
+ summaryReport.summaries.push(summary);
267
273
  };
268
274
  // Save the summary report.
269
275
  const summaryDir = `${reportDir}/summarized`;
@@ -302,6 +308,40 @@ const callCompare = async (what, compareProcID, selector) => {
302
308
  }
303
309
  }
304
310
  };
311
+ // Fulfills a tracking request.
312
+ const callTrack = async (trackerID, what, selector, targetWhat) => {
313
+ // Get the summary report.
314
+ try {
315
+ const summaryReport = await getSummaryReport(selector);
316
+ // Remove unwanted results, if any, from it.
317
+ if (targetWhat) {
318
+ summaryReport.summaries = summaryReport.summaries.filter(
319
+ result => result.sources
320
+ && result.sources.target
321
+ && result.sources.target.what === targetWhat
322
+ );
323
+ }
324
+ // If any results remain:
325
+ if (summaryReport.summaries.length) {
326
+ // Get the tracker.
327
+ const {tracker} = require(`${functionDir}/track/${trackerID}/index`);
328
+ // Track the results.
329
+ const [reportID, trackingReport] = await track(tracker, what, summaryReport);
330
+ // Save the tracking report.
331
+ await fs.mkdir(`${reportDir}/tracking`, {recursive: true});
332
+ const reportPath = `${reportDir}/tracking/${reportID}.html`;
333
+ await fs.writeFile(reportPath, trackingReport);
334
+ console.log(`Tracking report saved in ${reportPath}`);
335
+ }
336
+ // Otherwise, i.e. if no results remain:
337
+ else {
338
+ console.log('ERROR: No results match the request');
339
+ }
340
+ }
341
+ catch(error) {
342
+ console.log(`ERROR: Tracking request invalid (${error.message})`);
343
+ }
344
+ };
305
345
  // Fulfills a credit request.
306
346
  const callCredit = async (what, selector = '') => {
307
347
  // Get the IDs of the scored reports to be credited.
@@ -331,40 +371,6 @@ const callCredit = async (what, selector = '') => {
331
371
  console.log('ERROR: No scored reports to be credited');
332
372
  }
333
373
  };
334
- // Fulfills a tracking request.
335
- const callTrack = async (trackerID, selector, targetWhat) => {
336
- // Get the summary report.
337
- try {
338
- const summaryReport = await getSummaryReport(selector);
339
- // Remove unwanted results from it.
340
- summaryReport.data = summaryReport.data.filter(
341
- result => targetWhat
342
- ? result.sources
343
- && result.sources.target
344
- && result.sources.target.what !== targetWhat
345
- : true
346
- );
347
- // If any results remain:
348
- if (summaryReport.data.length) {
349
- // Get the tracker.
350
- const {tracker} = require(`${functionDir}/track/${trackerID}/index`);
351
- // Track the results.
352
- const [reportID, trackingReport] = await track(tracker, summaryReport);
353
- // Save the tracking report.
354
- await fs.mkdir(`${reportDir}/tracking`, {recursive: true});
355
- const reportPath = `${reportDir}/tracking/${reportID}.html`;
356
- await fs.writeFile(reportPath, trackingReport);
357
- console.log(`Tracking report saved in ${reportPath}`);
358
- }
359
- // Otherwise, i.e. if no results remain:
360
- else {
361
- console.log('ERROR: No results match the request');
362
- }
363
- }
364
- catch(error) {
365
- console.log(`ERROR: Tracking request invalid (${error.message})`);
366
- }
367
- };
368
374
 
369
375
  // ########## OPERATION
370
376
 
@@ -423,14 +429,14 @@ else if (fn === 'compare' && fnArgs.length === 3) {
423
429
  console.log('Execution completed');
424
430
  });
425
431
  }
426
- else if (fn === 'credit' && fnArgs.length > 0 && fnArgs.length < 3) {
427
- callCredit(... fnArgs)
432
+ else if (fn === 'track' && fnArgs.length > 2 && fnArgs.length < 6) {
433
+ callTrack(... fnArgs)
428
434
  .then(() => {
429
435
  console.log('Execution completed');
430
436
  });
431
437
  }
432
- else if (fn === 'track' && fnArgs.length > 1 && fnArgs.length < 5) {
433
- callTrack(... fnArgs)
438
+ else if (fn === 'credit' && fnArgs.length > 0 && fnArgs.length < 3) {
439
+ callCredit(... fnArgs)
434
440
  .then(() => {
435
441
  console.log('Execution completed');
436
442
  });
package/compare.js CHANGED
@@ -11,6 +11,6 @@
11
11
  // Compares the summarized reports and returns a comparison.
12
12
  exports.compare = async (id, what, comparer, summaryReport) => {
13
13
  // Return the comparison.
14
- console.log(`Comparison complete. Report count: ${summaryReport.data.length}`);
14
+ console.log(`Comparison complete. Report count: ${summaryReport.summaries.length}`);
15
15
  return comparer(id, what, summaryReport);
16
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "30.0.0",
3
+ "version": "31.0.0",
4
4
  "description": "Prepares and processes Testaro reports",
5
5
  "main": "call.js",
6
6
  "scripts": {
@@ -17,13 +17,13 @@ const innestJoiner = '\n ';
17
17
  // ########## FUNCTIONS
18
18
 
19
19
  // Returns the maximum score.
20
- const getMaxScore = summaryReport => summaryReport.data.reduce(
20
+ const getMaxScore = summaryReport => summaryReport.summaries.reduce(
21
21
  (max, result) => Math.max(max, result.score), 0
22
22
  );
23
23
  // Converts summary report data to a table body.
24
24
  const getTableBody = async summaryReport => {
25
25
  const maxScore = getMaxScore(summaryReport);
26
- const rows = summaryReport.data
26
+ const rows = summaryReport.summaries
27
27
  .sort((a, b) => a.score - b.score)
28
28
  .map(result => {
29
29
  const {id, sources, score} = result;
@@ -42,7 +42,7 @@ const getTableBody = async summaryReport => {
42
42
  const populateQuery = async (id, what, summaryReport, query) => {
43
43
  query.id = id;
44
44
  query.what = what;
45
- query.pageCount = summaryReport.data.length;
45
+ query.pageCount = summaryReport.summaries.length;
46
46
  query.tableBody = await getTableBody(summaryReport);
47
47
  query.dateISO = getNowDate();
48
48
  query.dateSlash = getNowDateSlash();
@@ -18,7 +18,7 @@
18
18
  <h1>Accessibility tracking report</h1>
19
19
  </header>
20
20
  <h2>Introduction</h2>
21
- <p>This is tracking report <code>__id__</code>.</p>
21
+ <p>This is tracking report <code>__id__</code>, for __what__.</p>
22
22
  <p>It tracks accessibility scores over time. A perfect score is 0. The tracking was performed by Testilo procedure <code>__tp__</code>.</p>
23
23
  <p>The results are presented first as a graph, and then as a table.</p>
24
24
  <h2>Results as a graph</h2>
@@ -31,7 +31,7 @@
31
31
  const summaryReportJSON = '__summaryReportJSON__';
32
32
  const summaryReport = JSON.parse(summaryReportJSON);
33
33
  const graphData = [];
34
- summaryReport.data.forEach(result => {
34
+ summaryReport.summaries.forEach(result => {
35
35
  graphData.push({
36
36
  target: result.sources.target.what,
37
37
  time: new Date(`20${result.endTime}Z`),
@@ -67,7 +67,6 @@
67
67
  <tr>
68
68
  <th>Date and time</th>
69
69
  <th>Score</th>
70
- <th>Order</th>
71
70
  <th>Target</th>
72
71
  </tr>
73
72
  </thead>
@@ -21,32 +21,32 @@ const digestURL = process.env.DIGEST_URL;
21
21
  // FUNCTIONS
22
22
 
23
23
  // Adds parameters to a query for a tracking report.
24
- const populateQuery = async (id, summaryReport, query) => {
24
+ const populateQuery = async (id, what, summaryReport, query) => {
25
25
  // General parameters.
26
26
  query.id = id;
27
+ query.what = what;
27
28
  query.tp = trackerID;
28
29
  query.dateISO = getNowDate();
29
30
  query.dateSlash = getNowDateSlash();
30
31
  // JSON of pruned summary report.
31
- summaryReport.data.forEach(result => {
32
+ const {summaries} = summaryReport;
33
+ summaries.forEach(result => {
32
34
  delete result.sources.target.id;
33
35
  });
34
36
  query.summaryReportJSON = JSON.stringify(summaryReport);
35
37
  // For each score:
36
38
  const rows = [];
37
- const results = summaryReport.data;
38
- const targetWhats = Array.from(new Set(results.map(result => result.sources.target.what))).sort();
39
- summaryReport.data.forEach(result => {
39
+ const targetWhats = Array.from(new Set(summaries.map(result => result.sources.target.what))).sort();
40
+ summaries.forEach(result => {
40
41
  // Create an HTML table row for it.
41
42
  const timeCell = `<td>${result.endTime}</td>`;
42
43
  const digestLinkDestination = digestURL.replace('__id__', result.id);
43
44
  const scoreCell = `<td><a href=${digestLinkDestination}>${result.score}</a></td>`;
44
- const orderCell = `<td class="center">${result.order}</td>`;
45
45
  const {target} = result.sources;
46
46
  const targetID = alphaNumOf(targetWhats.indexOf(target.what));
47
47
  const targetLink = `<a href="${target.which}">${target.what}</a>`;
48
48
  const targetCell = `<td>${targetID}: ${targetLink}</td>`;
49
- const row = `<tr>${[timeCell, scoreCell, orderCell, targetCell].join('')}</tr>`;
49
+ const row = `<tr>${[timeCell, scoreCell, targetCell].join('')}</tr>`;
50
50
  // Add the row to the array of rows.
51
51
  rows.push(row);
52
52
  });
@@ -54,10 +54,10 @@ const populateQuery = async (id, summaryReport, query) => {
54
54
  query.scoreRows = rows.join(innerJoiner);
55
55
  };
56
56
  // Returns a tracking report.
57
- exports.tracker = async (id, summaryReport) => {
57
+ exports.tracker = async (id, what, summaryReport) => {
58
58
  // Create a query to replace placeholders.
59
59
  const query = {};
60
- await populateQuery(id, summaryReport, query);
60
+ await populateQuery(id, what, summaryReport, query);
61
61
  // Get the template.
62
62
  let template = await fs.readFile(`${__dirname}/index.html`, 'utf8');
63
63
  // Replace its placeholders.
package/track.js CHANGED
@@ -14,10 +14,9 @@ const {getFileID} = require('./procs/util');
14
14
  // ########## FUNCTIONS
15
15
 
16
16
  // Creates and returns a tracking report from a summary.
17
- exports.track = async (tracker, summaryReport) => {
17
+ exports.track = async (tracker, what, summaryReport) => {
18
18
  // Use the tracker to create a tracking report.
19
19
  const id = getFileID(2);
20
- const trackingReport = await tracker(id, summaryReport);
21
- console.log(`Tracking report ${id} created`);
20
+ const trackingReport = await tracker(id, what, summaryReport);
22
21
  return [id, trackingReport];
23
22
  };