@@ -44,9 +44,8 @@ function createTestInjector(): IInjector {
4444 injector . register ( "devicePlatformsConstants" , DevicePlatformsConstants ) ;
4545
4646 injector . register ( "mobileHelper" , {
47- isiOSPlatform : ( ) => {
48- return true ;
49- } ,
47+ isApplePlatform : ( platform : string ) =>
48+ [ "ios" , "visionos" , "tvos" ] . includes ( platform . toLowerCase ( ) ) ,
5049 } ) ;
5150
5251 injector . register ( "iOSSimulatorDiscovery" , IOSSimulatorDiscovery ) ;
@@ -86,45 +85,45 @@ describe("ios-simulator-discovery", () => {
8685 let expectedDeviceInfo : Mobile . IDeviceInfo = null ;
8786
8887 const detectNewSimulatorAttached = async (
89- runningSimulator : any
88+ runningSimulator : any ,
9089 ) : Promise < Mobile . IiOSDevice > => {
9190 return new Promise < Mobile . IiOSDevice > ( async ( resolve , reject ) => {
9291 currentlyRunningSimulators . push ( _ . cloneDeep ( runningSimulator ) ) ;
9392 iOSSimulatorDiscovery . once (
9493 DeviceDiscoveryEventNames . DEVICE_FOUND ,
9594 ( device : Mobile . IiOSDevice ) => {
9695 resolve ( device ) ;
97- }
96+ } ,
9897 ) ;
9998 await iOSSimulatorDiscovery . startLookingForDevices ( ) ;
10099 } ) ;
101100 } ;
102101
103102 const detectSimulatorDetached = async (
104- simulatorId : string
103+ simulatorId : string ,
105104 ) : Promise < Mobile . IiOSDevice > => {
106105 _ . remove (
107106 currentlyRunningSimulators ,
108- ( simulator ) => simulator . id === simulatorId
107+ ( simulator ) => simulator . id === simulatorId ,
109108 ) ;
110109 return new Promise < Mobile . IiOSDevice > ( async ( resolve , reject ) => {
111110 iOSSimulatorDiscovery . once (
112111 DeviceDiscoveryEventNames . DEVICE_LOST ,
113112 ( device : Mobile . IiOSDevice ) => {
114113 resolve ( device ) ;
115- }
114+ } ,
116115 ) ;
117116 await iOSSimulatorDiscovery . startLookingForDevices ( ) ;
118117 } ) ;
119118 } ;
120119
121120 const detectSimulatorChanged = async (
122121 oldId : string ,
123- newId : string
122+ newId : string ,
124123 ) : Promise < any > => {
125124 const currentlyRunningSimulator = _ . find (
126125 currentlyRunningSimulators ,
127- ( simulator ) => simulator . id === oldId
126+ ( simulator ) => simulator . id === oldId ,
128127 ) ;
129128 currentlyRunningSimulator . id = newId ;
130129 let lostDevicePromise : Promise < Mobile . IDevice > ;
@@ -134,14 +133,14 @@ describe("ios-simulator-discovery", () => {
134133 DeviceDiscoveryEventNames . DEVICE_LOST ,
135134 ( device : Mobile . IDevice ) => {
136135 lostDevicePromise = Promise . resolve ( device ) ;
137- }
136+ } ,
138137 ) ;
139138
140139 iOSSimulatorDiscovery . on (
141140 DeviceDiscoveryEventNames . DEVICE_FOUND ,
142141 ( device : Mobile . IDevice ) => {
143142 foundDevicePromise = Promise . resolve ( device ) ;
144- }
143+ } ,
145144 ) ;
146145
147146 await iOSSimulatorDiscovery . startLookingForDevices ( ) ;
@@ -183,11 +182,39 @@ describe("ios-simulator-discovery", () => {
183182 assert . deepStrictEqual ( device . deviceInfo , expectedDeviceInfo ) ;
184183 } ) ;
185184
185+ describe ( "when looking for a specific platform" , ( ) => {
186+ const detectForPlatform = async (
187+ platform : string ,
188+ ) : Promise < Mobile . IiOSDevice > => {
189+ currentlyRunningSimulators . push ( _ . cloneDeep ( defaultRunningSimulator ) ) ;
190+ let found : Mobile . IiOSDevice = null ;
191+ iOSSimulatorDiscovery . once (
192+ DeviceDiscoveryEventNames . DEVICE_FOUND ,
193+ ( device : Mobile . IiOSDevice ) => {
194+ found = device ;
195+ } ,
196+ ) ;
197+ await iOSSimulatorDiscovery . startLookingForDevices ( < any > { platform } ) ;
198+ return found ;
199+ } ;
200+
201+ _ . each ( [ "iOS" , "visionOS" , "tvOS" ] , ( platform ) => {
202+ it ( `finds running simulators for ${ platform } ` , async ( ) => {
203+ const device = await detectForPlatform ( platform ) ;
204+ assert . deepStrictEqual ( device . deviceInfo , expectedDeviceInfo ) ;
205+ } ) ;
206+ } ) ;
207+
208+ it ( "does not look for simulators for Android" , async ( ) => {
209+ assert . isNull ( await detectForPlatform ( "Android" ) ) ;
210+ } ) ;
211+ } ) ;
212+
186213 it ( "raises deviceLost when device is detached" , async ( ) => {
187214 const device = await detectNewSimulatorAttached ( defaultRunningSimulator ) ;
188215 assert . deepStrictEqual ( device . deviceInfo , expectedDeviceInfo ) ;
189216 const lostDevice = await detectSimulatorDetached (
190- device . deviceInfo . identifier
217+ device . deviceInfo . identifier ,
191218 ) ;
192219 assert . deepStrictEqual ( lostDevice , device ) ;
193220 } ) ;
@@ -199,7 +226,7 @@ describe("ios-simulator-discovery", () => {
199226
200227 const devices = await detectSimulatorChanged (
201228 device . deviceInfo . identifier ,
202- newId
229+ newId ,
203230 ) ;
204231 assert . deepStrictEqual ( devices . deviceLost , device ) ;
205232 expectedDeviceInfo . identifier = newId ;
@@ -211,7 +238,7 @@ describe("ios-simulator-discovery", () => {
211238 let device = await detectNewSimulatorAttached ( defaultRunningSimulator ) ;
212239 assert . deepStrictEqual ( device . deviceInfo , expectedDeviceInfo ) ;
213240 const lostDevice = await detectSimulatorDetached (
214- device . deviceInfo . identifier
241+ device . deviceInfo . identifier ,
215242 ) ;
216243 assert . deepStrictEqual ( lostDevice , device ) ;
217244
@@ -226,9 +253,9 @@ describe("ios-simulator-discovery", () => {
226253 DeviceDiscoveryEventNames . DEVICE_FOUND ,
227254 ( d : Mobile . IDevice ) => {
228255 throw new Error (
229- "Device found should not be raised for the same device."
256+ "Device found should not be raised for the same device." ,
230257 ) ;
231- }
258+ } ,
232259 ) ;
233260
234261 await iOSSimulatorDiscovery . startLookingForDevices ( ) ;
@@ -241,9 +268,9 @@ describe("ios-simulator-discovery", () => {
241268 DeviceDiscoveryEventNames . DEVICE_FOUND ,
242269 ( device : Mobile . IDevice ) => {
243270 throw new Error (
244- "Device found should not be raised when OS is not OS X."
271+ "Device found should not be raised when OS is not OS X." ,
245272 ) ;
246- }
273+ } ,
247274 ) ;
248275 await iOSSimulatorDiscovery . startLookingForDevices ( ) ;
249276 } ) ;
@@ -254,16 +281,16 @@ describe("ios-simulator-discovery", () => {
254281 DeviceDiscoveryEventNames . DEVICE_FOUND ,
255282 ( device : Mobile . IDevice ) => {
256283 throw new Error (
257- "Device found should not be raised when OS is not OS X."
284+ "Device found should not be raised when OS is not OS X." ,
258285 ) ;
259- }
286+ } ,
260287 ) ;
261288 await ( < any > iOSSimulatorDiscovery ) . checkForDevices ( ) ;
262289 } ) ;
263290
264291 it ( "find correctly two simulators" , async ( ) => {
265292 const firstSimulator = await detectNewSimulatorAttached (
266- defaultRunningSimulator
293+ defaultRunningSimulator ,
267294 ) ;
268295 assert . deepStrictEqual ( firstSimulator . deviceInfo , expectedDeviceInfo ) ;
269296
@@ -275,11 +302,11 @@ describe("ios-simulator-discovery", () => {
275302 } ;
276303
277304 const secondSimulator = await detectNewSimulatorAttached (
278- secondRunningSimulator
305+ secondRunningSimulator ,
279306 ) ;
280307 assert . deepStrictEqual (
281308 secondSimulator . deviceInfo ,
282- getDeviceInfo ( secondRunningSimulator )
309+ getDeviceInfo ( secondRunningSimulator ) ,
283310 ) ;
284311 } ) ;
285312} ) ;
0 commit comments