testilo 7.0.0 → 7.0.1

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
@@ -130,22 +130,21 @@ The `score` function performs scoring. It depends on a _score proc_ to define th
130
130
  Execution by a module:
131
131
 
132
132
  ```javaScript
133
- const fs = require('fs/promises');
134
- const scoreReport = async rawReport => {
133
+ const scoreReport = async (scoreProcID, rawReportID) => {
134
+ const fs = require('fs/promises');
135
135
  const {score} = require('testilo/score');
136
- const procJSON = await fs.readFile(`${process.env.SCOREPROCDIR}/sp25a.json`, 'utf8');
137
- const proc = JSON.parse(procJSON);
138
- const scoredReport = score(proc, rawReport);
136
+ const {scorer} = require(`${process.env.SCOREPROCDIR}/${scoreProcID}`);
137
+ const rawReportJSON = await fs.readFile(
138
+ `${process.env.REPORTDIR_RAW}/${rawReportID}.json`, 'utf8'
139
+ );
140
+ const rawReport = JSON.parse(rawReportJSON);
141
+ const scoredReport = score(scorer, rawReport);
139
142
  await fs.writeFile(
140
143
  `${process.env.REPORTDIR_SCORED}/${scoredReport.id}.json`, JSON.stringify(scoredReport, null, 2)
141
144
  );
142
145
  console.log(`Report ${scoredReport.id} scored`);
143
146
  };
144
- fs.readFile(`${process.env.REPORTDIR_RAW}/756mr-tp25-w3c.json`, 'utf8')
145
- .then(rawReportJSON => {
146
- const rawReport = JSON.parse(rawReportJSON);
147
- scoreReport(rawReport);
148
- });
147
+ scoreReport('sp25a', '756mr-tp25-w3c');
149
148
  ```
150
149
 
151
150
  Execution by a user:
@@ -192,22 +191,19 @@ The `digest` function converts scored reports into HTML documents with explanato
192
191
  Execution by a module:
193
192
 
194
193
  ```javaScript
195
- const fs = require('fs/promises');
196
- const digestReport = async scoredReport => {
194
+ const digestReport = async (digestProcID, scoredReportID) => {
195
+ const fs = require('fs/promises');
197
196
  const {digest} = require('testilo/digest');
198
- const procJSON = await fs.readFile(`${process.env.DIGESTPROCDIR}/dp25a.json`, 'utf8');
199
- const proc = JSON.parse(procJSON);
200
- const digest = digest(proc, scoredReport);
201
- await fs.writeFile(
202
- `${process.env.REPORTDIR_DIGESTED}/${digest.id}.json`, JSON.stringify(digest, null, 2)
197
+ const {makeQuery} = require(`${process.env.DIGESTPROCDIR}/${digestProcID}/index`);
198
+ const digestTemplate = await fs.readFile(
199
+ `${process.env.DIGESTPROCDIR}/${digestProcID}/index.html`
203
200
  );
204
- console.log(`Report ${digest.id} digested`);
201
+ const digestedReport = digest(digestTemplate, makeQuery, scoredReport);
202
+ const digestedReport = digest(makeQuery, scoredReport);
203
+ await fs.writeFile(`${process.env.REPORTDIR_DIGESTED}/${digestedReport.id}.html`, digestedReport);
204
+ console.log(`Report ${digestedReport.id} digested`);
205
205
  };
206
- fs.readFile(`${process.env.REPORTDIR_SCORED}/756mr-tp25-w3c.json`, 'utf8')
207
- .then(scoredReportJSON => {
208
- const scoredReport = JSON.parse(scoredReportJSON);
209
- digestReport(scoredReport);
210
- });
206
+ digestReport('dp25a', '756mr-tp25-w3c');
211
207
  ```
212
208
 
213
209
  Execution by a user:
package/aim.js CHANGED
@@ -6,7 +6,7 @@
6
6
  // ########## FUNCTIONS
7
7
 
8
8
  // Returns a script, aimed at a host.
9
- exports.aim = async (script, host, requester) => {
9
+ exports.aim = (script, host, requester) => {
10
10
  // Make all url commands in the script visit the host.
11
11
  script.commands.forEach(command => {
12
12
  if (command.type === 'url') {
package/call.js CHANGED
@@ -6,13 +6,15 @@
6
6
  0. function to execute.
7
7
  1+. arguments to pass to the function.
8
8
  Usage examples:
9
- node call aim script454 https://www.w3c.org/ 'World Wide Web Consortium' w3c
9
+ node call aim tp25 https://www.w3c.org/ 'World Wide Web Consortium' w3c developer@w3.org
10
10
  node call merge script454 webOrgs
11
- node call score sp25a (to score all reports in REPORTDIR_RAW)
12
- node call score sp25a 8ep9f- (same, but only if names start with 8ep9f-)
13
- node call digest dp25a (to digest all reports in REPORTDIR_SCORED)
14
- node call digest dp25a 8ep9f- (same, but only if names start with 8ep9f-)
15
- node call compare cp25a weborgs (to write weborgs.html, comparing all reports in REPORTDIR_SCORED)
11
+ node call score sp25a (to score the first raw report)
12
+ node call score sp25a 8ep9f (to score the first raw report whose name starts with 8ep9f)
13
+ node call multiScore sp25a
14
+ node call digest dp25a (to digest the first scored report)
15
+ node call digest dp25a 8ep9f (to digest the first scored report whose name starts with 8ep9f)
16
+ node call multiDigest dp25a
17
+ node call compare cp25a weborgs (to write weborgs.html, comparing all scored reports)
16
18
  */
17
19
 
18
20
  // ########## IMPORTS
@@ -24,16 +26,24 @@ const fs = require('fs/promises');
24
26
  const {aim} = require('./aim');
25
27
  // Function to process a script-batch merger.
26
28
  const {merge} = require('./merge');
27
- // Function to score reports.
29
+ // Function to score a report.
28
30
  const {score} = require('./score');
29
- // Function to digest reports.
31
+ // Function to score multiple reports.
32
+ const {multiScore} = require('./multiScore');
33
+ // Function to digest a report.
30
34
  const {digest} = require('./digest');
35
+ // Function to digest multiple reports.
36
+ const {multiDigest} = require('./multiDigest');
31
37
  // Function to compare scores.
32
38
  const {compare} = require('./compare');
33
39
 
34
40
  // ########## CONSTANTS
35
41
 
42
+ const scriptDir = process.env.SCRIPTDIR;
43
+ const scoreProcDir = process.env.SCOREPROCDIR;
44
+ const digestProcDir = process.env.DIGESTPROCDIR;
36
45
  const jobDir = process.env.JOBDIR;
46
+ const rawDir = process.env.REPORTDIR_RAW;
37
47
  const scoredDir = process.env.REPORTDIR_SCORED;
38
48
  const digestedDir = process.env.REPORTDIR_DIGESTED;
39
49
  const comparisonDir = process.env.COMPARISONDIR;
@@ -43,15 +53,17 @@ const fnArgs = process.argv.slice(3);
43
53
  // ########## FUNCTIONS
44
54
 
45
55
  // Fulfills an aiming request.
46
- const callAim = async (scriptName, hostURL, hostName, hostID, notifyee) => {
47
- const aimedScript = await aim(
48
- scriptName,
56
+ const callAim = async (scriptName, hostURL, hostName, hostID, requester) => {
57
+ const scriptJSON = await fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8');
58
+ const script = JSON.parse(scriptJSON);
59
+ const aimedScript = aim(
60
+ script,
49
61
  {
50
62
  id: hostID,
51
63
  which: hostURL,
52
64
  what: hostName
53
65
  },
54
- notifyee
66
+ requester
55
67
  );
56
68
  const aimedScriptID = aimedScript.id;
57
69
  await fs.writeFile(`${jobDir}/${aimedScriptID}.json`, JSON.stringify(aimedScript, null, 2));
@@ -64,16 +76,148 @@ const callMerge = async (scriptName, batchName) => {
64
76
  };
65
77
  // Fulfills a scoring request.
66
78
  const callScore = async (scoreProcID, reportIDStart) => {
67
- const reportCount = await score(scoreProcID, reportIDStart);
68
- console.log(
69
- `Scoring completed. Score proc: ${scoreProcID}. Report count: ${reportCount}. Directory: ${scoredDir}`
70
- );
79
+ // Identify the raw reports.
80
+ const rawFileNames = await fs.readdir(rawDir);
81
+ const rawReportNames = rawFileNames.filter(fileName => fileName.endsWith('.json'));
82
+ // If any exist:
83
+ if (rawReportNames.length) {
84
+ // Identify the one to be scored.
85
+ let rawReportName = '';
86
+ if (reportIDStart) {
87
+ rawReportName = rawReportNames.find(reportName => reportName.startsWith(reportIDStart));
88
+ }
89
+ else {
90
+ rawReportName = rawReportNames[0];
91
+ }
92
+ // If it exists:
93
+ if (rawReportName) {
94
+ // Score it.
95
+ const rawReportJSON = await fs.readFile(`${rawDir}/${rawReportName}.json`);
96
+ const rawReport = JSON.parse(rawReportJSON);
97
+ const {scorer} = require(`${scoreProcDir}/${scoreProcID}.js`);
98
+ const scoredReport = score(scorer, rawReport);
99
+ // Save it, scored.
100
+ await fs.writeFile(
101
+ `${scoredDir}/${scoredReport.id}.json`, JSON.stringify(scoredReport, null, 2)
102
+ );
103
+ console.log(`Report ${rawReport.id} scored and saved in ${scoredDir}`);
104
+ }
105
+ // Otherwise, i.e. if it does not exist:
106
+ else {
107
+ // Report this.
108
+ console.log('ERROR: Specified raw report not found');
109
+ }
110
+ }
111
+ // Otherwise, i.e. if no raw report found:
112
+ else {
113
+ // Report this.
114
+ console.log('ERROR: No raw report found');
115
+ }
116
+ };
117
+ // Fulfills a multiple-report scoring request.
118
+ const callMultiScore = async scoreProcID => {
119
+ // Identify all the raw reports.
120
+ const rawFileNames = await fs.readdir(rawDir);
121
+ const rawReportNames = rawFileNames.filter(fileName => fileName.endsWith('.json'));
122
+ // If any exist:
123
+ if (rawReportNames.length) {
124
+ // For each of them:
125
+ const {scorer} = require(`${scoreProcDir}/${scoreProcID}.js`);
126
+ for (const rawReportName of rawReportNames) {
127
+ // Score it.
128
+ const rawReportJSON = await fs.readFile(`${rawDir}/${rawReportName}.json`);
129
+ const rawReport = JSON.parse(rawReportJSON);
130
+ const scoredReport = score(scorer, rawReport);
131
+ // Save it, scored.
132
+ await fs.writeFile(
133
+ `${scoredDir}/${scoredReport.id}.json`, JSON.stringify(scoredReport, null, 2)
134
+ );
135
+ console.log(`Report ${rawReport.id} scored and saved in ${scoredDir}`);
136
+ }
137
+ }
138
+ // Otherwise, i.e. if no raw report exists:
139
+ else {
140
+ // Report this.
141
+ console.log('ERROR: No raw report found');
142
+ }
71
143
  };
144
+ // Prepares to fulfill a digesting request.
145
+ const digestPrep = async digestProcID => {
146
+ const {digest} = require('testilo/digest');
147
+ const {makeQuery} = require(`${digestProcDir}/${digestProcID}/index`);
148
+ const digestTemplate = await fs.readFile(`${digestProcDir}/${digestProcID}/index.html`, 'utf8');
149
+ // Identify the scored reports.
150
+ const scoredFileNames = await fs.readdir(scoredDir);
151
+ const scoredReportNames = scoredFileNames.filter(fileName => fileName.endsWith('.json'));
152
+ // Return the data required for the fulfillment of the request.
153
+ return {
154
+ anyScoredReports: scoredReportNames.length > 0,
155
+ digest,
156
+ makeQuery,
157
+ digestTemplate,
158
+ scoredReportNames
159
+ };
160
+ }
72
161
  // Fulfills a digesting request.
73
162
  const callDigest = async (digestProcID, reportIDStart) => {
74
- const reportCount = await digest(digestProcID, reportIDStart);
163
+ const prepData = await digestPrep(digestProcID);
164
+ // If any scored reports exist:
165
+ if (prepData.anyScoredReports) {
166
+ // Identify the one to be digested.
167
+ let scoredReportName = '';
168
+ if (reportIDStart) {
169
+ scoredReportName = prepData.scoredReportNames.find(
170
+ reportName => reportName.startsWith(reportIDStart)
171
+ );
172
+ }
173
+ else {
174
+ scoredReportName = prepData.scoredReportNames[0];
175
+ }
176
+ // If it exists:
177
+ 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}`);
185
+ }
186
+ // Otherwise, i.e. if it does not exist:
187
+ else {
188
+ // Report this.
189
+ console.log('ERROR: Specified scored report not found');
190
+ }
191
+ }
192
+ // Otherwise, i.e. if no scored report exists:
193
+ else {
194
+ // Report this.
195
+ console.log('ERROR: No scored report found');
196
+ }
197
+ };
198
+ // Fulfills a multiple-report digesting request.
199
+ const callMultiDigest = async digestProcID => {
200
+ const prepData = await digestPrep(digestProcID);
201
+ // If any scored reports exist:
202
+ if (prepData.anyScoredReports) {
203
+ // For each of them:
204
+ 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}`);
212
+ }
213
+ }
214
+ // Otherwise, i.e. if no raw report exists:
215
+ else {
216
+ // Report this.
217
+ console.log('ERROR: No raw report found');
218
+ }
75
219
  console.log(
76
- `Digesting completed. Digest proc: ${digestProcID}. Report count: ${reportCount}. Directory: ${digestedDir}`
220
+ `Digesting completed. Digest proc: ${digestProcID}. Report count: ${prepData.scoredReportNames.length}. Directory: ${digestedDir}`
77
221
  );
78
222
  };
79
223
  // Fulfills a comparison request.
package/multiScore.js CHANGED
@@ -24,7 +24,7 @@ const scoreProcDir = process.env.SCOREPROCDIR || `${__dirname}/procs/score`;
24
24
  // ########## FUNCTIONS
25
25
 
26
26
  // Score the specified reports and return their count.
27
- exports.score = async scoreProcID => {
27
+ exports.multiScore = async scoreProcID => {
28
28
  // Identify the reports to be scored.
29
29
  let reportFileNames = await fs.readdir(reportDirRaw);
30
30
  reportFileNames = reportFileNames.filter(fileName => fileName.endsWith('.json'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "description": "Client that scores and digests Testaro reports",
5
5
  "main": "aim.js",
6
6
  "scripts": {