testaro 5.7.0 → 5.7.4

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
@@ -93,6 +93,7 @@ A script is a JSON file with the properties:
93
93
 
94
94
  ```json
95
95
  {
96
+ "id": "string consisting of lower-case ASCII letters and digits",
96
97
  "what": "string: description of the script",
97
98
  "strict": "boolean: whether redirections should be treated as failures",
98
99
  "timeLimit": "number: limit in seconds on the execution of this script",
@@ -100,32 +101,33 @@ A script is a JSON file with the properties:
100
101
  }
101
102
  ```
102
103
 
103
- The `timeLimit` property is optional. If it is omitted, a default of 300 seconds (5 minutes) is set.
104
+ The `timeLimit` property is optional. If it is omitted, a default of 300 seconds (5 minutes) is set.
104
105
 
105
106
  ### Example
106
107
 
107
108
  Here is an example of a script:
108
109
 
109
- ```javascript
110
+ ```json
110
111
  {
111
- what: 'Test example.com with alfa',
112
+ "id": "samplescript",
113
+ what: "Test example.com with alfa",
112
114
  strict: true,
113
- timeLimit: 15,
115
+ timeLimit: 65,
114
116
  commands: [
115
117
  {
116
- type: 'launch',
117
- which: 'chromium',
118
- what: 'Chromium browser'
118
+ type: "launch",
119
+ which: "chromium",
120
+ what: "Chromium browser"
119
121
  },
120
122
  {
121
- type: 'url',
122
- which: 'https://example.com/',
123
- what: 'page with a few accessibility defects'
123
+ type: "url",
124
+ which: "https://example.com/",
125
+ what: "page with a few accessibility defects"
124
126
  },
125
127
  {
126
- type: 'test',
127
- which: 'alfa',
128
- what: 'Siteimprove alfa package'
128
+ type: "test",
129
+ which: "alfa",
130
+ what: "Siteimprove alfa package"
129
131
  }
130
132
  ]
131
133
  }
@@ -302,6 +304,10 @@ In case you want to perform more than one `tenon` test with the same script, you
302
304
 
303
305
  Tenon recommends giving it a public URL rather than giving it the content of a page, if possible. So, it is best to give the `withNewContent` property of the `tenonRequest` command the value `true`, unless the page is not public.
304
306
 
307
+ ###### Continuum
308
+
309
+ The `continuum` test makes use of the files in the `continuum` directory. The test inserts the contents of all three files into the page as scripts and then uses them to perform the tests of the Continuum package.
310
+
305
311
  ###### HTML CodeSniffer
306
312
 
307
313
  The `htmlcs` test makes use of the`htmlcs/HTMLCS.js` file. That file was created, and can be recreated if necessary, as follows:
@@ -336,7 +342,7 @@ The changes in `htmlcs/HTMLCS.js` are:
336
342
 
337
343
  ###### BBC Accessibility Standards Checker
338
344
 
339
- The BBC Accessibility Standards Checker has obsolete dependencies with security vulnerabilities. Therefore, it is not used as a dependency of Testaro. Instead, 6 of its tests were reimplemented, in some case with revisions, as Testaro tests. They were drawn from the 18 automated tests of the Checker. The other 12 tests were found too duplicative of other tests to justify reimplementation.
345
+ The BBC Accessibility Standards Checker has obsolete dependencies with security vulnerabilities. Therefore, it is not used as a dependency of Testaro. Instead, 6 of its tests are reimplemented, in some case with revisions, as Testaro tests. They are drawn from the 18 automated tests of the Checker. The other 12 tests were found too duplicative of other tests to justify reimplementation.
340
346
 
341
347
  ##### Branching
342
348
 
@@ -436,18 +442,18 @@ A typical use for an `expect` property is checking the correctness of a Testaro
436
442
 
437
443
  You may wish to have Testaro perform the same sequence of tests on multiple web pages. In that case, you can create a _batch_, with the following structure:
438
444
 
439
- ```javascript
445
+ ```json
440
446
  {
441
- what: 'Web leaders',
447
+ what: "Web leaders",
442
448
  hosts: {
443
- id: 'w3c',
444
- which: 'https://www.w3.org/',
445
- what: 'W3C'
449
+ id: "w3c",
450
+ which: "https://www.w3.org/",
451
+ what: "W3C"
446
452
  },
447
453
  {
448
- id: 'wikimedia',
449
- which: 'https://www.wikimedia.org/',
450
- what: 'Wikimedia'
454
+ id: "wikimedia",
455
+ which: "https://www.wikimedia.org/",
456
+ what: "Wikimedia"
451
457
  }
452
458
  }
453
459
  ```
@@ -487,7 +493,7 @@ The argument of `require` is a path relative to the directory of the module in w
487
493
 
488
494
  Another Node.js package that has Testaro as a dependency can execute the same statements, except changing `'./run'` to `'testaro/run'`.
489
495
 
490
- Testaro will run the script and populate the `log` and `acts` arrays of the `report` object. When Testaro finishes, the `log` and `acts` properties will contain the results. The final statement can further process the `report` object as desired in the `then` callback.
496
+ Testaro will run the script and modify the properties of the `report` object. When Testaro finishes, the `log`, `acts`, and other properties of `report` will contain the results. The final statement can further process the `report` object as desired in the `then` callback.
491
497
 
492
498
  #### High-level
493
499
 
@@ -500,7 +506,7 @@ Relative paths must be relative to the Testaro project directory. For example, i
500
506
 
501
507
  Also ensure that Testaro can read all those directories and write to `REPORTDIR`.
502
508
 
503
- Place a script into `SCRIPTDIR` and, optionally, a batch into `BATCHDIR`. Each should be named `idvalue.json`, where `idvalue` is replaced with the value of its `id` property. That value must consist of only lower-case ASCII letters and digits.
509
+ Place a script into `SCRIPTDIR` and, optionally, a batch into `BATCHDIR`. Each should be named with a `.json` extension., where `idvalue` is replaced with the value of its `id` property. That value must consist of only lower-case ASCII letters and digits.
504
510
 
505
511
  Then execute the statement `node high scriptID` or `node high scriptID batchID`, replacing `scriptID` and `batchID` with the `id` values of the script and the batch, respectively.
506
512
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "5.7.0",
3
+ "version": "5.7.4",
4
4
  "description": "Automation of accessibility testing",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/run.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*
2
- index.js
2
+ run.js
3
3
  testaro main script.
4
4
  */
5
5
 
@@ -103,6 +103,7 @@ let errorLogSize = 0;
103
103
  let prohibitedCount = 0;
104
104
  let visitTimeoutCount = 0;
105
105
  let visitRejectionCount = 0;
106
+ let visitLatency = 0;
106
107
  let actCount = 0;
107
108
  // Facts about the current browser.
108
109
  let browserContext;
@@ -511,6 +512,7 @@ const goto = async (page, url, timeout, waitUntil, isStrict) => {
511
512
  url = url.replace('file://', `file://${__dirname}/`);
512
513
  }
513
514
  // Visit the URL.
515
+ const startTime = Date.now();
514
516
  const response = await page.goto(url, {
515
517
  timeout,
516
518
  waitUntil
@@ -520,6 +522,7 @@ const goto = async (page, url, timeout, waitUntil, isStrict) => {
520
522
  visitTimeoutCount++;
521
523
  return 'error';
522
524
  });
525
+ visitLatency += Math.round((Date.now() - startTime) / 1000);
523
526
  // If the visit succeeded:
524
527
  if (typeof response !== 'string') {
525
528
  const httpStatus = response.status();
@@ -733,7 +736,7 @@ const doActs = async (report, actIndex, page) => {
733
736
  // If the command is a url:
734
737
  if (act.type === 'url') {
735
738
  // Visit it and wait until it is stable.
736
- page = await visit(act, page, report.strict);
739
+ page = await visit(act, page, report.isStrict);
737
740
  }
738
741
  // Otherwise, if the act is a wait for text:
739
742
  else if (act.type === 'wait') {
@@ -1335,6 +1338,7 @@ const doScript = async (report) => {
1335
1338
  report.prohibitedCount = prohibitedCount;
1336
1339
  report.visitTimeoutCount = visitTimeoutCount;
1337
1340
  report.visitRejectionCount = visitRejectionCount;
1341
+ report.visitLatency = visitLatency;
1338
1342
  // Add the end time and duration to the report.
1339
1343
  const endTime = new Date();
1340
1344
  report.endTime = endTime.toISOString().slice(0, 19);
package/tests/nuVal.js CHANGED
@@ -1,46 +1,72 @@
1
1
  /*
2
2
  nuVal
3
3
  This test subjects a page to the Nu Html Checker.
4
+ That API erratically replaces left and right double quotation marks with invalid UTF-8, which
5
+ appears as 2 or 3 successive instances of the replacement character (U+fffd). Therefore, this
6
+ test removes all such quotation marks and the replacement character. That causes
7
+ 'Bad value “” for' to become 'Bad value for'. Since the corruption of quotation marks is
8
+ erratic, no better solution is known.
4
9
  */
5
10
  const https = require('https');
6
11
  exports.reporter = async page => {
7
12
  const pageContent = await page.content();
8
13
  // Get the data from a Nu validation.
9
- const data = await new Promise(resolve => {
10
- const request = https.request(
11
- {
12
- host: 'validator.nu',
13
- path: '/?parser=html&out=json',
14
- method: 'POST',
15
- headers: {
16
- 'User-Agent': 'Mozilla/5.0',
17
- 'Content-Type': 'text/html; charset=utf-8'
18
- }
19
- },
20
- response => {
21
- let report = '';
22
- response.on('data', chunk => {
23
- report += chunk;
24
- });
25
- // When the data arrive:
26
- response.on('end', async () => {
27
- try {
28
- // Delete unnecessary properties.
29
- const result = JSON.parse(report);
30
- return resolve(result);
31
- }
32
- catch (error) {
33
- return resolve({
34
- prevented: true,
35
- error: error.message,
36
- report
37
- });
14
+ const data = await new Promise((resolve, reject) => {
15
+ try {
16
+ const request = https.request(
17
+ {
18
+ /*
19
+ Alternatives (more timeout-prone): host=validator.nu; path=/?parser=html@out=json
20
+ That host crashes instead of ending with a fatal error.
21
+ */
22
+ host: 'validator.w3.org',
23
+ path: '/nu/?parser=html&out=json',
24
+ method: 'POST',
25
+ headers: {
26
+ 'User-Agent': 'Mozilla/5.0',
27
+ 'Content-Type': 'text/html; charset=utf-8'
38
28
  }
29
+ },
30
+ response => {
31
+ let report = '';
32
+ response.on('data', chunk => {
33
+ report += chunk;
34
+ });
35
+ // When the data arrive:
36
+ response.on('end', async () => {
37
+ try {
38
+ // Delete left and right quotation marks and their erratic invalid replacements.
39
+ const result = JSON.parse(report.replace(/[\u{fffd}“”]/ug, ''));
40
+ return resolve(result);
41
+ }
42
+ catch (error) {
43
+ console.log(`Validation failed (${error.message})`);
44
+ return resolve({
45
+ prevented: true,
46
+ error: error.message,
47
+ report
48
+ });
49
+ }
50
+ });
51
+ }
52
+ );
53
+ request.write(pageContent);
54
+ request.end();
55
+ request.on('error', error => {
56
+ console.log(error.message);
57
+ return reject({
58
+ prevented: true,
59
+ error: error.message
39
60
  });
40
- }
41
- );
42
- request.write(pageContent);
43
- request.end();
61
+ });
62
+ }
63
+ catch(error) {
64
+ console.log(error.message);
65
+ return reject({
66
+ prevented: true,
67
+ error: error.message
68
+ });
69
+ }
44
70
  });
45
71
  return {result: data};
46
72
  };