testaro 8.0.7 → 8.1.0
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 +159 -65
- package/call.js +3 -3
- package/high.js +14 -12
- package/package.json +2 -2
- package/run.js +2 -2
- package/watch.js +14 -14
package/README.md
CHANGED
|
@@ -105,69 +105,163 @@ However, if the Playwright dependency is ever updated to a newer version, you mu
|
|
|
105
105
|
|
|
106
106
|
All of the tests that Testaro can perform are free of cost, except those in the Tenon and WAVE packages. The owner of each of those packages gives new registrants a free allowance of credits before it becomes necessary to pay for use of the API of the package. The required environment variables for authentication and payment are described below under “Environment variables”.
|
|
107
107
|
|
|
108
|
-
##
|
|
108
|
+
## Process objects
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
### Introduction
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
A _script_ is an object containing instructions for Testaro. The instructions may be incomplete.
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
A _job_ is an object containing complete instructions for Testaro.
|
|
115
115
|
|
|
116
|
-
A
|
|
116
|
+
A _report_ is an object containing a job and the results from Testaro running the job.
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
### Scripts
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
A script object is saved as a JSON file in the `process.env.SCRIPTDIR` directory, with a file name identical to its `id` value, plus a `.json` extension. Thus, the following script would be saved in a file named `tp25.json`.
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
121
123
|
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
id: 'tp25',
|
|
125
|
+
what: 'Test host with alfa',
|
|
126
|
+
strict: true,
|
|
127
|
+
timeLimit: 65,
|
|
128
|
+
commands: [
|
|
129
|
+
{
|
|
130
|
+
type: 'launch',
|
|
131
|
+
which: 'chromium',
|
|
132
|
+
what: 'Chromium browser'
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
type: 'url',
|
|
136
|
+
which: 'https://*',
|
|
137
|
+
what: 'any organization',
|
|
138
|
+
id: 'anyID'
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
type: 'test',
|
|
142
|
+
which: 'alfa',
|
|
143
|
+
what: 'Siteimprove alfa package'
|
|
144
|
+
}
|
|
145
|
+
]
|
|
127
146
|
}
|
|
128
147
|
```
|
|
129
148
|
|
|
130
|
-
|
|
149
|
+
This script tells Testaro to open a page in the Chromium browser, navigate to some URL, and, if the browser is not redirected, perform the tests in the `alfa` package on that URL, within 65 seconds.
|
|
131
150
|
|
|
132
|
-
|
|
151
|
+
Properties:
|
|
152
|
+
- `id`: This is a string consisting of alphanumeric ASCII characters and hyphen-minus (-). In a script, its value simply identifies the script. In a job, it becomes a unique job identifier.
|
|
153
|
+
- `what`: This is a description of the script.
|
|
154
|
+
- `strict`: This is `true` or `false`, indicating whether _substantive redirections_ should be treated as failures. These are redirections that do more than add or subtract a final slash. For example, a redirection from `xyz.com` to `www.xyz.com` or `xyz.com/en` will abort a job if `strict` is true.
|
|
155
|
+
- `timeLimit`: This is the number of seconds allowed for the execution of the job.
|
|
156
|
+
- `commands`: This is an array of the commands to be performed. Commands are documented below.
|
|
133
157
|
|
|
134
|
-
|
|
158
|
+
The `timeLimit` property is optional. If it is omitted, a default of 300 seconds (5 minutes) is set.
|
|
135
159
|
|
|
136
|
-
|
|
160
|
+
The `url` command in this example is incomplete. It contains a placeholder for a URL.
|
|
137
161
|
|
|
138
|
-
|
|
162
|
+
### Jobs
|
|
139
163
|
|
|
140
|
-
|
|
164
|
+
A job object is saved as a JSON file in the `process.env.JOBDIR` directory, with a file name identical to its `id` value, plus a `.json` extension. Thus, the following job would be saved in a file named `be76p-tp25-w3c.json`.
|
|
165
|
+
|
|
166
|
+
```javascript
|
|
141
167
|
{
|
|
142
|
-
|
|
143
|
-
what:
|
|
168
|
+
id: 'be76p-tp25-w3c',
|
|
169
|
+
what: 'Test host with alfa',
|
|
144
170
|
strict: true,
|
|
145
171
|
timeLimit: 65,
|
|
146
172
|
commands: [
|
|
147
173
|
{
|
|
148
|
-
type:
|
|
149
|
-
which:
|
|
150
|
-
what:
|
|
174
|
+
type: 'launch',
|
|
175
|
+
which: 'chromium',
|
|
176
|
+
what: 'Chromium browser'
|
|
151
177
|
},
|
|
152
178
|
{
|
|
153
|
-
type:
|
|
154
|
-
which:
|
|
155
|
-
what:
|
|
179
|
+
type: 'url',
|
|
180
|
+
which: 'https://www.w3c.org',
|
|
181
|
+
what: 'World Wide Web Consortium',
|
|
182
|
+
id: 'w3c'
|
|
156
183
|
},
|
|
157
184
|
{
|
|
158
|
-
type:
|
|
159
|
-
which:
|
|
160
|
-
what:
|
|
185
|
+
type: 'test',
|
|
186
|
+
which: 'alfa',
|
|
187
|
+
what: 'Siteimprove alfa package'
|
|
161
188
|
}
|
|
162
|
-
]
|
|
189
|
+
],
|
|
190
|
+
sources: {
|
|
191
|
+
script: 'tp25',
|
|
192
|
+
host: {
|
|
193
|
+
which: 'https://www.w3c.org',
|
|
194
|
+
what: 'World Wide Web Consortium',
|
|
195
|
+
id: 'w3c'
|
|
196
|
+
},
|
|
197
|
+
requester: 'user@domain.org'
|
|
198
|
+
},
|
|
199
|
+
jobCreationTime: '2023-05-26T14:28',
|
|
200
|
+
timeStamp: 'be76p'
|
|
163
201
|
}
|
|
164
202
|
```
|
|
165
203
|
|
|
166
|
-
This
|
|
204
|
+
This job completes the script, making it ready to be run by Testaro.
|
|
205
|
+
|
|
206
|
+
Properties:
|
|
207
|
+
- `id`: The original script ID has been replaced by a unique job identifier. That distinguishes multiple jobs that could be created from the same script.
|
|
208
|
+
- `commands`: This array is the same as in the script, except that in this case the second command has been changed from a plateholder to a description of a real host.
|
|
209
|
+
- `sources`: This object has properties describing where the job came from:
|
|
210
|
+
- `script`: This is the ID of the original script.
|
|
211
|
+
- `host`: This object describes the host that has replaced the placeholder data in `url` commands, or it is an empty object if the original `url` commands were complete.
|
|
212
|
+
- `requester`: This string is the email address to receive a notice of completion of the running of the job.
|
|
213
|
+
- `jobCreationTime`: This is the time when the job was created from a script.
|
|
214
|
+
- `timeStamp`: This string is a compact representation of the job creation time, for inclusion in the new ID of the job.
|
|
215
|
+
|
|
216
|
+
### Reports
|
|
167
217
|
|
|
168
|
-
|
|
218
|
+
A report object is saved as a JSON file in the `process.env.REPORTDIR_RAW` directory, with a file name identical to its `job.id` value, plus a `.json` extension. Thus, the following report would be saved in a file named `be76p-tp25-w3c.json`. Thus, a report file has the same name as the job file from which it was created, but is located in a different directory. The environment variable `REPORTDIR_RAW` is named to reflect the fact that Testaro produces _raw_ reports, containing the results of tests performed but not additional analysis that other tools (such as Testilo) can do.
|
|
169
219
|
|
|
170
|
-
|
|
220
|
+
```javascript
|
|
221
|
+
{
|
|
222
|
+
job: {
|
|
223
|
+
id: 'be76p-tp25-w3c',
|
|
224
|
+
what: 'Test host with alfa',
|
|
225
|
+
strict: true,
|
|
226
|
+
timeLimit: 65,
|
|
227
|
+
commands: [
|
|
228
|
+
{
|
|
229
|
+
type: 'launch',
|
|
230
|
+
which: 'chromium',
|
|
231
|
+
what: 'Chromium browser'
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
type: 'url',
|
|
235
|
+
which: 'https://www.w3c.org',
|
|
236
|
+
what: 'World Wide Web Consortium',
|
|
237
|
+
id: 'w3c'
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
type: 'test',
|
|
241
|
+
which: 'alfa',
|
|
242
|
+
what: 'Siteimprove alfa package'
|
|
243
|
+
}
|
|
244
|
+
],
|
|
245
|
+
sources: {
|
|
246
|
+
script: 'tp25',
|
|
247
|
+
host: {
|
|
248
|
+
which: 'https://www.w3c.org',
|
|
249
|
+
what: 'World Wide Web Consortium',
|
|
250
|
+
id: 'w3c'
|
|
251
|
+
},
|
|
252
|
+
requester: 'user@domain.org'
|
|
253
|
+
},
|
|
254
|
+
jobCreationTime: '2023-05-26T14:28',
|
|
255
|
+
timeStamp: 'be76p'
|
|
256
|
+
},
|
|
257
|
+
acts: [],
|
|
258
|
+
jobData: {}
|
|
259
|
+
}
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
This report is an object whose `job` property has a job as its value. It also has two additional properties:
|
|
263
|
+
- `acts`: This is initially an empty array. Testaro copies the `job.commands` property into `acts` and then modifies the array. Testaro can add more acts to the original ones. Testaro also adds results to the acts.
|
|
264
|
+
- `jobData`: Some results pertain to a job as a whole, not to any specific act. This property is an object where Testaro records such job-level results.
|
|
171
265
|
|
|
172
266
|
### Commands
|
|
173
267
|
|
|
@@ -530,18 +624,20 @@ Low-level execution is designed for a module to create a job and make Testaro ru
|
|
|
530
624
|
|
|
531
625
|
```javascript
|
|
532
626
|
const report = {
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
627
|
+
job: {…},
|
|
628
|
+
acts: [],
|
|
629
|
+
jobData: {}
|
|
536
630
|
};
|
|
537
631
|
const {doJob} = require('./run');
|
|
538
632
|
doJob(report)
|
|
539
633
|
.then(() => …);
|
|
540
634
|
```
|
|
541
635
|
|
|
542
|
-
Replace `{…}` with a
|
|
636
|
+
Replace `{…}` with a job object, like the example job shown above.
|
|
543
637
|
|
|
544
|
-
Testaro will run the script and modify the properties of the `report` object. When Testaro finishes, the `
|
|
638
|
+
Testaro will run the script and modify the `acts` and `jobData` properties of the `report` object. When Testaro finishes, the `acts` and `jobData` properties of `report` will contain the results. The final statement can further process the `report` object as desired in the `then` callback.
|
|
639
|
+
|
|
640
|
+
The Testilo package contains functions that can create jobs from scripts.
|
|
545
641
|
|
|
546
642
|
#### High-level
|
|
547
643
|
|
|
@@ -551,24 +647,24 @@ Execution by a module:
|
|
|
551
647
|
|
|
552
648
|
```javaScript
|
|
553
649
|
const {runJob} = require('./high');
|
|
554
|
-
runJob('
|
|
650
|
+
runJob('be76p-tp25-w3c');
|
|
555
651
|
```
|
|
556
652
|
|
|
557
653
|
Execution by a user:
|
|
558
654
|
|
|
559
655
|
```bash
|
|
560
|
-
node call high
|
|
656
|
+
node call high be76p-tp25-w3c
|
|
561
657
|
```
|
|
562
658
|
|
|
563
|
-
In either case, replace `
|
|
659
|
+
In either case, replace `be76p-tp25-w3c` with the ID of a job in the `process.env.JOBDIR` directory.
|
|
564
660
|
|
|
565
|
-
Testaro will find the named
|
|
661
|
+
Testaro will find the named job (e.g., `be76p-tp25-w3c.json`) in the `process.env.JOBDIR` directory and write the report in the `process.env.REPORTDIR_RAW` directory.
|
|
566
662
|
|
|
567
663
|
#### Watch
|
|
568
664
|
|
|
569
665
|
Watch execution is designed for either modules or users.
|
|
570
666
|
|
|
571
|
-
In watch mode, Testaro periodically checks for a
|
|
667
|
+
In watch mode, Testaro periodically checks for a job to run. When such a job exists, Testaro runs it and populates its `acts` and `jobData` properties to make it a report. Testaro may continue watching after the first report, or may quit.
|
|
572
668
|
|
|
573
669
|
Execution by a module:
|
|
574
670
|
|
|
@@ -584,17 +680,17 @@ node call watch true true 30
|
|
|
584
680
|
```
|
|
585
681
|
|
|
586
682
|
The arguments passed to `cycle` by either of these invocations are:
|
|
587
|
-
- whether to watch a directory (true) or the network (false)
|
|
588
|
-
- whether to continue watching indefinitely after the first report (true or false)
|
|
589
|
-
- how many seconds to wait before checking again (a nonnegative number)
|
|
683
|
+
- whether to watch a directory (`true`) or the network (`false`)
|
|
684
|
+
- whether to continue watching indefinitely after the first report (`true` or `false`)
|
|
685
|
+
- how many seconds to wait after finding no job before checking again (a nonnegative number)
|
|
590
686
|
|
|
591
687
|
##### Directory watch
|
|
592
688
|
|
|
593
|
-
With directory watch, Testaro checks whether the
|
|
689
|
+
With directory watch, Testaro checks whether the job directory (`process.env.JOBDIR`) in its host’s filesystem contains a job.
|
|
594
690
|
|
|
595
|
-
When Testaro finds one or more
|
|
691
|
+
When Testaro finds one or more jobs in the watch directory, Testaro runs the first job, writes the report into the `process.env.REPORTDIR_RAW` directory, and moves the job from the `process.env.JOBDIR` into the `process.env.DONEDIR` directory.
|
|
596
692
|
|
|
597
|
-
Since Testaro runs the first
|
|
693
|
+
Since Testaro runs the first job (i.e. the job whose name is first in ASCII order), whoever populates the `process.env.JOBDIR` directory with job files has control over the order in which Testaro runs them. For example, to force a new job to be run before the already waiting jobs, one can give it a filename that comes before that of the first waiting job.
|
|
598
694
|
|
|
599
695
|
##### Network watch
|
|
600
696
|
|
|
@@ -603,17 +699,15 @@ Network watching is designed for a situation in which:
|
|
|
603
699
|
- A workstation running Testaro can contact a managing server, but the server may not be able to contact a workstation.
|
|
604
700
|
- The functions of Testaro are limited to those requiring workstation features.
|
|
605
701
|
|
|
606
|
-
With network watch, the initiator of an interaction is Testaro, not the server. When Testaro is available, it requests a
|
|
702
|
+
With network watch, the initiator of an interaction is Testaro, not the server. When Testaro is available, it requests a job from a server. If the response is a JSON representation of a job, Testaro runs the job and sends the report to the server.
|
|
607
703
|
|
|
608
|
-
If multiple workstations run Testaro and do work for the same server, each
|
|
704
|
+
If multiple workstations run Testaro and do work for the same server, the server can assign jobs to specific agents by requiring each instance of Testaro to have a distinct value of `process.env.AGENT`.
|
|
609
705
|
|
|
610
706
|
### Environment variables
|
|
611
707
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
The `text` command can interpolate the value of an environment variable into text that it enters on a page, as documented in the `commands.js` file.
|
|
708
|
+
In addition to their uses described above, environment variables can be used by commands of type `text`, as documented in the `commands.js` file.
|
|
615
709
|
|
|
616
|
-
Before executing a Testaro script, you can optionally also set
|
|
710
|
+
Before executing a Testaro script, you can optionally also set `process.env.DEBUG` (to `'true'` or anything else) and/or `process.env.WAITS` (to a non-negative integer). The effects of these variables are described in the `run.js` file.
|
|
617
711
|
|
|
618
712
|
You may store environment variables in an untracked `.env` file if you wish, and Testaro will recognize them.
|
|
619
713
|
|
|
@@ -626,7 +720,7 @@ Testaro and its custom tests can be validated with the _executors_ located in th
|
|
|
626
720
|
The executors are:
|
|
627
721
|
|
|
628
722
|
- `low`: validates low-level invocation
|
|
629
|
-
- `high`: validates high-level invocation
|
|
723
|
+
- `high`: validates high-level invocation
|
|
630
724
|
- `watchDir`: validates directory watching
|
|
631
725
|
- `watchNet`: validates network watching
|
|
632
726
|
- `test`: validates a Testaro test
|
|
@@ -634,7 +728,7 @@ The executors are:
|
|
|
634
728
|
|
|
635
729
|
To validate any single Testaro test `xyz`, enter the statement `npm test xyz`.
|
|
636
730
|
|
|
637
|
-
To execute any other executor `xyz`, call it with the statement `
|
|
731
|
+
To execute any other executor `xyz`, call it with the statement `npm run xyz`.
|
|
638
732
|
|
|
639
733
|
The `tests` executor makes use of the scripts in the `validation/tests/scripts` directory, and they, in turn, run tests on HTML files in the `validation/tests/targets` directory.
|
|
640
734
|
|
|
@@ -683,20 +777,20 @@ The files in the `temp` directory are presumed ephemeral and are not tracked by
|
|
|
683
777
|
## Related packages
|
|
684
778
|
|
|
685
779
|
[Testilo](https://www.npmjs.com/package/testilo) is an application that:
|
|
686
|
-
-
|
|
687
|
-
- merges batches of hosts into scripts to produce multiple
|
|
688
|
-
- produces scores and adds them to the
|
|
780
|
+
- creates a job by aiming a script at a host
|
|
781
|
+
- merges batches of hosts into scripts to produce multiple jobs
|
|
782
|
+
- produces scores and adds them to the raw reports of Testaro
|
|
689
783
|
- produces human-oriented HTML digests from scored reports
|
|
690
|
-
- produces human-oriented HTML
|
|
784
|
+
- produces human-oriented HTML comparisons of the scores of hosts
|
|
691
785
|
|
|
692
786
|
Testilo contains procedures that reorganize report data by defect rather than test package, and that compensate for duplicative tests when computing scores.
|
|
693
787
|
|
|
694
|
-
Testaro is derived from [Autotest](https://github.com/jrpool/autotest).
|
|
788
|
+
Testaro is derived from [Autotest](https://github.com/jrpool/autotest). Autotest was created as a monolithic accessibility testing package, but that forced functionalities to be hosted on a workstation merely because it was impractical to host Playwright elsewhere. Testaro embodies an architectural decision to isolate workstation-dependent functionalities.
|
|
695
789
|
|
|
696
|
-
Testaro omits some functionalities of Autotest, such as:
|
|
790
|
+
Testaro therefore omits some functionalities of Autotest, such as:
|
|
697
791
|
- tests producing results intended to be human-inspected
|
|
698
|
-
- scoring (
|
|
699
|
-
- file operations for score aggregation, report revision, and HTML reports
|
|
792
|
+
- scoring (now in Testilo)
|
|
793
|
+
- file operations for score aggregation, report revision, and HTML reports (now in Testilo)
|
|
700
794
|
- a web user interface
|
|
701
795
|
|
|
702
796
|
## Code style
|
package/call.js
CHANGED
|
@@ -29,9 +29,9 @@ const reportDir = process.env.REPORTDIR;
|
|
|
29
29
|
// ########## FUNCTIONS
|
|
30
30
|
|
|
31
31
|
// Fulfills a high-level testing request.
|
|
32
|
-
const callHigh = async
|
|
33
|
-
await runJob(
|
|
34
|
-
console.log(`Job completed and report ${
|
|
32
|
+
const callHigh = async jobID => {
|
|
33
|
+
await runJob(jobID);
|
|
34
|
+
console.log(`Job completed and report ${jobID}.json saved in ${reportDir}`);
|
|
35
35
|
};
|
|
36
36
|
// Starts a watch.
|
|
37
37
|
const callWatch = async (isDirWatch, isForever, interval) => {
|
package/high.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
high.js
|
|
3
3
|
Invokes Testaro with the high-level method.
|
|
4
|
-
Usage example: node high
|
|
4
|
+
Usage example: node high tp25
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
// ########## IMPORTS
|
|
@@ -15,7 +15,7 @@ const {doJob} = require('./run');
|
|
|
15
15
|
|
|
16
16
|
// ########## CONSTANTS
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
const jobDir = process.env.JOBDIR;
|
|
19
19
|
const reportDir = process.env.REPORTDIR;
|
|
20
20
|
|
|
21
21
|
// ########## VARIABLES
|
|
@@ -26,23 +26,25 @@ let timeLimit = 300;
|
|
|
26
26
|
// ########## FUNCTIONS
|
|
27
27
|
|
|
28
28
|
// Performs a file-based job and writes a report file.
|
|
29
|
-
exports.runJob = async
|
|
29
|
+
exports.runJob = async jobID => {
|
|
30
30
|
try {
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
// Get the job.
|
|
32
|
+
const jobJSON = await fs.readFile(`${jobDir}/${jobID}.json`, 'utf8');
|
|
33
|
+
const job = JSON.parse(jobJSON);
|
|
34
|
+
// If the job has no time limit, give it the default one.
|
|
35
|
+
if (! job.timeLimit) {
|
|
36
|
+
job.timeLimit = timeLimit;
|
|
36
37
|
}
|
|
37
|
-
//
|
|
38
|
+
// Initialize a report for the job.
|
|
38
39
|
const report = {
|
|
39
|
-
|
|
40
|
+
job,
|
|
40
41
|
acts: []
|
|
41
42
|
};
|
|
43
|
+
// Run the job, adding the results to the report.
|
|
42
44
|
await doJob(report);
|
|
43
45
|
const reportJSON = JSON.stringify(report, null, 2);
|
|
44
|
-
await fs.writeFile(`${reportDir}/${
|
|
45
|
-
console.log(`Report ${
|
|
46
|
+
await fs.writeFile(`${reportDir}/${jobID}.json`, reportJSON);
|
|
47
|
+
console.log(`Report ${jobID}.json recorded in ${process.env.REPORTDIR}`);
|
|
46
48
|
}
|
|
47
49
|
catch(error) {
|
|
48
50
|
console.log(`ERROR running job (${error.message})\n${error.stack}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "testaro",
|
|
3
|
-
"version": "8.0
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Automation of accessibility testing",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"low": "node validation/executors/low",
|
|
10
10
|
"high": "node validation/executors/high",
|
|
11
11
|
"watchDir": "node validation/executors/watchDir",
|
|
12
|
-
"watchNet": "node validation/executors/
|
|
12
|
+
"watchNet": "node validation/executors/watchNet"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
package/run.js
CHANGED
|
@@ -1499,9 +1499,9 @@ const injectLaunches = acts => {
|
|
|
1499
1499
|
}
|
|
1500
1500
|
}
|
|
1501
1501
|
};
|
|
1502
|
-
//
|
|
1502
|
+
// Runs a job and adds the results to the report of the job.
|
|
1503
1503
|
exports.doJob = async report => {
|
|
1504
|
-
// If the report
|
|
1504
|
+
// If the report is valid:
|
|
1505
1505
|
if(isValidReport(report)) {
|
|
1506
1506
|
// Add the script commands to the report as its initial acts.
|
|
1507
1507
|
report.acts = JSON.parse(JSON.stringify(report.script.commands));
|
package/watch.js
CHANGED
|
@@ -18,7 +18,7 @@ const protocol = process.env.PROTOCOL || 'https';
|
|
|
18
18
|
const client = require(protocol);
|
|
19
19
|
const jobURL = process.env.JOB_URL;
|
|
20
20
|
const agent = process.env.AGENT;
|
|
21
|
-
const
|
|
21
|
+
const jobDir = process.env.JOBDIR;
|
|
22
22
|
const doneDir = process.env.DONEDIR;
|
|
23
23
|
const reportURL = process.env.REPORT_URL;
|
|
24
24
|
const reportDir = process.env.REPORTDIR;
|
|
@@ -28,11 +28,11 @@ const reportDir = process.env.REPORTDIR;
|
|
|
28
28
|
// Checks for a directory job.
|
|
29
29
|
const checkDirJob = async () => {
|
|
30
30
|
try {
|
|
31
|
-
const jobDirFileNames = await fs.readdir(
|
|
31
|
+
const jobDirFileNames = await fs.readdir(jobDir);
|
|
32
32
|
const jobFileNames = jobDirFileNames.filter(fileName => fileName.endsWith('.json'));
|
|
33
33
|
if (jobFileNames.length) {
|
|
34
34
|
console.log('Directory job found');
|
|
35
|
-
const scriptJSON = await fs.readFile(`${
|
|
35
|
+
const scriptJSON = await fs.readFile(`${jobDir}/${jobFileNames[0]}`, 'utf8');
|
|
36
36
|
try {
|
|
37
37
|
const script = JSON.parse(scriptJSON, null, 2);
|
|
38
38
|
return script;
|
|
@@ -133,7 +133,7 @@ const writeNetReport = async report => {
|
|
|
133
133
|
const archiveJob = async script => {
|
|
134
134
|
const scriptJSON = JSON.stringify(script, null, 2);
|
|
135
135
|
await fs.writeFile(`${doneDir}/${script.id}.json`, scriptJSON);
|
|
136
|
-
await fs.rm(`${
|
|
136
|
+
await fs.rm(`${jobDir}/${script.id}.json`);
|
|
137
137
|
};
|
|
138
138
|
// Waits.
|
|
139
139
|
const wait = ms => {
|
|
@@ -200,25 +200,25 @@ exports.cycle = async (isDirWatch, isForever, interval) => {
|
|
|
200
200
|
await wait(intervalMS);
|
|
201
201
|
}
|
|
202
202
|
// Check for a job.
|
|
203
|
-
let
|
|
203
|
+
let job;
|
|
204
204
|
if (isDirWatch) {
|
|
205
|
-
|
|
205
|
+
job = await checkDirJob();
|
|
206
206
|
}
|
|
207
207
|
else {
|
|
208
|
-
|
|
208
|
+
job = await checkNetJob();
|
|
209
209
|
}
|
|
210
210
|
// If there was one:
|
|
211
|
-
if (
|
|
211
|
+
if (job.id) {
|
|
212
212
|
// Run it and save a report.
|
|
213
|
-
console.log(`Running
|
|
214
|
-
statusOK = await exports.runJob(
|
|
215
|
-
console.log(`Job ${
|
|
213
|
+
console.log(`Running job ${job.id}`);
|
|
214
|
+
statusOK = await exports.runJob(job, isDirWatch);
|
|
215
|
+
console.log(`Job ${job.id} finished`);
|
|
216
216
|
if (statusOK) {
|
|
217
217
|
// If a directory was watched:
|
|
218
218
|
if (isDirWatch) {
|
|
219
|
-
// Archive the
|
|
220
|
-
await archiveJob(
|
|
221
|
-
console.log(`Script ${
|
|
219
|
+
// Archive the job.
|
|
220
|
+
await archiveJob(job);
|
|
221
|
+
console.log(`Script ${job.id} archived`);
|
|
222
222
|
}
|
|
223
223
|
// If watching was specified for only 1 job, stop.
|
|
224
224
|
statusOK = isForever;
|