testaro 8.1.0 → 8.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/README.md CHANGED
@@ -251,7 +251,7 @@ A report object is saved as a JSON file in the `process.env.REPORTDIR_RAW` direc
251
251
  },
252
252
  requester: 'user@domain.org'
253
253
  },
254
- jobCreationTime: '2023-05-26T14:28',
254
+ jobCreationTime: '2023-05-26T14:28:22',
255
255
  timeStamp: 'be76p'
256
256
  },
257
257
  acts: [],
package/call.js CHANGED
@@ -39,7 +39,6 @@ const callWatch = async (isDirWatch, isForever, interval) => {
39
39
  `Starting a ${isForever === 'true' ? 'repeating' : 'one-time'} ${isDirWatch === 'true' ? 'directory' : 'network'} watch`
40
40
  );
41
41
  await cycle(isDirWatch === 'true', isForever === 'true', Number.parseInt(interval, 10));
42
- console.log('Watching ended');
43
42
  };
44
43
 
45
44
  // ########## OPERATION
package/high.js CHANGED
@@ -38,7 +38,8 @@ exports.runJob = async jobID => {
38
38
  // Initialize a report for the job.
39
39
  const report = {
40
40
  job,
41
- acts: []
41
+ acts: [],
42
+ jobData: {}
42
43
  };
43
44
  // Run the job, adding the results to the report.
44
45
  await doJob(report);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/run.js CHANGED
@@ -236,21 +236,31 @@ const isValidCommand = command => {
236
236
  // Validates a report object.
237
237
  const isValidReport = report => {
238
238
  if (report) {
239
- // Return whether the report is valid.
240
- const {script, acts} = report;
241
- const {what, strict, commands} = script;
242
- return what
243
- && typeof strict === 'boolean'
244
- && commands
245
- && typeof what === 'string'
246
- && Array.isArray(commands)
247
- && commands[0].type === 'launch'
248
- && commands.length > 1
249
- && commands[1].type === 'url'
250
- && isURL(commands[1].which)
251
- && commands.every(command => isValidCommand(command))
252
- && Array.isArray(acts)
253
- && ! acts.length;
239
+ // Return whether the job is valid.
240
+ const {job, acts, jobData} = report;
241
+ const {id, what, strict, commands, sources, jobCreationTime, timeStamp} = job;
242
+ const isValid = job
243
+ && acts
244
+ && jobData
245
+ && id
246
+ && what
247
+ && typeof strict === 'boolean'
248
+ && commands
249
+ && sources
250
+ && jobCreationTime
251
+ && timeStamp
252
+ && Array.isArray(acts)
253
+ && typeof id === 'string'
254
+ && typeof what === 'string'
255
+ && Array.isArray(commands)
256
+ && commands[0].type === 'launch'
257
+ && commands.length > 1
258
+ && commands[1].type === 'url'
259
+ && isURL(commands[1].which)
260
+ && commands.every(command => isValidCommand(command))
261
+ && sources.script
262
+ && sources.host;
263
+ return isValid;
254
264
  }
255
265
  else {
256
266
  return false;
@@ -651,7 +661,7 @@ const doActs = async (report, actIndex, page) => {
651
661
  const resolved = act.which.replace('__dirname', __dirname);
652
662
  requestedURL = resolved;
653
663
  // Visit it and wait until the network is idle.
654
- const {strict} = report.script;
664
+ const {strict} = report.job;
655
665
  let response = await goTo(report, page, requestedURL, 15000, 'networkidle', strict);
656
666
  // If the visit fails:
657
667
  if (response.error) {
@@ -1504,7 +1514,7 @@ exports.doJob = async report => {
1504
1514
  // If the report is valid:
1505
1515
  if(isValidReport(report)) {
1506
1516
  // Add the script commands to the report as its initial acts.
1507
- report.acts = JSON.parse(JSON.stringify(report.script.commands));
1517
+ report.acts = JSON.parse(JSON.stringify(report.job.commands));
1508
1518
  /*
1509
1519
  Inject launch and url acts where necessary to undo DOM changes, if specified.
1510
1520
  Injection of url acts alone does not guarantee test independence.
@@ -1514,24 +1524,22 @@ exports.doJob = async report => {
1514
1524
  }
1515
1525
  // Add initialized job data to the report.
1516
1526
  const startTime = new Date();
1517
- report.jobData = {
1518
- startTime: nowString(),
1519
- endTime: '',
1520
- elapsedSeconds: 0,
1521
- visitLatency: 0,
1522
- logCount: 0,
1523
- logSize: 0,
1524
- errorLogCount: 0,
1525
- errorLogSize: 0,
1526
- prohibitedCount: 0,
1527
- visitTimeoutCount: 0,
1528
- visitRejectionCount: 0,
1529
- aborted: false,
1530
- abortedAct: null,
1531
- presses: 0,
1532
- amountRead: 0,
1533
- testTimes: []
1534
- };
1527
+ report.jobData.startTime = nowString();
1528
+ report.jobData.endTime = '';
1529
+ report.jobData.elapsedSeconds = 0;
1530
+ report.jobData.visitLatency = 0;
1531
+ report.jobData.logCount = 0;
1532
+ report.jobData.logSize = 0;
1533
+ report.jobData.errorLogCount = 0;
1534
+ report.jobData.errorLogSize = 0;
1535
+ report.jobData.prohibitedCount = 0;
1536
+ report.jobData.visitTimeoutCount = 0;
1537
+ report.jobData.visitRejectionCount = 0;
1538
+ report.jobData.aborted = false;
1539
+ report.jobData.abortedAct = null;
1540
+ report.jobData.presses = 0;
1541
+ report.jobData.amountRead = 0;
1542
+ report.jobData.testTimes = [];
1535
1543
  // Recursively perform the specified acts.
1536
1544
  await doActs(report, 0, null);
1537
1545
  // Add the end time and duration to the report.
@@ -1539,4 +1547,7 @@ exports.doJob = async report => {
1539
1547
  report.jobData.endTime = nowString();
1540
1548
  report.jobData.elapsedSeconds = Math.floor((endTime - startTime) / 1000);
1541
1549
  }
1550
+ else {
1551
+ console.log('ERROR: Initialized job report invalid');
1552
+ }
1542
1553
  };
package/watch.js CHANGED
@@ -85,11 +85,11 @@ const checkNetJob = async () => {
85
85
  };
86
86
  // Writes a directory report.
87
87
  const writeDirReport = async report => {
88
- const scriptID = report && report.script && report.script.id;
89
- if (scriptID) {
88
+ const jobID = report && report.job && report.job.id;
89
+ if (jobID) {
90
90
  try {
91
91
  const reportJSON = JSON.stringify(report, null, 2);
92
- const reportName = `${scriptID}.json`;
92
+ const reportName = `${jobID}.json`;
93
93
  await fs.writeFile(`${reportDir}/${reportName}`, reportJSON);
94
94
  console.log(`Report ${reportName} saved`);
95
95
  return true;
@@ -99,6 +99,10 @@ const writeDirReport = async report => {
99
99
  return false;
100
100
  }
101
101
  }
102
+ else {
103
+ console.log('ERROR: Job has no ID');
104
+ return false;
105
+ }
102
106
  };
103
107
  // Submits a network report.
104
108
  const writeNetReport = async report => {
@@ -130,10 +134,10 @@ const writeNetReport = async report => {
130
134
  return ack;
131
135
  };
132
136
  // Archives a job.
133
- const archiveJob = async script => {
134
- const scriptJSON = JSON.stringify(script, null, 2);
135
- await fs.writeFile(`${doneDir}/${script.id}.json`, scriptJSON);
136
- await fs.rm(`${jobDir}/${script.id}.json`);
137
+ const archiveJob = async job => {
138
+ const jobJSON = JSON.stringify(job, null, 2);
139
+ await fs.writeFile(`${doneDir}/${job.id}.json`, jobJSON);
140
+ await fs.rm(`${jobDir}/${job.id}.json`);
137
141
  };
138
142
  // Waits.
139
143
  const wait = ms => {
@@ -144,15 +148,15 @@ const wait = ms => {
144
148
  });
145
149
  };
146
150
  // Runs a job and returns a report.
147
- exports.runJob = async (script, isDirWatch) => {
148
- const {id} = script;
151
+ exports.runJob = async (job, isDirWatch) => {
152
+ const {id} = job;
149
153
  if (id) {
150
154
  try {
151
155
  // Initialize a report.
152
156
  const report = {
153
- log: [],
154
- script,
155
- acts: []
157
+ job,
158
+ acts: [],
159
+ jobData: {}
156
160
  };
157
161
  // Run the job, adding to the report.
158
162
  await doJob(report);
@@ -218,7 +222,7 @@ exports.cycle = async (isDirWatch, isForever, interval) => {
218
222
  if (isDirWatch) {
219
223
  // Archive the job.
220
224
  await archiveJob(job);
221
- console.log(`Script ${job.id} archived`);
225
+ console.log(`Job ${job.id} archived`);
222
226
  }
223
227
  // If watching was specified for only 1 job, stop.
224
228
  statusOK = isForever;