testaro 8.4.7 → 9.0.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.
Files changed (45) hide show
  1. package/README.md +94 -155
  2. package/{commands.js → actSpecs.js} +1 -1
  3. package/call.js +35 -13
  4. package/package.json +2 -3
  5. package/run.js +155 -181
  6. package/samples/00000-ts18-example.json +3 -3
  7. package/validation/executors/run.js +40 -0
  8. package/validation/executors/watchDir.js +7 -6
  9. package/validation/executors/watchNet.js +5 -6
  10. package/validation/jobs/done/README.md +3 -0
  11. package/validation/jobs/{00000-simple-example.json → todo/00000-simple-example.json} +6 -7
  12. package/validation/jobs/{README.md → todo/README.md} +0 -0
  13. package/validation/tests/jobs/allHidden.json +3 -2
  14. package/validation/tests/jobs/bulk.json +3 -2
  15. package/validation/tests/jobs/docType.json +3 -2
  16. package/validation/tests/jobs/elements.json +3 -2
  17. package/validation/tests/jobs/embAc.json +3 -2
  18. package/validation/tests/jobs/filter.json +3 -2
  19. package/validation/tests/jobs/focAll.json +3 -2
  20. package/validation/tests/jobs/focInd.json +3 -2
  21. package/validation/tests/jobs/focOp.json +3 -2
  22. package/validation/tests/jobs/focVis.json +3 -2
  23. package/validation/tests/jobs/hover.json +3 -2
  24. package/validation/tests/jobs/labClash.json +3 -2
  25. package/validation/tests/jobs/linkTo.json +3 -2
  26. package/validation/tests/jobs/linkUl.json +3 -2
  27. package/validation/tests/jobs/menuNav.json +3 -2
  28. package/validation/tests/jobs/miniText.json +3 -2
  29. package/validation/tests/jobs/motion.json +3 -2
  30. package/validation/tests/jobs/nonTable.json +3 -2
  31. package/validation/tests/jobs/radioSet.json +3 -2
  32. package/validation/tests/jobs/role.json +3 -2
  33. package/validation/tests/jobs/styleDiff.json +3 -2
  34. package/validation/tests/jobs/tabNav.json +3 -2
  35. package/validation/tests/jobs/textNodes.json +3 -2
  36. package/validation/tests/jobs/title.json +3 -2
  37. package/validation/tests/jobs/titledEl.json +3 -2
  38. package/validation/tests/jobs/zIndex.json +3 -2
  39. package/validation/validateTest.js +3 -8
  40. package/validation/watch/{README.md → done/README.md} +0 -0
  41. package/validation/watch/todo/README.md +3 -0
  42. package/watch.js +39 -49
  43. package/high.js +0 -60
  44. package/validation/executors/high.js +0 -52
  45. package/validation/executors/low.js +0 -53
@@ -0,0 +1,3 @@
1
+ # jobs
2
+
3
+ Directory watched by executor `watchDir`.
package/watch.js CHANGED
@@ -19,7 +19,6 @@ const client = require(protocol);
19
19
  const jobURL = process.env.JOB_URL;
20
20
  const agent = process.env.AGENT;
21
21
  const jobDir = process.env.JOBDIR;
22
- const doneDir = process.env.DONEDIR;
23
22
  const reportURL = process.env.REPORT_URL;
24
23
  const reportDir = process.env.REPORTDIR;
25
24
 
@@ -28,11 +27,11 @@ const reportDir = process.env.REPORTDIR;
28
27
  // Checks for a directory job.
29
28
  const checkDirJob = async () => {
30
29
  try {
31
- const jobDirFileNames = await fs.readdir(jobDir);
32
- const jobFileNames = jobDirFileNames.filter(fileName => fileName.endsWith('.json'));
30
+ const toDoDirFileNames = await fs.readdir(`${jobDir}/todo`);
31
+ const jobFileNames = toDoDirFileNames.filter(fileName => fileName.endsWith('.json'));
33
32
  if (jobFileNames.length) {
34
33
  console.log('Directory job found');
35
- const jobJSON = await fs.readFile(`${jobDir}/${jobFileNames[0]}`, 'utf8');
34
+ const jobJSON = await fs.readFile(`${jobDir}/todo/${jobFileNames[0]}`, 'utf8');
36
35
  try {
37
36
  const job = JSON.parse(jobJSON, null, 2);
38
37
  return job;
@@ -89,26 +88,24 @@ const checkNetJob = async () => {
89
88
  };
90
89
  // Writes a directory report.
91
90
  const writeDirReport = async report => {
92
- const jobID = report && report.job && report.job.id;
91
+ const jobID = report && report.id;
93
92
  if (jobID) {
94
93
  try {
95
94
  const reportJSON = JSON.stringify(report, null, 2);
96
95
  const reportName = `${jobID}.json`;
97
- await fs.writeFile(`${reportDir}/${reportName}`, reportJSON);
98
- console.log(`Report ${reportName} saved`);
99
- return true;
96
+ const rawDir = `${reportDir}/raw`;
97
+ await fs.writeFile(`${rawDir}/${reportName}`, reportJSON);
98
+ console.log(`Report ${reportName} saved in ${rawDir}`);
100
99
  }
101
100
  catch(error) {
102
101
  console.log(`ERROR: Failed to write report (${error.message})`);
103
- return false;
104
102
  }
105
103
  }
106
104
  else {
107
105
  console.log('ERROR: Job has no ID');
108
- return false;
109
106
  }
110
107
  };
111
- // Submits a network report.
108
+ // Submits a network report to a server and returns the server response.
112
109
  const writeNetReport = async report => {
113
110
  const ack = await new Promise(resolve => {
114
111
  const wholeURL = `${process.env.PROTOCOL}://${reportURL}`;
@@ -132,22 +129,27 @@ const writeNetReport = async report => {
132
129
  }
133
130
  });
134
131
  });
135
- report.agent = agent;
132
+ report.jobData.agent = agent;
136
133
  request.on('error', error => {
137
134
  console.log(`ERROR submitting job report (${error.message})`);
138
- resolve({});
135
+ resolve({
136
+ error: 'ERROR: Job report submission failed',
137
+ message: error.message
138
+ });
139
139
  });
140
+ // Send the report to the server.
140
141
  request.write(JSON.stringify(report, null, 2));
141
142
  request.end();
142
- console.log(`Report ${report.job.id} submitted`);
143
+ console.log(`Report ${report.id} submitted`);
143
144
  });
145
+ // Return the server response.
144
146
  return ack;
145
147
  };
146
148
  // Archives a job.
147
149
  const archiveJob = async job => {
148
150
  const jobJSON = JSON.stringify(job, null, 2);
149
- await fs.writeFile(`${doneDir}/${job.id}.json`, jobJSON);
150
- await fs.rm(`${jobDir}/${job.id}.json`);
151
+ await fs.writeFile(`${jobDir}/done/${job.id}.json`, jobJSON);
152
+ await fs.rm(`${jobDir}/todo/${job.id}.json`);
151
153
  };
152
154
  // Waits.
153
155
  const wait = ms => {
@@ -157,49 +159,38 @@ const wait = ms => {
157
159
  }, ms);
158
160
  });
159
161
  };
160
- // Runs a job and returns a report.
162
+ // Runs a job.
161
163
  const runJob = async (job, isDirWatch) => {
164
+ // If the job has an ID:
162
165
  const {id} = job;
163
166
  if (id) {
164
167
  try {
165
- // Initialize a report.
166
- const report = {
167
- job,
168
- acts: [],
169
- jobData: {}
170
- };
171
168
  // Run the job, adding to the report.
172
- await doJob(report);
169
+ await doJob(job);
173
170
  // If a directory was watched:
174
171
  if (isDirWatch) {
175
172
  // Save the report.
176
- return await writeDirReport(report);
173
+ await writeDirReport(job);
177
174
  }
178
175
  // Otherwise, i.e. if the network was watched:
179
176
  else {
180
177
  // Send the report to the server.
181
- const ack = await writeNetReport(report);
178
+ const ack = await writeNetReport(job);
182
179
  if (ack.error) {
183
180
  console.log(JSON.stringify(ack, null, 2));
184
- return false;
185
- }
186
- else {
187
- return true;
188
181
  }
189
182
  }
190
183
  }
184
+ // If the job failed:
191
185
  catch(error) {
186
+ // Report this.
192
187
  console.log(`ERROR: ${error.message}\n${error.stack}`);
193
- return {
194
- error: `ERROR: ${error.message}\n${error.stack}`
195
- };
196
188
  }
197
189
  }
190
+ // Otherwise, i.e. if the job has no ID:
198
191
  else {
192
+ // Report this.
199
193
  console.log('ERROR: Job has no id');
200
- return {
201
- error: 'ERROR: Job has no id'
202
- };
203
194
  }
204
195
  };
205
196
  // Checks for a job, performs it, and submits a report, once or repeatedly.
@@ -225,25 +216,24 @@ exports.cycle = async (isDirWatch, isForever, interval) => {
225
216
  if (job.id) {
226
217
  // Run it and save a report.
227
218
  console.log(`Running job ${job.id}`);
228
- statusOK = await runJob(job, isDirWatch);
219
+ await runJob(JSON.parse(JSON.stringify(job)), isDirWatch);
229
220
  console.log(`Job ${job.id} finished`);
230
- if (statusOK) {
231
- // If a directory was watched:
232
- if (isDirWatch) {
233
- // Archive the job.
234
- await archiveJob(job);
235
- console.log(`Job ${job.id} archived`);
236
- }
237
- // If watching was specified for only 1 job, stop.
238
- statusOK = isForever;
239
- // Prevent a wait before the next iteration.
240
- empty = false;
221
+ // If a directory was watched:
222
+ if (isDirWatch) {
223
+ // Archive the job.
224
+ await archiveJob(job);
225
+ console.log(`Job ${job.id} archived`);
241
226
  }
227
+ // If watching was specified for only 1 job, quit.
228
+ statusOK = isForever;
229
+ // Prevent a wait before the next iteration.
230
+ empty = false;
242
231
  }
232
+ // Otherwise, i.e. if no job was found:
243
233
  else {
234
+ // Cause a wait before the next check.
244
235
  empty = true;
245
236
  }
246
237
  }
247
238
  console.log('Watching ended');
248
- return '';
249
239
  };
package/high.js DELETED
@@ -1,60 +0,0 @@
1
- /*
2
- high.js
3
- Invokes Testaro with the high-level method.
4
- Usage example: node high tp25
5
- */
6
-
7
- // ########## IMPORTS
8
-
9
- // Module to keep secrets.
10
- require('dotenv').config();
11
- // Module to read and write files.
12
- const fs = require('fs/promises');
13
- // Module to run jobs and report results.
14
- const {doJob} = require('./run');
15
-
16
- // ########## CONSTANTS
17
-
18
- const jobDir = process.env.JOBDIR;
19
- const reportDir = process.env.REPORTDIR;
20
-
21
- // ########## VARIABLES
22
-
23
- // Set 5 minutes as a default time limit.
24
- let timeLimit = 300;
25
-
26
- // ########## FUNCTIONS
27
-
28
- // Performs a file-based job and writes a report file.
29
- exports.runJob = async jobID => {
30
- try {
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;
37
- }
38
- // Initialize a report for the job.
39
- const report = {
40
- job,
41
- acts: [],
42
- jobData: {}
43
- };
44
- // If the initialized report is valid, run the job, adding the results to the report.
45
- const done = await doJob(report);
46
- if (done) {
47
- const reportJSON = JSON.stringify(report, null, 2);
48
- await fs.writeFile(`${reportDir}/${jobID}.json`, reportJSON);
49
- console.log(`Report ${jobID}.json recorded in ${process.env.REPORTDIR}`);
50
- return true;
51
- }
52
- else {
53
- return false;
54
- }
55
- }
56
- catch(error) {
57
- console.log(`ERROR running job (${error.message})\n${error.stack}`);
58
- return false;
59
- }
60
- };
@@ -1,52 +0,0 @@
1
- // high.js
2
- // Validator for high-level invocation of Testaro.
3
-
4
- // ########## IMPORTS
5
-
6
- const fs = require('fs/promises');
7
-
8
- // ########## CONSTANTS
9
-
10
- const projectRoot = `${__dirname}/../..`;
11
- process.env.JOBDIR = `${projectRoot}/validation/jobs`;
12
- process.env.REPORTDIR = `${projectRoot}/temp`;
13
- const reportDir = process.env.REPORTDIR;
14
- const jobID = '00000-simple-example';
15
-
16
- // ########## OPERATION
17
-
18
- // Run the simple job and write a report.
19
- const {runJob} = require(`${projectRoot}/high`);
20
- runJob(jobID)
21
- .then(
22
- // When the report has been written:
23
- async () => {
24
- try {
25
- // Check it against expectations.
26
- const reportJSON = await fs.readFile(`${reportDir}/${jobID}.json`, 'utf8');
27
- const report = JSON.parse(reportJSON);
28
- const {job, acts, jobData} = report;
29
- if (! job) {
30
- console.log('Failure: Report omits job');
31
- }
32
- else if (acts.length !== 3) {
33
- console.log('Failure: Counts of acts is not 3');
34
- }
35
- else if (! jobData) {
36
- console.log('Failure: Report omits jobData');
37
- }
38
- else if (jobData.endTime < jobData.startTime) {
39
- console.log('Failure: End time precedes start time');
40
- }
41
- else {
42
- console.log(`Success (report is in temp/${jobID}.json)`);
43
- }
44
- }
45
- catch(error) {
46
- console.log(`ERROR: ${error.message}`);
47
- }
48
- },
49
- error => {
50
- console.log(`ERROR running job (${error.message})`);
51
- }
52
- );
@@ -1,53 +0,0 @@
1
- // low.js
2
- // Validator for low-level invocation of Testaro.
3
-
4
- // ########## IMPORTS
5
-
6
- const fs = require('fs/promises');
7
-
8
- // ########## CONSTANTS
9
-
10
- const projectRoot = `${__dirname}/../..`;
11
- const {doJob} = require(`${projectRoot}/run`);
12
- process.env.JOBDIR = `${projectRoot}/validation/jobs`;
13
- process.env.REPORTDIR = `${projectRoot}/temp`;
14
- const jobID = '00000-simple-example';
15
-
16
- // ########## OPERATION
17
-
18
- // Get the simple job.
19
- fs.readFile(`${process.env.JOBDIR}/${jobID}.json`)
20
- .then(async jobJSON => {
21
- const job = JSON.parse(jobJSON);
22
- const report = {
23
- job,
24
- acts: [],
25
- jobData: {}
26
- };
27
- // Run it.
28
- await doJob(report);
29
- try {
30
- // Check the report against expectations.
31
- const reportJSON = await fs.readFile(`${process.env.REPORTDIR}/${jobID}.json`, 'utf8');
32
- const report = JSON.parse(reportJSON);
33
- const {job, acts, jobData} = report;
34
- if (! job) {
35
- console.log('Failure: Report omits job');
36
- }
37
- else if (acts.length !== 3) {
38
- console.log('Failure: Counts of acts is not 3');
39
- }
40
- else if (! jobData) {
41
- console.log('Failure: Report omits jobData');
42
- }
43
- else if (jobData.endTime < jobData.startTime) {
44
- console.log('Failure: End time precedes start time');
45
- }
46
- else {
47
- console.log(`Success (report is in temp/${jobID}.json)`);
48
- }
49
- }
50
- catch(error) {
51
- console.log(`ERROR: ${error.message}`);
52
- }
53
- });