testilo 33.6.2 → 34.0.1

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
@@ -343,7 +343,7 @@ const standard = 'only';
343
343
  const observe = false;
344
344
  const requester = 'me@mydomain.tld';
345
345
  const timeStamp = '241215T1200';
346
- const jobs = merge(script, batch, standard, observe, requester, timeStamp);
346
+ const jobs = merge(script, batch, standard, observe, requester, timeStamp, deviceID);
347
347
  ```
348
348
 
349
349
  The first two arguments are a script and a batch obtained from files or from prior calls to `script()` and `batch()`.
@@ -356,6 +356,8 @@ The `requester` argument is an email address to which any notices about the job
356
356
 
357
357
  The `timeStamp` argument specifies the earliest UTC date and time when the jobs may be assigned, or it may be an empty string if now.
358
358
 
359
+ The `deviceID` argument specifies the ID of the test device. It must be either `'default'` or the ID of one of the test devices recognized by Playwright, published at `https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json`.
360
+
359
361
  The `merge()` function returns the jobs in an array. The invoking module can further dispose of the jobs as needed.
360
362
 
361
363
  ##### By a user
@@ -367,13 +369,13 @@ A user can invoke `merge()` in this way:
367
369
  - In the Testilo project directory, execute the statement:
368
370
 
369
371
  ```javascript
370
- node call merge scriptID batchID standard observe requester timeStamp todoDir
372
+ node call merge scriptID batchID standard observe requester timeStamp deviceID todoDir
371
373
  ```
372
374
 
373
375
  In this statement, replace:
374
376
  - `scriptID` with the ID (which is also the base of the file name) of the script.
375
377
  - `batchID` with the ID (which is also the base of the file name) of the batch.
376
- - `standard`, `observe`, `requester`, and `timeStamp` as described above.
378
+ - `standard`, `observe`, `requester`, `timeStamp`, and `deviceID` as described above.
377
379
  - `todoDir`: `true` if the jobs are to be saved in the `todo` subdirectory, or `false` if they are to be saved in the `pending` subdirectory, of the `JOBDIR` directory.
378
380
 
379
381
  The `call` module will retrieve the named script and batch from their respective directories.
@@ -399,6 +401,7 @@ A Testaro job produced by `merge` may look like this:
399
401
  type: 'launch',
400
402
  which: 'webkit',
401
403
  what: 'Acme Clothes',
404
+ deviceID: 'Galaxy S8',
402
405
  url: 'https://acmeclothes.com/'
403
406
  },
404
407
  {
@@ -412,6 +415,7 @@ A Testaro job produced by `merge` may look like this:
412
415
  type: 'launch',
413
416
  which: 'webkit',
414
417
  what: 'Acme Clothes',
418
+ deviceID: 'Galaxy S8',
415
419
  url: 'https://acmeclothes.com/'
416
420
  },
417
421
  {
@@ -929,7 +933,7 @@ node call credit legislators 241106
929
933
  ```
930
934
 
931
935
  When a user invokes `credit` in this example, the `call` module:
932
- - gets all reports, or if the third argument to `call()` exists all reports whose file names begin with `'241106'`, in the `scored` subdirectory of the `REPORTDIR` directory.
936
+ - gets all reports, or if the third argument to `call()` exists all reports whose file names begin with `'241106'`, in the `scored` subdirectory of the `REPORTDIR` directory.
933
937
  - gets the `score` properties of those reports.
934
938
  - creates an ID for the credit report.
935
939
  - writes the credit report as a JSON file, with the ID as the base of its file name and `legislators` as its description, to the `credit` subdirectory of the `REPORTDIR` directory.
package/call.js CHANGED
@@ -185,6 +185,7 @@ const callMerge = async (
185
185
  observe,
186
186
  requester,
187
187
  timeStamp,
188
+ deviceID,
188
189
  todoDir
189
190
  ) => {
190
191
  try {
@@ -199,7 +200,7 @@ const callMerge = async (
199
200
  const batchJSON = await fs.readFile(`${specDir}/batches/${batchID}.json`, 'utf8');
200
201
  const batch = JSON.parse(batchJSON);
201
202
  // Merge them into an array of jobs.
202
- const jobs = merge(script, batch, standard, observe === 'true', requester, timeStamp);
203
+ const jobs = merge(script, batch, standard, observe === 'true', requester, timeStamp, deviceID);
203
204
  // Save the jobs.
204
205
  const subdir = `${jobDir}/${todoDir === 'true' ? 'todo' : 'pending'}`;
205
206
  for (const job of jobs) {
@@ -362,7 +363,7 @@ const callSummarize = async (what, selector = '') => {
362
363
  };
363
364
  // Save the summary report.
364
365
  const summaryDir = `${reportDir}/summarized`;
365
- await fs.mkdir(summaryDir, {recursive: true});
366
+ await fs.mkdir(summaryDir, {recursive: true});
366
367
  const filePath = `${summaryDir}/${summaryReport.id}.json`;
367
368
  await fs.writeFile(filePath, `${JSON.stringify(summaryReport, null, 2)}\n`);
368
369
  console.log(`Reports summarized and summary report saved as ${filePath}`);
@@ -385,7 +386,7 @@ const callCompare = async (what, compareProcID, selector) => {
385
386
  const {comparer} = require(`${comparerDir}/index`);
386
387
  // Compare the reports and save the comparison.
387
388
  const comparisonDir = `${reportDir}/comparative`;
388
- await fs.mkdir(comparisonDir, {recursive: true});
389
+ await fs.mkdir(comparisonDir, {recursive: true});
389
390
  const id = getFileID(2);
390
391
  const comparison = await compare(id, what, comparer, summaryReport);
391
392
  const comparisonPath = `${comparisonDir}/${id}.html`;
@@ -476,7 +477,7 @@ else if (fn === 'script' && (fnArgs.length === 2 || fnArgs.length > 3)) {
476
477
  console.log('Execution completed');
477
478
  });
478
479
  }
479
- else if (fn === 'merge' && fnArgs.length === 7) {
480
+ else if (fn === 'merge' && fnArgs.length === 8) {
480
481
  callMerge(... fnArgs)
481
482
  .then(() => {
482
483
  console.log('Execution completed');
package/merge.js CHANGED
@@ -8,7 +8,7 @@
8
8
  // Module to keep secrets.
9
9
  require('dotenv').config();
10
10
  // Utility module.
11
- const {alphaNumOf, dateOf, getRandomString, getNowStamp} = require('./procs/util');
11
+ const {alphaNumOf, dateOf, getRandomString, getNowStamp, isValidDeviceID} = require('./procs/util');
12
12
 
13
13
  // ########## CONSTANTS
14
14
 
@@ -27,7 +27,7 @@ const mergeIDLength = 2;
27
27
  // ########## FUNCTIONS
28
28
 
29
29
  // Merges a script and a batch and returns jobs.
30
- exports.merge = (script, batch, standard, observe, requester, timeStamp) => {
30
+ exports.merge = (script, batch, standard, observe, requester, timeStamp, deviceID) => {
31
31
  // If standard is invalid:
32
32
  if (! ['also', 'only', 'no'].includes(standard)) {
33
33
  // Report this and quit.
@@ -45,7 +45,7 @@ exports.merge = (script, batch, standard, observe, requester, timeStamp) => {
45
45
  // If it is invalid:
46
46
  if (! dateOf(timeStamp)) {
47
47
  // Report this and quit.
48
- console.log(`ERROR: Timestamp invalid`);
48
+ console.log('ERROR: Timestamp invalid');
49
49
  return [];
50
50
  }
51
51
  }
@@ -54,6 +54,12 @@ exports.merge = (script, batch, standard, observe, requester, timeStamp) => {
54
54
  // Create one for the job.
55
55
  timeStamp = getNowStamp();
56
56
  }
57
+ // If deviceID is invalid:
58
+ if (! isValidDeviceID(deviceID)) {
59
+ // Report this and quit.
60
+ console.log('ERROR: Device ID invalid');
61
+ return [];
62
+ }
57
63
  // Initialize a job as a copy of the script.
58
64
  const protoJob = JSON.parse(JSON.stringify(script));
59
65
  // Add an initialized sources property to it.
@@ -137,11 +143,12 @@ exports.merge = (script, batch, standard, observe, requester, timeStamp) => {
137
143
  if (replacerName && target.acts) {
138
144
  let replacerActs = target.acts[replacerName];
139
145
  if (replacerActs) {
140
- // Add a which property to any launch act in the replacer.
146
+ // Add properties to any launch act in the replacer.
141
147
  replacerActs = JSON.parse(JSON.stringify(replacerActs));
142
148
  for (const replacerAct of replacerActs) {
143
149
  if (replacerAct.type === 'launch') {
144
150
  replacerAct.which = act.launch;
151
+ replacerAct.deviceID = deviceID;
145
152
  }
146
153
  }
147
154
  acts[actIndex] = replacerActs;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "33.6.2",
3
+ "version": "34.0.1",
4
4
  "description": "Prepares Testaro jobs and processes Testaro reports",
5
5
  "main": "call.js",
6
6
  "scripts": {
@@ -18,7 +18,8 @@
18
18
  },
19
19
  "homepage": "https://github.com/jrpool/testilo",
20
20
  "dependencies": {
21
- "dotenv": "*"
21
+ "dotenv": "*",
22
+ "playwright": "*"
22
23
  },
23
24
  "devDependencies": {
24
25
  "eslint": "*"
package/procs/util.js CHANGED
@@ -3,6 +3,11 @@
3
3
  Utility functions.
4
4
  */
5
5
 
6
+ // IMPORTS
7
+
8
+ // Devices recognized by Playwright.
9
+ const {devices} = require('playwright');
10
+
6
11
  // CONSTANTS
7
12
 
8
13
  // Array of 62 alphanumeric characters.
@@ -87,3 +92,8 @@ exports.getBarCell = (num, colMax, svgWidth, isRight = false) => {
87
92
  const cell = `<td aria-hidden="true"${rightClass}>${svg}</td>`;
88
93
  return cell;
89
94
  };
95
+ // Returns whether a device ID is recognized by Playwright.
96
+ exports.isValidDeviceID = deviceID => {
97
+ const deviceIDs = Object.keys(devices);
98
+ return deviceIDs.includes(deviceID);
99
+ };