pagean 8.0.4 → 10.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/LICENSE +1 -1
- package/README.md +238 -83
- package/bin/pagean.js +15 -10
- package/bin/pageanrc-lint.js +2 -2
- package/docs/upgrade-guide.md +14 -5
- package/index.js +12 -7
- package/lib/config.js +54 -15
- package/lib/default-config.json +3 -0
- package/lib/external-file-utils.js +8 -2
- package/lib/link-utils.js +9 -9
- package/lib/logger.js +14 -14
- package/lib/report-template.handlebars +63 -39
- package/lib/reporter.js +8 -6
- package/lib/schema-errors.js +2 -2
- package/lib/sitemap.js +120 -0
- package/lib/test-utils.js +4 -4
- package/lib/tests.js +14 -15
- package/package.json +28 -27
- package/schemas/pageanrc.schema.json +52 -1
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
# Pagean
|
|
2
2
|
|
|
3
|
-
Pagean is a web page analysis tool designed to automate tests requiring web
|
|
3
|
+
Pagean is a web page analysis tool designed to automate tests requiring web
|
|
4
|
+
pages to be loaded in a browser window (for example 404 error loading an
|
|
5
|
+
external resource, page renders with horizontal scrollbars). The specific tests
|
|
6
|
+
are outlined below, but are all general tests that do not include any
|
|
7
|
+
page-specific logic.
|
|
4
8
|
|
|
5
9
|
## Installation
|
|
6
10
|
|
|
7
|
-
Install Pagean globally (as shown below), or locally, via
|
|
11
|
+
Install Pagean globally (as shown below), or locally, via
|
|
12
|
+
[npm](https://www.npmjs.com/).
|
|
8
13
|
|
|
9
14
|
```
|
|
10
15
|
npm install -g pagean
|
|
@@ -27,19 +32,31 @@ Options:
|
|
|
27
32
|
-h, --help display help for command
|
|
28
33
|
```
|
|
29
34
|
|
|
30
|
-
Pagean requires a configuration file named, which can be specified via the CLI
|
|
35
|
+
Pagean requires a configuration file named, which can be specified via the CLI
|
|
36
|
+
as detailed previously, or use the default file `.pageanrc.json` in the project
|
|
37
|
+
root. This file provides the URLs to be tested and options to configure the
|
|
38
|
+
tests and reports. Details on the available tests and the configuration file
|
|
39
|
+
format are provided below.
|
|
31
40
|
|
|
32
|
-
## Test
|
|
41
|
+
## Test cases
|
|
33
42
|
|
|
34
|
-
The tests use [Puppeteer](https://github.com/GoogleChrome/puppeteer) to launch
|
|
43
|
+
The tests use [Puppeteer](https://github.com/GoogleChrome/puppeteer) to launch
|
|
44
|
+
a headless Chrome browser. The URLs defined in the configuration file are each
|
|
45
|
+
loaded once, and after page load the applicable tests are executed. Test
|
|
46
|
+
results are `passed` or `failed`, but can be configured to report `warning`
|
|
47
|
+
instead of failure. Only a `failed` test causes the test process to fail and
|
|
48
|
+
exit with an error code (a `warning` doesn't).
|
|
35
49
|
|
|
36
|
-
### Horizontal
|
|
50
|
+
### Horizontal scrollbar test
|
|
37
51
|
|
|
38
|
-
The horizontal scrollbar test fails if the rendered page has a horizontal
|
|
52
|
+
The horizontal scrollbar test fails if the rendered page has a horizontal
|
|
53
|
+
scrollbar. If a specific browser viewport size is desired for this test, that
|
|
54
|
+
can be configured in the `puppeteerLaunchOptions`.
|
|
39
55
|
|
|
40
|
-
### Console
|
|
56
|
+
### Console output test
|
|
41
57
|
|
|
42
|
-
The console output test fails if any output is written to the browser console.
|
|
58
|
+
The console output test fails if any output is written to the browser console.
|
|
59
|
+
An array is included in the report with all entries, as shown below:
|
|
43
60
|
|
|
44
61
|
```json
|
|
45
62
|
[
|
|
@@ -53,13 +70,20 @@ The console output test fails if any output is written to the browser console. A
|
|
|
53
70
|
]
|
|
54
71
|
```
|
|
55
72
|
|
|
56
|
-
### Console
|
|
73
|
+
### Console error test
|
|
57
74
|
|
|
58
|
-
The console error test fails if any error is written to the browser console,
|
|
75
|
+
The console error test fails if any error is written to the browser console,
|
|
76
|
+
but is otherwise the same as the console output test. This separation allows
|
|
77
|
+
for testing for console errors, but allowing any other console output.
|
|
59
78
|
|
|
60
|
-
### Rendered HTML
|
|
79
|
+
### Rendered HTML test
|
|
61
80
|
|
|
62
|
-
The rendered HTML test is intended for cases where content is dynamically
|
|
81
|
+
The rendered HTML test is intended for cases where content is dynamically
|
|
82
|
+
created prior to page load (that is, the `load` event firing). The rendered
|
|
83
|
+
HTML is returned and checked with
|
|
84
|
+
[HTML Hint](https://www.npmjs.com/package/htmlhint) and the test fails if any
|
|
85
|
+
issues are found. An array is included in the report with all HTML Hint issues,
|
|
86
|
+
as shown below:
|
|
63
87
|
|
|
64
88
|
```json
|
|
65
89
|
[
|
|
@@ -79,23 +103,43 @@ The rendered HTML test is intended for cases where content is dynamically create
|
|
|
79
103
|
]
|
|
80
104
|
```
|
|
81
105
|
|
|
82
|
-
An htmlhintrc file can be specified in the configuration file, otherwise the
|
|
106
|
+
An htmlhintrc file can be specified in the configuration file, otherwise the
|
|
107
|
+
default "./.htmlhintrc" file is used (if it exists). See the Configuration
|
|
108
|
+
section below.
|
|
83
109
|
|
|
84
|
-
Note:
|
|
110
|
+
Note: this test may not find some errors in the original HTML that are
|
|
111
|
+
removed/resolved as the page is parsed (for example closing tags with no
|
|
112
|
+
opening tags).
|
|
85
113
|
|
|
86
|
-
### Page
|
|
114
|
+
### Page load time test
|
|
87
115
|
|
|
88
|
-
The page load time test fails if the page load time (from start through the
|
|
116
|
+
The page load time test fails if the page load time (from start through the
|
|
117
|
+
`load` event) exceeds the defined threshold in the configuration file (or the
|
|
118
|
+
default of 2 seconds). The actual load time is included in the report. Tests
|
|
119
|
+
time out at twice the page load time threshold.
|
|
89
120
|
|
|
90
|
-
### External
|
|
121
|
+
### External script test
|
|
91
122
|
|
|
92
|
-
The external script test is intended to identify any externally loaded
|
|
123
|
+
The external script test is intended to identify any externally loaded
|
|
124
|
+
JavaScript files (for example loaded from a CDN) and aggregate those files so
|
|
125
|
+
they can undergo further analysis (for example dependency vulnerability
|
|
126
|
+
scanning). The test is included here since these tests load fully rendered
|
|
127
|
+
pages, therefore allowing the aggregation of this data for pages generated
|
|
128
|
+
using any language or framework. By default the test returns a warning if the
|
|
129
|
+
page includes any JavaScript files loaded from a different domain than the page
|
|
130
|
+
(although this could be overridden to fail instead via setting
|
|
131
|
+
`failWarn: false`, see the Configuration section below). These files are then
|
|
132
|
+
downloaded and saved in the "pagean-external-files" directory in the project
|
|
133
|
+
root. Subdirectories are created for each domain, then following the URL path.
|
|
134
|
+
For example, the following script…
|
|
93
135
|
|
|
94
136
|
```html
|
|
95
137
|
<script src="https://bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
|
|
96
138
|
```
|
|
97
139
|
|
|
98
|
-
|
|
140
|
+
…is saved as `./bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js`. The
|
|
141
|
+
`data` array in the test report includes the original file URL and the local
|
|
142
|
+
saved filename or applicable error, as shown below.
|
|
99
143
|
|
|
100
144
|
```json
|
|
101
145
|
[
|
|
@@ -110,21 +154,51 @@ The external script test is intended to identify any externally loaded javascrip
|
|
|
110
154
|
]
|
|
111
155
|
```
|
|
112
156
|
|
|
113
|
-
Each external script is saved only once, but
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
157
|
+
Each external script is saved only once, but is reported on any page where it's
|
|
158
|
+
referenced.
|
|
159
|
+
|
|
160
|
+
### Broken link test
|
|
161
|
+
|
|
162
|
+
The broken link test checks for broken links on the page. It checks any `<a>`
|
|
163
|
+
tag on the page with `href` pointing to another location on the current page or
|
|
164
|
+
another page (that is, only `http(s)` or `file` protocols).
|
|
165
|
+
|
|
166
|
+
- For links within the page, this test checks for existence of the element on
|
|
167
|
+
the page, passing if the element exists and failing otherwise (and passing
|
|
168
|
+
for cases that are always valid, for example `#` or `#top` for the current
|
|
169
|
+
page). It doesn't check the visibility of the element. Failing tests return a
|
|
170
|
+
response of "#element Not Found" (where `#element` identifies the specific
|
|
171
|
+
element).
|
|
172
|
+
- For links to other pages, the test tries to most efficiently confirm whether
|
|
173
|
+
the target link is valid. It first makes a `HEAD` request for that URL and
|
|
174
|
+
checks the response. If an erroneous response is returned (>= 400 with no
|
|
175
|
+
execution error) and not code 429 (Too Many Requests), the request is retried
|
|
176
|
+
with a `GET` request. The test passes for HTTP responses < 400 and fails
|
|
177
|
+
otherwise (if HTTP response is >= 400 or another error occurs).
|
|
178
|
+
- This can result in false failure indications, specifically for `file:`
|
|
179
|
+
links (`404` or `ECONNREFUSED`) or where the browser passes a domain
|
|
180
|
+
identity with the request (page loads when tested, but `401` response for
|
|
181
|
+
links to that page). For these cases, or other false failures, the test
|
|
182
|
+
configuration allows a Boolean `checkWithBrowser` option that instead
|
|
183
|
+
checks links by loading the target in the browser (via `puppeteer`). Note
|
|
184
|
+
this can increase test execution time, in some cases substantially, due to
|
|
185
|
+
the time to open a new browser tab and plus load the page and all assets.
|
|
186
|
+
- Note that `file:` links can only be tested with the `checkWithBrowser`
|
|
187
|
+
option.
|
|
188
|
+
- If the link to another page includes a hash it's removed prior to checking.
|
|
189
|
+
The test in this case is confirming a valid link, not that the element
|
|
190
|
+
exists, which is only done for the current page.
|
|
191
|
+
- The test configuration allows an `ignoredLinks` array listing link URLs to
|
|
192
|
+
ignore for this test. Note this only applies to links to other pages, not
|
|
193
|
+
links within the page, which are always checked.
|
|
194
|
+
- To optimize performance, link test results are cached and those links aren't
|
|
195
|
+
re-tested for the entire test run (across all tested URLs). The test
|
|
196
|
+
configuration allows a Boolean `ignoreDuplicates` option that can be set to
|
|
197
|
+
`false` to bypass this behavior and re-test all links. The results for any
|
|
198
|
+
failed links are included in the reports in any case.
|
|
199
|
+
|
|
200
|
+
For any failing test, the `data` array in the test report includes the original
|
|
201
|
+
URL and the response code or error as shown below.
|
|
128
202
|
|
|
129
203
|
```json
|
|
130
204
|
[
|
|
@@ -133,7 +207,7 @@ For any failing test, the `data` array in the test report includes the original
|
|
|
133
207
|
"status": 404
|
|
134
208
|
},
|
|
135
209
|
{
|
|
136
|
-
"href": "http://localhost:
|
|
210
|
+
"href": "http://localhost:3000/brokenLinks.html#notlinked",
|
|
137
211
|
"status": "#notlinked Not Found"
|
|
138
212
|
},
|
|
139
213
|
{
|
|
@@ -143,38 +217,71 @@ For any failing test, the `data` array in the test report includes the original
|
|
|
143
217
|
]
|
|
144
218
|
```
|
|
145
219
|
|
|
146
|
-
Note:
|
|
220
|
+
Note: this test checks all links on the page, and doesn't respect mechanisms
|
|
221
|
+
intended to limit web crawlers such as `robots.txt` or `noindex` tags.
|
|
147
222
|
|
|
148
223
|
## Reports
|
|
149
224
|
|
|
150
|
-
Based on the `reporters` configuration, Pagean results may be displayed in the
|
|
225
|
+
Based on the `reporters` configuration, Pagean results may be displayed in the
|
|
226
|
+
console and saved in two reports in the project root directory (any or all of
|
|
227
|
+
the three):
|
|
151
228
|
|
|
152
|
-
- A JSON report named
|
|
153
|
-
|
|
229
|
+
- A JSON report named
|
|
230
|
+
[`pagean-results.json`](https://gitlab-ci-utils.gitlab.io/pagean/pagean-results.json)
|
|
231
|
+
- An HTML report named
|
|
232
|
+
[`pagean-results.html`](https://gitlab-ci-utils.gitlab.io/pagean/pagean-results.html)
|
|
154
233
|
|
|
155
234
|
Both reports contain:
|
|
156
235
|
|
|
157
236
|
- The time of test execution
|
|
158
237
|
- A summary of the total tests and results (passed, warning, failed)
|
|
159
|
-
- The detailed test results, including the URL tested, list of tests performed
|
|
238
|
+
- The detailed test results, including the URL tested, list of tests performed
|
|
239
|
+
on that URL with results, and, if applicable, any relevant data associated
|
|
240
|
+
with the test failure (for example the console errors if the console error
|
|
241
|
+
test fails).
|
|
160
242
|
|
|
161
|
-
Complete reports for the example case in this project (the tests as specified
|
|
243
|
+
Complete reports for the example case in this project (the tests as specified
|
|
244
|
+
in the project
|
|
245
|
+
[`.pageanrc.json`](https://gitlab.com/gitlab-ci-utils/pagean/-/blob/master/.pageanrc.json)
|
|
246
|
+
file) can be found at the preceding links.
|
|
162
247
|
|
|
163
248
|
## Configuration
|
|
164
249
|
|
|
165
|
-
Pagean looks for a configuration file as specified via the CLI, or defaults to
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
- `
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
250
|
+
Pagean looks for a configuration file as specified via the CLI, or defaults to
|
|
251
|
+
a file named `.pageanrc.json` in the project root. If the configuration file is
|
|
252
|
+
not found, is not valid JSON, or doesn't contain any URLs to check the job
|
|
253
|
+
fails.
|
|
254
|
+
|
|
255
|
+
Below is an example `.pageanrc.json` file, which is broken into seven major
|
|
256
|
+
properties:
|
|
257
|
+
|
|
258
|
+
- `htmlhintrc`: An optional path to an htmlhintrc file to be used in the
|
|
259
|
+
rendered HTML test
|
|
260
|
+
- `project`: An optional name of the project, which is included in HTML and
|
|
261
|
+
JSON reports.
|
|
262
|
+
- `puppeteerLaunchOptions`: An optional set of options to pass to Puppeteer on
|
|
263
|
+
launch. There are no default options. The complete list of available options
|
|
264
|
+
can be found at
|
|
265
|
+
https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions.
|
|
266
|
+
- `reporters`: An optional array of reporters indicating the test reports that
|
|
267
|
+
should be provided. There are three possible options - `cli`, `html`, and
|
|
268
|
+
`json`. The `cli` option reports all test details to the console, but the
|
|
269
|
+
final results summary is always output (even with `cli` disabled). If
|
|
270
|
+
`reporters` is specified, at least one reporter must be included. The default
|
|
271
|
+
value, as specified below, is all three reporters enabled.
|
|
272
|
+
- `settings`: These settings enable/disable or configure tests, and are applied
|
|
273
|
+
to all tests overriding the default values.
|
|
274
|
+
- The shorthand notation allows easy enabling/disabling of tests. In this
|
|
275
|
+
format the test name is given with a Boolean value to enable or disable the
|
|
276
|
+
test. In this case any other test-specific settings use the default values.
|
|
277
|
+
- The longhand version includes an object for each test. Every test includes
|
|
278
|
+
two possible properties (some tests include additional settings):
|
|
279
|
+
- `enabled`: A Boolean value to enable/disable the test, and some tests
|
|
280
|
+
include additional settings (default `true` for all tests).
|
|
281
|
+
- `failWarn`: A Boolean value causing a failed test to report a warning
|
|
282
|
+
instead of failure. A warning result doesn't cause the test process to
|
|
283
|
+
fail (exit with an error code). The default value for all tests is
|
|
284
|
+
`false` except the `externalScriptTest`, as shown below.
|
|
178
285
|
|
|
179
286
|
The shorthand:
|
|
180
287
|
|
|
@@ -197,7 +304,28 @@ is equivalent to the longhand:
|
|
|
197
304
|
|
|
198
305
|
All available settings with the default values are shown below.
|
|
199
306
|
|
|
200
|
-
- `
|
|
307
|
+
- `sitemap`: Specify a sitemap with URLs to test. If a sitemap is specified,
|
|
308
|
+
the URLs from the sitemap are added to the `urls` array. If a URL is in the
|
|
309
|
+
`urls` array with `settings`, those settings are retained. Note that
|
|
310
|
+
`<sitemapindex>` is currently not supported. The `sitemap` object can have
|
|
311
|
+
the following properties:
|
|
312
|
+
- `url`: The URL of the sitemap (required if `sitemap` is included). This can
|
|
313
|
+
be either an actual URL or a local file.
|
|
314
|
+
- `find`: A string to search for in sitemap URLs (for example
|
|
315
|
+
`https://somehere.test`) (required if `replace` is specified).
|
|
316
|
+
- `replace`: The string to replace the `find` string with (for example
|
|
317
|
+
`http://localhost:3000`) (required if `find` is specified).
|
|
318
|
+
- `exclude`: An array of strings with regular expressions to exclude URLs
|
|
319
|
+
from the sitemap (for example `['\.pdf$']` to exclude any PDF files). Since
|
|
320
|
+
these are string representations of regular expressions, the backslash must
|
|
321
|
+
be escaped (for example `\\.`). Exclude is performed before find/replace,
|
|
322
|
+
so uses the original URLs from the sitemap.
|
|
323
|
+
- `urls`: An array of URLs to be tested, which must contain at least one value.
|
|
324
|
+
Each array entry can either be a URL string, or an object that contains a
|
|
325
|
+
`url` string and an optional `settings` object. This object can contain any
|
|
326
|
+
of the `settings` values identified previously and overrides that setting for
|
|
327
|
+
testing that URL. The `url` string can be either an actual URL or a local
|
|
328
|
+
file, as shown in the example below.
|
|
201
329
|
|
|
202
330
|
```json
|
|
203
331
|
{
|
|
@@ -242,7 +370,7 @@ All available settings with the default values are shown below.
|
|
|
242
370
|
"urls": [
|
|
243
371
|
"https://gitlab.com/gitlab-ci-utils/pagean/",
|
|
244
372
|
{
|
|
245
|
-
"url": "./tests/
|
|
373
|
+
"url": "./tests/fixtures/site/consoleLog.html",
|
|
246
374
|
"settings": {
|
|
247
375
|
"consoleOutputTest": false
|
|
248
376
|
}
|
|
@@ -251,19 +379,31 @@ All available settings with the default values are shown below.
|
|
|
251
379
|
}
|
|
252
380
|
```
|
|
253
381
|
|
|
254
|
-
##
|
|
382
|
+
## Container images
|
|
255
383
|
|
|
256
|
-
Provided with the Pagean project are
|
|
384
|
+
Provided with the Pagean project are container images configured to run the
|
|
385
|
+
tests. All available image tags can be found in the `gitlab-ci-utils/pagean`
|
|
386
|
+
repository at https://gitlab.com/gitlab-ci-utils/pagean/container_registry.
|
|
387
|
+
Details on each release can be found on the
|
|
388
|
+
[Releases](https://gitlab.com/gitlab-ci-utils/pagean/releases) page.
|
|
257
389
|
|
|
258
|
-
**Note:**
|
|
390
|
+
**Note:** any images in the `gitlab-ci-utils/pagean/tmp` repository are
|
|
391
|
+
temporary images used during the build process and may be deleted at any point.
|
|
259
392
|
|
|
260
|
-
### Puppeteer
|
|
393
|
+
### Puppeteer cache location
|
|
261
394
|
|
|
262
|
-
In [Puppeteer v19](https://github.com/puppeteer/puppeteer/releases/tag/v19.0.0)
|
|
395
|
+
In [Puppeteer v19](https://github.com/puppeteer/puppeteer/releases/tag/v19.0.0)
|
|
396
|
+
the default cache location for installing the Chrome binary was changed from
|
|
397
|
+
within the project's `node_modules` folder to `~/.cache/puppeteer`. To simplify
|
|
398
|
+
execution in a container, the `PUPPETEER_CACHE_DIR` environment variable is set
|
|
399
|
+
to install the Chrome binaries in `/home/pptruser/.cache/puppeteer` during
|
|
400
|
+
container build, so setting to another value before execution can cause errors
|
|
401
|
+
where Puppeteer can't find the Chrome binary.
|
|
263
402
|
|
|
264
|
-
## GitLab CI
|
|
403
|
+
## GitLab CI configuration
|
|
265
404
|
|
|
266
|
-
The following is an example job from a .gitlab-ci.yml file to use this image to
|
|
405
|
+
The following is an example job from a .gitlab-ci.yml file to use this image to
|
|
406
|
+
run Pagean against another project in GitLab CI:
|
|
267
407
|
|
|
268
408
|
```yaml
|
|
269
409
|
pagean:
|
|
@@ -279,9 +419,17 @@ pagean:
|
|
|
279
419
|
- pagean-external-scripts/
|
|
280
420
|
```
|
|
281
421
|
|
|
282
|
-
### Testing
|
|
422
|
+
### Testing with static HTTP server
|
|
283
423
|
|
|
284
|
-
The
|
|
424
|
+
The container image shown previously includes
|
|
425
|
+
[`serve`](https://www.npmjs.com/package/serve) and
|
|
426
|
+
[`wait-on`](https://www.npmjs.com/package/wait-on) installed globally to run a
|
|
427
|
+
local HTTP server for testing static content. The example job below illustrates
|
|
428
|
+
how to use this for Pagean tests. The script starts the server in this
|
|
429
|
+
project's `./tests/fixtures/site` directory and uses `wait-on` to hold the
|
|
430
|
+
script until the server is running and returns a valid response. The referenced
|
|
431
|
+
`pageanrc` file is the same as the project default `pageanrc`, but references
|
|
432
|
+
all test URLs from the local server.
|
|
285
433
|
|
|
286
434
|
```yaml
|
|
287
435
|
pagean:
|
|
@@ -289,10 +437,8 @@ pagean:
|
|
|
289
437
|
stage: test
|
|
290
438
|
before_script:
|
|
291
439
|
# Start static server in test cases directory, discarding any console output,
|
|
292
|
-
# and wait until the server is running.
|
|
293
|
-
|
|
294
|
-
# to resolve localhost with no issue, see example in static-server.pageanrc.json.
|
|
295
|
-
- http-server ./tests/test-cases > /dev/null 2>&1 & wait-on http://127.0.0.1:8080
|
|
440
|
+
# and wait until the server is running.
|
|
441
|
+
- serve ./tests/fixtures/site > /dev/null 2>&1 & wait-on http://localhost:3000
|
|
296
442
|
script:
|
|
297
443
|
- pagean -c static-server.pageanrc.json
|
|
298
444
|
artifacts:
|
|
@@ -303,9 +449,10 @@ pagean:
|
|
|
303
449
|
- pagean-external-scripts/
|
|
304
450
|
```
|
|
305
451
|
|
|
306
|
-
## Linting
|
|
452
|
+
## Linting pageanrc files
|
|
307
453
|
|
|
308
|
-
A command line tool is also available to lint pageanrc files, which is executed
|
|
454
|
+
A command line tool is also available to lint pageanrc files, which is executed
|
|
455
|
+
as follows:
|
|
309
456
|
|
|
310
457
|
```
|
|
311
458
|
Installed globally:
|
|
@@ -322,20 +469,28 @@ Options:
|
|
|
322
469
|
-h, --help display help for command
|
|
323
470
|
```
|
|
324
471
|
|
|
325
|
-
The `--json` option outputs the JSON results to stdout in all cases for
|
|
472
|
+
The `--json` option outputs the JSON results to stdout in all cases for
|
|
473
|
+
consistency (`[]` if no errors found, so that it always outputs valid
|
|
474
|
+
JSON). Otherwise errors are output to stderr, for example:
|
|
326
475
|
|
|
327
476
|
```sh
|
|
328
477
|
.\tests\test-configs\cli-tests\some-test.pageanrc.json
|
|
329
|
-
<pageanrc>.puppeteerLaunchOptions
|
|
330
|
-
<pageanrc>.reporters[0]
|
|
331
|
-
<pageanrc>.settings.consoleOutputTest
|
|
332
|
-
<pageanrc>.settings.pageLoadTimeTest.foo
|
|
333
|
-
<pageanrc>.settings.pageLoadTimeTest
|
|
334
|
-
<pageanrc>.
|
|
335
|
-
<pageanrc>.urls[
|
|
336
|
-
<pageanrc>.urls[
|
|
478
|
+
<pageanrc>.puppeteerLaunchOptions must NOT have fewer than 1 properties
|
|
479
|
+
<pageanrc>.reporters[0] must be equal to one of the allowed values (cli, html, json)
|
|
480
|
+
<pageanrc>.settings.consoleOutputTest must be either Boolean or object with the appropriate properties
|
|
481
|
+
<pageanrc>.settings.pageLoadTimeTest.foo must NOT contain additional properties: "foo"
|
|
482
|
+
<pageanrc>.settings.pageLoadTimeTest must be either Boolean or object with the appropriate properties
|
|
483
|
+
<pageanrc>.sitemap must use 'find' and 'replace' together
|
|
484
|
+
<pageanrc>.urls[2].settings.consoleOutputTest must be either Boolean or object with the appropriate properties
|
|
485
|
+
<pageanrc>.urls[3] must be either URL string or object with the appropriate properties
|
|
486
|
+
<pageanrc>.urls[5] must have required property 'url'
|
|
337
487
|
```
|
|
338
488
|
|
|
339
|
-
In some cases, a single error might result in multiple messages based on the
|
|
489
|
+
In some cases, a single error might result in multiple messages based on the
|
|
490
|
+
options in the schema definition, especially for cases that can be either a
|
|
491
|
+
single value or an object with specific properties (for example the errors for
|
|
492
|
+
`<pageanrc>.settings.pageLoadTimeTest` in the preceding example).
|
|
340
493
|
|
|
341
|
-
Note that because of the large number of options, which are dependent on an
|
|
494
|
+
Note that because of the large number of options, which are dependent on an
|
|
495
|
+
external project, the linting of `puppeteerLaunchOptions` only checks that at
|
|
496
|
+
least one property is provided, it doesn't check the detailed settings.
|
package/bin/pagean.js
CHANGED
|
@@ -19,14 +19,19 @@ program
|
|
|
19
19
|
.parse(process.argv);
|
|
20
20
|
const options = program.opts();
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
getConfig(options.config)
|
|
23
|
+
/* eslint-disable-next-line promise/always-return -- required instead
|
|
24
|
+
of top level await */
|
|
25
|
+
.then((config) => {
|
|
26
|
+
pagean.executeAllTests(config);
|
|
27
|
+
})
|
|
28
|
+
/* eslint-disable-next-line promise/prefer-await-to-callbacks --
|
|
29
|
+
required instead of top level await */
|
|
30
|
+
.catch((error) => {
|
|
31
|
+
log({
|
|
32
|
+
errorCode: 1,
|
|
33
|
+
exitOnError: true,
|
|
34
|
+
level: Levels.Error,
|
|
35
|
+
message: `Error executing pagean tests\n${error.message}`
|
|
36
|
+
});
|
|
31
37
|
});
|
|
32
|
-
}
|
package/bin/pageanrc-lint.js
CHANGED
|
@@ -19,13 +19,13 @@ program
|
|
|
19
19
|
const options = program.opts();
|
|
20
20
|
|
|
21
21
|
const logError = (message, exitOnError = true) => {
|
|
22
|
-
log({
|
|
22
|
+
log({ errorCode: 1, exitOnError, level: Levels.Error, message });
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
const outputJsonResults = (configFileName, lintResults) => {
|
|
26
26
|
// Log JSON to stdout for consistency, and eliminates extraneous stderr
|
|
27
27
|
// output in PowerShell which produces invalid JSON if piped to file.
|
|
28
|
-
// eslint-disable-next-line no-magic-numbers -- index
|
|
28
|
+
// eslint-disable-next-line no-magic-numbers -- no-magic-numbers - index
|
|
29
29
|
log({ message: JSON.stringify(lintResults.errors, undefined, 2) });
|
|
30
30
|
if (!lintResults.isValid) {
|
|
31
31
|
logError(`Errors found in file ${configFileName}`);
|
package/docs/upgrade-guide.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
# Version
|
|
1
|
+
# Version upgrade guide
|
|
2
2
|
|
|
3
3
|
## Upgrading from v4.x to v5.0
|
|
4
4
|
|
|
5
|
-
1. Update to a Node.js current or LTS release
|
|
5
|
+
1. Update to a Node.js current or LTS release
|
|
6
|
+
(`^12.20.0 || ^14.15.0 || >=16.0.0`). Pagean may still work in other
|
|
7
|
+
releases, but is not specifically tested or supported.
|
|
6
8
|
|
|
7
|
-
2. The Broken Link Test default setting was originally to fail with warning,
|
|
9
|
+
2. The Broken Link Test default setting was originally to fail with warning,
|
|
10
|
+
but this was updated to fail (without warning) to be consistent with the
|
|
11
|
+
other tests. To return to the previous behavior, update your configuration
|
|
12
|
+
settings with:
|
|
8
13
|
|
|
9
14
|
```json
|
|
10
15
|
{
|
|
@@ -18,9 +23,13 @@
|
|
|
18
23
|
|
|
19
24
|
## Upgrading from v3.x (`page-load-tests`) to v4.0 (`pagean`)
|
|
20
25
|
|
|
21
|
-
1. Change the configurations
|
|
26
|
+
1. Change the configurations filename from `.pltconfig.json` to
|
|
27
|
+
`.pageanrc.json`
|
|
22
28
|
|
|
23
|
-
2. Pagean v4.0.0 updated the configuration file format to allow test-specific
|
|
29
|
+
2. Pagean v4.0.0 updated the configuration file format to allow test-specific
|
|
30
|
+
settings. With this change, `pageLoadTimeThreshold` must now appears as a
|
|
31
|
+
setting of the `pageLoadTimeTest` test, rather than at the same level as the
|
|
32
|
+
other tests. See the example from/to below:
|
|
24
33
|
|
|
25
34
|
**From:**
|
|
26
35
|
|
package/index.js
CHANGED
|
@@ -12,13 +12,15 @@ const testReporter = require('./lib/reporter');
|
|
|
12
12
|
const { ...testFunctions } = require('./lib/tests');
|
|
13
13
|
const { createLinkChecker } = require('./lib/link-utils');
|
|
14
14
|
|
|
15
|
+
/* eslint-disable no-await-in-loop, max-lines-per-function --
|
|
16
|
+
no-await-in-loop - tests are deliberately performed synchronously,
|
|
17
|
+
max-lines-per-function - allowed to test executor */
|
|
15
18
|
/**
|
|
16
19
|
* Executes Pagean tests as specified in config and reports results.
|
|
17
20
|
*
|
|
18
21
|
* @param {object} config The Pagean test configuration.
|
|
19
22
|
* @static
|
|
20
23
|
*/
|
|
21
|
-
// eslint-disable-next-line max-lines-per-function
|
|
22
24
|
const executeAllTests = async (config) => {
|
|
23
25
|
const logger = testLogger(config);
|
|
24
26
|
const linkChecker = createLinkChecker();
|
|
@@ -31,22 +33,24 @@ const executeAllTests = async (config) => {
|
|
|
31
33
|
const page = await browser.newPage();
|
|
32
34
|
page.on('console', (message) =>
|
|
33
35
|
consoleLog.push({
|
|
34
|
-
|
|
36
|
+
location: message.location(),
|
|
35
37
|
text: message.text(),
|
|
36
|
-
|
|
38
|
+
type: message.type()
|
|
37
39
|
})
|
|
38
40
|
);
|
|
41
|
+
// User provided test input required.
|
|
42
|
+
// nosemgrep: puppeteer-goto-injection
|
|
39
43
|
await page.goto(testUrl.url, { waitUntil: 'load' });
|
|
40
44
|
|
|
41
45
|
const testContext = {
|
|
42
|
-
page,
|
|
43
46
|
consoleLog,
|
|
47
|
+
linkChecker,
|
|
48
|
+
logger,
|
|
49
|
+
page,
|
|
44
50
|
urlSettings: {
|
|
45
51
|
...testUrl.settings,
|
|
46
52
|
htmlHintConfig: config.htmlHintConfig
|
|
47
|
-
}
|
|
48
|
-
logger,
|
|
49
|
-
linkChecker
|
|
53
|
+
}
|
|
50
54
|
};
|
|
51
55
|
for (const test of Object.keys(testFunctions)) {
|
|
52
56
|
await testFunctions[test](testContext);
|
|
@@ -64,5 +68,6 @@ const executeAllTests = async (config) => {
|
|
|
64
68
|
process.exit(2);
|
|
65
69
|
}
|
|
66
70
|
};
|
|
71
|
+
/* eslint-enable no-await-in-loop, max-lines-per-function -- enable */
|
|
67
72
|
|
|
68
73
|
module.exports.executeAllTests = executeAllTests;
|