testilo 4.0.0 → 4.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 +6 -18
- package/merge.js +24 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,10 +3,12 @@ Utilities for Testaro
|
|
|
3
3
|
|
|
4
4
|
## Introduction
|
|
5
5
|
|
|
6
|
-
The Testilo package contains utilities that facilitate the use of the [Testaro
|
|
6
|
+
The Testilo package contains utilities that facilitate the use of the [Testaro](https://www.npmjs.com/package/testaro) package.
|
|
7
7
|
|
|
8
8
|
Testaro performs digital accessibility tests on web artifacts and creates reports in JSON format. The utilities in Testilo prepare jobs for Testaro to run and create additional value from the reports that Testaro produces.
|
|
9
9
|
|
|
10
|
+
Because Testilo supports Testaro, this `README` file presumes that you have access to the Testaro `README` file and therefore does not repeat information provided there.
|
|
11
|
+
|
|
10
12
|
## Dependencies
|
|
11
13
|
|
|
12
14
|
The `dotenv` dependency lets you set environment variables in an untracked `.env` file. This prevents secret data, such as passwords, from being shared as part of this package.
|
|
@@ -25,23 +27,9 @@ The reason for Testilo being an independent package, rather than part of Testaro
|
|
|
25
27
|
|
|
26
28
|
### `merge`
|
|
27
29
|
|
|
28
|
-
Testaro
|
|
29
|
-
|
|
30
|
-
Sometimes you may want Testaro to perform a set of tests on multiple targets. The `merge` utility in Testilo facilitates this. It creates Testaro jobs out of a _script_ and a _batch_.
|
|
31
|
-
|
|
32
|
-
A script tells Testaro where to go and what to do. If the where-to-go part identifies a specific URL, the script can be a job, ready for Testaro to run. But the where-to-go part can also be generic, such as `http://*.*`. Then the script needs to be converted to a job by having its generic destination replaced with a specific URL. A batch is a list of _hosts_ (URLs and metadata). Merging a batch and a script means generating from the script as many jobs as there are hosts in the batch. In each job, one host from the batch becomes the specific target.
|
|
33
|
-
|
|
34
|
-
A script is a JSON file representing a `script` object, which contains a sequence of _commands_. Scripts are documented in detail in the Testaro `README.md` file.
|
|
35
|
-
|
|
36
|
-
A batch is a JSON file representing a `batch` object, which contains an array of _hosts_. Each host is an object with three properties:
|
|
37
|
-
- `id`: a string unique in the batch
|
|
38
|
-
- `which`: a URL
|
|
39
|
-
- `what`: a string naming the entity associated with the URL
|
|
30
|
+
The `merge` utility is useful when you want Testaro to perform the same set of operations on multiple hosts. For example, you may want the same tests run on multiple web pages. You would have a single script, and you would want multiple jobs created from it. Each job would target one host, and, for that purpose, any `url` command in the script would be modified so that its properties are those of that host. The `merge` utility (similar to mail merge in office applications) does this. It creates Testaro jobs out of a script and a _batch_.
|
|
40
31
|
|
|
41
|
-
|
|
42
|
-
- `id`: a string composed of ASCII letters and digits
|
|
43
|
-
- `what`: a string describing the batch
|
|
44
|
-
- `hosts`: an array of host objects
|
|
32
|
+
A batch is a JSON-format file representing a `batch` object, which contains an array of _hosts_.
|
|
45
33
|
|
|
46
34
|
Here is an example of a batch:
|
|
47
35
|
|
|
@@ -83,7 +71,7 @@ Suppose that:
|
|
|
83
71
|
- There is a script file named `testall.json`.
|
|
84
72
|
- The above batch example is in a file named `usFedExec1.json`.
|
|
85
73
|
|
|
86
|
-
The statement `node merge testall usFedExec1 allFedExec` would tell Testilo to merge the batch `../testing/batches/usFedExec1.json` and the script `../testing/scripts/testall.json`
|
|
74
|
+
The statement `node merge testall usFedExec1 allFedExec` would tell Testilo to merge the batch `../testing/batches/usFedExec1.json` and the script `../testing/scripts/testall.json` into two job files and save those files in the directory `../testing/jobs/allFedExec`. Testilo will create any directories necessary to save the files there.
|
|
87
75
|
|
|
88
76
|
### `score`
|
|
89
77
|
|
package/merge.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
/*
|
|
2
2
|
merge.js
|
|
3
|
-
Merges a batch and a script to produce
|
|
3
|
+
Merges a batch and a script to produce host-specific scripts.
|
|
4
4
|
Arguments:
|
|
5
5
|
0. base of name of script located in process.env.SCRIPTDIR.
|
|
6
6
|
1. base of name of batch located in process.env.BATCHDIR.
|
|
7
|
-
2. name of subdirectory of process.env.JOBDIR into which to write host scripts.
|
|
8
7
|
Usage example:
|
|
9
|
-
node merge tp18 weborgs
|
|
8
|
+
node merge tp18 weborgs
|
|
10
9
|
Note: The subdirectory for host scripts will be created if it does not exist.
|
|
11
10
|
*/
|
|
12
11
|
|
|
@@ -21,40 +20,44 @@ const fs = require('fs/promises');
|
|
|
21
20
|
|
|
22
21
|
const scriptDir = process.env.SCRIPTDIR || 'scripts';
|
|
23
22
|
const batchDir = process.env.BATCHDIR || 'batches';
|
|
24
|
-
const
|
|
23
|
+
const watchDir = process.env.WATCHDIR || 'watch';
|
|
25
24
|
const scriptName = process.argv[2];
|
|
26
25
|
const batchName = process.argv[3];
|
|
27
|
-
const jobSubdir = process.argv[4];
|
|
28
26
|
|
|
29
27
|
// ########## FUNCTIONS
|
|
30
28
|
|
|
31
|
-
// Merges a batch into a script and writes host scripts.
|
|
32
|
-
const merge = async (script, batch
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
// Merges a batch into a script and writes host-specific scripts.
|
|
30
|
+
const merge = async (script, batch) => {
|
|
31
|
+
// Create the watch directory if it does not exist.
|
|
32
|
+
await fs.mkdir(watchDir, {recursive: true});
|
|
35
33
|
// For each host in the batch:
|
|
36
|
-
const
|
|
34
|
+
const {hosts} = batch;
|
|
35
|
+
const newScripts = hosts.map(host => {
|
|
37
36
|
// Copy the script.
|
|
38
37
|
const newScript = JSON.parse(JSON.stringify(script));
|
|
39
38
|
// In the copy, make all url commands visit the host.
|
|
40
39
|
newScript.commands.forEach(command => {
|
|
41
40
|
if (command.type === 'url') {
|
|
41
|
+
command.id = host.id;
|
|
42
42
|
command.which = host.which;
|
|
43
43
|
command.what = host.what;
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
// Add source information to the script.
|
|
47
|
+
newScript.sources = {
|
|
48
|
+
script: script.id,
|
|
49
|
+
batch: batch.id
|
|
50
|
+
}
|
|
51
|
+
// Change the script id property to include the host ID.
|
|
52
|
+
newScript.id += `-${host.id}`;
|
|
53
|
+
// Return the host-specific script.
|
|
54
|
+
return newScript;
|
|
52
55
|
});
|
|
53
|
-
// Write the host scripts.
|
|
54
|
-
for (const
|
|
55
|
-
await fs.writeFile(`${
|
|
56
|
+
// Write the host-specific scripts.
|
|
57
|
+
for (const newScript of newScripts) {
|
|
58
|
+
await fs.writeFile(`${watchDir}/${newScript.id}.json`, JSON.stringify(newScript, null, 2));
|
|
56
59
|
};
|
|
57
|
-
console.log(`Merger completed. Count of
|
|
60
|
+
console.log(`Merger completed. Count of scripts created: ${hosts.length}`);
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
// ########## OPERATION
|
|
@@ -65,8 +68,6 @@ fs.readFile(`${scriptDir}/${scriptName}.json`, 'utf8')
|
|
|
65
68
|
.then(async batchFile => {
|
|
66
69
|
const script = JSON.parse(scriptFile);
|
|
67
70
|
const batch = JSON.parse(batchFile);
|
|
68
|
-
|
|
69
|
-
const outDir = `${jobDir}/${jobSubdir}`;
|
|
70
|
-
await merge(script, batch, timeStamp, outDir);
|
|
71
|
+
await merge(script, batch);
|
|
71
72
|
});
|
|
72
73
|
});
|