forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
210 lines (177 loc) · 9.16 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
const { expect } = require('chai');
const { castArray } = require('lodash');
const { errorInEachBrowserContains } = require('../../assertion-helper.js');
const {
CLIENT_ERROR_MESSAGE,
CLIENT_PAGE_URL,
CALLBACK_FUNC_ERROR,
CLIENT_ERROR_REGEXP, SKIP_JS_ERRORS_CALLBACK_OPTIONS,
} = require('./constants');
const { createReporter } = require('../../utils/reporter');
const experimentalDebug = !!process.env.EXPERIMENTAL_DEBUG;
describe('Test should fail after js-error on the page', () => {
it('if an error is raised before test done', () => {
return runTests('./testcafe-fixtures/error-on-load-test.js', 'Empty test', { shouldFail: true })
.catch(errs => {
errorInEachBrowserContains(errs, 'The first error on page load', 0);
errorInEachBrowserContains(errs, 'http://localhost:3000/fixtures/page-js-errors/pages/error-on-load.html', 0);
});
});
it('if an error is raised before a command', () => {
return runTests('./testcafe-fixtures/error-on-load-test.js', 'Click body', { shouldFail: true })
.catch(errs => {
errorInEachBrowserContains(errs, 'The first error on page load', 0);
});
});
it('if an error is raised after a command', () => {
return runTests('./testcafe-fixtures/error-after-click-test.js', 'Click button', { shouldFail: true })
.catch(errs => {
errorInEachBrowserContains(errs, 'Error on click', 0);
});
});
it('if an error is raised after a command after the page reloaded', () => {
return runTests('./testcafe-fixtures/error-after-reload-test.js', 'Click button', { shouldFail: true })
.catch(errs => {
errorInEachBrowserContains(errs, 'The first error on page load', 0);
});
});
it('if an error is raised after a command before the page reloaded', () => {
return runTests('./testcafe-fixtures/error-before-reload-test.js', 'Click button', { shouldFail: true })
.catch(errs => {
errorInEachBrowserContains(errs, 'Error before reload', 0);
});
});
it('if unhandled promise rejection is raised', () => {
return runTests('./testcafe-fixtures/unhandled-promise-rejection-test.js', 'Click button',
{
shouldFail: true,
only: 'chrome',
})
.catch(errs => {
expect(errs[0]).contains('Rejection reason');
expect(errs[0]).contains('No stack trace available');
});
});
});
describe('Should ignore an js-error on the page if the skipJsErrors option is set to true', () => {
it('uncaught JavaScript error', () => {
return runTests('./testcafe-fixtures/error-after-click-test.js', 'Click button', { skipJsErrors: true });
});
it('unhandled Promise rejection', () => {
return runTests('./testcafe-fixtures/unhandled-promise-rejection-test.js', 'Click button',
{
skipJsErrors: true,
only: 'chrome',
});
});
});
const expectFailAttempt = (errors, expectedMessage) => {
Object.values(errors).forEach(err => {
const error = castArray(err);
expect(error[0].message || error[0]).contains(expectedMessage);
});
};
// TODO: fix tests for Debug task
(experimentalDebug ? describe.skip : describe)('Customize SkipJSErrors (GH-2775)', () => {
describe('TestController method', () => {
it('Should skip JS errors without param', async () => {
return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors without param');
});
it('Should skip JS errors with boolean param', async () => {
return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors with boolean param');
});
it('Should skip JS errors with message and stack options', async () => {
return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors with multiple options');
});
it('Should skip JS errors with SkipJsErrorsCallbackOptions', async () => {
return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors with SkipJsErrorsCallbackOptions');
});
it('Should skip JS errors with SkipJsErrorsCallbackOptions containing RegExp enclosed in quotes', async () => {
return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors with SkipJsErrorsCallbackOptions containing RegExp enclosed in quotes');
});
it('Should skip JS errors with callback function returning Promise', async () => {
return runTests('./testcafe-fixtures/test-controller.js', 'Should skip JS errors with callback function returning Promise', { skip: ['ie'] });
});
it('Should skip first error and fail on second error when skipJsError method called twice', async () => {
const reporterContext = {
actionsFinished: 0,
errors: [],
};
const reporter = createReporter({
reportTestActionDone: () => {
reporterContext.actionsFinished++;
},
reportTestDone: (name, testRunInfo) => {
reporterContext.errors = testRunInfo.errs;
},
});
return runTests('./testcafe-fixtures/test-controller.js', 'Should correctly skip JS errors with multiple method calls', {
reporter: [reporter],
})
.then(() => {
expect(reporterContext.actionsFinished).eql(4 * reporterContext.errors.length);
expect(reporterContext.errors[0].code).eql('E1');
});
});
it("Should fail if message option doesn't satisfy the client error message", async () => {
return runTests('./testcafe-fixtures/test-controller.js', "Should fail if message option doesn't satisfy the client error message", { shouldFail: true })
.catch(errs => {
expectFailAttempt(errs, CLIENT_ERROR_MESSAGE);
});
});
it("Should fail if callback function logic doesn't satisfy the client error message", async () => {
return runTests('./testcafe-fixtures/test-controller.js', 'Should fail with SkipJsErrorsCallbackOptions', { shouldFail: true })
.catch(errs => {
expectFailAttempt(errs, CLIENT_ERROR_MESSAGE);
});
});
it('Should fail if error occurred in callback function', async () => {
return runTests('./testcafe-fixtures/test-controller.js', 'Should fail due to error in callback function', { shouldFail: true })
.catch(errs => {
expectFailAttempt(errs, CALLBACK_FUNC_ERROR);
});
});
});
describe('Fixture and Test method', () => {
it('Should skip JS errors with fixture.skipJsErrors', () => {
return runTests('./testcafe-fixtures/fixture-and-test.js', 'Should skip JS errors with callback function specified in fixture');
});
it('Should skip JS errors with test.skipJsErrors', () => {
return runTests('./testcafe-fixtures/fixture-and-test.js', 'Should skip JS errors with callback function specified in test');
});
});
describe('Runner option and method', () => {
it('Should skip errors with SkipJsErrors options object specified in run options', () => {
const skipJsErrors = {
message: CLIENT_ERROR_REGEXP,
pageUrl: CLIENT_PAGE_URL,
};
return runTests('./testcafe-fixtures/runner.js', 'Throw client error', { skipJsErrors });
});
it('Should skip errors with SkipJsErrorsCallbackOptions specified in run options', () => {
const skipJsErrors = SKIP_JS_ERRORS_CALLBACK_OPTIONS;
return runTests('./testcafe-fixtures/runner.js', 'Throw client error', { skipJsErrors });
});
});
describe('Override skipJsErrors option', () => {
it('runner -> fixture', () => {
const skipJsErrors = {
message: CLIENT_ERROR_MESSAGE,
pageUrl: 'incorrectUrl',
};
return runTests('./testcafe-fixtures/fixture-and-test.js', 'Should skip JS errors with callback function specified in fixture', { skipJsErrors });
});
it('fixture -> test', () => {
return runTests('./testcafe-fixtures/fixture-and-test.js', 'Should fail due to test skipJsErrors(false) method call', { shouldFail: true })
.catch(errs => {
expectFailAttempt(errs, CLIENT_ERROR_MESSAGE);
});
});
it('test -> testController', () => {
return runTests('./testcafe-fixtures/fixture-and-test.js', 'Should fail if value specified in test is overridden to false in TestController', { shouldFail: true })
.catch(errs => {
expectFailAttempt(errs, CLIENT_ERROR_MESSAGE);
});
});
});
});