@@ -4,17 +4,16 @@ describe('Detox', () => {
4
4
let fs ;
5
5
let Detox ;
6
6
let detox ;
7
- let minimist ;
8
- let clientMockData = { lastConstructorArguments : null } ;
9
- let deviceMockData = { lastConstructorArguments : null } ;
7
+ const clientMockData = { lastConstructorArguments : null } ;
8
+ const deviceMockData = { lastConstructorArguments : null } ;
10
9
11
10
beforeEach ( async ( ) => {
12
11
function setCustomMock ( modulePath , dataObject ) {
13
12
const JestMock = jest . genMockFromModule ( modulePath ) ;
14
13
class FinalMock extends JestMock {
15
- constructor ( ) {
16
- super ( ... arguments ) ;
17
- dataObject . lastConstructorArguments = arguments ;
14
+ constructor ( ... rest ) {
15
+ super ( rest ) ;
16
+ dataObject . lastConstructorArguments = rest ;
18
17
}
19
18
}
20
19
jest . setMock ( modulePath , FinalMock ) ;
@@ -23,12 +22,12 @@ describe('Detox', () => {
23
22
jest . mock ( 'npmlog' ) ;
24
23
jest . mock ( 'fs' ) ;
25
24
fs = require ( 'fs' ) ;
26
- jest . mock ( 'minimist' ) ;
27
- minimist = require ( 'minimist' ) ;
28
25
jest . mock ( './ios/expect' ) ;
29
26
setCustomMock ( './client/Client' , clientMockData ) ;
30
27
setCustomMock ( './devices/Device' , deviceMockData ) ;
31
28
29
+ process . env = { } ;
30
+
32
31
jest . mock ( './devices/IosDriver' ) ;
33
32
jest . mock ( './devices/SimulatorDriver' ) ;
34
33
jest . mock ( './devices/Device' ) ;
@@ -66,7 +65,7 @@ describe('Detox', () => {
66
65
} ) ;
67
66
68
67
it ( `Passing --cleanup should shutdown the currently running device` , async ( ) => {
69
- mockCommandLineArgs ( { cleanup : true } ) ;
68
+ process . env . cleanup = true ;
70
69
Detox = require ( './Detox' ) ;
71
70
72
71
detox = new Detox ( schemes . validOneDeviceNoSession ) ;
@@ -99,7 +98,7 @@ describe('Detox', () => {
99
98
} ) ;
100
99
101
100
it ( `Two valid devices, detox should init with the device passed in '--configuration' cli option` , async ( ) => {
102
- mockCommandLineArgs ( { configuration : 'ios.sim.debug' } ) ;
101
+ process . env . configuration = 'ios.sim.debug' ;
103
102
Detox = require ( './Detox' ) ;
104
103
105
104
detox = new Detox ( schemes . validTwoDevicesNoSession ) ;
@@ -108,7 +107,7 @@ describe('Detox', () => {
108
107
} ) ;
109
108
110
109
it ( `Two valid devices, detox should throw if device passed in '--configuration' cli option doesn't exist` , async ( ) => {
111
- mockCommandLineArgs ( { configuration : 'nonexistent' } ) ;
110
+ process . env . configuration = 'nonexistent' ;
112
111
Detox = require ( './Detox' ) ;
113
112
114
113
detox = new Detox ( schemes . validTwoDevicesNoSession ) ;
@@ -121,7 +120,7 @@ describe('Detox', () => {
121
120
} ) ;
122
121
123
122
it ( `Two valid devices, detox should throw if device passed in '--configuration' cli option doesn't exist` , async ( ) => {
124
- mockCommandLineArgs ( { configuration : 'nonexistent' } ) ;
123
+ process . env . configuration = 'nonexistent' ;
125
124
Detox = require ( './Detox' ) ;
126
125
127
126
detox = new Detox ( schemes . validTwoDevicesNoSession ) ;
@@ -165,22 +164,22 @@ describe('Detox', () => {
165
164
} ) ;
166
165
167
166
it ( `Detox should use session defined per configuration - none` , async ( ) => {
168
- mockCommandLineArgs ( { configuration : 'ios.sim.none' } ) ;
167
+ process . env . configuration = 'ios.sim.none' ;
169
168
Detox = require ( './Detox' ) ;
170
169
detox = new Detox ( schemes . sessionPerConfiguration ) ;
171
170
await detox . init ( ) ;
172
171
173
- let expectedSession = schemes . sessionPerConfiguration . configurations [ 'ios.sim.none' ] . session ;
172
+ const expectedSession = schemes . sessionPerConfiguration . configurations [ 'ios.sim.none' ] . session ;
174
173
expect ( clientMockData . lastConstructorArguments [ 0 ] ) . toBe ( expectedSession ) ;
175
174
} ) ;
176
175
177
176
it ( `Detox should use session defined per configuration - release` , async ( ) => {
178
- mockCommandLineArgs ( { configuration : 'ios.sim.release' } ) ;
177
+ process . env . configuration = 'ios.sim.release' ;
179
178
Detox = require ( './Detox' ) ;
180
179
detox = new Detox ( schemes . sessionPerConfiguration ) ;
181
180
await detox . init ( ) ;
182
181
183
- let expectedSession = schemes . sessionPerConfiguration . configurations [ 'ios.sim.release' ] . session ;
182
+ const expectedSession = schemes . sessionPerConfiguration . configurations [ 'ios.sim.release' ] . session ;
184
183
expect ( clientMockData . lastConstructorArguments [ 0 ] ) . toBe ( expectedSession ) ;
185
184
} ) ;
186
185
@@ -189,12 +188,12 @@ describe('Detox', () => {
189
188
detox = new Detox ( schemes . sessionInCommonAndInConfiguration ) ;
190
189
await detox . init ( ) ;
191
190
192
- let expectedSession = schemes . sessionInCommonAndInConfiguration . configurations [ 'ios.sim.none' ] . session ;
191
+ const expectedSession = schemes . sessionInCommonAndInConfiguration . configurations [ 'ios.sim.none' ] . session ;
193
192
expect ( clientMockData . lastConstructorArguments [ 0 ] ) . toBe ( expectedSession ) ;
194
193
} ) ;
195
194
196
195
it ( `beforeEach() - should set device artifacts destination` , async ( ) => {
197
- mockCommandLineArgs ( { 'artifacts-location' : '/tmp' } ) ;
196
+ process . env . artifactsLocation = '/tmp' ;
198
197
Detox = require ( './Detox' ) ;
199
198
detox = new Detox ( schemes . validOneDeviceAndSession ) ;
200
199
await detox . init ( ) ;
@@ -211,7 +210,7 @@ describe('Detox', () => {
211
210
} ) ;
212
211
213
212
it ( `afterEach() - should call device.finalizeArtifacts` , async ( ) => {
214
- mockCommandLineArgs ( { 'artifacts-location' : '/tmp' } ) ;
213
+ process . env . artifactsLocation = '/tmp' ;
215
214
Detox = require ( './Detox' ) ;
216
215
detox = new Detox ( schemes . validOneDeviceAndSession ) ;
217
216
await detox . init ( ) ;
@@ -228,13 +227,11 @@ describe('Detox', () => {
228
227
} ) ;
229
228
230
229
it ( `the constructor should catch exception from ArtifactsPathsProvider` , async ( ) => {
231
- mockCommandLineArgs ( { 'artifacts-location' : '/tmp' } ) ;
232
- fs . mkdirSync = jest . fn ( ( ) => { throw 'Could not create artifacts root dir' } ) ;
230
+ process . env . artifactsLocation = '/tmp' ;
231
+ fs . mkdirSync = jest . fn ( ( ) => {
232
+ throw Error ( 'Could not create artifacts root dir' ) ;
233
+ } ) ;
233
234
Detox = require ( './Detox' ) ;
234
235
detox = new Detox ( schemes . validOneDeviceAndSession ) ;
235
236
} ) ;
236
-
237
- function mockCommandLineArgs ( args ) {
238
- minimist . mockReturnValue ( args ) ;
239
- }
240
237
} ) ;
0 commit comments