-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
81 lines (71 loc) · 2.63 KB
/
index.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
var browserStack = require('browserstack'),
browserStackTunnel = require('browserstacktunnel-wrapper'),
async = require('async');
var config = null,
bsClient = null;
function generateWorkerName(browser) {
return [browser.os, browser.os_version, browser.browser, browser.browser_version, browser.device].join(' ').trim();
}
exports.createWorkers = function createWorkers(browsers, callback) {
async.map(browsers, function(browser, callback) {
var workerName = browser.worker_name || generateWorkerName(browser),
browserInfo = {
os: browser.os,
os_version: browser.os_version,
browser: browser.browser,
browser_version: browser.browser_version,
device: browser.device,
url: 'http://' + config.TestCafe.hostname + ':' + config.TestCafe.controlPanelPort +
'/worker/add/' + encodeURI(workerName)
};
bsClient.createWorker(browserInfo, function(err, worker) {
callback(err, !err && worker.id);
});
}, function(err, workerIds) {
callback && callback(workerIds, err);
});
};
exports.removeWorkers = function removeWorkers(workerIds, callback) {
async.map(workerIds, function(workerId, callback) {
bsClient.terminateWorker(workerId, function(err) {
callback && callback(err);
});
}, function(err) {
callback && callback(err);
});
};
exports.removeAllWorkers = function removeAllWorkers(callback) {
bsClient.getWorkers(function(err, workers) {
if(!err)
exports.removeWorkers(workers.map(function(worker) { return worker.id; }), callback);
else
callback && callback(err);
});
};
exports.init = function(data, callback) {
config = data;
bsClient = browserStack.createClient({
"username" : config.BrowserStack.username,
"password" : config.BrowserStack.password
});
if (config.BrowserStack.localTesting) {
var bsTunnel = new browserStackTunnel({
key: config.BrowserStack.accessKey,
hosts: [{
name: config.TestCafe.hostname,
port: config.TestCafe.controlPanelPort,
sslFlag: 0
}, {
name: config.TestCafe.hostname,
port: config.TestCafe.servicePort1,
sslFlag: 0
}, {
name: config.TestCafe.hostname,
port: config.TestCafe.servicePort2,
sslFlag: 0
}]
});
bsTunnel.start(callback);
} else
callback && callback();
};