@@ -2,70 +2,201 @@ const DetoxConfigErrorBuilder = require('../errors/DetoxConfigErrorBuilder');
2
2
3
3
describe ( 'composeSessionConfig' , ( ) => {
4
4
let composeSessionConfig ;
5
- let detoxConfig , deviceConfig ;
5
+ let cliConfig , detoxConfig , deviceConfig ;
6
6
/** @type {DetoxConfigErrorBuilder } */
7
7
let errorBuilder ;
8
8
9
9
beforeEach ( ( ) => {
10
10
composeSessionConfig = require ( './composeSessionConfig' ) ;
11
11
errorBuilder = new DetoxConfigErrorBuilder ( ) ;
12
+ cliConfig = { } ;
12
13
detoxConfig = { } ;
13
14
deviceConfig = { } ;
14
15
} ) ;
15
16
16
17
const compose = ( ) => composeSessionConfig ( {
18
+ cliConfig,
17
19
detoxConfig,
18
20
deviceConfig,
19
21
errorBuilder,
20
22
} ) ;
21
23
22
24
it ( 'should generate a default config' , async ( ) => {
23
- const sessionConfig = await compose ( ) ;
24
-
25
- expect ( sessionConfig ) . toMatchObject ( {
25
+ expect ( await compose ( ) ) . toEqual ( {
26
26
autoStart : true ,
27
- server : expect . stringMatching ( / ^ w s : .* l o c a l h o s t : / ) ,
28
- sessionId : expect . stringMatching ( / ^ [ a - f 0 - 9 ] { 8 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 12 } $ / i) ,
27
+ debugSynchronization : false ,
28
+ server : expect . any ( String ) ,
29
+ sessionId : expect . any ( String ) ,
30
+ } ) ;
31
+ } ) ;
32
+
33
+ describe ( 'sessionId' , function ( ) {
34
+ describe ( 'by default' , ( ) => {
35
+ it ( 'should be autogenerated GUID' , async ( ) => {
36
+ expect ( await compose ( ) ) . toMatchObject ( {
37
+ sessionId : expect . stringMatching ( / ^ [ a - f 0 - 9 ] { 8 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 12 } $ / i) ,
38
+ } ) ;
39
+ } ) ;
40
+ } ) ;
41
+
42
+ it ( 'should pass validations' , async ( ) => {
43
+ detoxConfig . session = { sessionId : 1234 } ;
44
+ await expect ( compose ( ) ) . rejects . toThrowError ( errorBuilder . invalidSessionIdProperty ( ) ) ;
45
+
46
+ detoxConfig . session = { sessionId : '' } ;
47
+ await expect ( compose ( ) ) . rejects . toThrowError ( errorBuilder . invalidSessionIdProperty ( ) ) ;
48
+ } ) ;
49
+
50
+ describe ( 'when defined in global config' , ( ) => {
51
+ beforeEach ( ( ) => {
52
+ detoxConfig . session = { sessionId : 'someSessionId' } ;
53
+ } ) ;
54
+
55
+ it ( 'should use the specified value' , async ( ) => {
56
+ expect ( ( await compose ( ) ) . sessionId ) . toBe ( 'someSessionId' ) ;
57
+ } ) ;
58
+
59
+ describe ( 'and in device config' , ( ) => {
60
+ beforeEach ( ( ) => {
61
+ deviceConfig . session = { sessionId : 'otherSessionId' } ;
62
+ } ) ;
63
+
64
+ it ( 'should use the specified value' , async ( ) => {
65
+ expect ( ( await compose ( ) ) . sessionId ) . toBe ( 'otherSessionId' ) ;
66
+ } ) ;
67
+ } ) ;
68
+ } ) ;
69
+ } ) ;
70
+
71
+ describe ( 'server' , function ( ) {
72
+ describe ( 'by default' , ( ) => {
73
+ it ( 'should be autogenerated' , async ( ) => {
74
+ expect ( await compose ( ) ) . toMatchObject ( {
75
+ server : expect . stringMatching ( / ^ w s : .* l o c a l h o s t : / ) ,
76
+ } ) ;
77
+ } ) ;
78
+ } ) ;
79
+
80
+ it ( 'should pass validations' , async ( ) => {
81
+ detoxConfig . session = { server : 1234 } ;
82
+ await expect ( compose ( ) ) . rejects . toThrowError ( errorBuilder . invalidServerProperty ( ) ) ;
83
+
84
+ detoxConfig . session = { server : 'http://invalid-protocol.com' } ;
85
+ await expect ( compose ( ) ) . rejects . toThrowError ( errorBuilder . invalidServerProperty ( ) ) ;
86
+ } ) ;
87
+
88
+ describe ( 'when defined in global config' , ( ) => {
89
+ beforeEach ( ( ) => {
90
+ detoxConfig . session = { server : 'ws://myserver:1100' } ;
91
+ } ) ;
92
+
93
+ it ( 'should use the specified value' , async ( ) => {
94
+ expect ( await compose ( ) ) . toMatchObject ( {
95
+ server : 'ws://myserver:1100' ,
96
+ } ) ;
97
+ } ) ;
98
+
99
+ describe ( 'and in device config' , ( ) => {
100
+ beforeEach ( ( ) => {
101
+ deviceConfig . session = { server : 'ws://otherserver:1100' } ;
102
+ } ) ;
103
+
104
+ it ( 'should use the specified value' , async ( ) => {
105
+ expect ( await compose ( ) ) . toMatchObject ( {
106
+ server : 'ws://otherserver:1100' ,
107
+ } ) ;
108
+ } ) ;
109
+ } ) ;
29
110
} ) ;
30
111
} ) ;
31
112
32
- describe ( 'if detoxConfig.session is defined' , function ( ) {
33
- beforeEach ( ( ) => {
34
- detoxConfig . session = {
35
- server : 'ws://localhost:9999' ,
36
- sessionId : 'someSessionId' ,
37
- } ;
38
- } )
113
+ describe ( 'autoStart' , function ( ) {
114
+ describe ( 'by default' , ( ) => {
115
+ it ( 'should be true' , async ( ) => {
116
+ expect ( await compose ( ) ) . toMatchObject ( { autoStart : true } ) ;
117
+ } ) ;
118
+ } ) ;
119
+
120
+ describe ( 'when autoStart is explicitly false' , function ( ) {
121
+ beforeEach ( ( ) => {
122
+ detoxConfig . session = { autoStart : false } ;
123
+ } ) ;
124
+
125
+ it ( 'should override the value' , async ( ) => {
126
+ expect ( await compose ( ) ) . toMatchObject ( { autoStart : false } ) ;
127
+ } ) ;
128
+ } ) ;
129
+
130
+ describe ( 'when server is defined' , ( ) => {
131
+ beforeEach ( ( ) => {
132
+ detoxConfig . session = { server : 'ws://localhost:1100' } ;
133
+ } ) ;
134
+
135
+ it ( 'should be false' , async ( ) => {
136
+ expect ( await compose ( ) ) . toMatchObject ( { autoStart : false } ) ;
137
+ } ) ;
39
138
40
- it ( 'should return detoxConfig.session' , async ( ) => {
41
- expect ( await compose ( ) ) . toEqual ( {
42
- server : 'ws://localhost:9999' ,
43
- sessionId : 'someSessionId' ,
139
+ describe ( 'when autoStart is explicitly true' , function ( ) {
140
+ beforeEach ( ( ) => {
141
+ detoxConfig . session . autoStart = true ;
142
+ } ) ;
143
+
144
+ it ( 'should override the value' , async ( ) => {
145
+ expect ( await compose ( ) ) . toMatchObject ( { autoStart : true } ) ;
146
+ } ) ;
44
147
} ) ;
45
148
} ) ;
149
+ } ) ;
46
150
47
- test ( `providing empty server config should throw` , ( ) => {
48
- delete detoxConfig . session . server ;
49
- expect ( compose ( ) ) . rejects . toThrowError ( errorBuilder . missingServerProperty ( ) ) ;
151
+ describe ( 'debugSynchronization' , function ( ) {
152
+ describe ( 'by default' , ( ) => {
153
+ it ( 'should be false' , async ( ) => {
154
+ expect ( await compose ( ) ) . toMatchObject ( {
155
+ debugSynchronization : false ,
156
+ } ) ;
157
+ } ) ;
50
158
} ) ;
51
159
52
- test ( `providing server config with no session should throw` , ( ) => {
53
- delete detoxConfig . session . sessionId ;
54
- expect ( compose ( ) ) . rejects . toThrowError ( errorBuilder . missingSessionIdProperty ( ) ) ;
160
+ it ( 'should pass validations' , async ( ) => {
161
+ detoxConfig . session = { debugSynchronization : - 1 } ;
162
+ await expect ( compose ( ) ) . rejects . toThrowError ( errorBuilder . invalidDebugSynchronizationProperty ( ) ) ;
163
+
164
+ detoxConfig . session = { debugSynchronization : '3000' } ;
165
+ await expect ( compose ( ) ) . rejects . toThrowError ( errorBuilder . invalidDebugSynchronizationProperty ( ) ) ;
55
166
} ) ;
56
167
57
- describe ( 'if deviceConfig.session is defined ' , function ( ) {
168
+ describe ( 'when defined in global config ' , ( ) => {
58
169
beforeEach ( ( ) => {
59
- detoxConfig . session = {
60
- server : 'ws://localhost:1111' ,
61
- sessionId : 'anotherSession' ,
62
- } ;
170
+ detoxConfig . session = { debugSynchronization : 10000 } ;
63
171
} ) ;
64
172
65
- it ( 'should return deviceConfig.session instead of detoxConfig.session' , async ( ) => {
66
- expect ( await compose ( ) ) . toEqual ( {
67
- server : 'ws://localhost:1111' ,
68
- sessionId : 'anotherSession' ,
173
+ it ( 'should use that value' , async ( ) => {
174
+ expect ( await compose ( ) ) . toMatchObject ( {
175
+ debugSynchronization : 10000 ,
176
+ } ) ;
177
+ } ) ;
178
+
179
+ describe ( 'and in device config' , ( ) => {
180
+ beforeEach ( ( ) => {
181
+ deviceConfig . session = { debugSynchronization : 20000 } ;
182
+ } ) ;
183
+
184
+ it ( 'should use that value' , async ( ) => {
185
+ expect ( await compose ( ) ) . toMatchObject ( {
186
+ debugSynchronization : 20000 ,
187
+ } ) ;
188
+ } ) ;
189
+
190
+ describe ( 'and in CLI config' , ( ) => {
191
+ beforeEach ( ( ) => {
192
+ cliConfig . debugSynchronization = 3000 ;
193
+ } ) ;
194
+
195
+ it ( 'should use that value' , async ( ) => {
196
+ expect ( await compose ( ) ) . toMatchObject ( {
197
+ debugSynchronization : 3000 ,
198
+ } ) ;
199
+ } ) ;
69
200
} ) ;
70
201
} ) ;
71
202
} ) ;
0 commit comments