-
Notifications
You must be signed in to change notification settings - Fork 682
Expand file tree
/
Copy pathbootstrapper-test.js
More file actions
227 lines (184 loc) · 8.78 KB
/
bootstrapper-test.js
File metadata and controls
227 lines (184 loc) · 8.78 KB
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
const { expect } = require('chai');
const BrowserConnection = require('../../lib/browser/connection');
const Bootstrapper = require('../../lib/runner/bootstrapper');
const Test = require('../../lib/api/structure/test');
const delay = require('../../lib/utils/delay');
const {
browserConnectionGatewayMock,
configurationMock,
createBrowserProviderMock,
} = require('./helpers/mocks');
describe('Bootstrapper', () => {
describe('.createRunnableConfiguration()', () => {
let bootstrapper = null;
beforeEach(() => {
bootstrapper = new Bootstrapper({
browserConnectionGateway: browserConnectionGatewayMock,
configuration: configurationMock,
});
bootstrapper.browserInitTimeout = 100;
bootstrapper.TESTS_COMPILATION_UPPERBOUND = 0;
bootstrapper.browsers = [ new BrowserConnection(browserConnectionGatewayMock, { provider: createBrowserProviderMock({ local: false }) }) ];
bootstrapper._compileTests = async () => {
await delay(1500);
return [ new Test({ currentFixture: void 0 }) ];
};
});
it('Browser connection error message should include hint that tests compilation takes too long', async function () {
this.timeout(3000);
try {
await bootstrapper.createRunnableConfiguration();
throw new Error('Promise rejection expected');
}
catch (err) {
expect(err.message).contains('Tests took too long to compile');
}
});
it('Should raise an error if fixture.globalBefore is not a function', async function () {
bootstrapper.hooks = {
fixture: {
before: 'yo',
},
};
try {
await bootstrapper.createRunnableConfiguration();
throw new Error('Promise rejection expected');
}
catch (err) {
expect(err.message).eql('Cannot prepare tests due to the following error:\n\n' +
'The fixture.globalBefore hook (string) is not of expected type (function).');
}
});
it('Should raise an error if fixture.globalAfter is not a function', async function () {
bootstrapper.hooks = {
fixture: {
after: 'yo',
},
};
try {
await bootstrapper.createRunnableConfiguration();
throw new Error('Promise rejection expected');
}
catch (err) {
expect(err.message).eql('Cannot prepare tests due to the following error:\n\n' +
'The fixture.globalAfter hook (string) is not of expected type (function).');
}
});
it('Should raise an error if test.globalBefore is not a function', async function () {
bootstrapper.hooks = {
test: {
before: 'yo',
},
};
try {
await bootstrapper.createRunnableConfiguration();
throw new Error('Promise rejection expected');
}
catch (err) {
expect(err.message).eql('Cannot prepare tests due to the following error:\n\n' +
'The test.globalBefore hook (string) is not of expected type (function).');
}
});
it('Should raise an error if test.globalAfter is not a function', async function () {
bootstrapper.hooks = {
test: {
after: 'yo',
},
};
try {
await bootstrapper.createRunnableConfiguration();
throw new Error('Promise rejection expected');
}
catch (err) {
expect(err.message).eql('Cannot prepare tests due to the following error:\n\n' +
'The test.globalAfter hook (string) is not of expected type (function).');
}
});
it("Should disable native automation mode if it's necessary", async () => {
let remoteBrowserConnections = [];
let automatedBrowserConnections = [];
const chromeBrowserInfoMock = {
provider: {
supportNativeAutomation: () => true,
},
};
const firefoxBrowserInfoMock = {
provider: {
supportNativeAutomation: () => false,
},
};
const remoteBrowserConnectionMock = {
isNativeAutomationEnabled: () => false,
};
bootstrapper.configuration.clear();
bootstrapper._disableNativeAutomationIfNecessary(remoteBrowserConnections, automatedBrowserConnections);
expect(bootstrapper.configuration._mergedOptions).to.be.undefined;
remoteBrowserConnections = [remoteBrowserConnectionMock];
bootstrapper._disableNativeAutomationIfNecessary(remoteBrowserConnections, automatedBrowserConnections);
expect(bootstrapper.configuration._mergedOptions).eql({ disableNativeAutomation: true });
bootstrapper.configuration.clear();
remoteBrowserConnections = [];
automatedBrowserConnections = [chromeBrowserInfoMock];
bootstrapper._disableNativeAutomationIfNecessary(remoteBrowserConnections, automatedBrowserConnections);
expect(bootstrapper.configuration._mergedOptions).to.be.undefined;
bootstrapper.configuration.clear();
automatedBrowserConnections = [chromeBrowserInfoMock, firefoxBrowserInfoMock];
bootstrapper._disableNativeAutomationIfNecessary(remoteBrowserConnections, automatedBrowserConnections);
expect(bootstrapper.configuration._mergedOptions).eql({ disableNativeAutomation: true });
bootstrapper.configuration.clear();
});
it('Should throw an error if browser is opened with the "userProfile" option in the Native Automation mode', async function () {
try {
bootstrapper.browsers = [{
alias: 'chrome',
browserOption: { userProfile: true },
provider: {
isLocalBrowser: () => true,
supportNativeAutomation: () => true,
},
}, {
alias: 'edge',
browserOption: { userProfile: true },
provider: {
isLocalBrowser: () => true,
supportNativeAutomation: () => true,
},
}];
await bootstrapper.createRunnableConfiguration();
throw new Error('Promise rejection expected');
}
catch (err) {
expect(err.message).eql('Cannot initialize the test run. When TestCafe uses native automation, it can only ' +
'launch browsers with an empty user profile. Disable native automation, or remove ' +
'the "userProfile" suffix from the following browser aliases: "chrome, edge".');
}
});
it('Should use localhost hostname strategy for local browsers in proxy mode', async () => {
let calculateHostnameOptions = null;
const originalGetOption = bootstrapper.configuration.getOption;
const originalCalculateHostname = bootstrapper.configuration.calculateHostname;
try {
bootstrapper.configuration.getOption = optionName => {
if (optionName === 'disableNativeAutomation')
return true;
return originalGetOption(optionName);
};
bootstrapper.configuration.calculateHostname = options => {
calculateHostnameOptions = options;
};
await bootstrapper._setupProxy([{
browserName: 'firefox',
provider: createBrowserProviderMock({ local: true }),
}]);
expect(calculateHostnameOptions).eql({
nativeAutomation: false,
allBrowsersLocal: true,
});
}
finally {
bootstrapper.configuration.getOption = originalGetOption;
bootstrapper.configuration.calculateHostname = originalCalculateHostname;
}
});
});
});