1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var _ = require('lodash');
|
11 |
|
12 | var ALL_BROWSERS = require('../default-sauce-browsers.json');
|
13 |
|
14 | var TRAVIS_BROWSERS = require('../travis-browsers.json');
|
15 |
|
16 |
|
17 | var DEFAULT_BROWSERS = process.env.TRAVIS ? TRAVIS_BROWSERS : ALL_BROWSERS;
|
18 |
|
19 |
|
20 | var BROWSER_SPEC = /^([^\/@]+)\/([^\/@]+)(?:@(.*))?$/;
|
21 |
|
22 | var PROPERTY_BLACKLIST = ['accessKey', 'browsers', 'disabled', 'username'];
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | function expand(pluginOptions, done) {
|
32 | var browsers = pluginOptions.browsers;
|
33 |
|
34 | if (browsers.indexOf('default') !== -1 || browsers.indexOf('all') !== -1) {
|
35 |
|
36 |
|
37 | browsers = browsers.concat(_.cloneDeep(DEFAULT_BROWSERS));
|
38 | browsers = _.difference(browsers, ['default', 'all']);
|
39 | }
|
40 |
|
41 | done(null, _.compact(browsers.map(_expandBrowser.bind(
|
42 | null,
|
43 | pluginOptions,
|
44 | _.omit(pluginOptions, PROPERTY_BLACKLIST)
|
45 | ))));
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function _expandBrowser(options, extend, browser) {
|
56 | if (!_.isObject(browser)) {
|
57 | var match = _.isString(browser) && browser.match(BROWSER_SPEC);
|
58 |
|
59 | if (!match) {
|
60 | console.log('Invalid sauce browser spec:', browser);
|
61 | return null;
|
62 | }
|
63 | else {
|
64 | browser = {
|
65 | browserName: match[2],
|
66 | platform: match[1],
|
67 | version: match[3] || '',
|
68 | };
|
69 | }
|
70 | }
|
71 |
|
72 | return _.extend(browser, {
|
73 | url: {
|
74 | accessKey: options.accessKey,
|
75 | hostname: 'ondemand.saucelabs.com',
|
76 | port: 80,
|
77 | username: options.username,
|
78 | },
|
79 | }, extend);
|
80 | }
|
81 |
|
82 | module.exports = {
|
83 | expand: expand,
|
84 | };
|