pagean 10.0.2 → 10.1.1

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/index.js +42 -3
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -12,6 +12,47 @@ const testReporter = require('./lib/reporter');
12
12
  const { ...testFunctions } = require('./lib/tests');
13
13
  const { createLinkChecker } = require('./lib/link-utils');
14
14
 
15
+ /**
16
+ * @typedef {object} PageOptions
17
+ * @property {number} retryCount - The number of times to retry navigation.
18
+ * @property {number} timeout - The timeout for navigation.
19
+ */
20
+ const defaultPageOptions = {
21
+ retryCount: 2,
22
+ timeout: 60_000
23
+ };
24
+
25
+ /**
26
+ * Opens the specified URL in the given page, with retry logic.
27
+ *
28
+ * @param {string} page The puppeteer page object.
29
+ * @param {string} url The URL to navigate to.
30
+ * @param {PageOptions} options The options for navigating to the URL.
31
+ * @static
32
+ * @private
33
+ */
34
+ const gotoPage = async (page, url, options) => {
35
+ let retryCount = 0;
36
+ while (retryCount < options.retryCount) {
37
+ try {
38
+ /* eslint-disable no-await-in-loop -- loop for retry only */
39
+ // User provided test input required.
40
+ // nosemgrep: puppeteer-goto-injection
41
+ await page.goto(url, {
42
+ timeout: options.timeout,
43
+ waitUntil: 'domcontentloaded'
44
+ });
45
+ /* eslint-enable no-await-in-loop -- loop for retry only */
46
+ break;
47
+ } catch {
48
+ retryCount++;
49
+ console.error(
50
+ `Failed to navigate to ${url}. Retrying (${retryCount}/${options.retryCount})...`
51
+ );
52
+ }
53
+ }
54
+ };
55
+
15
56
  /* eslint-disable no-await-in-loop, max-lines-per-function --
16
57
  no-await-in-loop - tests are deliberately performed synchronously,
17
58
  max-lines-per-function - allowed to test executor */
@@ -38,9 +79,7 @@ const executeAllTests = async (config) => {
38
79
  type: message.type()
39
80
  })
40
81
  );
41
- // User provided test input required.
42
- // nosemgrep: puppeteer-goto-injection
43
- await page.goto(testUrl.url, { waitUntil: 'load' });
82
+ await gotoPage(page, testUrl.url, defaultPageOptions);
44
83
 
45
84
  const testContext = {
46
85
  consoleLog,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pagean",
3
- "version": "10.0.2",
3
+ "version": "10.1.1",
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,7 +51,7 @@
51
51
  },
52
52
  "homepage": "https://gitlab.com/gitlab-ci-utils/pagean",
53
53
  "devDependencies": {
54
- "@aarongoldenthal/eslint-config-standard": "^27.0.0",
54
+ "@aarongoldenthal/eslint-config-standard": "^27.0.1",
55
55
  "@aarongoldenthal/stylelint-config-standard": "^17.0.1",
56
56
  "bin-tester": "^5.0.0",
57
57
  "eslint": "^8.57.0",
@@ -60,7 +60,7 @@
60
60
  "markdownlint-cli2": "^0.12.1",
61
61
  "prettier": "^3.2.5",
62
62
  "strip-ansi": "^6.0.1",
63
- "stylelint": "^16.2.1"
63
+ "stylelint": "^16.3.1"
64
64
  },
65
65
  "dependencies": {
66
66
  "ajv": "^8.12.0",
@@ -74,7 +74,7 @@
74
74
  "kleur": "^4.1.5",
75
75
  "normalize-url": "^6.1.0",
76
76
  "protocolify": "^3.0.0",
77
- "puppeteer": "^22.5.0",
77
+ "puppeteer": "^22.6.2",
78
78
  "xml2js": "^0.6.2"
79
79
  }
80
80
  }