/
detectBackend.test.js
157 lines (139 loc) · 5.15 KB
/
detectBackend.test.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import { detectBackend } from '../src/utils'
describe('detectBackend', () => {
it('should not set anything if host is set in caps', () => {
const caps = {
hostname: '0.0.0.0',
port: 1234,
protocol: 'http'
}
expect(detectBackend(caps)).toEqual(caps)
})
it('should default to local selenium server', () => {
const caps = detectBackend({})
expect(caps.hostname).toBe('127.0.0.1')
expect(caps.port).toBe(4444)
const otherCaps = detectBackend()
expect(otherCaps.hostname).toBe('127.0.0.1')
expect(otherCaps.port).toBe(4444)
})
it('should default if host or port is not given', () => {
let caps = detectBackend({ port: 1234 })
expect(caps.hostname).toBe('127.0.0.1')
expect(caps.port).toBe(1234)
caps = detectBackend({ hostname: 'foobar' })
expect(caps.hostname).toBe('foobar')
expect(caps.port).toBe(4444)
})
it('should detect browserstack user', () => {
const caps = detectBackend({
user: 'foobar',
key: 'zHcv9sZ39ip8ZPsxBVJ2'
})
expect(caps.hostname).toBe('hub-cloud.browserstack.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should detect testingbot user', () => {
const caps = detectBackend({
user: 'foobar',
key: 'ec337d7b677720a4dde7bd72be0bfc67'
})
expect(caps.hostname).toBe('hub.testingbot.com')
expect(caps.port).toBe(80)
})
it('should detect saucelabs user', () => {
const caps = detectBackend({
user: 'foobar',
key: '50aa152c-1932-B2f0-9707-18z46q2n1mb0'
})
expect(caps.hostname).toBe('ondemand.saucelabs.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should detect saucelabs user running in the default DC', () => {
const caps = detectBackend({
user: 'foobar',
key: '50aa152c-1932-B2f0-9707-18z46q2n1mb0',
region: 'us'
})
expect(caps.hostname).toBe('ondemand.saucelabs.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should detect saucelabs user running in an EU DC', () => {
const caps = detectBackend({
user: 'foobar',
key: '50aa152c-1932-B2f0-9707-18z46q2n1mb0',
region: 'eu'
})
expect(caps.hostname).toBe('ondemand.eu-central-1.saucelabs.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should detect saucelabs user running on a random DC and default to the us', () => {
const caps = detectBackend({
user: 'foobar',
key: '50aa152c-1932-B2f0-9707-18z46q2n1mb0',
region: 'foobar'
})
expect(caps.hostname).toBe('ondemand.saucelabs.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should detect saucelabs user but recognise custom endpoint properties', () => {
const caps = detectBackend({
user: 'foobar',
key: '50aa152c-1932-B2f0-9707-18z46q2n1mb0',
hostname: 'foobar.com',
port: 1234,
protocol: 'tcp'
})
expect(caps.hostname).toBe('foobar.com')
expect(caps.port).toBe(1234)
expect(caps.protocol).toBe('tcp')
})
it('should detect saucelabs rdc user that had not defaulted a region', () => {
const caps = detectBackend({}, true)
expect(caps.hostname).toBe('us1.appium.testobject.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should detect saucelabs us rdc user', () => {
const caps = detectBackend({ region: 'us' }, true)
expect(caps.hostname).toBe('us1.appium.testobject.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should detect saucelabs eu rdc user', () => {
const caps = detectBackend({ region: 'eu' }, true)
expect(caps.hostname).toBe('eu1.appium.testobject.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should detect saucelabs headless user', () => {
const caps = detectBackend({
user: 'foobar',
key: '50aa152c-1932-B2f0-9707-18z46q2n1mb0',
region: 'eu',
headless: true
})
expect(caps.hostname).toBe('ondemand.us-east-1.saucelabs.com')
expect(caps.port).toBe(443)
expect(caps.protocol).toBe('https')
})
it('should throw if user and key are given but can not be connected to a cloud', () => {
expect(() => detectBackend({
user: 'foobar',
key: 'barfoo'
})).toThrow()
})
it('should not throw if user and key are invalid but a custom host was set', () => {
const caps = detectBackend({
user: 'foobar',
key: 'barfoo',
hostname: 'foobar.com'
})
expect(caps.hostname).toBe('foobar.com')
expect(caps.port).toBe(4444)
})
})