pagean 7.0.0 → 8.0.0

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
@@ -282,8 +282,10 @@ pagean:
282
282
  stage: test
283
283
  before_script:
284
284
  # Start static server in test cases directory, discarding any console output,
285
- # and wait until the server is running
286
- - http-server ./tests/test-cases > /dev/null 2>&1 & wait-on http://localhost:8080
285
+ # and wait until the server is running. Have wait-on check by IP based on DNS
286
+ # change in Node 17 and issues with it resolving `localhost`. Pagean is able
287
+ # to resolve localhost with no issue, see example in static-server.pageanrc.json.
288
+ - http-server ./tests/test-cases > /dev/null 2>&1 & wait-on http://127.0.0.1:8080
287
289
  script:
288
290
  - pagean -c static-server.pageanrc.json
289
291
  artifacts:
package/index.js CHANGED
@@ -15,8 +15,8 @@ const { createLinkChecker } = require('./lib/link-utils');
15
15
  /**
16
16
  * Executes Pagean tests as specified in config and reports results.
17
17
  *
18
- * @static
19
18
  * @param {object} config The Pagean test configuration.
19
+ * @static
20
20
  */
21
21
  // eslint-disable-next-line max-lines-per-function
22
22
  const executeAllTests = async (config) => {
package/lib/config.js CHANGED
@@ -51,8 +51,8 @@ const consolidateTestSettings = (
51
51
  globalSettings,
52
52
  urlSettings
53
53
  ) => {
54
- const sanitizedGlobalSettings = globalSettings ? globalSettings : {};
55
- const sanitizedUrlSettings = urlSettings ? urlSettings : {};
54
+ const sanitizedGlobalSettings = globalSettings || {};
55
+ const sanitizedUrlSettings = urlSettings || {};
56
56
  const processedSettings = {};
57
57
  for (const key of Object.keys(defaultSettings)) {
58
58
  processedSettings[key] = {
@@ -114,9 +114,10 @@ const getConfigFromFile = (configFileName) => {
114
114
  * Loads config from file and returns consolidated config with
115
115
  * defaults where values are not specified.
116
116
  *
117
+ * @param {string} configFileName Pagean configuration file name.
118
+ * @returns {object} Consolidated Pagean configuration.
119
+ * @throws {TypeError} Throws if config file has an invalid schema.
117
120
  * @static
118
- * @param {string} configFileName Pagean configuration file name.
119
- * @returns {object} Consolidated Pagean configuration.
120
121
  */
121
122
  const processConfig = (configFileName) => {
122
123
  const config = getConfigFromFile(configFileName);
@@ -133,16 +134,16 @@ const processConfig = (configFileName) => {
133
134
  htmlHintConfig: getHtmlHintConfig(
134
135
  config.htmlhintrc || defaultHtmlHintConfigFilename
135
136
  ),
136
- reporters: config.reporters ? config.reporters : defaultConfig.reporters
137
+ reporters: config.reporters || defaultConfig.reporters
137
138
  };
138
139
  };
139
140
 
140
141
  /**
141
142
  * Lints the configuration file schema.
142
143
  *
143
- * @static
144
144
  * @param {string} configFileName Pagean configuration file name.
145
145
  * @returns {boolean} True if file has valid Pagean config schema.
146
+ * @static
146
147
  */
147
148
  const lintConfigFile = (configFileName) => {
148
149
  const config = getConfigFromFile(configFileName);
@@ -15,10 +15,10 @@ const externalFilePath = 'pagean-external-scripts';
15
15
  /**
16
16
  * Checks if the JavaScript is external to the page and should be saved.
17
17
  *
18
- * @static
19
18
  * @param {string} script The URL of the JavaScript file.
20
19
  * @param {string} page The URL of the current page.
21
20
  * @returns {boolean} True if the script is external to the page.
21
+ * @static
22
22
  */
23
23
  const shouldSaveFile = (script, page) => {
24
24
  const scriptUrl = new URL(script);
@@ -30,10 +30,10 @@ const shouldSaveFile = (script, page) => {
30
30
  * Loads the JavaScript file from the specified URL and
31
31
  * saves it to disc.
32
32
  *
33
- * @static
34
33
  * @param {string} script The URL of the JavaScript file.
35
34
  * @returns {object} An object with original script
36
35
  * URL and local file name.
36
+ * @static
37
37
  */
38
38
  const saveExternalScript = async (script) => {
39
39
  const result = { url: script };
package/lib/link-utils.js CHANGED
@@ -16,9 +16,9 @@ const timeoutSeconds = 120;
16
16
  /**
17
17
  * Enum for HTTP responses.
18
18
  *
19
- * @public
20
19
  * @readonly
21
20
  * @enum {number}
21
+ * @public
22
22
  */
23
23
  const httpResponse = Object.freeze({
24
24
  continue: 100,
@@ -31,19 +31,18 @@ const httpResponse = Object.freeze({
31
31
 
32
32
  const noRetryResponses = new Set([httpResponse.tooManyRequests]);
33
33
 
34
- /* eslint-disable jsdoc/require-description-complete-sentence */
35
34
  /**
36
35
  * Normalizes a URL (with https://www.npmjs.com/package/normalize-url).
37
36
  * Uses defaults plus the following overrides.
38
- * 1. Set default protocol to https if protocol-relative
39
- * 2. Do not remove any querystring parameters
40
- * 3. Strip hash from URL
41
- * 4. Do not strip "www." from the URL
37
+ * 1. Set default protocol to https if protocol-relative.
38
+ * 2. Do not remove any querystring parameters.
39
+ * 3. Strip hash from URL.
40
+ * 4. Do not strip "www." from the URL.
42
41
  *
43
- * @public
42
+ * @param {string} url The URL to normalize.
43
+ * @returns {string} The normalized URL.
44
44
  * @static
45
- * @param {string} url The URL to normalize.
46
- * @returns {string} The normalized URL.
45
+ * @public
47
46
  */
48
47
  const normalizeLink = (url) =>
49
48
  normalizeUrl(url, {
@@ -57,12 +56,12 @@ const normalizeLink = (url) =>
57
56
  /**
58
57
  * Checks settings to determine if the provided link should be ignored.
59
58
  *
60
- * @private
59
+ * @param {object} settings Test settings object, which may contain an
60
+ * ignoredLinks array.
61
+ * @param {string} link The link to check against the ignore list.
62
+ * @returns {boolean} True if the link should be ignored, otherwise false.
61
63
  * @static
62
- * @param {object} settings Test settings object, which may contain an
63
- * ignoredLinks array.
64
- * @param {string} link The link to check against the ignore list.
65
- * @returns {boolean} True if the link should be ignored, otherwise false.
64
+ * @private
66
65
  */
67
66
  const ignoreLink = (settings, link) =>
68
67
  settings.ignoredLinks && settings.ignoredLinks.includes(link);
@@ -71,10 +70,10 @@ const ignoreLink = (settings, link) =>
71
70
  * Checks a response to an HTTP request, either a response code or explicit error,
72
71
  * to identify any failed responses.
73
72
  *
74
- * @public
75
- * @static
76
73
  * @param {(string|number)} response The response to an HTTP request to check for failure.
77
74
  * @returns {boolean} True if failed, otherwise false.
75
+ * @static
76
+ * @public
78
77
  */
79
78
  const isFailedResponse = (response) =>
80
79
  Number.isNaN(Number(response.status)) ||
@@ -83,11 +82,11 @@ const isFailedResponse = (response) =>
83
82
  /**
84
83
  * Checks a Puppeteer page for the element specified in the hash of the provided link.
85
84
  *
86
- * @private
87
- * @static
88
85
  * @param {object} page A Puppeteer page object.
89
86
  * @param {string} link The link to check.
90
87
  * @returns {(string|number)} The link status (HTTP response code or error).
88
+ * @static
89
+ * @private
91
90
  */
92
91
  const checkSamePageLink = async (page, link) => {
93
92
  const selector = link.slice(page.url().length);
@@ -102,11 +101,11 @@ const checkSamePageLink = async (page, link) => {
102
101
  /**
103
102
  * Checks the provided link for validity by loading in a Puppeteer page.
104
103
  *
105
- * @private
106
- * @static
107
104
  * @param {object} page A Puppeteer page object.
108
105
  * @param {string} link The link to check.
109
106
  * @returns {(string|number)} The link status (HTTP response code or error).
107
+ * @static
108
+ * @private
110
109
  */
111
110
  const checkExternalPageLinkBrowser = async (page, link) => {
112
111
  let status;
@@ -127,12 +126,12 @@ const checkExternalPageLinkBrowser = async (page, link) => {
127
126
  * Checks the provided link for validity by requesting with axios. If useGet if false,
128
127
  * a HEAD request is made for efficiency. If useGet is true, a full GET request is made.
129
128
  *
130
- * @private
131
- * @static
132
129
  * @param {object} page A Puppeteer page object.
133
130
  * @param {string} link The link to check.
134
131
  * @param {boolean} [useGet] Used to identify the request method to use (HEAD or GET).
135
132
  * @returns {(string|number)} The link status (HTTP response code or error).
133
+ * @static
134
+ * @private
136
135
  */
137
136
  // eslint-disable-next-line sonarjs/cognitive-complexity -- Allow less than 10
138
137
  const checkExternalPageLink = async (page, link, useGet = false) => {
@@ -175,9 +174,9 @@ const checkExternalPageLink = async (page, link, useGet = false) => {
175
174
  * Factory function returning a linkChecker object with a {@link checkLink}
176
175
  * function that caches checked link results.
177
176
  *
178
- * @public
179
- * @static
180
177
  * @returns {object} Link checker object.
178
+ * @static
179
+ * @public
181
180
  */
182
181
  const createLinkChecker = () => {
183
182
  const checkedLinks = new Map();
@@ -187,11 +186,11 @@ const createLinkChecker = () => {
187
186
  * Checks the provided link for validity using context object for a
188
187
  * reference to the Puppeteer page and applicable settings.
189
188
  *
190
- * @public
191
189
  * @instance
192
190
  * @param {object} context A Pagean test context object.
193
191
  * @param {string} link The link to check.
194
192
  * @returns {(string|number)} The link status (HTTP response code or error).
193
+ * @public
195
194
  */
196
195
  // eslint-disable-next-line sonarjs/cognitive-complexity
197
196
  checkLink: async (context, link) => {
package/lib/logger.js CHANGED
@@ -21,9 +21,9 @@ const nullFunction = () => {};
21
21
  * Factory function that creates an instance of a
22
22
  * logger object to manage logging functions.
23
23
  *
24
- * @static
25
24
  * @param {object} config Pagean configuration.
26
25
  * @returns {object} A logger object.
26
+ * @static
27
27
  */
28
28
  // eslint-disable-next-line max-lines-per-function
29
29
  module.exports = (config) => {
@@ -13,9 +13,9 @@
13
13
  color: #333333;
14
14
  font-family: Arial, Helvetica, sans-serif;
15
15
  font-size: 0.85rem;
16
- padding: 1rem;
17
16
  margin: auto;
18
17
  max-width: 1000px;
18
+ padding: 1rem;
19
19
  }
20
20
 
21
21
  ul {
@@ -31,9 +31,9 @@
31
31
  }
32
32
 
33
33
  h1 {
34
+ margin: 1rem 0 0.75rem;
34
35
  margin-block: 0;
35
36
  margin-inline: 0;
36
- margin: 1rem 0 0.75rem;
37
37
  }
38
38
 
39
39
  h2 {
package/lib/reporter.js CHANGED
@@ -41,9 +41,9 @@ const reporterTypes = Object.freeze({
41
41
  /**
42
42
  * Outputs the given results with specified reporters.
43
43
  *
44
- * @static
45
44
  * @param {object} results Consolidated Pagean results for a all tests.
46
45
  * @param {string[]} reporters The configured reporters.
46
+ * @static
47
47
  */
48
48
  const saveReports = (results, reporters) => {
49
49
  if (reporters.includes(reporterTypes.json)) {
@@ -48,9 +48,9 @@ const processErrorParameters = (error) => {
48
48
  * Generates formatted schema strings for output to stdout for all
49
49
  * schema errors.
50
50
  *
51
- * @static
52
51
  * @param {object[]} errors Array of Pagean config schema errors.
53
52
  * @returns {string[]} Array of formatted schema error strings.
53
+ * @static
54
54
  */
55
55
  const formatErrors = (errors) => {
56
56
  const margin = 2;
package/lib/test-utils.js CHANGED
@@ -26,12 +26,12 @@ const getTestSettings = (testSettingProperty, urlSettings) => {
26
26
  * test-specific settings from configuration, passing the test context,
27
27
  * and logging results.
28
28
  *
29
- * @static
30
29
  * @param {string} name The name of the test.
31
30
  * @param {Function} testFunction The test function to be executed.
32
31
  * @param {object} testContext The test execution context.
33
32
  * @param {string} testSettingProperty The name of the config property
34
33
  * with settings for the current test.
34
+ * @static
35
35
  */
36
36
  const pageanTest = async (
37
37
  name,
package/lib/tests.js CHANGED
@@ -16,8 +16,8 @@ const msPerSec = 1000;
16
16
  /**
17
17
  * Tests the current page for the existence of a horizontal scroll bar.
18
18
  *
19
- * @static
20
19
  * @param {object} context Test execution context.
20
+ * @static
21
21
  */
22
22
  const horizontalScrollbarTest = async (context) => {
23
23
  await pageanTest(
@@ -44,8 +44,8 @@ const horizontalScrollbarTest = async (context) => {
44
44
  /**
45
45
  * Tests the current page for any console output.
46
46
  *
47
- * @static
48
47
  * @param {object} context Test execution context.
48
+ * @static
49
49
  */
50
50
  const consoleOutputTest = (context) => {
51
51
  pageanTest(
@@ -71,8 +71,8 @@ const consoleOutputTest = (context) => {
71
71
  /**
72
72
  * Tests the current page for any console errors.
73
73
  *
74
- * @static
75
74
  * @param {object} context Test execution context.
75
+ * @static
76
76
  */
77
77
  const consoleErrorTest = (context) => {
78
78
  pageanTest(
@@ -101,8 +101,8 @@ const consoleErrorTest = (context) => {
101
101
  /**
102
102
  * Tests the current page for any HTML lint issues.
103
103
  *
104
- * @static
105
104
  * @param {object} context Test execution context.
105
+ * @static
106
106
  */
107
107
  const renderedHtmlTest = async (context) => {
108
108
  await pageanTest(
@@ -133,8 +133,8 @@ const renderedHtmlTest = async (context) => {
133
133
  /**
134
134
  * Tests the current page for load time.
135
135
  *
136
- * @static
137
136
  * @param {object} context Test execution context.
137
+ * @static
138
138
  */
139
139
  // eslint-disable-next-line max-lines-per-function
140
140
  const pageLoadTimeTest = async (context) => {
@@ -176,8 +176,8 @@ const pageLoadTimeTest = async (context) => {
176
176
  * Tests the current page for any external JavaScript files and
177
177
  * downloads the files for further analysis.
178
178
  *
179
- * @static
180
179
  * @param {object} context Test execution context.
180
+ * @static
181
181
  */
182
182
  // eslint-disable-next-line max-lines-per-function
183
183
  const externalScriptTest = async (context) => {
@@ -220,8 +220,8 @@ const externalScriptTest = async (context) => {
220
220
  /**
221
221
  * Tests the current page for any broken links (external or within the page).
222
222
  *
223
- * @static
224
223
  * @param {object} context Test execution context.
224
+ * @static
225
225
  */
226
226
  // eslint-disable-next-line max-lines-per-function
227
227
  const brokenLinkTest = async (context) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pagean",
3
- "version": "7.0.0",
3
+ "version": "8.0.0",
4
4
  "description": "Pagean is a web page analysis tool designed to automate tests requiring web pages to be loaded in a browser window (e.g. horizontal scrollbar, console errors)",
5
5
  "bin": {
6
6
  "pagean": "./bin/pagean.js",
@@ -51,28 +51,28 @@
51
51
  },
52
52
  "homepage": "https://gitlab.com/gitlab-ci-utils/pagean",
53
53
  "devDependencies": {
54
- "@aarongoldenthal/eslint-config-standard": "^15.0.0",
55
- "@aarongoldenthal/stylelint-config-standard": "^9.0.0",
56
- "bin-tester": "^2.0.1",
57
- "eslint": "^8.17.0",
58
- "jest": "^28.1.1",
59
- "jest-junit": "^13.2.0",
60
- "markdownlint-cli": "^0.31.1",
61
- "prettier": "^2.7.0",
54
+ "@aarongoldenthal/eslint-config-standard": "^17.0.1",
55
+ "@aarongoldenthal/stylelint-config-standard": "^11.2.1",
56
+ "bin-tester": "^3.0.0",
57
+ "eslint": "^8.26.0",
58
+ "jest": "^29.2.2",
59
+ "jest-junit": "^14.0.1",
60
+ "markdownlint-cli": "^0.32.2",
61
+ "prettier": "^2.7.1",
62
62
  "strip-ansi": "^6.0.1",
63
- "stylelint": "^14.9.1"
63
+ "stylelint": "^14.14.0"
64
64
  },
65
65
  "dependencies": {
66
66
  "ajv": "^8.11.0",
67
67
  "ajv-errors": "^3.0.0",
68
- "axios": "^0.27.2",
69
- "ci-logger": "^5.0.0",
70
- "commander": "^9.3.0",
68
+ "axios": "^1.1.3",
69
+ "ci-logger": "^5.1.0",
70
+ "commander": "^9.4.1",
71
71
  "handlebars": "^4.7.7",
72
72
  "htmlhint": "^1.1.4",
73
- "kleur": "^4.1.4",
73
+ "kleur": "^4.1.5",
74
74
  "normalize-url": "^6.1.0",
75
75
  "protocolify": "^3.0.0",
76
- "puppeteer": "^14.4.0"
76
+ "puppeteer": "^19.2.0"
77
77
  }
78
78
  }