1 | var
|
2 | expand = require('../lib/browsers').expand,
|
3 | expect = require('chai').expect,
|
4 | slice = Array.prototype.slice,
|
5 | _ = require('lodash')
|
6 | ;
|
7 |
|
8 | const DEFAULT_BROWSERS = require('../default-sauce-browsers.json');
|
9 | const DEFAULT_OPTIONS = {
|
10 | accessKey: 'access-key-' + Date.now(),
|
11 | browsers: ['default'],
|
12 | username: 'catpants-' + Date.now()
|
13 | };
|
14 | const DEFAULT_URL = {
|
15 | accessKey: DEFAULT_OPTIONS.accessKey,
|
16 | hostname: 'ondemand.saucelabs.com',
|
17 | port: 80,
|
18 | username: DEFAULT_OPTIONS.username
|
19 | };
|
20 |
|
21 | function browserOptions() {
|
22 | var options = _.cloneDeep(DEFAULT_OPTIONS);
|
23 | options.browsers = slice.call(arguments);
|
24 |
|
25 | return options;
|
26 | }
|
27 |
|
28 | describe('expand', function() {
|
29 | ['all', 'default'].forEach(function(keyword) {
|
30 | it('should respect browser keyword: ' + keyword, function(done) {
|
31 | expand(browserOptions(keyword), function(error, browsers) {
|
32 | expect(browsers).to.have.length(DEFAULT_BROWSERS.length);
|
33 |
|
34 | browsers.forEach(function(browser) {
|
35 | expect(browser).to.have.all.keys('browserName', 'platform', 'url', 'version');
|
36 |
|
37 | expect(browser.url).to.deep.equal(DEFAULT_URL);
|
38 | });
|
39 |
|
40 | done();
|
41 | });
|
42 | });
|
43 | });
|
44 |
|
45 | it('should remove bad browser instances', function(done) {
|
46 | expand(browserOptions('default', null, 'all', 0, false, 'What?'), function(error, browsers) {
|
47 | expect(browsers).to.have.length(DEFAULT_BROWSERS.length);
|
48 |
|
49 | browsers.forEach(function(browser) {
|
50 | expect(browser).to.have.all.keys('browserName', 'platform', 'url', 'version');
|
51 |
|
52 | expect(browser.url).to.deep.equal(DEFAULT_URL);
|
53 | });
|
54 |
|
55 | done();
|
56 | });
|
57 | });
|
58 |
|
59 | it('should allow objects to pass through', function(done) {
|
60 | var browser = {foo: 'bar', baz: 1};
|
61 |
|
62 | expand(browserOptions(browser), function(error, browsers) {
|
63 | expect(browsers).to.have.length(1);
|
64 |
|
65 | expect(browsers[0]).to.deep.equal(browser);
|
66 |
|
67 | done();
|
68 | });
|
69 | });
|
70 |
|
71 | it('should pass custom browsers', function(done) {
|
72 | var
|
73 | browser = 'browers name here',
|
74 | platform = 'os or platform',
|
75 | version = String(Date.now())
|
76 | ;
|
77 |
|
78 | expand(browserOptions(platform + '/' + browser + '@' + version), function(error, browsers) {
|
79 | var result;
|
80 |
|
81 | expect(browsers).to.have.length(1);
|
82 |
|
83 | result = browsers[0];
|
84 |
|
85 | expect(result).to.have.property('browserName', browser);
|
86 | expect(result).to.have.property('platform', platform);
|
87 | expect(result).to.have.property('version', version);
|
88 | expect(result.url).to.deep.equal(DEFAULT_URL);
|
89 |
|
90 | done();
|
91 | });
|
92 | });
|
93 |
|
94 | it('should extend browsers with custom metadata', function(done) {
|
95 | var
|
96 | buildNumber = Date.now(),
|
97 | customName = 'custom name ' + Date.now(),
|
98 | options = browserOptions('platform/browser@eleventy', 'default'),
|
99 | tags = ['custom', 'tags', 'here']
|
100 | ;
|
101 |
|
102 | _.extend(options, {
|
103 | build: buildNumber,
|
104 | disabled: true,
|
105 | name: customName,
|
106 | tags: tags
|
107 | });
|
108 |
|
109 | expand(options, function(error, browsers) {
|
110 | expect(browsers).to.have.length(DEFAULT_BROWSERS.length + 1);
|
111 |
|
112 | browsers.forEach(function(browser) {
|
113 | expect(browser).to.contain.all.keys('browserName', 'platform', 'url', 'version');
|
114 |
|
115 | expect(browser).to.have.property('build', buildNumber);
|
116 | expect(browser).to.have.property('name', customName);
|
117 | expect(browser).to.have.property('tags', tags);
|
118 | expect(browser.url).to.deep.equal(DEFAULT_URL);
|
119 |
|
120 | expect(browser).to.not.have.keys('browsers', 'disabled');
|
121 | });
|
122 |
|
123 | done();
|
124 | });
|
125 | });
|
126 | });
|