-
Notifications
You must be signed in to change notification settings - Fork 19
/
helpers.js
84 lines (73 loc) · 1.94 KB
/
helpers.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
var browserstack = require("browserstack"),
config = require("./config");
var workers = [],
timeout = config.browserstack.timeout || 480, // 8 minutes
client = browserstack.createClient(config.browserstack),
osMap = {};
var loadBrowsers = function(browsers) {
browsers.forEach(function(browser, idx){
client.createWorker(browser, function(err, worker){
if(err) {
console.log(err);
console.log("Whoops! BrowserStack failed to create a worker: %s", err);
} else {
console.log(" BrowserStack "+ (browser.browser || browser.device) + " " + browser.version +" worker launched: %s", worker.id);
workers.push(worker.id);
}
});
});
},
availableBrowsers = function(cb) {
client.getBrowsers(function(err, browsers){
if(!err) {
cb(browsers);
}
console.log(err);
});
},
killBrowser = function(id, cb) {
client.terminateWorker(id, function(err, data, id) {
if(cb) {
cb(err, data, id);
}
});
},
killBrowsers = function() {
client.getWorkers(function(err, workers) {
var ids = [];
workers.forEach(function(worker, i){
ids.push(worker.id);
});
ids.forEach(function(id, i){
killBrowser(id, function(err, data, id){
console.log("Worker %s successfully killed, it ran for %ss", id, Math.round(data.time));
});
});
});
},
platformBrowsers = function(os) {
osMap = {};
availableBrowsers(function(browsers) {
browsers.forEach(function(browser, i) {
if(!osMap[browser.os]) {
osMap[browser.os] = [];
}
osMap[browser.os].push({
browser: browser.browser || "",
device: browser.device || "",
version: browser.version,
os: browser.os,
url: "http://" + config.tunnellink,
timeout: timeout
});
});
loadBrowsers(osMap[os]);
});
};
module.exports = {
loadBrowsers: loadBrowsers,
availableBrowsers: availableBrowsers,
killBrowser: killBrowser,
killBrowsers: killBrowsers,
platformBrowsers: platformBrowsers
};