testilo 7.0.1 → 7.0.3

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.
Files changed (4) hide show
  1. package/aim.js +9 -5
  2. package/call.js +33 -20
  3. package/merge.js +1 -1
  4. package/package.json +1 -1
package/aim.js CHANGED
@@ -5,7 +5,9 @@
5
5
 
6
6
  // ########## FUNCTIONS
7
7
 
8
- // Returns a script, aimed at a host.
8
+ // Returns a string representing the date and time.
9
+ const nowString = () => (new Date()).toISOString().slice(0, 19);
10
+ // Returns a script, aimed at a host, as a job.
9
11
  exports.aim = (script, host, requester) => {
10
12
  // Make all url commands in the script visit the host.
11
13
  script.commands.forEach(command => {
@@ -16,15 +18,17 @@ exports.aim = (script, host, requester) => {
16
18
  }
17
19
  });
18
20
  // Add source information to the script.
19
- script.source = {
21
+ script.sources = {
20
22
  script: script.id,
21
23
  host,
22
24
  requester
23
25
  }
24
26
  // Create a job-creation time stamp.
25
27
  const timeStamp = Math.floor((Date.now() - Date.UTC(2022, 1)) / 2000).toString(36);
26
- // Add a job-ID property to the script, including the time stamp, the script ID, and the host ID.
27
- script.jobID = `${timeStamp}-${script.id}-${host.id}`;
28
- // Return the host-specific script.
28
+ // Change the script ID to a job ID.
29
+ script.id = `${timeStamp}-${script.id}-${host.id}`;
30
+ // Add the job-creation time to the script.
31
+ script.jobCreationTime = nowString();
32
+ // Return the job.
29
33
  return script;
30
34
  };
package/call.js CHANGED
@@ -65,9 +65,10 @@ const callAim = async (scriptName, hostURL, hostName, hostID, requester) => {
65
65
  },
66
66
  requester
67
67
  );
68
- const aimedScriptID = aimedScript.id;
69
- await fs.writeFile(`${jobDir}/${aimedScriptID}.json`, JSON.stringify(aimedScript, null, 2));
70
- console.log(`Script ${aimedScriptID}.json has been aimed at ${hostName} and saved in ${jobDir}`);
68
+ const scriptID = script.sources.script;
69
+ const jobID = aimedScript.id;
70
+ await fs.writeFile(`${jobDir}/${jobID}.json`, `${JSON.stringify(aimedScript, null, 2)}\n`);
71
+ console.log(`Script ${scriptID} aimed at ${hostName} saved as ${jobID}.json in ${jobDir}`);
71
72
  };
72
73
  // Fulfills a merger request.
73
74
  const callMerge = async (scriptName, batchName) => {
@@ -75,7 +76,7 @@ const callMerge = async (scriptName, batchName) => {
75
76
  console.log(`Batch ${batchName}.json merged into script ${scriptName} in ${jobDir}`);
76
77
  };
77
78
  // Fulfills a scoring request.
78
- const callScore = async (scoreProcID, reportIDStart) => {
79
+ const callScore = async (scoreProcID, reportIDStart = '') => {
79
80
  // Identify the raw reports.
80
81
  const rawFileNames = await fs.readdir(rawDir);
81
82
  const rawReportNames = rawFileNames.filter(fileName => fileName.endsWith('.json'));
@@ -157,9 +158,19 @@ const digestPrep = async digestProcID => {
157
158
  digestTemplate,
158
159
  scoredReportNames
159
160
  };
160
- }
161
+ };
162
+ // Digests and saves a report.
163
+ const digestReport = async (scoredReportName, prepData) => {
164
+ // Digest the specified report.
165
+ const scoredReportJSON = await fs.readFile(`${scoredDir}/${scoredReportName}.json`, 'utf8');
166
+ const scoredReport = JSON.parse(scoredReportJSON);
167
+ const digestedReport = digest(prepData.digestTemplate, prepData.makeQuery, scoredReport);
168
+ // Save it, digested.
169
+ await fs.writeFile(`${digestedDir}/${digestedReport.id}.html`, digestedReport);
170
+ console.log(`Report ${scoredReport.id} digested and saved in ${digestedDir}`);
171
+ };
161
172
  // Fulfills a digesting request.
162
- const callDigest = async (digestProcID, reportIDStart) => {
173
+ const callDigest = async (digestProcID, reportIDStart = '') => {
163
174
  const prepData = await digestPrep(digestProcID);
164
175
  // If any scored reports exist:
165
176
  if (prepData.anyScoredReports) {
@@ -175,13 +186,8 @@ const callDigest = async (digestProcID, reportIDStart) => {
175
186
  }
176
187
  // If it exists:
177
188
  if (scoredReportName) {
178
- // Digest it.
179
- const scoredReportJSON = await fs.readFile(`${scoredDir}/${scoredReportName}.json`, 'utf8');
180
- const scoredReport = JSON.parse(scoredReportJSON);
181
- const digestedReport = digest(prepData.digestTemplate, makeQuery, scoredReport);
182
- // Save it, digested.
183
- await fs.writeFile(`${digestedDir}/${digestedReport.id}.html`, digestedReport);
184
- console.log(`Report ${scoredReport.id} digested and saved in ${digestedDir}`);
189
+ // Digest and save it.
190
+ await digestReport(scoredReportName, prepData);
185
191
  }
186
192
  // Otherwise, i.e. if it does not exist:
187
193
  else {
@@ -202,13 +208,8 @@ const callMultiDigest = async digestProcID => {
202
208
  if (prepData.anyScoredReports) {
203
209
  // For each of them:
204
210
  for (const scoredReportName of prepData.scoredReportNames) {
205
- // Digest it.
206
- const scoredReportJSON = await fs.readFile(`${scoredDir}/${scoredReportName}.json`, 'utf8');
207
- const scoredReport = JSON.parse(scoredReportJSON);
208
- const digestedReport = digest(prepData.digestTemplate, makeQuery, scoredReport);
209
- // Save it, digested.
210
- await fs.writeFile(`${digestedDir}/${digestedReport.id}.html`, digestedReport);
211
- console.log(`Report ${scoredReport.id} digested and saved in ${digestedDir}`);
211
+ // Digest and save it.
212
+ await digestReport(scoredReportName, prepData);
212
213
  }
213
214
  }
214
215
  // Otherwise, i.e. if no raw report exists:
@@ -249,12 +250,24 @@ else if (fn === 'score' && fnArgs.length > 0 && fnArgs.length < 3) {
249
250
  console.log('Execution completed');
250
251
  });
251
252
  }
253
+ else if (fn === 'multiScore' && fnArgs.length === 1) {
254
+ callMultiScore(... fnArgs)
255
+ .then(() => {
256
+ console.log('Execution completed');
257
+ });
258
+ }
252
259
  else if (fn === 'digest' && fnArgs.length > 0 && fnArgs.length < 3) {
253
260
  callDigest(... fnArgs)
254
261
  .then(() => {
255
262
  console.log('Execution completed');
256
263
  });
257
264
  }
265
+ else if (fn === 'multiDigest' && fnArgs.length === 1) {
266
+ callMultiDigest(... fnArgs)
267
+ .then(() => {
268
+ console.log('Execution completed');
269
+ });
270
+ }
258
271
  else if (fn === 'compare' && fnArgs.length === 2) {
259
272
  callCompare(... fnArgs)
260
273
  .then(() => {
package/merge.js CHANGED
@@ -56,7 +56,7 @@ exports.merge = async (scriptName, batchName) => {
56
56
  }
57
57
  // Add the job-creation time to the script.
58
58
  newScript.jobCreationTime = nowString();
59
- // Change the script id property to include the time stamp and the host ID.
59
+ // Change the script ID to a job ID.
60
60
  newScript.id = `${timeStamp}-${newScript.id}-${host.id}`;
61
61
  // Return the host-specific script.
62
62
  return newScript;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "7.0.1",
3
+ "version": "7.0.3",
4
4
  "description": "Client that scores and digests Testaro reports",
5
5
  "main": "aim.js",
6
6
  "scripts": {