testilo 7.0.5 → 7.0.6

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
@@ -107,7 +107,7 @@ Execution by a module:
107
107
 
108
108
  ```javaScript
109
109
  const {merge} = require('testilo/merge');
110
- merge('tp25', 'weborgs')
110
+ merge('tp25', 'weborgs', 'developer@w3.org')
111
111
  .then(() => {
112
112
  console.log('Merger complete');
113
113
  });
@@ -116,10 +116,10 @@ merge('tp25', 'weborgs')
116
116
  Execution by a user:
117
117
 
118
118
  ```bash
119
- node call merge tp25 weborgs
119
+ node call merge tp25 weborgs developer@w3.org
120
120
  ```
121
121
 
122
- In these examples, a copy of the script file named `tp25.json` in the `SCRIPTDIR` directory is aimed at all the hosts in the batch file named `weborgs.json` in the `BATCHDIR` directory, and the resulting host-specific scripts are saved in the `JOBDIR` directory.
122
+ In these examples, a copy of the script file named `tp25.json` in the `SCRIPTDIR` directory is aimed at all the hosts in the batch file named `weborgs.json` in the `BATCHDIR` directory, and the resulting jobs are saved in the `JOBDIR` directory. Each job has a `sources` property that identifies an email address to be notified after the job has been run.
123
123
 
124
124
  ### `score`
125
125
 
package/aim.js CHANGED
@@ -1,6 +1,11 @@
1
1
  /*
2
2
  aim.js
3
3
  Module for aiming a script at a host.
4
+ Arguments:
5
+ 0. script object.
6
+ 1. host object.
7
+ 2. email address to be notified of completion.
8
+ 3?. time stamp.
4
9
  */
5
10
 
6
11
  // ########## FUNCTIONS
@@ -8,7 +13,7 @@
8
13
  // Returns a string representing the date and time.
9
14
  const nowString = () => (new Date()).toISOString().slice(0, 19);
10
15
  // Returns a script, aimed at a host, as a job.
11
- exports.aim = (script, host, requester) => {
16
+ exports.aim = (script, host, requester, timeStamp = '') => {
12
17
  // Initialize a job based on the script.
13
18
  const job = JSON.parse(JSON.stringify(script));
14
19
  // Make all url commands in the script visit the host.
@@ -22,11 +27,13 @@ exports.aim = (script, host, requester) => {
22
27
  // Add source information to the script.
23
28
  job.sources = {
24
29
  script: script.id,
30
+ batch: '',
25
31
  host,
26
32
  requester
27
33
  }
28
- // Create a job-creation time stamp.
29
- const timeStamp = Math.floor((Date.now() - Date.UTC(2022, 1)) / 2000).toString(36);
34
+ // Create a job-creation time stamp, if not specified.
35
+
36
+ timeStamp = timeStamp || Math.floor((Date.now() - Date.UTC(2022, 1)) / 2000).toString(36);
30
37
  // Change the script ID to a job ID.
31
38
  job.id = `${timeStamp}-${script.id}-${host.id}`;
32
39
  // Add the job-creation time to the script.
package/call.js CHANGED
@@ -71,8 +71,8 @@ const callAim = async (scriptName, hostURL, hostName, hostID, requester) => {
71
71
  console.log(`Script ${scriptID} aimed at ${hostName} saved as job ${jobID}.json in ${jobDir}`);
72
72
  };
73
73
  // Fulfills a merger request.
74
- const callMerge = async (scriptName, batchName) => {
75
- await merge(scriptName, batchName);
74
+ const callMerge = async (scriptName, batchName, requester) => {
75
+ await merge(scriptName, batchName, requester);
76
76
  console.log(`Batch ${batchName}.json merged into script ${scriptName} in ${jobDir}`);
77
77
  };
78
78
  // Fulfills a scoring request.
@@ -238,7 +238,7 @@ if (fn === 'aim' && fnArgs.length === 5) {
238
238
  console.log('Execution completed');
239
239
  });
240
240
  }
241
- else if (fn === 'merge' && fnArgs.length === 2) {
241
+ else if (fn === 'merge' && fnArgs.length === 3) {
242
242
  callMerge(... fnArgs)
243
243
  .then(() => {
244
244
  console.log('Execution completed');
package/merge.js CHANGED
@@ -1,12 +1,13 @@
1
1
  /*
2
2
  merge.js
3
- Merges a batch and a script to produce host-specific scripts.
3
+ Merges a batch and a script to produce jobs.
4
4
  Arguments:
5
5
  0. base of name of script located in process.env.SCRIPTDIR.
6
6
  1. base of name of batch located in process.env.BATCHDIR.
7
+ 2. email address to be notified of completion.
7
8
  Usage example:
8
- node merge tp18 weborgs
9
- Note: The subdirectory for host-specific scripts will be created if it does not exist.
9
+ node merge tp25 weborgs developer@w3.org
10
+ Note: The subdirectory for jobs will be created if it does not exist.
10
11
  */
11
12
 
12
13
  // ########## IMPORTS
@@ -15,6 +16,8 @@
15
16
  require('dotenv').config();
16
17
  // Module to read and write files.
17
18
  const fs = require('fs/promises');
19
+ // Module to aim a script at a host.
20
+ const {aim} = require('./aim');
18
21
 
19
22
  // ########## CONSTANTS
20
23
 
@@ -24,46 +27,25 @@ const jobDir = process.env.JOBDIR || 'watch';
24
27
 
25
28
  // ########## FUNCTIONS
26
29
 
27
- // Returns a string representing the date and time.
28
- const nowString = () => (new Date()).toISOString().slice(0, 19);
29
- // Merges a batch into a script and writes host-specific scripts.
30
- exports.merge = async (scriptName, batchName) => {
30
+ // Merges a batch into a script and writes jobs.
31
+ exports.merge = async (scriptName, batchName, requester) => {
32
+ // Get the script and the batch.
31
33
  const scriptJSON = await fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8');
32
34
  const batchJSON = await fs.readFile(`${batchDir}/${batchName}.json`, 'utf8');
33
35
  const script = JSON.parse(scriptJSON);
34
36
  const batch = JSON.parse(batchJSON);
35
- // Create the watch directory if it does not exist.
36
- await fs.mkdir(jobDir, {recursive: true});
37
- // Create a job-creation time stamp.
38
37
  const timeStamp = Math.floor((Date.now() - Date.UTC(2022, 1)) / 2000).toString(36);
38
+ // Create the job directory if it does not exist.
39
+ await fs.mkdir(jobDir, {recursive: true});
39
40
  // For each host in the batch:
40
41
  const {hosts} = batch;
41
- const newScripts = hosts.map(host => {
42
- // Copy the script.
43
- const newScript = JSON.parse(JSON.stringify(script));
44
- // In the copy, make all url commands visit the host.
45
- newScript.commands.forEach(command => {
46
- if (command.type === 'url') {
47
- command.id = host.id;
48
- command.which = host.which;
49
- command.what = host.what;
50
- }
51
- });
52
- // Add source information to the script.
53
- newScript.sources = {
54
- script: script.id,
55
- batch: batch.id
56
- }
57
- // Add the job-creation time to the script.
58
- newScript.jobCreationTime = nowString();
59
- // Change the script ID to a job ID.
60
- newScript.id = `${timeStamp}-${newScript.id}-${host.id}`;
61
- // Return the host-specific script.
62
- return newScript;
63
- });
64
- // Write the host-specific scripts.
65
- for (const newScript of newScripts) {
66
- await fs.writeFile(`${jobDir}/${newScript.id}.json`, JSON.stringify(newScript, null, 2));
42
+ for (const host of hosts) {
43
+ // Aim the script at the host.
44
+ const job = await aim(script, host, requester, timeStamp);
45
+ // Add the batch name to the job.
46
+ job.sources.batch = batchName;
47
+ // Save the job.
48
+ await fs.writeFile(`${jobDir}/${job.id}.json`, JSON.stringify(job, null, 2));
67
49
  };
68
- console.log(`Merger completed. Script count: ${hosts.length}. Time stamp: ${timeStamp}`);
50
+ console.log(`Merger completed. Job count: ${hosts.length}. Time stamp ${timeStamp}.`);
69
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "7.0.5",
3
+ "version": "7.0.6",
4
4
  "description": "Client that scores and digests Testaro reports",
5
5
  "main": "aim.js",
6
6
  "scripts": {