testilo 5.0.0 → 6.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/aim.js CHANGED
@@ -1,14 +1,6 @@
1
1
  /*
2
2
  aim.js
3
- Returns a script aimed at a host.
4
- Arguments:
5
- 0. base of name of script located in process.env.SCRIPTDIR.
6
- 1. ID of the host.
7
- 2. URL of the host.
8
- 3. Name of the host.
9
- 4. ID of the requester.
10
- Usage example:
11
- node aim tp18 w3c https://www.w3.org/ 'World Wide Web Consortium'
3
+ Module for aiming a script at a host.
12
4
  */
13
5
 
14
6
  // ########## IMPORTS
package/compare.js CHANGED
@@ -28,7 +28,7 @@ const comparisonNameBase = process.argv[3];
28
28
  const replaceHolders = (content, query) => content
29
29
  .replace(/__([a-zA-Z]+)__/g, (ph, qp) => query[qp]);
30
30
  // Creates and saves a web page containing a comparative table.
31
- const compare = async () => {
31
+ exports.compare = async () => {
32
32
  const comparisonDirAbs = `${__dirname}/${comparisonDir}`;
33
33
  const {getQuery} = require(`./procs/compare/${compareProcID}/index`);
34
34
  const query = await getQuery();
@@ -37,7 +37,3 @@ const compare = async () => {
37
37
  await fs.writeFile(`${comparisonDirAbs}/${comparisonNameBase}.html`, page);
38
38
  console.log(`Page ${comparisonNameBase}.html created and saved`);
39
39
  };
40
-
41
- // ########## OPERATION
42
-
43
- compare();
package/digest.js CHANGED
@@ -21,8 +21,6 @@ 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 digesterID = process.argv[2];
25
- const reportIDStart = process.argv[3];
26
24
 
27
25
  // ########## FUNCTIONS
28
26
 
@@ -30,7 +28,7 @@ const reportIDStart = process.argv[3];
30
28
  const replaceHolders = (content, query) => content
31
29
  .replace(/__([a-zA-Z]+)__/g, (ph, qp) => query[qp]);
32
30
  // Creates digests.
33
- const digest = async () => {
31
+ exports.digest = async (digesterID, reportIDStart) => {
34
32
  const reportDirScoredAbs = `${__dirname}/${reportDirScored}`;
35
33
  let reportFileNames = await fs.readdir(reportDirScoredAbs);
36
34
  reportFileNames = reportFileNames.filter(fileName => fileName.endsWith('.json'));
@@ -52,7 +50,3 @@ const digest = async () => {
52
50
  console.log(`Report ${fileNameBase} digested and saved`);
53
51
  };
54
52
  };
55
-
56
- // ########## OPERATION
57
-
58
- digest();
package/do.js ADDED
@@ -0,0 +1,94 @@
1
+ /*
2
+ do.js
3
+ Invokes Testilo modules with arguments.
4
+ This is the universal module for use of Testilo from a command line.
5
+ Arguments:
6
+ 0. function to execute.
7
+ 1+. arguments to pass to the function.
8
+ Usage examples:
9
+ node do aim script454 https://www.w3c.org/ 'World Wide Web Consortium' w3c
10
+ node do merge script454 webOrgs
11
+ node do score sp25a (to score all reports in REPORTDIR_RAW)
12
+ node do score sp25a 8ep9f- (same, but only if names start with 8ep9f-)
13
+ node do digest dp25a (to digest all reports in REPORTDIR_SCORED)
14
+ node do digest dp25a 8ep9f- (same, but only if names start with 8ep9f-)
15
+ node do compare cp25a weborgs (to write weborgs.html, comparing all reports in REPORTDIR_SCORED)
16
+ */
17
+
18
+ // ########## IMPORTS
19
+
20
+ // Module to keep secrets.
21
+ require('dotenv').config();
22
+ // Function to process a script aiming.
23
+ const {aim} = require('./aim');
24
+ // Function to process a script-batch merger.
25
+ const {merge} = require('./merge');
26
+ // Function to score reports.
27
+ const {score} = require('./score');
28
+ // Function to digest reports.
29
+ const {digest} = require('./digest');
30
+ // Function to compare scores.
31
+ const {compare} = require('./compare');
32
+
33
+ // ########## CONSTANTS
34
+
35
+ const watchDir = process.env.WATCHDIR;
36
+ const rawDir = process.env.REPORTDIR_RAW;
37
+ const scoredDir = process.env.REPORTDIR_SCORED;
38
+ const digestedDir = process.env.REPORTDIR_DIGESTED;
39
+ const comparisonDir = process.env.COMPARISONDIR;
40
+
41
+ // ########## FUNCTIONS
42
+
43
+ // Fulfills a high-level testing request.
44
+ const doAim = async (scriptName, hostURL, hostName, hostID, notifyee) => {
45
+ await aim(
46
+ scriptName,
47
+ {
48
+ id: hostID,
49
+ which: hostURL,
50
+ what: hostName
51
+ },
52
+ notifyee
53
+ );
54
+ console.log(`Request for aiming ${scriptID}.json at ${hostName} completed`);
55
+ };
56
+ // Fulfills a merger request.
57
+ const doMerge = async (scriptName, batchName) => {
58
+ await merge(scriptName, batchName);
59
+ console.log(`Batch ${batchName}.json merged into script ${scriptName} in ${watchDir}`);
60
+ };
61
+ // Fulfills a scoring request.
62
+ const doScore = async (scoreProcID, reportIDStart) => {
63
+ const reportCount = await score(scoreProcID, reportIDStart);
64
+ console.log(
65
+ `Scoring completed. Score proc: ${scoreProcID}. Report count: ${reportCount}. Directory: ${scoredDir}`
66
+ );
67
+ };
68
+ // Starts a watch.
69
+ const doWatch = async (isDirWatch, isForever, interval) => {
70
+ console.log(
71
+ `Starting a ${isForever ? 'repeating' : 'one-time'} ${isDirWatch ? 'directory' : 'network'} watch`
72
+ );
73
+ await cycle(isDirWatch, isForever, interval);
74
+ console.log('Watching ended');
75
+ };
76
+
77
+ // ########## OPERATION
78
+
79
+ // Execute the requested function.
80
+ if (fn === 'high' && fnArgs.length === 1) {
81
+ doHigh(fnArgs)
82
+ .then(() => {
83
+ console.log('Execution completed');
84
+ });
85
+ }
86
+ else if (fn === 'watch' && fnArgs.length === 3) {
87
+ doWatch(... fnArgs)
88
+ .then(() => {
89
+ console.log('Execution completed');
90
+ });
91
+ }
92
+ else {
93
+ console.log('ERROR: Invalid statement');
94
+ }
package/merge.js CHANGED
@@ -21,15 +21,17 @@ const fs = require('fs/promises');
21
21
  const scriptDir = process.env.SCRIPTDIR || 'scripts';
22
22
  const batchDir = process.env.BATCHDIR || 'batches';
23
23
  const watchDir = process.env.WATCHDIR || 'watch';
24
- const scriptName = process.argv[2];
25
- const batchName = process.argv[3];
26
24
 
27
25
  // ########## FUNCTIONS
28
26
 
29
27
  // Returns a string representing the date and time.
30
28
  const nowString = () => (new Date()).toISOString().slice(0, 19);
31
29
  // Merges a batch into a script and writes host-specific scripts.
32
- const merge = async (script, batch) => {
30
+ exports.merge = async (scriptName, batchName) => {
31
+ const scriptJSON = await fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8');
32
+ const batchJSON = await fs.readFile(`${batchDir}/${batchName}.json`, 'utf8');
33
+ const script = JSON.parse(scriptJSON);
34
+ const batch = JSON.parse(batchJSON);
33
35
  // Create the watch directory if it does not exist.
34
36
  await fs.mkdir(watchDir, {recursive: true});
35
37
  // Create a job-creation time stamp.
@@ -52,8 +54,6 @@ const merge = async (script, batch) => {
52
54
  script: script.id,
53
55
  batch: batch.id
54
56
  }
55
- // Add a job-creation time stamp to the script.
56
- newScript.timeStamp = timeStamp;
57
57
  // Add the job-creation time to the script.
58
58
  newScript.jobCreationTime = nowString();
59
59
  // Change the script id property to include the time stamp and the host ID.
@@ -67,15 +67,3 @@ const merge = async (script, batch) => {
67
67
  };
68
68
  console.log(`Merger completed. Script count: ${hosts.length}. Time stamp: ${timeStamp}`);
69
69
  };
70
-
71
- // ########## OPERATION
72
-
73
- fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8')
74
- .then(scriptFile => {
75
- fs.readFile(`${batchDir}/${batchName}.json`, 'utf8')
76
- .then(async batchFile => {
77
- const script = JSON.parse(scriptFile);
78
- const batch = JSON.parse(batchFile);
79
- await merge(script, batch);
80
- });
81
- });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "5.0.0",
3
+ "version": "6.0.0",
4
4
  "description": "Client that scores and digests Testaro reports",
5
5
  "main": "aim.js",
6
6
  "scripts": {
package/score.js CHANGED
@@ -21,13 +21,11 @@ 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 scoreProcID = process.argv[2];
25
- const reportIDStart = process.argv[3];
26
24
 
27
25
  // ########## FUNCTIONS
28
26
 
29
- // Score the specified reports.
30
- const score = async () => {
27
+ // Score the specified reports and return their count.
28
+ exports.score = async (scoreProcID, reportIDStart) => {
31
29
  // Identify the reports to be scored.
32
30
  const reportDirRawAbs = `${__dirname}/${reportDirRaw}`;
33
31
  let reportFileNames = await fs.readdir(reportDirRawAbs);
@@ -48,8 +46,5 @@ const score = async () => {
48
46
  await fs.writeFile(`${__dirname}/${reportDirScored}/${fileName}`, `${scoredReportJSON}\n`);
49
47
  console.log(`Report ${fileName.slice(0, -5)} scored and saved`);
50
48
  };
49
+ return reportFileNames.length;
51
50
  };
52
-
53
- // ########## OPERATION
54
-
55
- score();