testilo 3.9.12 → 3.9.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testilo",
3
- "version": "3.9.12",
3
+ "version": "3.9.14",
4
4
  "description": "Client that scores and digests Testaro reports",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
 
10
10
  This proc computes a score that is intended to represent how accessibly a web page offers
11
11
  a user an opportunity to report an accessibility issue about that page. Scores can range
12
- from 0 to 16.
12
+ from perfect 0 to 16.
13
13
  */
14
14
 
15
15
  // CONSTANTS
@@ -22,69 +22,75 @@ const scoreProcID = 'a11ymessage';
22
22
  // Scores the contact links of a type.
23
23
  const contactScorer = (result, score, type) => {
24
24
  const links = result.items;
25
- score[type] += 1;
26
- if (
27
- links.some(
28
- link => link.textContent.toLowerCase().includes('accessibility')
29
- )
30
- ) {
31
- score[type] += 2;
25
+ if (links.some(
26
+ link => link.textContent.toLowerCase().includes('accessibility')
27
+ )) {
28
+ score[type] -= 3;
32
29
  }
33
- else if (
34
- links.some(
35
- link => link.parentTextContent.toLowerCase().includes('accessibility')
36
- )
37
- ) {
38
- score[type] += 1;
30
+ else if (links.some(
31
+ link => link.parentTextContent.toLowerCase().includes('accessibility')
32
+ )) {
33
+ score[type] -= 2;
39
34
  }
40
35
  };
41
36
  // Scores a report.
42
37
  exports.scorer = async report => {
43
38
  const {acts} = report;
39
+ report.scoreProcID = scoreProcID;
44
40
  report.score = {
45
- page: 0,
46
- a11yLink: 0,
47
- title: 0,
48
- heading: 0,
49
- mailLink: 0,
50
- telLink: 0,
51
- total: 0
41
+ page: 3,
42
+ a11yLink: 4,
43
+ title: 3,
44
+ heading: 3,
45
+ mailLink: 3,
46
+ telLink: 3
52
47
  };
53
48
  const {score} = report;
54
49
  if (Array.isArray(acts)) {
55
50
  // Act 1: page loads.
56
51
  if (acts[1].result.startsWith('http')) {
57
- score.page = 2;
52
+ score.page -= 2;
53
+ if (acts[1].endTime - acts[1].startTime < 2500) {
54
+ score.page -= 1;
55
+ }
58
56
  // Act 2: accessibility link exists and loads promptly.
59
- if (acts[2].result.move === 'clicked') {
60
- score.a11yLink = 2;
61
- const loadScore = ['incomplete', 'loaded', 'idle'].indexOf(acts[2].result.loadState);
62
- if (loadScore > -1) {
63
- score.a11yLink += loadScore;
64
- }
65
- // Act 3: next page has an accessibility title.
66
- const act3Result = acts[3].result;
67
- if (act3Result && act3Result.toLowerCase().includes('accessibility')) {
68
- score.title = 2;
69
- // Act 4: page has exactly 1 h1 heading.
70
- const act4Result = acts[4].result;
71
- if (act4Result && act4Result.total === 1) {
72
- score.heading = 1;
73
- // Act 4: h1 is an accessibility heading.
74
- if (act4Result.items[0].textContent.toLowerCase().includes('accessibility')) {
75
- score.heading += 1;
57
+ const {result} = acts[2];
58
+ // If a link with text content including accessibility was found:
59
+ if (result.found) {
60
+ score.a11yLink -= 2;
61
+ // If it was clickable and the resulting load finished:
62
+ if (result.success) {
63
+ score.a11yLink -= 1;
64
+ // If the navigation and load took less than 1.5 seconds:
65
+ if (acts[2].endTime - acts[2].startTime < 1500) {
66
+ score.a11yLink -= 1;
67
+ }
68
+ // Act 3: next page has an accessibility title.
69
+ let {result} = acts[3];
70
+ if (result && result.success) {
71
+ score.title -= 1;
72
+ if (result.title.toLowerCase().includes('accessibility')) {
73
+ score.title -= 2;
76
74
  }
77
75
  }
78
- }
79
- // Act 5: page has accessibility email and telephone links.
80
- const act5Result = acts[5].result;
81
- if (act5Result.total) {
82
- contactScorer(act5Result, score, 'mailLink');
83
- }
84
- // Act 6: page has accessibility email and telephone links.
85
- const act6Result = acts[6].result;
86
- if (act6Result.total) {
87
- contactScorer(act6Result, score, 'telLink');
76
+ // Act 4: page has 1 h1 heading, and it is about accessibility.
77
+ result = acts[4].result;
78
+ if (result && result.total === 1) {
79
+ score.heading -= 1;
80
+ if (result.items[0].textContent.toLowerCase().includes('accessibility')) {
81
+ score.heading -= 2;
82
+ }
83
+ }
84
+ // Act 5: page has an accessibility email link.
85
+ result = acts[5].result;
86
+ if (result.total) {
87
+ contactScorer(result, score, 'mailLink');
88
+ }
89
+ // Act 6: page has accessibility telephone link.
90
+ result = acts[6].result;
91
+ if (result.total) {
92
+ contactScorer(result, score, 'telLink');
93
+ }
88
94
  }
89
95
  }
90
96
  }