pagean 6.0.7 → 7.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 +104 -110
- package/bin/pagean.js +14 -7
- package/bin/pageanrc-lint.js +14 -13
- package/docs/upgrade-guide.md +26 -26
- package/index.js +18 -7
- package/lib/config.js +35 -13
- package/lib/default-config.json +2 -8
- package/lib/{externalFileUtils.js → external-file-utils.js} +7 -4
- package/lib/{linkUtils.js → link-utils.js} +36 -35
- package/lib/logger.js +7 -3
- package/lib/reporter.js +4 -2
- package/lib/{schemaErrors.js → schema-errors.js} +26 -10
- package/lib/{testUtils.js → test-utils.js} +20 -8
- package/lib/tests.js +194 -94
- package/package.json +25 -21
- package/schemas/pageanrc.schema.json +3 -11
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Pagean
|
|
2
2
|
|
|
3
|
-
Pagean is a web page analysis tool designed to automate tests requiring web pages to be loaded in a browser window (e.g. 404 error loading an external resource, page renders with horizontal scrollbars).
|
|
3
|
+
Pagean is a web page analysis tool designed to automate tests requiring web pages to be loaded in a browser window (e.g. 404 error loading an external resource, page renders with horizontal scrollbars). The specific tests are outlined below, but are all general tests that do not include any page-specific logic.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -27,57 +27,55 @@ Options:
|
|
|
27
27
|
-h, --help display help for command
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
-
Pagean requires a configuration file named, which can be specified via the CLI as detailed above, or use the default file `.pageanrc.json` in the project root.
|
|
30
|
+
Pagean requires a configuration file named, which can be specified via the CLI as detailed above, or use the default file `.pageanrc.json` in the project root. This file provides the URLs to be tested and options to configure the tests and reports. Details on the available tests and the configuration file format are provided below.
|
|
31
31
|
|
|
32
32
|
## Test Cases
|
|
33
33
|
|
|
34
|
-
The tests use [Puppeteer](https://github.com/GoogleChrome/puppeteer) to launch a headless Chrome browser.
|
|
34
|
+
The tests use [Puppeteer](https://github.com/GoogleChrome/puppeteer) to launch a headless Chrome browser. The URLs defined in the configuration file are each loaded once, and after page load the applicable tests are executed. Test results are `passed` or `failed`, but can be configured to report `warning` instead of failure. Only a `failed` test will cause the test process to fail and exit with an error code (a `warning` will not).
|
|
35
35
|
|
|
36
36
|
### Horizontal Scrollbar Test
|
|
37
37
|
|
|
38
|
-
The horizontal scrollbar test fails if the rendered page has a horizontal scrollbar.
|
|
38
|
+
The horizontal scrollbar test fails if the rendered page has a horizontal scrollbar. If a specific browser viewport size is desired for this test, that can be configured in the `puppeteerLaunchOptions`.
|
|
39
39
|
|
|
40
40
|
### Console Output Test
|
|
41
41
|
|
|
42
|
-
The console output test fails if any output is written to the browser console.
|
|
42
|
+
The console output test fails if any output is written to the browser console. An array is included in the report with all entries, as shown below:
|
|
43
43
|
|
|
44
44
|
```json
|
|
45
45
|
[
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
"_text": "Failed to load resource: net::ERR_NAME_NOT_RESOLVED",
|
|
53
|
-
"_type": "error"
|
|
46
|
+
{
|
|
47
|
+
"type": "error",
|
|
48
|
+
"text": "Failed to load resource: net::ERR_NAME_NOT_RESOLVED",
|
|
49
|
+
"location": {
|
|
50
|
+
"url": "https://this.url.does.not.exist/file.js"
|
|
54
51
|
}
|
|
52
|
+
}
|
|
55
53
|
]
|
|
56
54
|
```
|
|
57
55
|
|
|
58
56
|
### Console Error Test
|
|
59
57
|
|
|
60
|
-
The console error test fails if any error is written to the browser console, but is otherwise the same as the console output test.
|
|
58
|
+
The console error test fails if any error is written to the browser console, but is otherwise the same as the console output test. This separation allows for testing for console errors, but allowing any other console output.
|
|
61
59
|
|
|
62
60
|
### Rendered HTML Test
|
|
63
61
|
|
|
64
|
-
The rendered HTML test is intended for cases where content is dynamically created prior to page load (i.e. the `load` event firing).
|
|
62
|
+
The rendered HTML test is intended for cases where content is dynamically created prior to page load (i.e. the `load` event firing). The rendered HTML is returned and checked with [HTML Hint](https://www.npmjs.com/package/htmlhint) and the test fails if any issues are found. An array is included in the report with all HTML Hint issues, as shown below:
|
|
65
63
|
|
|
66
64
|
```json
|
|
67
65
|
[
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
66
|
+
{
|
|
67
|
+
"col": 9,
|
|
68
|
+
"evidence": " <div id=\"div1\"></div>",
|
|
69
|
+
"line": 6,
|
|
70
|
+
"message": "The id value [ div1 ] must be unique.",
|
|
71
|
+
"raw": " id=\"div1\"",
|
|
72
|
+
"rule": {
|
|
73
|
+
"description": "The value of id attributes must be unique.",
|
|
74
|
+
"id": "id-unique",
|
|
75
|
+
"link": "https://github.com/thedaviddias/HTMLHint/wiki/id-unique"
|
|
76
|
+
},
|
|
77
|
+
"type": "error"
|
|
78
|
+
}
|
|
81
79
|
]
|
|
82
80
|
```
|
|
83
81
|
|
|
@@ -87,28 +85,28 @@ Note: This test may not find some errors in the original HTML that are removed/r
|
|
|
87
85
|
|
|
88
86
|
### Page Load Time Test
|
|
89
87
|
|
|
90
|
-
The page load time test fails if the page load time (from start through the `load` event) exceeds the defined threshold in the configuration file (or the default of 2 seconds).
|
|
88
|
+
The page load time test fails if the page load time (from start through the `load` event) exceeds the defined threshold in the configuration file (or the default of 2 seconds). The actual load time is included in the report. Tests will time out at twice the page load time threshold.
|
|
91
89
|
|
|
92
90
|
### External Script Test
|
|
93
91
|
|
|
94
|
-
The external script test is intended to identify any externally loaded javascript files (e.g. loaded from a CDN) and aggregate those files so they can undergo further analysis (e.g. dependency vulnerability scanning). The test is included here since these tests load fully rendered pages, therefore allowing the aggregation of this data for pages generated using any language or framework.
|
|
92
|
+
The external script test is intended to identify any externally loaded javascript files (e.g. loaded from a CDN) and aggregate those files so they can undergo further analysis (e.g. dependency vulnerability scanning). The test is included here since these tests load fully rendered pages, therefore allowing the aggregation of this data for pages generated using any language or framework. By default the test returns a warning if the page includes any javascript files loaded from a different domain than the page (although this could be overridden to fail instead via setting `failWarn: false`, see the Configuration section below). These files are then downloaded and saved in the "pagean-external-files" directory in the project root. Subdirectories are created for each domain, then following the URL path. For example, the following script...
|
|
95
93
|
|
|
96
94
|
```html
|
|
97
95
|
<script src="https://bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
|
|
98
96
|
```
|
|
99
97
|
|
|
100
|
-
...will be saved as `./bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js`.
|
|
98
|
+
...will be saved as `./bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js`. The `data` array in the test report includes the original file URL and the local saved filename or applicable error, as shown below.
|
|
101
99
|
|
|
102
100
|
```json
|
|
103
101
|
[
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
102
|
+
{
|
|
103
|
+
"url": "https://code.jquery.com/jquery-3.4.1.slim.min.js",
|
|
104
|
+
"localFile": "pagean-external-scripts/code.jquery.com/jquery-3.4.1.slim.min.js"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"url": "http://bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js",
|
|
108
|
+
"error": "Request failed with status code 404"
|
|
109
|
+
}
|
|
112
110
|
]
|
|
113
111
|
```
|
|
114
112
|
|
|
@@ -118,8 +116,8 @@ Each external script is saved only once, but will be reported on any page where
|
|
|
118
116
|
|
|
119
117
|
The broken link test checks for broken links on the page. It checks any `<a>` tag on the page with `href` pointing to another location on the current page or another page (i.e. only `http(s)` or `file` protocols).
|
|
120
118
|
|
|
121
|
-
- 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).
|
|
122
|
-
- 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.
|
|
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
|
+
- 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).
|
|
123
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.
|
|
124
122
|
- 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.
|
|
125
123
|
- 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.
|
|
@@ -129,18 +127,18 @@ For any failing test, the `data` array in the test report includes the original
|
|
|
129
127
|
|
|
130
128
|
```json
|
|
131
129
|
[
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
130
|
+
{
|
|
131
|
+
"href": "https://about.gitlab.com/not-found",
|
|
132
|
+
"status": 404
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
"href": "http://localhost:8080/brokenLinks.html#notlinked",
|
|
136
|
+
"status": "#notlinked Not Found"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"href": "https://this.url.does.not.exist/",
|
|
140
|
+
"status": "ENOTFOUND"
|
|
141
|
+
}
|
|
144
142
|
]
|
|
145
143
|
```
|
|
146
144
|
|
|
@@ -161,19 +159,19 @@ Complete reports for the example case in this project (the tests as specified in
|
|
|
161
159
|
|
|
162
160
|
## Configuration
|
|
163
161
|
|
|
164
|
-
Pagean looks for a configuration file as specified via the CLI, or defaults to a file named `.pageanrc.json` in the project root.
|
|
162
|
+
Pagean looks for a configuration file as specified via the CLI, or defaults to a file named `.pageanrc.json` in the project root. If the configuration file is not found, is not valid JSON, or does not contain any URLs to check the job will fail.
|
|
165
163
|
|
|
166
164
|
Below is an example `.pageanrc.json` file, which is broken into six major properties:
|
|
167
165
|
|
|
168
166
|
- `htmlhintrc`: An optional path to an htmlhintrc file to be used in the rendered HTML test
|
|
169
167
|
- `project`: An optional name of the project, which is included in HTML and JSON reports.
|
|
170
|
-
- `puppeteerLaunchOptions`: An optional set of options to pass to Puppeteer on launch.
|
|
171
|
-
- `reporters`:
|
|
168
|
+
- `puppeteerLaunchOptions`: An optional set of options to pass to Puppeteer on launch. There are no default options. The complete list of available options can be found at https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions.
|
|
169
|
+
- `reporters`: An optional array of reporters indicating the test reports that should be provided. There are three possible options - `cli`, `html`, and `json`. The `cli` option reports all test details to the console, but the final results summary is always output (even with `cli` disabled). If `reporters` is specified, at least one reporter must be included. The default value, as specified below, is all three reporters enabled.
|
|
172
170
|
- `settings`: These settings enable/disable or configure tests, and are applied to all tests overriding the default values.
|
|
173
|
-
- The shorthand notation allows easy enabling/disabling of tests. In this format the test name is given with a boolean value to enable or disable the test.
|
|
171
|
+
- The shorthand notation allows easy enabling/disabling of tests. In this format the test name is given with a boolean value to enable or disable the test. In this case any other test-specific settings use the default values.
|
|
174
172
|
- The longhand version includes an object for each test. Every test includes two possible properties (some tests include additional settings):
|
|
175
173
|
- `enabled`: A boolean value to enable/disable the test, and some tests include additional settings (default `true` for all tests).
|
|
176
|
-
- `failWarn`: A boolean value causing a failed test to report a warning instead of failure.
|
|
174
|
+
- `failWarn`: A boolean value causing a failed test to report a warning instead of failure. A warning result will not cause the test process to fail (exit with an error code). The default value for all tests is `false` except the `externalScriptTest`, as shown below.
|
|
177
175
|
|
|
178
176
|
The shorthand:
|
|
179
177
|
|
|
@@ -196,67 +194,63 @@ is equivalent to the longhand:
|
|
|
196
194
|
|
|
197
195
|
All available settings with the default values are shown below.
|
|
198
196
|
|
|
199
|
-
- `urls`: An array of URLs to be tested, which must contain at least one value.
|
|
197
|
+
- `urls`: An array of URLs to be tested, which must contain at least one value. Each array entry can either be a URL string, or an object that contains a `url` string and an optional `settings` object. This object can contain any of the `settings` values identified above and will override that setting for testing that URL. The `url` string can be either an actual URL or a local file, as shown in the example below.
|
|
200
198
|
|
|
201
199
|
```json
|
|
202
200
|
{
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
"puppeteerLaunchOptions": {
|
|
202
|
+
"args": ["--no-sandbox"]
|
|
203
|
+
},
|
|
204
|
+
"reporters": ["cli", "html", "json"],
|
|
205
|
+
"settings": {
|
|
206
|
+
"horizontalScrollbarTest": {
|
|
207
|
+
"enabled": true,
|
|
208
|
+
"failWarn": false
|
|
209
|
+
},
|
|
210
|
+
"consoleOutputTest": {
|
|
211
|
+
"enabled": true,
|
|
212
|
+
"failWarn": false
|
|
213
|
+
},
|
|
214
|
+
"consoleErrorTest": {
|
|
215
|
+
"enabled": true,
|
|
216
|
+
"failWarn": false
|
|
205
217
|
},
|
|
206
|
-
"
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
"json"
|
|
210
|
-
],
|
|
211
|
-
"settings": {
|
|
212
|
-
"horizontalScrollbarTest": {
|
|
213
|
-
"enabled": true,
|
|
214
|
-
"failWarn": false
|
|
215
|
-
},
|
|
216
|
-
"consoleOutputTest": {
|
|
217
|
-
"enabled": true,
|
|
218
|
-
"failWarn": false
|
|
219
|
-
},
|
|
220
|
-
"consoleErrorTest": {
|
|
221
|
-
"enabled": true,
|
|
222
|
-
"failWarn": false
|
|
223
|
-
},
|
|
224
|
-
"renderedHtmlTest": {
|
|
225
|
-
"enabled": true,
|
|
226
|
-
"failWarn": false
|
|
227
|
-
},
|
|
228
|
-
"pageLoadTimeTest": {
|
|
229
|
-
"enabled": true,
|
|
230
|
-
"failWarn": false,
|
|
231
|
-
"pageLoadTimeThreshold": 2
|
|
232
|
-
},
|
|
233
|
-
"externalScriptTest": {
|
|
234
|
-
"enabled": true,
|
|
235
|
-
"failWarn": true
|
|
236
|
-
},
|
|
237
|
-
"brokenLinkTest": {
|
|
238
|
-
"enabled": true,
|
|
239
|
-
"failWarn": false,
|
|
240
|
-
"checkWithBrowser": false,
|
|
241
|
-
"ignoreDuplicates": true,
|
|
242
|
-
"ignoredLinks": []
|
|
243
|
-
}
|
|
218
|
+
"renderedHtmlTest": {
|
|
219
|
+
"enabled": true,
|
|
220
|
+
"failWarn": false
|
|
244
221
|
},
|
|
245
|
-
"
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
222
|
+
"pageLoadTimeTest": {
|
|
223
|
+
"enabled": true,
|
|
224
|
+
"failWarn": false,
|
|
225
|
+
"pageLoadTimeThreshold": 2
|
|
226
|
+
},
|
|
227
|
+
"externalScriptTest": {
|
|
228
|
+
"enabled": true,
|
|
229
|
+
"failWarn": true
|
|
230
|
+
},
|
|
231
|
+
"brokenLinkTest": {
|
|
232
|
+
"enabled": true,
|
|
233
|
+
"failWarn": false,
|
|
234
|
+
"checkWithBrowser": false,
|
|
235
|
+
"ignoreDuplicates": true,
|
|
236
|
+
"ignoredLinks": []
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
"urls": [
|
|
240
|
+
"https://gitlab.com/gitlab-ci-utils/pagean/",
|
|
241
|
+
{
|
|
242
|
+
"url": "./tests/test-cases/consoleLog.html",
|
|
243
|
+
"settings": {
|
|
244
|
+
"consoleOutputTest": false
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
]
|
|
254
248
|
}
|
|
255
249
|
```
|
|
256
250
|
|
|
257
251
|
## Docker Images
|
|
258
252
|
|
|
259
|
-
Provided with the Pagean project are Docker images configured to run the tests.
|
|
253
|
+
Provided with the Pagean project are Docker images configured to run the tests. All available image tags can be found in the `gitlab-ci-utils/pagean` repository at https://gitlab.com/gitlab-ci-utils/pagean/container_registry. Details on each release can be found on the [Releases](https://gitlab.com/gitlab-ci-utils/pagean/releases) page.
|
|
260
254
|
|
|
261
255
|
**Note:** Any images in the `gitlab-ci-utils/pagean/tmp` repository are temporary images used during the build process and may be deleted at any point.
|
|
262
256
|
|
|
@@ -280,7 +274,7 @@ pagean:
|
|
|
280
274
|
|
|
281
275
|
### Testing With Static HTTP Server
|
|
282
276
|
|
|
283
|
-
The Docker image shown above includes [`http-server`](https://www.npmjs.com/package/http-server) and [`wait-on`](https://www.npmjs.com/package/wait-on) installed globally to run a local HTTP server for testing static content.
|
|
277
|
+
The Docker image shown above includes [`http-server`](https://www.npmjs.com/package/http-server) and [`wait-on`](https://www.npmjs.com/package/wait-on) installed globally to run a local HTTP server for testing static content. The example job below illustrates how to use this for Pagean tests. The script starts the server in this project's `test-cases` directory and uses `wait-on` to hold the script until the server is running and returns a valid response. The referenced `pageanrc` file is the same as the project default `pageanrc`, but references all test URLs from the local server.
|
|
284
278
|
|
|
285
279
|
```yaml
|
|
286
280
|
pagean:
|
package/bin/pagean.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const { log,
|
|
4
|
+
const { log, Levels } = require('ci-logger');
|
|
5
5
|
const program = require('commander');
|
|
6
6
|
const pagean = require('../index');
|
|
7
7
|
const getConfig = require('../lib/config');
|
|
@@ -9,17 +9,24 @@ const pkg = require('../package.json');
|
|
|
9
9
|
|
|
10
10
|
const defaultConfigFileName = './.pageanrc.json';
|
|
11
11
|
|
|
12
|
-
program
|
|
13
|
-
.
|
|
12
|
+
program
|
|
13
|
+
.version(pkg.version)
|
|
14
|
+
.option(
|
|
15
|
+
'-c, --config <file>',
|
|
14
16
|
'the path to the pagean configuration file',
|
|
15
|
-
defaultConfigFileName
|
|
17
|
+
defaultConfigFileName
|
|
18
|
+
)
|
|
16
19
|
.parse(process.argv);
|
|
17
20
|
const options = program.opts();
|
|
18
21
|
|
|
19
22
|
try {
|
|
20
23
|
const config = getConfig(options.config);
|
|
21
24
|
pagean.executeAllTests(config);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
} catch (error) {
|
|
26
|
+
log({
|
|
27
|
+
message: `Error executing pagean tests\n${error.message}`,
|
|
28
|
+
level: Levels.Error,
|
|
29
|
+
exitOnError: true,
|
|
30
|
+
errorCode: 1
|
|
31
|
+
});
|
|
25
32
|
}
|
package/bin/pageanrc-lint.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const { log,
|
|
4
|
+
const { log, Levels } = require('ci-logger');
|
|
5
5
|
const program = require('commander');
|
|
6
6
|
const { green, underline } = require('kleur');
|
|
7
7
|
const { lintConfigFile } = require('../lib/config');
|
|
8
|
-
const { formatErrors } = require('../lib/
|
|
8
|
+
const { formatErrors } = require('../lib/schema-errors');
|
|
9
9
|
const pkg = require('../package.json');
|
|
10
10
|
|
|
11
11
|
const defaultConfigFileName = './.pageanrc.json';
|
|
12
12
|
|
|
13
|
-
program
|
|
13
|
+
program
|
|
14
|
+
.version(pkg.version)
|
|
14
15
|
.option('-j, --json', 'output JSON with full details')
|
|
15
16
|
.description('Lint a pageanrc file')
|
|
16
17
|
.usage(`[options] [file] (default: "${defaultConfigFileName}")`)
|
|
@@ -18,7 +19,7 @@ program.version(pkg.version)
|
|
|
18
19
|
const options = program.opts();
|
|
19
20
|
|
|
20
21
|
const logError = (message, exitOnError = true) => {
|
|
21
|
-
log({ message, level:
|
|
22
|
+
log({ message, level: Levels.Error, exitOnError, errorCode: 1 });
|
|
22
23
|
};
|
|
23
24
|
|
|
24
25
|
const outputJsonResults = (configFileName, lintResults) => {
|
|
@@ -34,26 +35,26 @@ const outputJsonResults = (configFileName, lintResults) => {
|
|
|
34
35
|
const outputConsoleResults = (configFileName, lintResults) => {
|
|
35
36
|
if (lintResults.isValid) {
|
|
36
37
|
log({ message: `\n${configFileName}: ${green('valid')}\n` });
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
38
|
+
} else {
|
|
39
39
|
logError(`\n${underline(configFileName)}`, false);
|
|
40
|
-
formatErrors(lintResults.errors)
|
|
40
|
+
for (const error of formatErrors(lintResults.errors)) {
|
|
41
|
+
logError(error, false);
|
|
42
|
+
}
|
|
41
43
|
// Add line for spacing and error exits process
|
|
42
44
|
logError('');
|
|
43
45
|
}
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
try {
|
|
47
|
-
const configFileName =
|
|
49
|
+
const configFileName =
|
|
50
|
+
program.args.length > 0 ? program.args[0] : defaultConfigFileName;
|
|
48
51
|
const lintResults = lintConfigFile(configFileName);
|
|
49
52
|
|
|
50
53
|
if (options.json) {
|
|
51
54
|
outputJsonResults(configFileName, lintResults);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
55
|
+
} else {
|
|
54
56
|
outputConsoleResults(configFileName, lintResults);
|
|
55
57
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
logError(`Error linting pageanrc file\n${err.message}`);
|
|
58
|
+
} catch (error) {
|
|
59
|
+
logError(`Error linting pageanrc file\n${error.message}`);
|
|
59
60
|
}
|
package/docs/upgrade-guide.md
CHANGED
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
|
|
27
27
|
```json
|
|
28
28
|
{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
"settings": {
|
|
30
|
+
"pageLoadTimeThreshold": 2
|
|
31
|
+
},
|
|
32
|
+
"urls": [
|
|
33
|
+
"https://somewhere.com/",
|
|
34
|
+
{
|
|
35
|
+
"url": "https://somewhere-else.com",
|
|
36
|
+
"settings": {
|
|
37
|
+
"pageLoadTimeThreshold": 3
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
41
|
}
|
|
42
42
|
```
|
|
43
43
|
|
|
@@ -45,21 +45,21 @@
|
|
|
45
45
|
|
|
46
46
|
```json
|
|
47
47
|
{
|
|
48
|
-
|
|
48
|
+
"settings": {
|
|
49
|
+
"pageLoadTimeTest": {
|
|
50
|
+
"pageLoadTimeThreshold": 2
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"urls": [
|
|
54
|
+
"https://somewhere.com/",
|
|
55
|
+
{
|
|
56
|
+
"url": "https://somewhere-else.com",
|
|
57
|
+
"settings": {
|
|
49
58
|
"pageLoadTimeTest": {
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
"urls": [
|
|
54
|
-
"https://somewhere.com/",
|
|
55
|
-
{
|
|
56
|
-
"url": "https://somewhere-else.com",
|
|
57
|
-
"settings": {
|
|
58
|
-
"pageLoadTimeTest": {
|
|
59
|
-
"pageLoadTimeThreshold": 3
|
|
60
|
-
}
|
|
61
|
-
}
|
|
59
|
+
"pageLoadTimeThreshold": 3
|
|
62
60
|
}
|
|
63
|
-
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
64
|
}
|
|
65
65
|
```
|
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const puppeteer = require('puppeteer');
|
|
|
10
10
|
const testLogger = require('./lib/logger');
|
|
11
11
|
const testReporter = require('./lib/reporter');
|
|
12
12
|
const { ...testFunctions } = require('./lib/tests');
|
|
13
|
-
const { createLinkChecker } = require('./lib/
|
|
13
|
+
const { createLinkChecker } = require('./lib/link-utils');
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Executes Pagean tests as specified in config and reports results.
|
|
@@ -18,6 +18,7 @@ const { createLinkChecker } = require('./lib/linkUtils');
|
|
|
18
18
|
* @static
|
|
19
19
|
* @param {object} config The Pagean test configuration.
|
|
20
20
|
*/
|
|
21
|
+
// eslint-disable-next-line max-lines-per-function
|
|
21
22
|
const executeAllTests = async (config) => {
|
|
22
23
|
const logger = testLogger(config);
|
|
23
24
|
const linkChecker = createLinkChecker();
|
|
@@ -28,14 +29,24 @@ const executeAllTests = async (config) => {
|
|
|
28
29
|
|
|
29
30
|
const consoleLog = [];
|
|
30
31
|
const page = await browser.newPage();
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
page.on('console', (message) =>
|
|
33
|
+
consoleLog.push({
|
|
34
|
+
type: message.type(),
|
|
35
|
+
text: message.text(),
|
|
36
|
+
location: message.location()
|
|
37
|
+
})
|
|
38
|
+
);
|
|
34
39
|
await page.goto(testUrl.url, { waitUntil: 'load' });
|
|
35
40
|
|
|
36
41
|
const testContext = {
|
|
37
|
-
page,
|
|
38
|
-
|
|
42
|
+
page,
|
|
43
|
+
consoleLog,
|
|
44
|
+
urlSettings: {
|
|
45
|
+
...testUrl.settings,
|
|
46
|
+
htmlHintConfig: config.htmlHintConfig
|
|
47
|
+
},
|
|
48
|
+
logger,
|
|
49
|
+
linkChecker
|
|
39
50
|
};
|
|
40
51
|
for (const test of Object.keys(testFunctions)) {
|
|
41
52
|
await testFunctions[test](testContext);
|
|
@@ -49,7 +60,7 @@ const executeAllTests = async (config) => {
|
|
|
49
60
|
|
|
50
61
|
if (testResults.summary.failed > 0) {
|
|
51
62
|
// For test harness want process to exit with error code
|
|
52
|
-
// eslint-disable-next-line no-process-exit, no-magic-numbers
|
|
63
|
+
// eslint-disable-next-line unicorn/no-process-exit, no-process-exit, no-magic-numbers
|
|
53
64
|
process.exit(2);
|
|
54
65
|
}
|
|
55
66
|
};
|