@@ -28,8 +28,8 @@ class DevicesServiceInheritor extends DevicesService {
28
28
return super . startEmulatorIfNecessary ( data ) ;
29
29
}
30
30
31
- public startDeviceDetectionInterval ( deviceInitOpts : Mobile . IDevicesServicesInitializationOptions = { } ) : Promise < void > {
32
- return super . startDeviceDetectionInterval ( deviceInitOpts ) ;
31
+ public startDeviceDetectionIntervals ( deviceInitOpts : Mobile . IDevicesServicesInitializationOptions = { } ) : Promise < void > {
32
+ return super . startDeviceDetectionIntervals ( deviceInitOpts ) ;
33
33
}
34
34
35
35
public detectCurrentlyAttachedDevices ( options ?: Mobile . IDevicesServicesInitializationOptions ) : Promise < void > {
@@ -236,6 +236,15 @@ function resetDefaultSetInterval(): void {
236
236
global . setInterval = originalSetInterval ;
237
237
}
238
238
239
+ async function assertOnNextTick ( assertionFunction : Function ) : Promise < void > {
240
+ await new Promise ( resolve => {
241
+ process . nextTick ( ( ) => {
242
+ assertionFunction ( ) ;
243
+ resolve ( ) ;
244
+ } ) ;
245
+ } ) ;
246
+ }
247
+
239
248
describe ( "devicesService" , ( ) => {
240
249
let counter = 0 ;
241
250
const iOSDevice = {
@@ -1184,7 +1193,7 @@ describe("devicesService", () => {
1184
1193
} ) ;
1185
1194
} ) ;
1186
1195
1187
- describe ( "startDeviceDetectionInterval " , ( ) => {
1196
+ describe ( "startDeviceDetectionIntervals " , ( ) => {
1188
1197
let setIntervalsCalledCount : number ;
1189
1198
1190
1199
beforeEach ( ( ) => {
@@ -1203,7 +1212,7 @@ describe("devicesService", () => {
1203
1212
hasStartedDeviceDetectionInterval = true ;
1204
1213
} ) ;
1205
1214
1206
- await devicesService . startDeviceDetectionInterval ( ) ;
1215
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1207
1216
1208
1217
assert . isTrue ( hasStartedDeviceDetectionInterval ) ;
1209
1218
} ) ;
@@ -1227,11 +1236,11 @@ describe("devicesService", () => {
1227
1236
} ;
1228
1237
} ;
1229
1238
1230
- await devicesService . startDeviceDetectionInterval ( ) ;
1231
- await devicesService . startDeviceDetectionInterval ( ) ;
1232
- await devicesService . startDeviceDetectionInterval ( ) ;
1239
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1240
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1241
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1233
1242
1234
- assert . deepEqual ( setIntervalsCalledCount , 1 ) ;
1243
+ assert . deepEqual ( setIntervalsCalledCount , 2 ) ;
1235
1244
} ) ;
1236
1245
1237
1246
describe ( "ios devices check" , ( ) => {
@@ -1248,15 +1257,15 @@ describe("devicesService", () => {
1248
1257
hasCheckedForIosDevices = true ;
1249
1258
} ;
1250
1259
1251
- await devicesService . startDeviceDetectionInterval ( ) ;
1260
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1252
1261
1253
1262
assert . isTrue ( hasCheckedForIosDevices ) ;
1254
1263
} ) ;
1255
1264
1256
1265
it ( "should not throw if ios device check fails throws an exception." , async ( ) => {
1257
1266
( < any > $iOSDeviceDiscovery ) . checkForDevices = throwErrorFunction ;
1258
1267
1259
- await assert . isFulfilled ( devicesService . startDeviceDetectionInterval ( ) ) ;
1268
+ await assert . isFulfilled ( devicesService . startDeviceDetectionIntervals ( ) ) ;
1260
1269
} ) ;
1261
1270
} ) ;
1262
1271
@@ -1267,22 +1276,22 @@ describe("devicesService", () => {
1267
1276
$androidDeviceDiscovery = testInjector . resolve ( "androidDeviceDiscovery" ) ;
1268
1277
} ) ;
1269
1278
1270
- it ( "should check for android devices." , async ( ) => {
1279
+ it ( "should start interval that will check for android devices." , async ( ) => {
1271
1280
let hasCheckedForAndroidDevices = false ;
1272
1281
1273
1282
$androidDeviceDiscovery . startLookingForDevices = async ( ) : Promise < void > => {
1274
1283
hasCheckedForAndroidDevices = true ;
1275
1284
} ;
1276
1285
1277
- await devicesService . startDeviceDetectionInterval ( ) ;
1278
-
1279
- assert . isTrue ( hasCheckedForAndroidDevices ) ;
1286
+ mockSetInterval ( ) ;
1287
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1288
+ await assertOnNextTick ( ( ) => assert . isTrue ( hasCheckedForAndroidDevices ) ) ;
1280
1289
} ) ;
1281
1290
1282
1291
it ( "should not throw if android device check fails throws an exception." , async ( ) => {
1283
1292
$androidDeviceDiscovery . startLookingForDevices = throwErrorFunction ;
1284
1293
1285
- await assert . isFulfilled ( devicesService . startDeviceDetectionInterval ( ) ) ;
1294
+ await assert . isFulfilled ( devicesService . startDeviceDetectionIntervals ( ) ) ;
1286
1295
} ) ;
1287
1296
} ) ;
1288
1297
@@ -1305,7 +1314,7 @@ describe("devicesService", () => {
1305
1314
it ( "should not throw if ios simulator check fails throws an exception." , async ( ) => {
1306
1315
( < any > $iOSSimulatorDiscovery ) . checkForDevices = throwErrorFunction ;
1307
1316
1308
- await assert . isFulfilled ( devicesService . startDeviceDetectionInterval ( ) ) ;
1317
+ await assert . isFulfilled ( devicesService . startDeviceDetectionIntervals ( ) ) ;
1309
1318
} ) ;
1310
1319
} ) ;
1311
1320
@@ -1317,22 +1326,23 @@ describe("devicesService", () => {
1317
1326
devicesService . addDeviceDiscovery ( customDeviceDiscovery ) ;
1318
1327
} ) ;
1319
1328
1320
- it ( "should check for devices. " , async ( ) => {
1329
+ it ( "should check for devices in interval " , async ( ) => {
1321
1330
let hasCheckedForDevices = false ;
1322
1331
1323
1332
customDeviceDiscovery . startLookingForDevices = async ( ) : Promise < void > => {
1324
1333
hasCheckedForDevices = true ;
1325
1334
} ;
1326
1335
1327
- await devicesService . startDeviceDetectionInterval ( ) ;
1336
+ mockSetInterval ( ) ;
1337
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1328
1338
1329
- assert . isTrue ( hasCheckedForDevices ) ;
1339
+ await assertOnNextTick ( ( ) => assert . isTrue ( hasCheckedForDevices ) ) ;
1330
1340
} ) ;
1331
1341
1332
1342
it ( "should not throw if device check fails throws an exception." , async ( ) => {
1333
1343
customDeviceDiscovery . startLookingForDevices = throwErrorFunction ;
1334
1344
1335
- await assert . isFulfilled ( devicesService . startDeviceDetectionInterval ( ) ) ;
1345
+ await assert . isFulfilled ( devicesService . startDeviceDetectionIntervals ( ) ) ;
1336
1346
} ) ;
1337
1347
} ) ;
1338
1348
@@ -1361,34 +1371,38 @@ describe("devicesService", () => {
1361
1371
} ) ;
1362
1372
1363
1373
it ( "should check for application updates for all connected devices." , async ( ) => {
1364
- await devicesService . startDeviceDetectionInterval ( ) ;
1374
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1365
1375
1366
- assert . isTrue ( hasCheckedForAndroidAppUpdates ) ;
1367
- assert . isTrue ( hasCheckedForIosAppUpdates ) ;
1376
+ await assertOnNextTick ( ( ) => {
1377
+ assert . isTrue ( hasCheckedForAndroidAppUpdates ) ;
1378
+ assert . isTrue ( hasCheckedForIosAppUpdates ) ;
1379
+ } ) ;
1368
1380
} ) ;
1369
1381
1370
1382
it ( "should check for application updates if the check on one device throws an exception." , async ( ) => {
1371
1383
iOSDevice . applicationManager . checkForApplicationUpdates = throwErrorFunction ;
1372
1384
1373
- await devicesService . startDeviceDetectionInterval ( ) ;
1385
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1374
1386
1375
- assert . isTrue ( hasCheckedForAndroidAppUpdates ) ;
1387
+ await assertOnNextTick ( ( ) => assert . isTrue ( hasCheckedForAndroidAppUpdates ) ) ;
1376
1388
} ) ;
1377
1389
1378
1390
it ( "should check for application updates only on devices with status Connected" , async ( ) => {
1379
1391
androidDevice . deviceInfo . status = constants . UNREACHABLE_STATUS ;
1380
- await devicesService . startDeviceDetectionInterval ( ) ;
1392
+ await devicesService . startDeviceDetectionIntervals ( ) ;
1381
1393
1382
- assert . isFalse ( hasCheckedForAndroidAppUpdates ) ;
1383
- assert . isTrue ( hasCheckedForIosAppUpdates ) ;
1394
+ await assertOnNextTick ( ( ) => {
1395
+ assert . isFalse ( hasCheckedForAndroidAppUpdates ) ;
1396
+ assert . isTrue ( hasCheckedForIosAppUpdates ) ;
1397
+ } ) ;
1384
1398
} ) ;
1385
1399
1386
1400
it ( "should not throw if all checks for application updates on all devices throw exceptions." , ( ) => {
1387
1401
iOSDevice . applicationManager . checkForApplicationUpdates = throwErrorFunction ;
1388
1402
androidDevice . applicationManager . checkForApplicationUpdates = throwErrorFunction ;
1389
1403
1390
1404
const callback = ( ) => {
1391
- devicesService . startDeviceDetectionInterval . call ( devicesService ) ;
1405
+ devicesService . startDeviceDetectionIntervals . call ( devicesService ) ;
1392
1406
} ;
1393
1407
1394
1408
assert . doesNotThrow ( callback ) ;
0 commit comments