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.
- package/LICENSE +1 -1
- package/README.md +9 -9
- package/docs/upgrade-guide.md +16 -0
- package/index.js +7 -4
- package/lib/config.js +2 -2
- package/lib/default-config.json +41 -39
- package/lib/externalFileUtils.js +1 -1
- package/lib/linkUtils.js +162 -25
- package/lib/logger.js +1 -1
- package/lib/report-template.handlebars +224 -209
- package/lib/schemaErrors.js +5 -4
- package/lib/testUtils.js +1 -1
- package/lib/tests.js +14 -14
- package/package.json +28 -30
- package/schemas/pageanrc.schema.json +199 -191
- package/.codeclimate.json +0 -8
- package/.depcheckrc.json +0 -3
- package/.dockerignore +0 -12
- package/.eslintrc.json +0 -19
- package/.gitattributes +0 -4
- package/.gitlab/gitlab-releaser.json +0 -16
- package/.htmlhintrc +0 -25
- package/.markdownlint.json +0 -13
- package/.pa11yci.json +0 -5
- package/.pageanrc.json +0 -55
- package/.stylelintrc.json +0 -7
- package/CHANGELOG.md +0 -204
- package/gitlab.pageanrc.json +0 -16
- package/jest.config.json +0 -22
- package/static-server.pageanrc.json +0 -50
- package/tests/__snapshots__/config.test.js.snap +0 -591
- package/tests/__snapshots__/externalFileUtils.test.js.snap +0 -7
- package/tests/__snapshots__/index.test.js.snap +0 -30
- package/tests/__snapshots__/pagean.test.js.snap +0 -82
- package/tests/__snapshots__/pageanrc.test.js.snap +0 -759
- package/tests/__snapshots__/reporter.test.js.snap +0 -509
- package/tests/config.test.js +0 -264
- package/tests/externalFileUtils.test.js +0 -184
- package/tests/index.test.js +0 -181
- package/tests/linkUtils.test.js +0 -290
- package/tests/logger.test.js +0 -324
- package/tests/pagean.test.js +0 -85
- package/tests/pageanrc.test.js +0 -96
- package/tests/reporter.test.js +0 -82
- package/tests/schemaErrors.test.js +0 -88
- package/tests/test-cases/.htmlhintrc +0 -25
- package/tests/test-cases/brokenLinks.html +0 -22
- package/tests/test-cases/consoleLog.html +0 -11
- package/tests/test-cases/duplicateLinks.html +0 -22
- package/tests/test-cases/dynamicContent.html +0 -13
- package/tests/test-cases/externalScripts.html +0 -21
- package/tests/test-cases/horizontalScrollbar.html +0 -13
- package/tests/test-cases/htmlError.html +0 -11
- package/tests/test-cases/noExternalScripts.html +0 -12
- package/tests/test-cases/notDocumentLinks.html +0 -18
- package/tests/test-cases/pagean-results.json +0 -1
- package/tests/test-cases/scriptError404.html +0 -9
- package/tests/test-cases/slowLoad.html +0 -9
- package/tests/test-configs/cli-tests/.pageanrc.json +0 -28
- package/tests/test-configs/cli-tests/all-empty.pageanrc.json +0 -10
- package/tests/test-configs/cli-tests/all-errors.pageanrc.json +0 -69
- package/tests/test-configs/cli-tests/all-fail-cli.pageanrc.json +0 -9
- package/tests/test-configs/cli-tests/no-urls.pageanrc.json +0 -7
- package/tests/test-configs/cli-tests/pass-fail-cli.pageanrc.json +0 -14
- package/tests/test-configs/integration-tests/all-passing-tests.pageanrc.json +0 -63
- package/tests/test-configs/integration-tests/broken-links-error.pageanrc.json +0 -22
- package/tests/test-configs/integration-tests/console-error-reporter-cli-json.pageanrc.json +0 -20
- package/tests/test-configs/integration-tests/console-error-reporter-html.pageanrc.json +0 -19
- package/tests/test-configs/integration-tests/console-error.pageanrc.json +0 -16
- package/tests/test-configs/integration-tests/console-output.pageanrc.json +0 -16
- package/tests/test-configs/integration-tests/external-scripts-error.pageanrc.json +0 -19
- package/tests/test-configs/integration-tests/horizontal-scrollbar.pageanrc.json +0 -16
- package/tests/test-configs/integration-tests/html-error.pageanrc.json +0 -16
- package/tests/test-configs/integration-tests/page-load-time.pageanrc.json +0 -16
- package/tests/test-configs/unit-tests/empty-url-values.pageanrc.json +0 -9
- package/tests/test-configs/unit-tests/empty-urls.pageanrc.json +0 -3
- package/tests/test-configs/unit-tests/empty.pageanrc.json +0 -2
- package/tests/test-configs/unit-tests/global-and-test-specific-settings-shorthand.pageanrc.json +0 -30
- package/tests/test-configs/unit-tests/global-and-test-specific-settings-test-props.pageanrc.json +0 -42
- package/tests/test-configs/unit-tests/global-and-test-specific-settings.pageanrc.json +0 -34
- package/tests/test-configs/unit-tests/global-test-settings.pageanrc.json +0 -15
- package/tests/test-configs/unit-tests/htmlhintrc-invalid.pageanrc.json +0 -7
- package/tests/test-configs/unit-tests/htmlhintrc-valid.pageanrc.json +0 -7
- package/tests/test-configs/unit-tests/ignored-links-denormalized.pageanrc.json +0 -18
- package/tests/test-configs/unit-tests/invalid.pageanrc.json +0 -0
- package/tests/test-configs/unit-tests/no-test-settings.pageanrc.json +0 -6
- package/tests/test-configs/unit-tests/project-no-test-settings.pageanrc.json +0 -7
- package/tests/test-configs/unit-tests/puppeteer-no-test-settings.pageanrc.json +0 -9
- package/tests/test-configs/unit-tests/reporters-empty.pageanrc.json +0 -7
- package/tests/test-configs/unit-tests/reporters-invalid-type.pageanrc.json +0 -9
- package/tests/test-configs/unit-tests/reporters-not-array.pageanrc.json +0 -6
- package/tests/test-configs/unit-tests/reporters-valid.pageanrc.json +0 -9
- package/tests/test-configs/unit-tests/test-specific-settings.pageanrc.json +0 -26
- package/tests/test-configs/unit-tests/url-types.pageanrc.json +0 -10
- package/tests/testUtils.test.js +0 -244
- package/tests/tests.test.js +0 -533
package/tests/testUtils.test.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { testResultStates, pageanTest } = require('../lib/testUtils');
|
|
4
|
-
|
|
5
|
-
describe('testResultStates', () => {
|
|
6
|
-
it('should include a passed state', () => {
|
|
7
|
-
expect.assertions(1);
|
|
8
|
-
expect(testResultStates.passed).toBeDefined();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should include a warning state', () => {
|
|
12
|
-
expect.assertions(1);
|
|
13
|
-
expect(testResultStates.warning).toBeDefined();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should include a failed state', () => {
|
|
17
|
-
expect.assertions(1);
|
|
18
|
-
expect(testResultStates.failed).toBeDefined();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should provide string values for all states', () => {
|
|
22
|
-
expect.assertions(3); // eslint-disable-line no-magic-numbers
|
|
23
|
-
for (const state of Object.keys(testResultStates)) {
|
|
24
|
-
expect(typeof(testResultStates[state])).toStrictEqual('string');
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line max-lines-per-function
|
|
30
|
-
describe('pageanTest', () => {
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
jest.restoreAllMocks();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('should provide a template test function', () => {
|
|
36
|
-
expect.assertions(1);
|
|
37
|
-
expect(typeof(pageanTest)).toStrictEqual('function');
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// eslint-disable-next-line max-lines-per-function
|
|
41
|
-
const executeTestWithMocks = async(testArguments) => {
|
|
42
|
-
const { testIsEnabledSettingValue = true, testIsFailWarnValue = false, ...otherArguments } = testArguments;
|
|
43
|
-
const defaultTestArguments = {
|
|
44
|
-
testName: 'should run a test',
|
|
45
|
-
testSettingProperty: 'testIsEnabledSetting',
|
|
46
|
-
// Include context argument as a reminder of the argument passed even though
|
|
47
|
-
// this mock test function does not use it.
|
|
48
|
-
// eslint-disable-next-line no-unused-vars
|
|
49
|
-
testFunction: (context) => ({ result: testResultStates.passed }),
|
|
50
|
-
testContext: {
|
|
51
|
-
urlSettings: {
|
|
52
|
-
testIsEnabledSetting: {
|
|
53
|
-
enabled: testIsEnabledSettingValue,
|
|
54
|
-
failWarn: testIsFailWarnValue
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
logger: {
|
|
58
|
-
logTestResults: () => {}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
const finalTestArguments = Object.assign({}, defaultTestArguments, otherArguments);
|
|
63
|
-
const mockTestFunction = jest.fn().mockImplementationOnce(finalTestArguments.testFunction);
|
|
64
|
-
let logTestResultsSpy;
|
|
65
|
-
if (finalTestArguments.testContext.logger) {
|
|
66
|
-
logTestResultsSpy = jest.spyOn(finalTestArguments.testContext.logger, 'logTestResults');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
await pageanTest(finalTestArguments.testName, mockTestFunction, finalTestArguments.testContext, finalTestArguments.testSettingProperty);
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
mockTestFunction,
|
|
73
|
-
logTestResultsSpy
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
it('should throw if testSettingProperty is not specified', async() => {
|
|
78
|
-
expect.assertions(1);
|
|
79
|
-
await expect(executeTestWithMocks({ testSettingProperty: undefined })).rejects.toThrow('undefined');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should throw for invalid testSettingProperty', async() => {
|
|
83
|
-
expect.assertions(1);
|
|
84
|
-
const settingName = 'invalidSetting';
|
|
85
|
-
await expect(executeTestWithMocks({ testSettingProperty: settingName })).rejects.toThrow(settingName);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should execute test function for valid testSettingProperty that is true', async() => {
|
|
89
|
-
expect.assertions(1);
|
|
90
|
-
const { mockTestFunction } = await executeTestWithMocks({ testSettingProperty: 'testIsEnabledSetting', testIsEnabledSettingValue: true });
|
|
91
|
-
// eslint-disable-next-line jest/prefer-called-with
|
|
92
|
-
expect(mockTestFunction).toHaveBeenCalled();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('should not execute test function for valid testSettingProperty that is false', async() => {
|
|
96
|
-
expect.assertions(1);
|
|
97
|
-
const { mockTestFunction } = await executeTestWithMocks({ testSettingProperty: 'testIsEnabledSetting', testIsEnabledSettingValue: false });
|
|
98
|
-
expect(mockTestFunction).not.toHaveBeenCalled();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('should throw if testContext is undefined', async() => {
|
|
102
|
-
expect.assertions(1);
|
|
103
|
-
await expect(executeTestWithMocks({ testContext: undefined })).rejects.toThrow('logger');
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should throw if provided testContext does not have a urlSettings property', async() => {
|
|
107
|
-
expect.assertions(1);
|
|
108
|
-
const settingName = 'testIsEnabledSetting';
|
|
109
|
-
await expect(executeTestWithMocks({ testSettingProperty: settingName, testContext: {
|
|
110
|
-
logger: {
|
|
111
|
-
logTestResults: () => {}
|
|
112
|
-
}
|
|
113
|
-
} })).rejects.toThrow(settingName);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('should throw if provided testContext does not have a logger property', async() => {
|
|
117
|
-
expect.assertions(1);
|
|
118
|
-
const settingName = 'testIsEnabledSetting';
|
|
119
|
-
await expect(executeTestWithMocks({ testSettingProperty: settingName, testContext: {
|
|
120
|
-
urlSettings: {
|
|
121
|
-
testIsEnabledSetting: { enabled: true }
|
|
122
|
-
}
|
|
123
|
-
} })).rejects.toThrow('logTestResults');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('should throw if provided testContext.logger is an invalid object', async() => {
|
|
127
|
-
expect.assertions(1);
|
|
128
|
-
const settingName = 'testIsEnabledSetting';
|
|
129
|
-
await expect(executeTestWithMocks({ testSettingProperty: settingName, testContext: {
|
|
130
|
-
urlSettings: {
|
|
131
|
-
testIsEnabledSetting: { enabled: true }
|
|
132
|
-
},
|
|
133
|
-
logger: {
|
|
134
|
-
logTestResults: true
|
|
135
|
-
}
|
|
136
|
-
} })).rejects.toThrow('logTestResults');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('should execute testFunction passing testContext', async() => {
|
|
140
|
-
expect.assertions(1);
|
|
141
|
-
const testContext = {
|
|
142
|
-
urlSettings: {
|
|
143
|
-
testIsEnabledSetting: { enabled: true }
|
|
144
|
-
},
|
|
145
|
-
logger: {
|
|
146
|
-
logTestResults: () => {}
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
const { mockTestFunction } = await executeTestWithMocks({ testContext });
|
|
150
|
-
expect(mockTestFunction).toHaveBeenCalledWith(testContext);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('should add a testSettings property to the provided testContext', async() => {
|
|
154
|
-
expect.assertions(1);
|
|
155
|
-
const { mockTestFunction } = await executeTestWithMocks({ testSettingProperty: 'testIsEnabledSetting', testIsEnabledSettingValue: true });
|
|
156
|
-
expect(mockTestFunction).toHaveBeenCalledWith(expect.objectContaining({ testSettings: expect.any(Object) }));
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should log passed result for passing test', async() => {
|
|
160
|
-
expect.assertions(1);
|
|
161
|
-
const result = testResultStates.passed;
|
|
162
|
-
const testFunction = () => ({ result });
|
|
163
|
-
const { logTestResultsSpy } = await executeTestWithMocks({ testFunction });
|
|
164
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ result }));
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('should log failed result for failing test', async() => {
|
|
168
|
-
expect.assertions(1);
|
|
169
|
-
const result = testResultStates.failed;
|
|
170
|
-
const testFunction = () => ({ result });
|
|
171
|
-
const { logTestResultsSpy } = await executeTestWithMocks({ testFunction });
|
|
172
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ result }));
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it('should log warning result for failing test with failWarn true', async() => {
|
|
176
|
-
expect.assertions(1);
|
|
177
|
-
const testResult = testResultStates.failed;
|
|
178
|
-
const loggedResult = testResultStates.warning;
|
|
179
|
-
const testFunction = () => ({ result: testResult });
|
|
180
|
-
const { logTestResultsSpy } = await executeTestWithMocks({ testFunction, testIsFailWarnValue: true });
|
|
181
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ result: loggedResult }));
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
it('should log passed result for passing test with failWarn true', async() => {
|
|
185
|
-
expect.assertions(1);
|
|
186
|
-
const result = testResultStates.passed;
|
|
187
|
-
const testFunction = () => ({ result });
|
|
188
|
-
const { logTestResultsSpy } = await executeTestWithMocks({ testFunction, testIsFailWarnValue: true });
|
|
189
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ result }));
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
const executeTestThatTrows = async(errorMessage = 'test failed', testIsFailWarnValue = false) => {
|
|
193
|
-
const testFunction = () => {
|
|
194
|
-
throw new Error(errorMessage);
|
|
195
|
-
};
|
|
196
|
-
const { logTestResultsSpy } = await executeTestWithMocks({ testFunction, testIsFailWarnValue });
|
|
197
|
-
return logTestResultsSpy;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
it('should log failed results for failing test if testFunction throws', async() => {
|
|
201
|
-
expect.assertions(1);
|
|
202
|
-
const result = testResultStates.failed;
|
|
203
|
-
const logTestResultsSpy = await executeTestThatTrows();
|
|
204
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ result }));
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
it('should log warning results for failing test if testFunction throws and failWarn is true', async() => {
|
|
208
|
-
expect.assertions(1);
|
|
209
|
-
const result = testResultStates.warning;
|
|
210
|
-
const testIsFailWarn = true;
|
|
211
|
-
const logTestResultsSpy = await executeTestThatTrows('', testIsFailWarn);
|
|
212
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ result }));
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it('should log error as data if testFunction throws', async() => {
|
|
216
|
-
expect.assertions(2); // eslint-disable-line no-magic-numbers
|
|
217
|
-
const errorMessage = 'this test failed';
|
|
218
|
-
const logTestResultsSpy = await executeTestThatTrows(errorMessage);
|
|
219
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ data: { error: expect.any(Error) } }));
|
|
220
|
-
expect(logTestResultsSpy.mock.calls[0][0].data.error.message).toStrictEqual(errorMessage);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
it('should log results with given test name', async() => {
|
|
224
|
-
expect.assertions(1);
|
|
225
|
-
const { logTestResultsSpy } = await executeTestWithMocks({});
|
|
226
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ name: 'should run a test' }));
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('should log results with updated test name if overridden in testFunction', async() => {
|
|
230
|
-
expect.assertions(1);
|
|
231
|
-
const testName = 'should have a proper test name';
|
|
232
|
-
const { logTestResultsSpy } = await executeTestWithMocks({ testName });
|
|
233
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ name: testName }));
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it('should log results with test data if provided', async() => {
|
|
237
|
-
expect.assertions(1);
|
|
238
|
-
const result = testResultStates.passed;
|
|
239
|
-
const data = [{ foo1: 'bar1' }, { foo1: 'bar2' }];
|
|
240
|
-
const testFunction = () => ({ result, data });
|
|
241
|
-
const { logTestResultsSpy } = await executeTestWithMocks({ testFunction });
|
|
242
|
-
expect(logTestResultsSpy).toHaveBeenCalledWith(expect.objectContaining({ result, data }));
|
|
243
|
-
});
|
|
244
|
-
});
|