pagean 8.0.2 → 8.0.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 +2 -1
- package/lib/external-file-utils.js +5 -1
- package/lib/link-utils.js +10 -1
- package/package.json +14 -13
package/README.md
CHANGED
|
@@ -118,7 +118,8 @@ The broken link test checks for broken links on the page. It checks any `<a>` ta
|
|
|
118
118
|
|
|
119
119
|
- For links within the page, this test checks for existence of the element on the page, passing if the element exists and failing otherwise (and passing for cases that are always valid, e.g. `#` or `#top` for the current page). It does not check the visibility of the element. Failing tests return a response of "#element Not Found" (where `#element` identifies the specific element).
|
|
120
120
|
- For links to other pages, the test tries to most efficiently confirm whether the target link is valid. It first makes a `HEAD` request for that URL and checks the response. If an erroneous response is returned (>= 400 with no execution error) and not code 429 (Too Many Requests), the request is retried with a `GET` request. The test passes for HTTP responses < 400 and fails otherwise (if HTTP response is >= 400 or another error occurs).
|
|
121
|
-
- This can result in false failure indications, specifically for `file
|
|
121
|
+
- This can result in false failure indications, specifically for `file:` links (`404` or `ECONNREFUSED`) or where the browser passes a domain identity with the request (page loads when tested, but `401` response for links to that page). For these cases, or other false failures, the test configuration allows a boolean `checkWithBrowser` option that will instead check links by loading the target in the browser (via `puppeteer`). Note this can increase test execution time, in some cases substantially, due to the time to open a new browser tab and plus load the page and all assets.
|
|
122
|
+
- Note that `file:` links can only be tested with the `checkWithBrowser` option.
|
|
122
123
|
- If the link to another page includes a hash it is removed prior to checking. The test in this case is confirming a valid link, not that the element exists, which is only done for the current page.
|
|
123
124
|
- The test configuration allows an `ignoredLinks` array listing link URLs to ignore for this test. Note this only applies to links to other pages, not links within the page, which are always checked.
|
|
124
125
|
- To optimize performance, link test results are cached and those links are not re-tested for the entire test run (across all tested URLs). The test configuration allows a boolean `ignoreDuplicates` option that can be set to `false` to bypass this behavior and re-test all links. The results for any failed links are included in the reports in any case.
|
|
@@ -21,9 +21,13 @@ const externalFilePath = 'pagean-external-scripts';
|
|
|
21
21
|
* @static
|
|
22
22
|
*/
|
|
23
23
|
const shouldSaveFile = (script, page) => {
|
|
24
|
+
const validProtocols = ['http:', 'https:'];
|
|
24
25
|
const scriptUrl = new URL(script);
|
|
25
26
|
const pageUrl = new URL(page);
|
|
26
|
-
return
|
|
27
|
+
return (
|
|
28
|
+
scriptUrl.host !== pageUrl.host &&
|
|
29
|
+
validProtocols.includes(scriptUrl.protocol)
|
|
30
|
+
);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
/**
|
package/lib/link-utils.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
const https = require('https');
|
|
10
10
|
const axios = require('axios');
|
|
11
11
|
const normalizeUrl = require('normalize-url');
|
|
12
|
+
const cssesc = require('cssesc');
|
|
12
13
|
|
|
13
14
|
const msPerSec = 1000;
|
|
14
15
|
const timeoutSeconds = 120;
|
|
@@ -94,7 +95,11 @@ const checkSamePageLink = async (page, link) => {
|
|
|
94
95
|
return httpResponse.ok;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
const
|
|
98
|
+
const escapedSelector = `#${cssesc(selector.slice(1), {
|
|
99
|
+
isIdentifier: true
|
|
100
|
+
})}`;
|
|
101
|
+
const element = await page.$(escapedSelector);
|
|
102
|
+
// const element = await page.$(selector);
|
|
98
103
|
return element ? httpResponse.ok : `${selector} Not Found`;
|
|
99
104
|
};
|
|
100
105
|
|
|
@@ -135,6 +140,10 @@ const checkExternalPageLinkBrowser = async (page, link) => {
|
|
|
135
140
|
*/
|
|
136
141
|
// eslint-disable-next-line sonarjs/cognitive-complexity -- Allow less than 10
|
|
137
142
|
const checkExternalPageLink = async (page, link, useGet = false) => {
|
|
143
|
+
if (link.startsWith('file:')) {
|
|
144
|
+
return 'Cannot check "file:" URLs';
|
|
145
|
+
}
|
|
146
|
+
|
|
138
147
|
// Get user-agent from page so axios uses the same value for requesting links
|
|
139
148
|
const userAgent = await page.evaluate('navigator.userAgent');
|
|
140
149
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pagean",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.4",
|
|
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",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"prettier-fix": "prettier --write .",
|
|
19
19
|
"start": "node ./bin/pagean.js",
|
|
20
20
|
"start-lint": "node ./bin/pageanrc-lint.js",
|
|
21
|
-
"start-lint-all": "npm run start-lint && npm run start-lint
|
|
21
|
+
"start-lint-all": "npm run start-lint && npm run start-lint static-server.pageanrc.json && npm run start-lint ./lib/default-config.json",
|
|
22
22
|
"test": "jest --ci --config jest.config.json"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
26
|
-
"url": "
|
|
26
|
+
"url": "https://gitlab.com/gitlab-ci-utils/pagean.git"
|
|
27
27
|
},
|
|
28
28
|
"keywords": [
|
|
29
29
|
"analysis",
|
|
@@ -51,28 +51,29 @@
|
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://gitlab.com/gitlab-ci-utils/pagean",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@aarongoldenthal/eslint-config-standard": "^
|
|
55
|
-
"@aarongoldenthal/stylelint-config-standard": "^
|
|
56
|
-
"bin-tester": "^3.0.
|
|
57
|
-
"eslint": "^8.
|
|
58
|
-
"jest": "^29.3
|
|
54
|
+
"@aarongoldenthal/eslint-config-standard": "^20.0.0",
|
|
55
|
+
"@aarongoldenthal/stylelint-config-standard": "^13.0.1",
|
|
56
|
+
"bin-tester": "^3.0.1",
|
|
57
|
+
"eslint": "^8.34.0",
|
|
58
|
+
"jest": "^29.4.3",
|
|
59
59
|
"jest-junit": "^15.0.0",
|
|
60
60
|
"markdownlint-cli": "^0.33.0",
|
|
61
|
-
"prettier": "^2.8.
|
|
61
|
+
"prettier": "^2.8.4",
|
|
62
62
|
"strip-ansi": "^6.0.1",
|
|
63
|
-
"stylelint": "^
|
|
63
|
+
"stylelint": "^15.2.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"ajv": "^8.12.0",
|
|
67
67
|
"ajv-errors": "^3.0.0",
|
|
68
|
-
"axios": "^1.
|
|
69
|
-
"ci-logger": "^5.1.
|
|
68
|
+
"axios": "^1.3.3",
|
|
69
|
+
"ci-logger": "^5.1.1",
|
|
70
70
|
"commander": "^10.0.0",
|
|
71
|
+
"cssesc": "^3.0.0",
|
|
71
72
|
"handlebars": "^4.7.7",
|
|
72
73
|
"htmlhint": "^1.1.4",
|
|
73
74
|
"kleur": "^4.1.5",
|
|
74
75
|
"normalize-url": "^6.1.0",
|
|
75
76
|
"protocolify": "^3.0.0",
|
|
76
|
-
"puppeteer": "^19.
|
|
77
|
+
"puppeteer": "^19.7.1"
|
|
77
78
|
}
|
|
78
79
|
}
|