testaro 2.0.2 → 2.0.5
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 +12 -17
- package/index.js +14 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -413,33 +413,28 @@ A batch offers an efficient way to perform a uniform set of operations on every
|
|
|
413
413
|
|
|
414
414
|
A no-batch script offers a way to carry out a complex operation, which can include navigating from one host to another, which is not possible with a batch. Any `url` commands are performed as-is, without changes to their URLs.
|
|
415
415
|
|
|
416
|
-
## Reports
|
|
417
|
-
|
|
418
|
-
Testaro writes reports as files in JSON format. They contain detailed results.
|
|
419
|
-
|
|
420
|
-
Testaro also writes to standard output a list of the names of the files containing the reports.
|
|
421
|
-
|
|
422
416
|
## Execution
|
|
423
417
|
|
|
424
418
|
### Invocation
|
|
425
419
|
|
|
426
|
-
To run Testaro, create an
|
|
420
|
+
To run Testaro, create an options object like this:
|
|
427
421
|
|
|
428
422
|
```javascript
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
script:
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
handleRequest(options);
|
|
423
|
+
{
|
|
424
|
+
log: [],
|
|
425
|
+
reports: [],
|
|
426
|
+
script: {abc},
|
|
427
|
+
batch: {def}
|
|
428
|
+
}
|
|
436
429
|
```
|
|
437
430
|
|
|
438
|
-
|
|
431
|
+
Replace `{abc}` with a script object, like the example script shown above.
|
|
432
|
+
|
|
433
|
+
Replace `{def}` with a batch object, like the example batch shown above, or omit the `batch` property if there is no batch.
|
|
439
434
|
|
|
440
|
-
|
|
435
|
+
Then execute the statement `require('testaro').handleRequest(ghi)`, where `ghi` is replaced with the name of the options object. That statement will run Testaro.
|
|
441
436
|
|
|
442
|
-
|
|
437
|
+
While it runs, Testaro will populate the `log` and `reports` arrays of the options object. When Testaro finishes, the `log` and `reports` arrays will contain its results.
|
|
443
438
|
|
|
444
439
|
### Environment variables
|
|
445
440
|
|
package/index.js
CHANGED
|
@@ -1068,10 +1068,13 @@ const doActs = async (report, actIndex, page) => {
|
|
|
1068
1068
|
await doActs(report, actIndex + 1, page);
|
|
1069
1069
|
}
|
|
1070
1070
|
};
|
|
1071
|
-
// Performs the commands in a script
|
|
1072
|
-
const doScript = async report => {
|
|
1071
|
+
// Performs the commands in a script.
|
|
1072
|
+
const doScript = async (options, report) => {
|
|
1073
1073
|
// Reinitialize the log statistics.
|
|
1074
1074
|
logCount = logSize = prohibitedCount = visitTimeoutCount = visitRejectionCount= 0;
|
|
1075
|
+
// Add the start time to the report.
|
|
1076
|
+
const startTime = new Date();
|
|
1077
|
+
report.startTime = startTime.toISOString().slice(0, 19);
|
|
1075
1078
|
// Add initialized properties to the report.
|
|
1076
1079
|
report.presses = 0;
|
|
1077
1080
|
report.amountRead = 0;
|
|
@@ -1105,6 +1108,12 @@ const doScript = async report => {
|
|
|
1105
1108
|
}
|
|
1106
1109
|
}
|
|
1107
1110
|
}
|
|
1111
|
+
// Add the end time and duration to the report.
|
|
1112
|
+
const endTime = new Date();
|
|
1113
|
+
report.endTime = endTime.toISOString().slice(0, 19);
|
|
1114
|
+
report.elapsedSeconds = Math.floor((endTime - startTime) / 1000);
|
|
1115
|
+
// Add the report to the reports array.
|
|
1116
|
+
options.reports.push(report);
|
|
1108
1117
|
};
|
|
1109
1118
|
// Recursively performs commands on the hosts of a batch.
|
|
1110
1119
|
const doBatch = async (options, reportTemplate, hostIndex = 0) => {
|
|
@@ -1122,7 +1131,7 @@ const doBatch = async (options, reportTemplate, hostIndex = 0) => {
|
|
|
1122
1131
|
}
|
|
1123
1132
|
});
|
|
1124
1133
|
// Perform the commands on the host.
|
|
1125
|
-
await doScript(hostReport);
|
|
1134
|
+
await doScript(options, hostReport);
|
|
1126
1135
|
// Process the remaining hosts.
|
|
1127
1136
|
await doBatch(options, reportTemplate, hostIndex + 1);
|
|
1128
1137
|
}
|
|
@@ -1139,7 +1148,7 @@ const doScriptOrBatch = async (options, reportTemplate) => {
|
|
|
1139
1148
|
else {
|
|
1140
1149
|
// Perform the script.
|
|
1141
1150
|
console.log('Starting no-batch script');
|
|
1142
|
-
await doScript(reportTemplate);
|
|
1151
|
+
await doScript(options, reportTemplate);
|
|
1143
1152
|
}
|
|
1144
1153
|
// Add an end time to the log.
|
|
1145
1154
|
options.log.push({
|
|
@@ -1189,7 +1198,7 @@ exports.handleRequest = async options => {
|
|
|
1189
1198
|
},
|
|
1190
1199
|
{
|
|
1191
1200
|
event: 'timeStamp',
|
|
1192
|
-
value: Math.floor((Date.now() - Date.UTC(2022,
|
|
1201
|
+
value: Math.floor((Date.now() - Date.UTC(2022, 1)) / 10000).toString(36)
|
|
1193
1202
|
}
|
|
1194
1203
|
);
|
|
1195
1204
|
// Add the batch size to the log if there is a batch.
|