testaro 53.0.2 → 53.1.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/netWatch.js +16 -12
- package/package.json +1 -1
- package/procs/doTestAct.js +6 -5
- package/run.js +7 -5
package/netWatch.js
CHANGED
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
|
|
32
32
|
// Module to keep secrets.
|
|
33
33
|
require('dotenv').config();
|
|
34
|
+
// Module to perform file operations.
|
|
35
|
+
const fs = require('fs/promises');
|
|
34
36
|
// Module to validate jobs.
|
|
35
37
|
const {isValidJob} = require('./procs/job');
|
|
36
38
|
// Modules to make requests to servers.
|
|
@@ -63,8 +65,14 @@ const serveObject = (object, response) => {
|
|
|
63
65
|
response.setHeader('Content-Type', 'application/json; charset=utf-8');
|
|
64
66
|
response.end(JSON.stringify(object));
|
|
65
67
|
};
|
|
66
|
-
// Removes the query if any, or otherwise the final segment, from a URL.
|
|
68
|
+
// Removes the query, if any, or otherwise the final segment, from a URL.
|
|
67
69
|
const getURLBase = url => url.replace(/[?/][^?/.]+$/, '');
|
|
70
|
+
// Saves a report.
|
|
71
|
+
const rescueReport = async reportJSON => {
|
|
72
|
+
const reportDir = 'data/reports';
|
|
73
|
+
await fs.mkdir(reportDir, { recursive: true });
|
|
74
|
+
await fs.writeFile(reportDir, reportJSON);
|
|
75
|
+
};
|
|
68
76
|
/*
|
|
69
77
|
Requests a network job and, when found, performs and reports it.
|
|
70
78
|
Arguments:
|
|
@@ -197,6 +205,8 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
197
205
|
repResponse
|
|
198
206
|
// If the response to the report threw an error:
|
|
199
207
|
.on('error', async error => {
|
|
208
|
+
// Rescue the report.
|
|
209
|
+
await rescueReport(reportJSON);
|
|
200
210
|
// Report this.
|
|
201
211
|
console.log(`${reportLogStart}error message ${error.message}\n`);
|
|
202
212
|
resolve(true);
|
|
@@ -217,9 +227,9 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
217
227
|
}
|
|
218
228
|
// Otherwise, i.e. if it is not JSON:
|
|
219
229
|
catch(error) {
|
|
220
|
-
//
|
|
221
|
-
|
|
222
|
-
// Report
|
|
230
|
+
// Rescue the report.
|
|
231
|
+
await rescueReport(reportJSON);
|
|
232
|
+
// Report this.
|
|
223
233
|
console.log(
|
|
224
234
|
`ERROR: ${reportLogStart}status ${repResponse.statusCode}, error message ${error.message}, and response ${content.slice(0, 1000)}\n`
|
|
225
235
|
);
|
|
@@ -232,8 +242,8 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
232
242
|
})
|
|
233
243
|
// If the report submission throws an error:
|
|
234
244
|
.on('error', async error => {
|
|
235
|
-
//
|
|
236
|
-
|
|
245
|
+
// Rescue the report.
|
|
246
|
+
await rescueReport(reportJSON);
|
|
237
247
|
// Report this.
|
|
238
248
|
console.log(
|
|
239
249
|
`ERROR ${error.code} in report submission: ${reportLogStart}error message ${error.message}\n`
|
|
@@ -253,8 +263,6 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
253
263
|
}
|
|
254
264
|
// Otherwise, i.e. if it is not JSON:
|
|
255
265
|
catch(error) {
|
|
256
|
-
// Abort the watch.
|
|
257
|
-
abort = true;
|
|
258
266
|
// Report this.
|
|
259
267
|
console.log(`ERROR: Job request got non-JSON response (${error.message})`);
|
|
260
268
|
resolve(true);
|
|
@@ -277,15 +285,11 @@ exports.netWatch = async (isForever, intervalInSeconds, isCertTolerant = true) =
|
|
|
277
285
|
else if (error.message) {
|
|
278
286
|
// Report this.
|
|
279
287
|
console.log(`ERROR: ${logStart}got error message ${error.message.slice(0, 200)}`);
|
|
280
|
-
// Abort the watch.
|
|
281
|
-
abort = true;
|
|
282
288
|
}
|
|
283
289
|
// Otherwise, i.e. if it was any other error with no message:
|
|
284
290
|
else {
|
|
285
291
|
// Report this.
|
|
286
292
|
console.log(`ERROR: ${logStart}got an error with no message`);
|
|
287
|
-
// Abort the watch.
|
|
288
|
-
abort = true;
|
|
289
293
|
}
|
|
290
294
|
resolve(true);
|
|
291
295
|
})
|
package/package.json
CHANGED
package/procs/doTestAct.js
CHANGED
|
@@ -47,9 +47,10 @@ const actIndex = Number.parseInt(process.argv[2]);
|
|
|
47
47
|
// FUNCTIONS
|
|
48
48
|
|
|
49
49
|
const doTestAct = async () => {
|
|
50
|
-
const
|
|
50
|
+
const tempReportDir = `${__dirname}/../temp`;
|
|
51
|
+
const tempReportPath = `${tempReportDir}/report.json`;
|
|
51
52
|
// Get the saved report.
|
|
52
|
-
const reportJSON = await fs.readFile(
|
|
53
|
+
const reportJSON = await fs.readFile(tempReportPath, 'utf8');
|
|
53
54
|
const report = JSON.parse(reportJSON);
|
|
54
55
|
// Get the act.
|
|
55
56
|
const act = report.acts[actIndex];
|
|
@@ -67,7 +68,7 @@ const doTestAct = async () => {
|
|
|
67
68
|
if (report.jobData && report.jobData.aborted) {
|
|
68
69
|
// Save the revised report.
|
|
69
70
|
const reportJSON = JSON.stringify(report);
|
|
70
|
-
await fs.writeFile(
|
|
71
|
+
await fs.writeFile(tempReportPath, `${reportJSON}\n`);
|
|
71
72
|
// Report this.
|
|
72
73
|
process.send('ERROR: Job aborted');
|
|
73
74
|
}
|
|
@@ -97,7 +98,7 @@ const doTestAct = async () => {
|
|
|
97
98
|
}
|
|
98
99
|
const reportJSON = JSON.stringify(report);
|
|
99
100
|
// Save the revised report.
|
|
100
|
-
await fs.writeFile(
|
|
101
|
+
await fs.writeFile(tempReportPath, reportJSON);
|
|
101
102
|
// Send a completion message.
|
|
102
103
|
process.send('Act completed');
|
|
103
104
|
}
|
|
@@ -106,7 +107,7 @@ const doTestAct = async () => {
|
|
|
106
107
|
catch(error) {
|
|
107
108
|
// Save the revised report.
|
|
108
109
|
const reportJSON = JSON.stringify(report);
|
|
109
|
-
await fs.writeFile(
|
|
110
|
+
await fs.writeFile(tempReportPath, reportJSON);
|
|
110
111
|
// Report the failure.
|
|
111
112
|
const message = error.message.slice(0, 400);
|
|
112
113
|
console.log(`ERROR: Test act ${act.which} failed (${message})`);
|
package/run.js
CHANGED
|
@@ -541,8 +541,10 @@ const doActs = async (report) => {
|
|
|
541
541
|
const {acts} = report;
|
|
542
542
|
// Get the standardization specification.
|
|
543
543
|
const standard = report.standard || 'only';
|
|
544
|
-
const
|
|
545
|
-
|
|
544
|
+
const tempReportDir = 'temp';
|
|
545
|
+
const tempReportPath = `${tempReportDir}/report.json`;
|
|
546
|
+
await fs.mkdir(tempReportDir, {recursive: true});
|
|
547
|
+
// For each act in the report:
|
|
546
548
|
for (const doActsIndex in acts) {
|
|
547
549
|
actIndex = doActsIndex;
|
|
548
550
|
// If the job has not been aborted:
|
|
@@ -626,7 +628,7 @@ const doActs = async (report) => {
|
|
|
626
628
|
act.startTime = startTime;
|
|
627
629
|
// Save the report.
|
|
628
630
|
let reportJSON = JSON.stringify(report);
|
|
629
|
-
await fs.writeFile(
|
|
631
|
+
await fs.writeFile(tempReportPath, reportJSON);
|
|
630
632
|
// Create a process and wait for it to perform the act and add the result to the saved report.
|
|
631
633
|
const actResult = await new Promise(resolve => {
|
|
632
634
|
let closed = false;
|
|
@@ -647,7 +649,7 @@ const doActs = async (report) => {
|
|
|
647
649
|
});
|
|
648
650
|
});
|
|
649
651
|
// Get the revised report.
|
|
650
|
-
reportJSON = await fs.readFile(
|
|
652
|
+
reportJSON = await fs.readFile(tempReportPath, 'utf8');
|
|
651
653
|
report = JSON.parse(reportJSON);
|
|
652
654
|
// Get the revised act.
|
|
653
655
|
act = report.acts[actIndex];
|
|
@@ -1345,7 +1347,7 @@ const doActs = async (report) => {
|
|
|
1345
1347
|
}
|
|
1346
1348
|
console.log('Acts completed');
|
|
1347
1349
|
await browserClose();
|
|
1348
|
-
await fs.rm(
|
|
1350
|
+
await fs.rm(tempReportPath, {force: true});
|
|
1349
1351
|
return report;
|
|
1350
1352
|
};
|
|
1351
1353
|
/*
|