testaro 58.3.3 → 58.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/testaro/headEl.js +46 -61
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "58.3.3",
3
+ "version": "58.3.4",
4
4
  "description": "Run 1000 web accessibility tests from 11 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/testaro/headEl.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /*
2
2
  © 2023–2024 CVS Health and/or one of its affiliates. All rights reserved.
3
+ © 2025 Jonathan Robert Pool. All rights reserved.
3
4
 
4
5
  MIT License
5
6
 
@@ -25,14 +26,9 @@
25
26
  /*
26
27
  headEl
27
28
  Related to ASLint rule elements-not-allowed-in-head.
28
- This test reports invalid descendants of the head element in the source of the document.
29
+ This test reports invalid descendants of the head of the document.
29
30
  */
30
31
 
31
- // ########## IMPORTS
32
-
33
- // Module to get the document source.
34
- const {getSource} = require('../procs/getSource');
35
-
36
32
  // ########## FUNCTIONS
37
33
 
38
34
  // Performs the test.
@@ -44,63 +40,52 @@ exports.reporter = async page => {
44
40
  };
45
41
  let totals = [];
46
42
  const standardInstances = [];
47
- // Get the source.
48
- const sourceData = await getSource(page);
49
- // If it was not obtained:
50
- if (sourceData.prevented) {
51
- // Report this.
52
- data.prevented = true;
53
- data.error = 'ERROR getting page source';
54
- }
55
- // Otherwise, i.e. if it was obtained:
56
- else {
57
- let rawPage = sourceData.source;
58
- // Change any spacing character sequences in it to single spaces.
59
- rawPage = rawPage.replace(/\s+/g, ' ');
60
- // Delete everything in it except the head content.
61
- rawPage = rawPage.replace(/^.*<head>|<\/head>.*$/g, '');
62
- // Delete any scripts from it.
63
- rawPage = rawPage.replace(/<script[ >].+?<\/script>/g, '');
64
- // Get the tag names of the remaining elements.
65
- const tags = rawPage.match(/<([a-z]+)/g);
66
- const ucTagNames = tags.map(tag => tag.toUpperCase().slice(1));
67
- const validTagNames = [
68
- 'BASE',
69
- 'LINK',
70
- 'META',
71
- 'SCRIPT',
72
- 'STYLE',
73
- 'TITLE',
74
- 'NOSCRIPT',
75
- 'TEMPLATE'
76
- ];
77
- // For each tag name:
78
- ucTagNames.forEach(tagName => {
79
- // If it is invalid:
80
- if (! validTagNames.includes(tagName)) {
81
- // Add this to the result.
82
- data.total++;
83
- data.badTagNames.push(tagName);
84
- }
85
- });
86
- // If there are any instances:
87
- if (data.total) {
88
- // Add a summary instance.
89
- standardInstances.push({
90
- ruleID: 'headEl',
91
- what: `Invalid elements within the head: ${data.badTagNames.join(', ')}`,
92
- ordinalSeverity: 2,
93
- count: data.total,
94
- location: {
95
- doc: '',
96
- type: '',
97
- spec: ''
98
- },
99
- excerpt: ''
100
- });
43
+ // Get the tag names of the elements in the head, even if the head tags are omitted.
44
+ const headElTagNames = await page.evaluate(() => {
45
+ const head = document.head;
46
+ const headChildren = head.children;
47
+ const tagNames = [];
48
+ for (const child of headChildren) {
49
+ tagNames.push(child.tagName);
50
+ }
51
+ return tagNames;
52
+ });
53
+ const validTagNames = [
54
+ 'BASE',
55
+ 'LINK',
56
+ 'META',
57
+ 'SCRIPT',
58
+ 'STYLE',
59
+ 'TITLE',
60
+ 'NOSCRIPT',
61
+ 'TEMPLATE'
62
+ ];
63
+ // For each head child:
64
+ headElTagNames.forEach(tagName => {
65
+ // If it is invalid:
66
+ if (! validTagNames.includes(tagName)) {
67
+ // Add its tag name to the result.
68
+ data.total++;
69
+ data.badTagNames.push(tagName);
101
70
  }
102
- totals = [0, 0, data.total, 0];
71
+ });
72
+ // If there are any instances:
73
+ if (data.total) {
74
+ // Add a summary instance.
75
+ standardInstances.push({
76
+ ruleID: 'headEl',
77
+ what: `Invalid elements within the head: ${data.badTagNames.join(', ')}`,
78
+ ordinalSeverity: 2,
79
+ count: data.total,
80
+ location: {
81
+ doc: '',
82
+ type: '',
83
+ spec: ''
84
+ },
85
+ excerpt: ''
86
+ });
103
87
  }
88
+ totals = [0, 0, data.total, 0];
104
89
  // Return the data.
105
90
  return {
106
91
  data,