forked from theintern/intern
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.js
261 lines (234 loc) · 7.52 KB
/
runner.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*jshint node:true */
if (typeof process !== 'undefined' && typeof define === 'undefined') {
(function () {
// this.require must be exposed explicitly in order to allow the loader to be
// reconfigured from the configuration file
var req = this.require = require('dojo/dojo');
req({
baseUrl: process.cwd(),
packages: [
{ name: 'intern', location: __dirname }
],
map: {
intern: {
dojo: 'intern/node_modules/dojo',
chai: 'intern/node_modules/chai/chai'
},
'*': {
'intern/dojo': 'intern/node_modules/dojo'
}
}
}, [ 'intern/runner' ]);
})();
}
else {
define([
'require',
'./main',
'./lib/createProxy',
'dojo/node!istanbul/lib/instrumenter',
'dojo/node!sauce-connect-launcher',
'./lib/args',
'./lib/util',
'./lib/Suite',
'./lib/ClientSuite',
'./lib/wd',
'dojo/lang',
'dojo/topic',
'./lib/EnvironmentType',
'./lib/reporterManager'
], function (
require,
main,
createProxy,
Instrumenter,
startConnect,
args,
util,
Suite,
ClientSuite,
wd,
lang,
topic,
EnvironmentType,
reporterManager
) {
if (!args.config) {
throw new Error('Required option "config" not specified');
}
require([ args.config ], function (config) {
config = lang.deepCopy({
capabilities: {
name: args.config,
'idle-timeout': 60
},
loader: {},
maxConcurrency: 3,
proxyPort: 9000,
proxyUrl: 'http://localhost:9000',
useSauceConnect: true,
webdriver: {
host: 'localhost',
port: 4444
}
}, config);
this.require(config.loader);
if (!args.reporters) {
if (config.reporters) {
args.reporters = config.reporters;
}
else {
console.info('Defaulting to "runner" reporter');
args.reporters = 'runner';
}
}
args.reporters = [].concat(args.reporters).map(function (reporterModuleId) {
// Allow 3rd party reporters to be used simply by specifying a full mid, or built-in reporters by
// specifying the reporter name only
if (reporterModuleId.indexOf('/') === -1) {
reporterModuleId = './lib/reporters/' + reporterModuleId;
}
return reporterModuleId;
});
require(args.reporters, function () {
/*jshint maxcomplexity:13 */
// A hash map, { reporter module ID: reporter definition }
var reporters = [].slice.call(arguments, 0).reduce(function (map, reporter, i) {
map[args.reporters[i]] = reporter;
return map;
}, {});
reporterManager.add(reporters);
config.proxyUrl = config.proxyUrl.replace(/\/*$/, '/');
var basePath = (config.loader.baseUrl || process.cwd()).replace(/\/*$/, '/'),
proxy = createProxy({
basePath: basePath,
excludeInstrumentation: config.excludeInstrumentation,
instrumenter: new Instrumenter({
// coverage variable is changed primarily to avoid any jshint complaints, but also to make
// it clearer where the global is coming from
coverageVariable: '__internCoverage',
// compacting code makes it harder to look at but it does not really matter
noCompact: true,
// auto-wrap breaks code
noAutoWrap: true
}),
port: config.proxyPort
});
// Running just the proxy and aborting is useful mostly for debugging, but also lets you get code
// coverage reporting on the client if you want
if (args.proxyOnly) {
return;
}
// TODO: Verify that upon using delete, it is not possible for the program to retrieve these environment
// variables another way.
if (process.env.SAUCE_USERNAME) {
config.webdriver.username = process.env.SAUCE_USERNAME;
if (!(delete process.env.SAUCE_USERNAME)) {
throw new Error('Failed to clear sensitive environment variable SAUCE_USERNAME');
}
}
if (process.env.SAUCE_ACCESS_KEY) {
config.webdriver.accessKey = process.env.SAUCE_ACCESS_KEY;
if (!(delete process.env.SAUCE_ACCESS_KEY)) {
throw new Error('Failed to clear sensitive environment variable SAUCE_ACCESS_KEY');
}
}
var startup;
if (config.useSauceConnect) {
if (!config.webdriver.username || !config.webdriver.accessKey) {
throw new Error('Missing Sauce username or access key. Disable Sauce Connect or provide ' +
'this information.');
}
if (!config.capabilities['tunnel-identifier']) {
config.capabilities['tunnel-identifier'] = '' + Date.now();
}
startup = util.adapt(startConnect);
}
else {
startup = function () {
return {
then: function (callback) {
callback();
}
};
};
}
main.maxConcurrency = config.maxConcurrency || Infinity;
if (process.env.TRAVIS_COMMIT) {
config.capabilities.build = process.env.TRAVIS_COMMIT;
}
util.flattenEnvironments(config.capabilities, config.environments).forEach(function (environmentType) {
var suite = new Suite({
name: 'main',
remote: wd.remote(config.webdriver, environmentType),
publishAfterSetup: true,
setup: function () {
var remote = this.remote;
return remote.init()
.then(function getEnvironmentInfo(/* [ sessionId, capabilities? ] */ environmentInfo) {
// wd incorrectly puts the session ID on a `sessionID` property, which violates
// JavaScript style convention
remote.sessionId = environmentInfo[0];
// the remote needs to know the proxy URL and base filesystem path length so it can
// munge filesystem paths passed to `get`
remote.proxyUrl = config.proxyUrl;
remote.proxyBasePathLength = basePath.length;
})
// capabilities object is not returned from `init` by at least ChromeDriver 2.25.0;
// calling `sessionCapabilities` works every time
.sessionCapabilities()
.then(function (capabilities) {
remote.environmentType = new EnvironmentType(capabilities);
topic.publish('/session/start', remote);
});
},
teardown: function () {
var remote = this.remote;
return remote.quit().always(function () {
topic.publish('/session/end', remote);
});
}
});
suite.tests.push(new ClientSuite({ parent: suite, config: config }));
main.suites.push(suite);
});
startup({
/*jshint camelcase:false */
logger: function () {
console.log.apply(console, arguments);
},
tunnelIdentifier: config.capabilities['tunnel-identifier'],
username: config.webdriver.username,
accessKey: config.webdriver.accessKey,
port: config.webdriver.port,
no_progress: !process.stdout.isTTY
}).then(function (connectProcess) {
require(config.functionalSuites || [], function () {
var hasErrors = false;
topic.subscribe('/error, /test/fail', function () {
hasErrors = true;
});
process.on('exit', function () {
// calling `process.exit` after the main test loop finishes will cause any remaining
// in-progress operations to abort, which is undesirable if there are any asynchronous
// I/O operations that a reporter wants to perform once all tests are complete; calling
// from within the exit event avoids this problem by allowing Node.js to decide when to
// terminate
process.exit(hasErrors ? 1 : 0);
});
topic.publish('/runner/start');
main.run().always(function () {
topic.publish('/runner/end');
connectProcess && connectProcess.close();
proxy.close();
reporterManager.clear();
});
});
}, function (error) {
console.error(error);
proxy.close();
});
});
});
});
}