testaro 30.0.0 → 30.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/package.json +1 -1
- package/procs/tellServer.js +4 -4
- package/tests/testaro.js +10 -0
- package/watch.js +11 -5
package/package.json
CHANGED
package/procs/tellServer.js
CHANGED
|
@@ -17,13 +17,13 @@ exports.tellServer = (report, messageParams, logMessage) => {
|
|
|
17
17
|
const whoParams = `agent=${agent}&jobID=${report.id || ''}`;
|
|
18
18
|
const wholeURL = `${observer}?${whoParams}&${messageParams}`;
|
|
19
19
|
const client = wholeURL.startsWith('https://') ? httpsClient : httpClient;
|
|
20
|
-
|
|
20
|
+
client.request(wholeURL)
|
|
21
21
|
// If the notification threw an error:
|
|
22
|
-
|
|
22
|
+
.on('error', error => {
|
|
23
23
|
// Report the error.
|
|
24
24
|
const errorMessage = 'ERROR notifying the server';
|
|
25
25
|
console.log(`${errorMessage} (${error.message})`);
|
|
26
|
-
})
|
|
27
|
-
|
|
26
|
+
})
|
|
27
|
+
.end();
|
|
28
28
|
console.log(`${logMessage} (server notified)`);
|
|
29
29
|
};
|
package/tests/testaro.js
CHANGED
|
@@ -99,6 +99,14 @@ const jsonTest = async (ruleID, ruleArgs) => {
|
|
|
99
99
|
withItems, all, ruleObj.ruleID, whats, ruleObj.ordinalSeverity, ruleObj.summaryTagName
|
|
100
100
|
);
|
|
101
101
|
};
|
|
102
|
+
// Waits.
|
|
103
|
+
const wait = ms => {
|
|
104
|
+
return new Promise(resolve => {
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
resolve('');
|
|
107
|
+
}, ms);
|
|
108
|
+
});
|
|
109
|
+
};
|
|
102
110
|
// Conducts and reports Testaro tests.
|
|
103
111
|
exports.reporter = async (page, options) => {
|
|
104
112
|
const {withItems, stopOnFail, granular, args} = options;
|
|
@@ -119,6 +127,8 @@ exports.reporter = async (page, options) => {
|
|
|
119
127
|
&& ['y', 'n'].includes(rules[0])
|
|
120
128
|
&& rules.slice(1).every(rule => evalRules[rule] || etcRules[rule])
|
|
121
129
|
) {
|
|
130
|
+
// Wait 1 second to prevent out-of-order logging with granular reporting.
|
|
131
|
+
await wait(1000);
|
|
122
132
|
// For each rule invoked:
|
|
123
133
|
const calledRules = rules[0] === 'y'
|
|
124
134
|
? rules.slice(1)
|
package/watch.js
CHANGED
|
@@ -59,11 +59,17 @@ const writeDirReport = async report => {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
// Archives a job.
|
|
62
|
-
const archiveJob = async job => {
|
|
62
|
+
const archiveJob = async (job, isFile) => {
|
|
63
|
+
// Save the job in the done subdirectory.
|
|
63
64
|
const {id} = job;
|
|
64
65
|
const jobJSON = JSON.stringify(job, null, 2);
|
|
66
|
+
await fs.mkdir(`${jobDir}/done`, {recursive: true});
|
|
65
67
|
await fs.writeFile(`${jobDir}/done/${id}.json`, jobJSON);
|
|
66
|
-
|
|
68
|
+
// If the job had been saved as a file in the todo subdirectory:
|
|
69
|
+
if (isFile) {
|
|
70
|
+
// Delete the file.
|
|
71
|
+
await fs.rm(`${jobDir}/todo/${id}.json`);
|
|
72
|
+
}
|
|
67
73
|
};
|
|
68
74
|
// Checks for a directory job and, if found, performs and reports it, once or repeatedly.
|
|
69
75
|
const checkDirJob = async (isForever, interval) => {
|
|
@@ -84,7 +90,7 @@ const checkDirJob = async (isForever, interval) => {
|
|
|
84
90
|
// Report it.
|
|
85
91
|
await writeDirReport(job);
|
|
86
92
|
// Archive it.
|
|
87
|
-
await archiveJob(job);
|
|
93
|
+
await archiveJob(job, true);
|
|
88
94
|
console.log(`Job ${id} archived in ${jobDir} (${nowString()})`);
|
|
89
95
|
// If watching is repetitive:
|
|
90
96
|
if (isForever) {
|
|
@@ -207,7 +213,7 @@ const checkNetJob = async (servers, serverIndex, isForever, interval, noJobCount
|
|
|
207
213
|
// Report it.
|
|
208
214
|
console.log(`${reportLogStart}${message}`);
|
|
209
215
|
// Archive the job.
|
|
210
|
-
await archiveJob(contentObj);
|
|
216
|
+
await archiveJob(contentObj, false);
|
|
211
217
|
console.log(`Job ${id} archived (${nowString()})`);
|
|
212
218
|
// Check the next server.
|
|
213
219
|
await checkNetJob(servers, serverIndex + 1, isForever, interval, 0);
|
|
@@ -228,7 +234,7 @@ const checkNetJob = async (servers, serverIndex, isForever, interval, noJobCount
|
|
|
228
234
|
catch(error) {
|
|
229
235
|
// Report it.
|
|
230
236
|
console.log(
|
|
231
|
-
`ERROR: ${reportLogStart}status ${repResponse.statusCode} and response ${content.slice(0, 1000)}`
|
|
237
|
+
`ERROR: ${reportLogStart}status ${repResponse.statusCode}, error message ${error.message}, and response ${content.slice(0, 1000)}`
|
|
232
238
|
);
|
|
233
239
|
// Check the next server, disregarding the failed job.
|
|
234
240
|
await checkNetJob(
|