pagean 4.4.2 → 6.0.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 (96) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -9
  3. package/docs/upgrade-guide.md +16 -0
  4. package/index.js +7 -4
  5. package/lib/config.js +2 -2
  6. package/lib/default-config.json +41 -39
  7. package/lib/externalFileUtils.js +1 -1
  8. package/lib/linkUtils.js +162 -25
  9. package/lib/logger.js +1 -1
  10. package/lib/report-template.handlebars +224 -209
  11. package/lib/schemaErrors.js +5 -4
  12. package/lib/testUtils.js +1 -1
  13. package/lib/tests.js +14 -14
  14. package/package.json +28 -30
  15. package/schemas/pageanrc.schema.json +199 -191
  16. package/.codeclimate.json +0 -8
  17. package/.depcheckrc.json +0 -3
  18. package/.dockerignore +0 -12
  19. package/.eslintrc.json +0 -19
  20. package/.gitattributes +0 -4
  21. package/.gitlab/gitlab-releaser.json +0 -16
  22. package/.htmlhintrc +0 -25
  23. package/.markdownlint.json +0 -13
  24. package/.pa11yci.json +0 -5
  25. package/.pageanrc.json +0 -55
  26. package/.stylelintrc.json +0 -7
  27. package/CHANGELOG.md +0 -204
  28. package/gitlab.pageanrc.json +0 -16
  29. package/jest.config.json +0 -22
  30. package/static-server.pageanrc.json +0 -50
  31. package/tests/__snapshots__/config.test.js.snap +0 -591
  32. package/tests/__snapshots__/externalFileUtils.test.js.snap +0 -7
  33. package/tests/__snapshots__/index.test.js.snap +0 -30
  34. package/tests/__snapshots__/pagean.test.js.snap +0 -82
  35. package/tests/__snapshots__/pageanrc.test.js.snap +0 -759
  36. package/tests/__snapshots__/reporter.test.js.snap +0 -509
  37. package/tests/config.test.js +0 -264
  38. package/tests/externalFileUtils.test.js +0 -184
  39. package/tests/index.test.js +0 -181
  40. package/tests/linkUtils.test.js +0 -290
  41. package/tests/logger.test.js +0 -324
  42. package/tests/pagean.test.js +0 -85
  43. package/tests/pageanrc.test.js +0 -96
  44. package/tests/reporter.test.js +0 -82
  45. package/tests/schemaErrors.test.js +0 -88
  46. package/tests/test-cases/.htmlhintrc +0 -25
  47. package/tests/test-cases/brokenLinks.html +0 -22
  48. package/tests/test-cases/consoleLog.html +0 -11
  49. package/tests/test-cases/duplicateLinks.html +0 -22
  50. package/tests/test-cases/dynamicContent.html +0 -13
  51. package/tests/test-cases/externalScripts.html +0 -21
  52. package/tests/test-cases/horizontalScrollbar.html +0 -13
  53. package/tests/test-cases/htmlError.html +0 -11
  54. package/tests/test-cases/noExternalScripts.html +0 -12
  55. package/tests/test-cases/notDocumentLinks.html +0 -18
  56. package/tests/test-cases/pagean-results.json +0 -1
  57. package/tests/test-cases/scriptError404.html +0 -9
  58. package/tests/test-cases/slowLoad.html +0 -9
  59. package/tests/test-configs/cli-tests/.pageanrc.json +0 -28
  60. package/tests/test-configs/cli-tests/all-empty.pageanrc.json +0 -10
  61. package/tests/test-configs/cli-tests/all-errors.pageanrc.json +0 -69
  62. package/tests/test-configs/cli-tests/all-fail-cli.pageanrc.json +0 -9
  63. package/tests/test-configs/cli-tests/no-urls.pageanrc.json +0 -7
  64. package/tests/test-configs/cli-tests/pass-fail-cli.pageanrc.json +0 -14
  65. package/tests/test-configs/integration-tests/all-passing-tests.pageanrc.json +0 -63
  66. package/tests/test-configs/integration-tests/broken-links-error.pageanrc.json +0 -22
  67. package/tests/test-configs/integration-tests/console-error-reporter-cli-json.pageanrc.json +0 -20
  68. package/tests/test-configs/integration-tests/console-error-reporter-html.pageanrc.json +0 -19
  69. package/tests/test-configs/integration-tests/console-error.pageanrc.json +0 -16
  70. package/tests/test-configs/integration-tests/console-output.pageanrc.json +0 -16
  71. package/tests/test-configs/integration-tests/external-scripts-error.pageanrc.json +0 -19
  72. package/tests/test-configs/integration-tests/horizontal-scrollbar.pageanrc.json +0 -16
  73. package/tests/test-configs/integration-tests/html-error.pageanrc.json +0 -16
  74. package/tests/test-configs/integration-tests/page-load-time.pageanrc.json +0 -16
  75. package/tests/test-configs/unit-tests/empty-url-values.pageanrc.json +0 -9
  76. package/tests/test-configs/unit-tests/empty-urls.pageanrc.json +0 -3
  77. package/tests/test-configs/unit-tests/empty.pageanrc.json +0 -2
  78. package/tests/test-configs/unit-tests/global-and-test-specific-settings-shorthand.pageanrc.json +0 -30
  79. package/tests/test-configs/unit-tests/global-and-test-specific-settings-test-props.pageanrc.json +0 -42
  80. package/tests/test-configs/unit-tests/global-and-test-specific-settings.pageanrc.json +0 -34
  81. package/tests/test-configs/unit-tests/global-test-settings.pageanrc.json +0 -15
  82. package/tests/test-configs/unit-tests/htmlhintrc-invalid.pageanrc.json +0 -7
  83. package/tests/test-configs/unit-tests/htmlhintrc-valid.pageanrc.json +0 -7
  84. package/tests/test-configs/unit-tests/ignored-links-denormalized.pageanrc.json +0 -18
  85. package/tests/test-configs/unit-tests/invalid.pageanrc.json +0 -0
  86. package/tests/test-configs/unit-tests/no-test-settings.pageanrc.json +0 -6
  87. package/tests/test-configs/unit-tests/project-no-test-settings.pageanrc.json +0 -7
  88. package/tests/test-configs/unit-tests/puppeteer-no-test-settings.pageanrc.json +0 -9
  89. package/tests/test-configs/unit-tests/reporters-empty.pageanrc.json +0 -7
  90. package/tests/test-configs/unit-tests/reporters-invalid-type.pageanrc.json +0 -9
  91. package/tests/test-configs/unit-tests/reporters-not-array.pageanrc.json +0 -6
  92. package/tests/test-configs/unit-tests/reporters-valid.pageanrc.json +0 -9
  93. package/tests/test-configs/unit-tests/test-specific-settings.pageanrc.json +0 -26
  94. package/tests/test-configs/unit-tests/url-types.pageanrc.json +0 -10
  95. package/tests/testUtils.test.js +0 -244
  96. package/tests/tests.test.js +0 -533
@@ -1,533 +0,0 @@
1
- /* eslint-disable max-lines */
2
- 'use strict';
3
-
4
- const fs = require('fs');
5
-
6
- const puppeteer = require('puppeteer');
7
- const protocolify = require('protocolify');
8
-
9
- const testLogger = require('../lib/logger');
10
- const {
11
- horizontalScrollbarTest,
12
- consoleOutputTest,
13
- consoleErrorTest,
14
- renderedHtmlTest,
15
- pageLoadTimeTest,
16
- externalScriptTest,
17
- brokenLinkTest
18
- } = require('../lib/tests');
19
- const { testResultStates } = require('../lib/testUtils');
20
- const fileUtils = require('../lib/externalFileUtils');
21
- const linkUtils = require('../lib/linkUtils');
22
- const defaultConfig = require('../lib/default-config.json');
23
-
24
- let browser, page;
25
-
26
- const getPage = async(url) => {
27
- if (!browser) {
28
- const puppeteerLaunchOptions = { args: ['--no-sandbox'] };
29
- browser = await puppeteer.launch(puppeteerLaunchOptions);
30
- }
31
- page = await browser.newPage();
32
- await page.goto(url, { waitUntil: 'load' });
33
- };
34
-
35
- // File is read each time instead of require to ensure original,
36
- // not cached or modified cached, values.
37
- const getDefaultSettings = () => {
38
- return JSON.parse(fs.readFileSync('./lib/default-config.json', 'utf-8')).settings;
39
- };
40
-
41
- const getContext = async(url, consoleLog, includePage = false) => {
42
- if (includePage) {
43
- await getPage(protocolify(url));
44
- }
45
- return {
46
- page,
47
- consoleLog,
48
- urlSettings: getDefaultSettings(),
49
- logger: testLogger(defaultConfig)
50
- };
51
- };
52
-
53
- const closePageAndBrowser = async() => {
54
- await page.close();
55
- page = undefined;
56
- await browser.close();
57
- browser = undefined;
58
- };
59
-
60
- const consoleLogWithoutErrors = [
61
- {
62
- _type: 'log',
63
- _text: 'This is a test',
64
- _location: {
65
- url: 'file:///E:/Users/agoldent/Documents/Projects/NodeJS/Page-Load-Tests/tests/test-cases/consoleLog.html',
66
- lineNumber: 7,
67
- columnNumber: 16
68
- }
69
- }
70
- ];
71
-
72
- const consoleLogWithErrors = [
73
- {
74
- _type: 'error',
75
- _text: 'Failed to load resource: net::ERR_NAME_NOT_RESOLVED',
76
- _location: {
77
- url: 'https://this.url.does.not.exist/file.js'
78
- }
79
- }
80
- ];
81
-
82
- const executeTestWithLoggerSpy = async(context, testFunction, checkLinkResult = linkUtils.httpResponse.ok) => {
83
- const loggerSpy = jest.spyOn(context.logger, 'logTestResults').mockImplementation(() => { });
84
- const saveScriptSpy = jest.spyOn(fileUtils, 'saveExternalScript').mockImplementation(() => { });
85
- const checkLinkSpy = jest.spyOn(linkUtils, 'checkLink').mockImplementation(() => checkLinkResult);
86
- await testFunction(context);
87
- return {
88
- loggerSpy,
89
- saveScriptSpy,
90
- checkLinkSpy
91
- };
92
- };
93
-
94
- // eslint-disable-next-line max-lines-per-function
95
- describe('consoleErrorTest', () => {
96
- // eslint-disable-next-line require-await
97
- const testConsoleErrorTest = async(context) => {
98
- return executeTestWithLoggerSpy(context, consoleErrorTest);
99
- };
100
-
101
- afterEach(() => {
102
- jest.restoreAllMocks();
103
- });
104
-
105
- it('should not execute consoleErrorTest if isEnabled setting is false', async() => {
106
- expect.assertions(1);
107
- const context = await getContext('', consoleLogWithErrors);
108
- context.urlSettings.consoleErrorTest.enabled = false;
109
- const { loggerSpy } = await testConsoleErrorTest(context);
110
- expect(loggerSpy).not.toHaveBeenCalled();
111
- });
112
-
113
- it('should log a passed test result if console log has no entries', async() => {
114
- expect.assertions(1);
115
- const context = await getContext('', []);
116
- const { loggerSpy } = await testConsoleErrorTest(context);
117
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
118
- });
119
-
120
- it('should log a passed test result if console log has entries without errors', async() => {
121
- expect.assertions(1);
122
- const context = await getContext('', consoleLogWithoutErrors);
123
- const { loggerSpy } = await testConsoleErrorTest(context);
124
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
125
- });
126
-
127
- it('should log a failed test result if console log has entries with errors', async() => {
128
- expect.assertions(1);
129
- const context = await getContext('', consoleLogWithErrors);
130
- const { loggerSpy } = await testConsoleErrorTest(context);
131
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.failed }));
132
- });
133
-
134
- it('should log data with console log errors for a failed test', async() => {
135
- expect.assertions(1);
136
- const context = await getContext('', consoleLogWithErrors);
137
- const { loggerSpy } = await testConsoleErrorTest(context);
138
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
139
- });
140
-
141
- it('should not log data with console log errors for a passed test', async() => {
142
- expect.assertions(1);
143
- const context = await getContext('', consoleLogWithoutErrors);
144
- const { loggerSpy } = await testConsoleErrorTest(context);
145
- expect(loggerSpy).not.toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
146
- });
147
- });
148
-
149
- // eslint-disable-next-line max-lines-per-function
150
- describe('consoleOutputTest', () => {
151
- // eslint-disable-next-line require-await
152
- const testConsoleOutputTest = async(context) => {
153
- return executeTestWithLoggerSpy(context, consoleOutputTest);
154
- };
155
-
156
- afterEach(() => {
157
- jest.restoreAllMocks();
158
- });
159
-
160
- it('should not execute consoleOutputTest if isEnabled setting is false', async() => {
161
- expect.assertions(1);
162
- const context = await getContext('', consoleLogWithErrors);
163
- context.urlSettings.consoleOutputTest.enabled = false;
164
- const { loggerSpy } = await testConsoleOutputTest(context);
165
- expect(loggerSpy).not.toHaveBeenCalled();
166
- });
167
-
168
- it('should log a passed test result if console log has no entries', async() => {
169
- expect.assertions(1);
170
- const context = await getContext('', []);
171
- const { loggerSpy } = await testConsoleOutputTest(context);
172
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
173
- });
174
-
175
- it('should log a failed test result if console log has entries', async() => {
176
- expect.assertions(1);
177
- const context = await getContext('', consoleLogWithoutErrors);
178
- const { loggerSpy } = await testConsoleOutputTest(context);
179
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.failed }));
180
- });
181
-
182
- it('should log data with console log for a failed test', async() => {
183
- expect.assertions(1);
184
- const context = await getContext('', consoleLogWithErrors);
185
- const { loggerSpy } = await testConsoleOutputTest(context);
186
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
187
- });
188
-
189
- it('should log not data with console log for a passed test', async() => {
190
- expect.assertions(1);
191
- const context = await getContext('', []);
192
- const { loggerSpy } = await testConsoleOutputTest(context);
193
- expect(loggerSpy).not.toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
194
- });
195
- });
196
-
197
- // eslint-disable-next-line max-lines-per-function
198
- describe('horizontalScrollbarTest', () => {
199
- const noHorizontalScrollbarUrl = 'tests/test-cases/consoleLog.html';
200
- const horizontalScrollbarUrl = 'tests/test-cases/horizontalScrollbar.html';
201
-
202
- // eslint-disable-next-line require-await
203
- const testHorizontalScrollbarTest = async(context) => {
204
- return executeTestWithLoggerSpy(context, horizontalScrollbarTest);
205
- };
206
-
207
- afterEach(() => {
208
- jest.restoreAllMocks();
209
- });
210
-
211
- it('should not execute horizontalScrollbarTest if isEnabled setting is false', async() => {
212
- expect.assertions(1);
213
- const context = await getContext(noHorizontalScrollbarUrl, [], true);
214
- context.urlSettings.horizontalScrollbarTest.enabled = false;
215
- const { loggerSpy } = await testHorizontalScrollbarTest(context);
216
- expect(loggerSpy).not.toHaveBeenCalled();
217
- });
218
-
219
- it('should log a passed test result for page with no horizontal scroll bar', async() => {
220
- expect.assertions(1);
221
- const context = await getContext(noHorizontalScrollbarUrl, [], true);
222
- const { loggerSpy } = await testHorizontalScrollbarTest(context);
223
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
224
- });
225
-
226
- it('should log a failed test result for page with a horizontal scroll bar', async() => {
227
- expect.assertions(1);
228
- const context = await getContext(horizontalScrollbarUrl, [], true);
229
- const { loggerSpy } = await testHorizontalScrollbarTest(context);
230
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.failed }));
231
- });
232
-
233
- afterAll(async() => {
234
- await closePageAndBrowser();
235
- });
236
- });
237
-
238
- // eslint-disable-next-line max-lines-per-function
239
- describe('pageLoadTimeTest', () => {
240
- const normalLoadTimeUrl = 'tests/test-cases/dynamicContent.html';
241
- const slowLoadTimeUrl = 'tests/test-cases/slowLoad.html';
242
-
243
- // eslint-disable-next-line require-await
244
- const testPageLoadTimeTest = async(context) => {
245
- return executeTestWithLoggerSpy(context, pageLoadTimeTest);
246
- };
247
-
248
- afterEach(() => {
249
- jest.restoreAllMocks();
250
- });
251
-
252
- it('should not execute pageLoadTimeTest if isEnabled setting is false', async() => {
253
- expect.assertions(1);
254
- const context = await getContext(normalLoadTimeUrl, [], true);
255
- context.urlSettings.pageLoadTimeTest.enabled = false;
256
- const { loggerSpy } = await testPageLoadTimeTest(context);
257
- expect(loggerSpy).not.toHaveBeenCalled();
258
- });
259
-
260
- it('should log a passed test result for page that loads within timeout', async() => {
261
- expect.assertions(1);
262
- const context = await getContext(normalLoadTimeUrl, [], true);
263
- const { loggerSpy } = await testPageLoadTimeTest(context);
264
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
265
- });
266
-
267
- it('should log a failed test result and data with page load time for page that does not load within timeout', async() => {
268
- expect.assertions(1);
269
- const context = await getContext(slowLoadTimeUrl, [], true);
270
- const { loggerSpy } = await testPageLoadTimeTest(context);
271
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.failed }));
272
- });
273
-
274
- it('should log data with page load time for a failed test', async() => {
275
- expect.assertions(1);
276
- const context = await getContext(slowLoadTimeUrl, [], true);
277
- const { loggerSpy } = await testPageLoadTimeTest(context);
278
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ data: { pageLoadTime: expect.any(Number) } }));
279
- });
280
-
281
- it('should not log data with page load time for a passed test', async() => {
282
- expect.assertions(1);
283
- const context = await getContext(normalLoadTimeUrl, [], true);
284
- const { loggerSpy } = await testPageLoadTimeTest(context);
285
- expect(loggerSpy).not.toHaveBeenCalledWith(expect.objectContaining({ data: { pageLoadTime: expect.any(Number) } }));
286
- });
287
-
288
- afterAll(async() => {
289
- await closePageAndBrowser();
290
- });
291
- });
292
-
293
- // eslint-disable-next-line max-lines-per-function
294
- describe('renderedHtmlTest', () => {
295
- const validHtmlUrl = 'tests/test-cases/scriptError404.html';
296
- const invalidHtmlUrl = 'tests/test-cases/htmlError.html';
297
-
298
- // eslint-disable-next-line require-await
299
- const testRenderedHtmlTest = async(context) => {
300
- return executeTestWithLoggerSpy(context, renderedHtmlTest);
301
- };
302
-
303
- afterEach(() => {
304
- jest.restoreAllMocks();
305
- });
306
-
307
- it('should not execute test if isEnabled setting is false', async() => {
308
- expect.assertions(1);
309
- const context = await getContext(validHtmlUrl, [], true);
310
- context.urlSettings.renderedHtmlTest.enabled = false;
311
- const { loggerSpy } = await testRenderedHtmlTest(context);
312
- expect(loggerSpy).not.toHaveBeenCalled();
313
- });
314
-
315
- it('should log a passed test result for page that has valid HTML', async() => {
316
- expect.assertions(1);
317
- const context = await getContext(validHtmlUrl, [], true);
318
- const { loggerSpy } = await testRenderedHtmlTest(context);
319
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
320
- });
321
-
322
- it('should log a failed test result for page that has invalid HTML', async() => {
323
- expect.assertions(1);
324
- const context = await getContext(invalidHtmlUrl, [], true);
325
- const { loggerSpy } = await testRenderedHtmlTest(context);
326
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.failed }));
327
- });
328
-
329
- it('should log data with HTML errors for a failed test', async() => {
330
- expect.assertions(1);
331
- const context = await getContext(invalidHtmlUrl, [], true);
332
- const { loggerSpy } = await testRenderedHtmlTest(context);
333
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
334
- });
335
-
336
- it('should not log data with HTML errors for a passed test', async() => {
337
- expect.assertions(1);
338
- const context = await getContext(validHtmlUrl, [], true);
339
- const { loggerSpy } = await testRenderedHtmlTest(context);
340
- expect(loggerSpy).not.toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
341
- });
342
-
343
- afterAll(async() => {
344
- await closePageAndBrowser();
345
- });
346
- });
347
-
348
- // eslint-disable-next-line max-lines-per-function
349
- describe('externalScriptTest', () => {
350
- const noScriptUrl = 'tests/test-cases/consoleLog.html';
351
- const noExternalScriptUrl = 'tests/test-cases/noExternalScripts.html';
352
- const externalScriptUrl = 'tests/test-cases/externalScripts.html';
353
-
354
- // eslint-disable-next-line require-await
355
- const testExternalScriptTest = async(context) => {
356
- return executeTestWithLoggerSpy(context, externalScriptTest);
357
- };
358
-
359
- afterEach(() => {
360
- jest.restoreAllMocks();
361
- });
362
-
363
- it('should not execute test if isEnabled setting is false', async() => {
364
- expect.assertions(1);
365
- const context = await getContext(noScriptUrl, [], true);
366
- context.urlSettings.externalScriptTest.enabled = false;
367
- const { loggerSpy } = await testExternalScriptTest(context);
368
- expect(loggerSpy).not.toHaveBeenCalled();
369
- });
370
-
371
- it('should execute test if enabled setting is set to true', async() => {
372
- expect.assertions(1);
373
- const context = await getContext(noScriptUrl, [], true);
374
- const { loggerSpy } = await testExternalScriptTest(context);
375
- // Allow since this is just a configuration test to ensure execution, detailed
376
- // tests follow checking arguments.
377
- // eslint-disable-next-line jest/prefer-called-with
378
- expect(loggerSpy).toHaveBeenCalled();
379
- });
380
-
381
- it('should log a passed test result for page that has no scripts', async() => {
382
- expect.assertions(1);
383
- const context = await getContext(noScriptUrl, [], true);
384
- const { loggerSpy } = await testExternalScriptTest(context);
385
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
386
- });
387
-
388
- it('should log a passed test result for page that has no external scripts', async() => {
389
- expect.assertions(1);
390
- const context = await getContext(noExternalScriptUrl, [], true);
391
- const { loggerSpy } = await testExternalScriptTest(context);
392
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
393
- });
394
-
395
- it('should log a warning test result for page that has external scripts', async() => {
396
- expect.assertions(1);
397
- const context = await getContext(externalScriptUrl, [], true);
398
- const { loggerSpy } = await testExternalScriptTest(context);
399
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.warning }));
400
- });
401
-
402
- it('should log data with HTML errors for a page that has external scripts', async() => {
403
- expect.assertions(1);
404
- const context = await getContext(externalScriptUrl, [], true);
405
- const { loggerSpy } = await testExternalScriptTest(context);
406
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
407
- });
408
-
409
- it('should not log data with HTML errors for a page that does not have external scripts', async() => {
410
- expect.assertions(1);
411
- const context = await getContext(noExternalScriptUrl, [], true);
412
- const { loggerSpy } = await testExternalScriptTest(context);
413
- expect(loggerSpy).not.toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
414
- });
415
-
416
- it('should save files with external scripts for a page that has external scripts', async() => {
417
- expect.assertions(1);
418
- const externalFileCount = 4;
419
- const context = await getContext(externalScriptUrl, [], true);
420
- const { saveScriptSpy } = await testExternalScriptTest(context);
421
- expect(saveScriptSpy).toHaveBeenCalledTimes(externalFileCount);
422
- });
423
-
424
- it('should not save files with external scripts for a page that does not have external scripts', async() => {
425
- expect.assertions(1);
426
- const context = await getContext(noExternalScriptUrl, [], true);
427
- const { saveScriptSpy } = await testExternalScriptTest(context);
428
- expect(saveScriptSpy).not.toHaveBeenCalled();
429
- });
430
-
431
- afterAll(async() => {
432
- await closePageAndBrowser();
433
- });
434
- });
435
-
436
- // eslint-disable-next-line max-lines-per-function
437
- describe('brokenLinkTest', () => {
438
- const noLinkUrl = 'tests/test-cases/htmlError.html';
439
- const brokenLinkUrl = 'tests/test-cases/brokenLinks.html';
440
- const notDocumentLinksUrl = 'tests/test-cases/notDocumentLinks.html';
441
- const duplicateLinkUrl = 'tests/test-cases/duplicateLinks.html';
442
-
443
- // eslint-disable-next-line require-await
444
- const testBrokenLinkTest = async(context, checkLinkResult) => {
445
- return executeTestWithLoggerSpy(context, brokenLinkTest, checkLinkResult);
446
- };
447
-
448
- afterEach(() => {
449
- jest.restoreAllMocks();
450
- });
451
-
452
- it('should not execute broken links test if isEnabled setting is false', async() => {
453
- expect.assertions(1);
454
- const context = await getContext(brokenLinkUrl, [], true);
455
- context.urlSettings.brokenLinkTest.enabled = false;
456
- const { loggerSpy } = await testBrokenLinkTest(context);
457
- expect(loggerSpy).not.toHaveBeenCalled();
458
- });
459
-
460
- it('should execute broken links test if enabled setting is set to true', async() => {
461
- expect.assertions(1);
462
- const context = await getContext(brokenLinkUrl, [], true);
463
- const { loggerSpy } = await testBrokenLinkTest(context);
464
- // Allow since this is just a configuration test to ensure execution, detailed
465
- // tests follow checking arguments.
466
- // eslint-disable-next-line jest/prefer-called-with
467
- expect(loggerSpy).toHaveBeenCalled();
468
- });
469
-
470
- it('should log a passed test result for page that has no broken links', async() => {
471
- expect.assertions(1);
472
- const context = await getContext(brokenLinkUrl, [], true);
473
- const { loggerSpy } = await testBrokenLinkTest(context, linkUtils.httpResponse.ok);
474
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.passed }));
475
- });
476
-
477
- it('should log a failed test result for page that has broken links', async() => {
478
- expect.assertions(1);
479
- const context = await getContext(brokenLinkUrl, [], true);
480
- context.urlSettings.brokenLinkTest.failWarn = false;
481
- const { loggerSpy } = await testBrokenLinkTest(context, linkUtils.httpResponse.unknownError);
482
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ result: testResultStates.failed }));
483
- });
484
-
485
- it('should log data with broken link errors for a page that has broken links', async() => {
486
- expect.assertions(1);
487
- const context = await getContext(brokenLinkUrl, [], true);
488
- const { loggerSpy } = await testBrokenLinkTest(context, linkUtils.httpResponse.unknownError);
489
- expect(loggerSpy).toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
490
- });
491
-
492
- it('should not log data with broken link errors for a page that does not have broken links', async() => {
493
- expect.assertions(1);
494
- const context = await getContext(brokenLinkUrl, [], true);
495
- const { loggerSpy } = await testBrokenLinkTest(context);
496
- expect(loggerSpy).not.toHaveBeenCalledWith(expect.objectContaining({ data: expect.any(Array) }));
497
- });
498
-
499
- it('should check for broken links for a page that has links', async() => {
500
- expect.assertions(1);
501
- const linkCount = 7;
502
- const context = await getContext(brokenLinkUrl, [], true);
503
- const { checkLinkSpy } = await testBrokenLinkTest(context);
504
- expect(checkLinkSpy).toHaveBeenCalledTimes(linkCount);
505
- });
506
-
507
- it('should not check for broken links for a page that does not have links', async() => {
508
- expect.assertions(1);
509
- const context = await getContext(noLinkUrl, [], true);
510
- const { checkLinkSpy } = await testBrokenLinkTest(context);
511
- expect(checkLinkSpy).not.toHaveBeenCalled();
512
- });
513
-
514
- it('should only check unique links for broken links', async() => {
515
- expect.assertions(1);
516
- // Test page includes 7 links with a duplicate same page link and external link
517
- const linkCount = 5;
518
- const context = await getContext(duplicateLinkUrl, [], true);
519
- const { checkLinkSpy } = await testBrokenLinkTest(context);
520
- expect(checkLinkSpy).toHaveBeenCalledTimes(linkCount);
521
- });
522
-
523
- it('should not check for broken links for a page with only links that are not documents (http/file)', async() => {
524
- expect.assertions(1);
525
- const context = await getContext(notDocumentLinksUrl, [], true);
526
- const { checkLinkSpy } = await testBrokenLinkTest(context);
527
- expect(checkLinkSpy).not.toHaveBeenCalled();
528
- });
529
-
530
- afterAll(async() => {
531
- await closePageAndBrowser();
532
- });
533
- });