testilo 7.0.0 → 7.0.2
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 +19 -23
- package/aim.js +1 -1
- package/call.js +176 -20
- package/multiScore.js +1 -1
- package/package.json +1 -1
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
|
|
134
|
-
const
|
|
133
|
+
const scoreReport = async (scoreProcID, rawReportID) => {
|
|
134
|
+
const fs = require('fs/promises');
|
|
135
135
|
const {score} = require('testilo/score');
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
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
|
-
|
|
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
|
|
196
|
-
const
|
|
194
|
+
const digestReport = async (digestProcID, scoredReportID) => {
|
|
195
|
+
const fs = require('fs/promises');
|
|
197
196
|
const {digest} = require('testilo/digest');
|
|
198
|
-
const
|
|
199
|
-
const
|
|
200
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
|
12
|
-
node call score sp25a 8ep9f
|
|
13
|
-
node call
|
|
14
|
-
node call digest dp25a
|
|
15
|
-
node call
|
|
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
|
|
29
|
+
// Function to score a report.
|
|
28
30
|
const {score} = require('./score');
|
|
29
|
-
// Function to
|
|
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,
|
|
47
|
-
const
|
|
48
|
-
|
|
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
|
-
|
|
66
|
+
requester
|
|
55
67
|
);
|
|
56
68
|
const aimedScriptID = aimedScript.id;
|
|
57
69
|
await fs.writeFile(`${jobDir}/${aimedScriptID}.json`, JSON.stringify(aimedScript, null, 2));
|
|
@@ -63,17 +75,149 @@ const callMerge = async (scriptName, batchName) => {
|
|
|
63
75
|
console.log(`Batch ${batchName}.json merged into script ${scriptName} in ${jobDir}`);
|
|
64
76
|
};
|
|
65
77
|
// Fulfills a scoring request.
|
|
66
|
-
const callScore = async (scoreProcID, reportIDStart) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
78
|
+
const callScore = async (scoreProcID, reportIDStart = '') => {
|
|
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
|
+
}
|
|
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
|
+
};
|
|
161
|
+
// Digests and saves a report.
|
|
162
|
+
const digestReport = async (scoredReportName, prepData) => {
|
|
163
|
+
// Digest the specified report.
|
|
164
|
+
const scoredReportJSON = await fs.readFile(`${scoredDir}/${scoredReportName}.json`, 'utf8');
|
|
165
|
+
const scoredReport = JSON.parse(scoredReportJSON);
|
|
166
|
+
const digestedReport = digest(prepData.digestTemplate, prepData.makeQuery, scoredReport);
|
|
167
|
+
// Save it, digested.
|
|
168
|
+
await fs.writeFile(`${digestedDir}/${digestedReport.id}.html`, digestedReport);
|
|
169
|
+
console.log(`Report ${scoredReport.id} digested and saved in ${digestedDir}`);
|
|
71
170
|
};
|
|
72
171
|
// Fulfills a digesting request.
|
|
73
|
-
const callDigest = async (digestProcID, reportIDStart) => {
|
|
74
|
-
const
|
|
172
|
+
const callDigest = async (digestProcID, reportIDStart = '') => {
|
|
173
|
+
const prepData = await digestPrep(digestProcID);
|
|
174
|
+
// If any scored reports exist:
|
|
175
|
+
if (prepData.anyScoredReports) {
|
|
176
|
+
// Identify the one to be digested.
|
|
177
|
+
let scoredReportName = '';
|
|
178
|
+
if (reportIDStart) {
|
|
179
|
+
scoredReportName = prepData.scoredReportNames.find(
|
|
180
|
+
reportName => reportName.startsWith(reportIDStart)
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
scoredReportName = prepData.scoredReportNames[0];
|
|
185
|
+
}
|
|
186
|
+
// If it exists:
|
|
187
|
+
if (scoredReportName) {
|
|
188
|
+
// Digest and save it.
|
|
189
|
+
await digestReport(scoredReportName, prepData);
|
|
190
|
+
}
|
|
191
|
+
// Otherwise, i.e. if it does not exist:
|
|
192
|
+
else {
|
|
193
|
+
// Report this.
|
|
194
|
+
console.log('ERROR: Specified scored report not found');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
// Otherwise, i.e. if no scored report exists:
|
|
198
|
+
else {
|
|
199
|
+
// Report this.
|
|
200
|
+
console.log('ERROR: No scored report found');
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
// Fulfills a multiple-report digesting request.
|
|
204
|
+
const callMultiDigest = async digestProcID => {
|
|
205
|
+
const prepData = await digestPrep(digestProcID);
|
|
206
|
+
// If any scored reports exist:
|
|
207
|
+
if (prepData.anyScoredReports) {
|
|
208
|
+
// For each of them:
|
|
209
|
+
for (const scoredReportName of prepData.scoredReportNames) {
|
|
210
|
+
// Digest and save it.
|
|
211
|
+
await digestReport(scoredReportName, prepData);
|
|
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: ${
|
|
220
|
+
`Digesting completed. Digest proc: ${digestProcID}. Report count: ${prepData.scoredReportNames.length}. Directory: ${digestedDir}`
|
|
77
221
|
);
|
|
78
222
|
};
|
|
79
223
|
// Fulfills a comparison request.
|
|
@@ -105,12 +249,24 @@ else if (fn === 'score' && fnArgs.length > 0 && fnArgs.length < 3) {
|
|
|
105
249
|
console.log('Execution completed');
|
|
106
250
|
});
|
|
107
251
|
}
|
|
252
|
+
else if (fn === 'multiScore' && fnArgs.length === 1) {
|
|
253
|
+
callMultiScore(... fnArgs)
|
|
254
|
+
.then(() => {
|
|
255
|
+
console.log('Execution completed');
|
|
256
|
+
});
|
|
257
|
+
}
|
|
108
258
|
else if (fn === 'digest' && fnArgs.length > 0 && fnArgs.length < 3) {
|
|
109
259
|
callDigest(... fnArgs)
|
|
110
260
|
.then(() => {
|
|
111
261
|
console.log('Execution completed');
|
|
112
262
|
});
|
|
113
263
|
}
|
|
264
|
+
else if (fn === 'multiDigest' && fnArgs.length === 1) {
|
|
265
|
+
callMultiDigest(... fnArgs)
|
|
266
|
+
.then(() => {
|
|
267
|
+
console.log('Execution completed');
|
|
268
|
+
});
|
|
269
|
+
}
|
|
114
270
|
else if (fn === 'compare' && fnArgs.length === 2) {
|
|
115
271
|
callCompare(... fnArgs)
|
|
116
272
|
.then(() => {
|
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.
|
|
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'));
|