-
Notifications
You must be signed in to change notification settings - Fork 1
/
karma-sauce-generator.js
40 lines (34 loc) · 1016 Bytes
/
karma-sauce-generator.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
const browserslist = require('browserslist');
const request = require('sync-request');
const res = request('GET', 'https://saucelabs.com/rest/v1/info/browsers/webdriver');
const lookup = (requestedBrowsers, cb) => {
const sauce = JSON.parse(res.getBody().toString())
let result = {};
browserslist(requestedBrowsers)
.map((browser) => {
const data = browser.split(' ');
let name = data[0];
let ver = data[1];
switch (name) {
case 'edge':
name = 'microsoftedge';
break;
case 'ie':
name = 'internet explorer';
break;
case 'ie_mob':
case 'ios_saf':
return;
}
return {
base: 'SauceLabs',
browserName: name,
version: ver
};
})
.filter(b => !!b)
.filter((b) => sauce.some((sB) => sB.api_name === b.browserName && sB.short_version === b.version))
.forEach(b => result[`sl_${b.browserName}_${b.version}`] = b)
return result;
}
module.exports = lookup