11import test from 'node:test' ;
22import assert from 'node:assert/strict' ;
3- import { normalizePlatformSelector , resolveApplePlatformName , selectDevice } from '../device.ts' ;
3+ import { normalizePlatformSelector , resolveApplePlatformName , resolveDevice } from '../device.ts' ;
44import type { DeviceInfo } from '../device.ts' ;
55import { AppError } from '../errors.ts' ;
66
@@ -17,9 +17,9 @@ test('resolveApplePlatformName resolves tv targets to tvOS', () => {
1717 assert . equal ( resolveApplePlatformName ( undefined ) , 'iOS' ) ;
1818} ) ;
1919
20- test ( 'selectDevice throws DEVICE_NOT_FOUND with scoped set guidance when simulatorSetPath is set and no devices found' , async ( ) => {
20+ test ( 'resolveDevice throws DEVICE_NOT_FOUND with scoped set guidance when simulatorSetPath is set and no devices found' , async ( ) => {
2121 const setPath = '/path/to/sessions/abc/Simulators' ;
22- const err = await selectDevice ( [ ] , { platform : 'ios' } , { simulatorSetPath : setPath } ) . catch ( ( e ) => e ) ;
22+ const err = await resolveDevice ( [ ] , { platform : 'ios' } , { simulatorSetPath : setPath } ) . catch ( ( e ) => e ) ;
2323 assert . ok ( err instanceof AppError ) ;
2424 assert . equal ( err . code , 'DEVICE_NOT_FOUND' ) ;
2525 assert . match ( err . message , / s c o p e d s i m u l a t o r s e t / ) ;
@@ -29,39 +29,39 @@ test('selectDevice throws DEVICE_NOT_FOUND with scoped set guidance when simulat
2929 assert . match ( err . details . hint as string , / c r e a t e / ) ;
3030} ) ;
3131
32- test ( 'selectDevice throws generic DEVICE_NOT_FOUND when no simulatorSetPath and no devices found' , async ( ) => {
33- const err = await selectDevice ( [ ] , { platform : 'ios' } ) . catch ( ( e ) => e ) ;
32+ test ( 'resolveDevice throws generic DEVICE_NOT_FOUND when no simulatorSetPath and no devices found' , async ( ) => {
33+ const err = await resolveDevice ( [ ] , { platform : 'ios' } ) . catch ( ( e ) => e ) ;
3434 assert . ok ( err instanceof AppError ) ;
3535 assert . equal ( err . code , 'DEVICE_NOT_FOUND' ) ;
3636 assert . equal ( err . message , 'No devices found' ) ;
3737 assert . equal ( err . details ?. simulatorSetPath , undefined ) ;
3838} ) ;
3939
40- test ( 'selectDevice does not apply scoped set guidance for non-iOS platform with simulatorSetPath' , async ( ) => {
40+ test ( 'resolveDevice does not apply scoped set guidance for non-iOS platform with simulatorSetPath' , async ( ) => {
4141 const setPath = '/path/to/sessions/abc/Simulators' ;
42- const err = await selectDevice ( [ ] , { platform : 'android' } , { simulatorSetPath : setPath } ) . catch ( ( e ) => e ) ;
42+ const err = await resolveDevice ( [ ] , { platform : 'android' } , { simulatorSetPath : setPath } ) . catch ( ( e ) => e ) ;
4343 assert . ok ( err instanceof AppError ) ;
4444 assert . equal ( err . code , 'DEVICE_NOT_FOUND' ) ;
4545 assert . equal ( err . message , 'No devices found' ) ;
4646 assert . equal ( err . details ?. simulatorSetPath , undefined ) ;
4747} ) ;
4848
49- test ( 'selectDevice applies scoped set guidance when no platform selector specified and simulatorSetPath is set' , async ( ) => {
49+ test ( 'resolveDevice applies scoped set guidance when no platform selector specified and simulatorSetPath is set' , async ( ) => {
5050 const setPath = '/path/to/sessions/abc/Simulators' ;
51- const err = await selectDevice ( [ ] , { } , { simulatorSetPath : setPath } ) . catch ( ( e ) => e ) ;
51+ const err = await resolveDevice ( [ ] , { } , { simulatorSetPath : setPath } ) . catch ( ( e ) => e ) ;
5252 assert . ok ( err instanceof AppError ) ;
5353 assert . equal ( err . code , 'DEVICE_NOT_FOUND' ) ;
5454 assert . match ( err . message , / s c o p e d s i m u l a t o r s e t / ) ;
5555 assert . equal ( err . details ?. simulatorSetPath , setPath ) ;
5656} ) ;
5757
58- test ( 'selectDevice returns a device when candidates are available' , async ( ) => {
58+ test ( 'resolveDevice returns a device when candidates are available' , async ( ) => {
5959 const device : DeviceInfo = { platform : 'ios' , id : 'abc123' , name : 'iPhone 16' , kind : 'simulator' , booted : true } ;
60- const result = await selectDevice ( [ device ] , { platform : 'ios' } ) ;
60+ const result = await resolveDevice ( [ device ] , { platform : 'ios' } ) ;
6161 assert . equal ( result . id , 'abc123' ) ;
6262} ) ;
6363
64- test ( 'selectDevice prefers simulator over physical device when no explicit device selector' , async ( ) => {
64+ test ( 'resolveDevice prefers simulator over physical device when no explicit device selector' , async ( ) => {
6565 const physical : DeviceInfo = { platform : 'ios' , id : 'phys-1' , name : 'My iPhone' , kind : 'device' , booted : true } ;
6666 const simulator : DeviceInfo = {
6767 platform : 'ios' ,
@@ -70,43 +70,42 @@ test('selectDevice prefers simulator over physical device when no explicit devic
7070 kind : 'simulator' ,
7171 booted : false ,
7272 } ;
73- const result = await selectDevice ( [ physical , simulator ] , { platform : 'ios' } ) ;
73+ const result = await resolveDevice ( [ physical , simulator ] , { platform : 'ios' } ) ;
7474 assert . equal ( result . id , 'sim-1' ) ;
7575 assert . equal ( result . kind , 'simulator' ) ;
7676} ) ;
7777
78- test ( 'selectDevice prefers booted simulator over physical device' , async ( ) => {
78+ test ( 'resolveDevice prefers booted simulator over physical device' , async ( ) => {
7979 const physical : DeviceInfo = { platform : 'ios' , id : 'phys-1' , name : 'My iPhone' , kind : 'device' , booted : true } ;
8080 const sim1 : DeviceInfo = { platform : 'ios' , id : 'sim-1' , name : 'iPhone 16' , kind : 'simulator' , booted : true } ;
8181 const sim2 : DeviceInfo = { platform : 'ios' , id : 'sim-2' , name : 'iPhone 15' , kind : 'simulator' , booted : false } ;
82- const result = await selectDevice ( [ physical , sim1 , sim2 ] , { platform : 'ios' } ) ;
82+ const result = await resolveDevice ( [ physical , sim1 , sim2 ] , { platform : 'ios' } ) ;
8383 assert . equal ( result . id , 'sim-1' ) ;
8484} ) ;
8585
86- test ( 'selectDevice falls back to physical device when no simulators exist' , async ( ) => {
86+ test ( 'resolveDevice falls back to physical device when no simulators exist' , async ( ) => {
8787 const physical : DeviceInfo = { platform : 'ios' , id : 'phys-1' , name : 'My iPhone' , kind : 'device' , booted : true } ;
88- const result = await selectDevice ( [ physical ] , { platform : 'ios' } ) ;
88+ const result = await resolveDevice ( [ physical ] , { platform : 'ios' } ) ;
8989 assert . equal ( result . id , 'phys-1' ) ;
9090} ) ;
9191
92- test ( 'selectDevice returns physical device when explicitly selected by deviceName' , async ( ) => {
92+ test ( 'resolveDevice returns physical device when explicitly selected by deviceName' , async ( ) => {
9393 const physical : DeviceInfo = { platform : 'ios' , id : 'phys-1' , name : 'My iPhone' , kind : 'device' , booted : true } ;
9494 const simulator : DeviceInfo = { platform : 'ios' , id : 'sim-1' , name : 'iPhone 16' , kind : 'simulator' , booted : true } ;
95- const result = await selectDevice ( [ physical , simulator ] , { platform : 'ios' , deviceName : 'My iPhone' } ) ;
95+ const result = await resolveDevice ( [ physical , simulator ] , { platform : 'ios' , deviceName : 'My iPhone' } ) ;
9696 assert . equal ( result . id , 'phys-1' ) ;
9797} ) ;
9898
99- test ( 'selectDevice returns physical device when explicitly selected by udid' , async ( ) => {
99+ test ( 'resolveDevice returns physical device when explicitly selected by udid' , async ( ) => {
100100 const physical : DeviceInfo = { platform : 'ios' , id : 'phys-1' , name : 'My iPhone' , kind : 'device' , booted : true } ;
101101 const simulator : DeviceInfo = { platform : 'ios' , id : 'sim-1' , name : 'iPhone 16' , kind : 'simulator' , booted : true } ;
102- const result = await selectDevice ( [ physical , simulator ] , { platform : 'ios' , udid : 'phys-1' } ) ;
102+ const result = await resolveDevice ( [ physical , simulator ] , { platform : 'ios' , udid : 'phys-1' } ) ;
103103 assert . equal ( result . id , 'phys-1' ) ;
104104} ) ;
105105
106- test ( 'selectDevice returns physical device when it is the only candidate (no simulators in list)' , async ( ) => {
106+ test ( 'resolveDevice returns physical device when it is the only candidate (no simulators in list)' , async ( ) => {
107107 const physical : DeviceInfo = { platform : 'ios' , id : 'phys-1' , name : 'My iPhone' , kind : 'device' , booted : true } ;
108- const result = await selectDevice ( [ physical ] , { platform : 'ios' } ) ;
108+ const result = await resolveDevice ( [ physical ] , { platform : 'ios' } ) ;
109109 assert . equal ( result . id , 'phys-1' ) ;
110110 assert . equal ( result . kind , 'device' ) ;
111111} ) ;
112-
0 commit comments