1+ import chai , { expect } from 'chai' ;
2+ import chaiAsPromised from 'chai-as-promised' ;
13import { getXctestrunFilePath , getAdditionalRunContent , getXctestrunFileName } from '../../lib/utils' ;
24import { PLATFORM_NAME_IOS , PLATFORM_NAME_TVOS } from '../../lib/constants' ;
35import { fs } from '@appium/support' ;
46import path from 'path' ;
57import { fail } from 'assert' ;
68import { arch } from 'os' ;
79import sinon from 'sinon' ;
10+ import type { DeviceInfo } from '../../lib/types' ;
811
9- function get_arch ( ) {
12+ chai . use ( chaiAsPromised ) ;
13+
14+ function get_arch ( ) : string {
1015 return arch ( ) === 'arm64' ? 'arm64' : 'x86_64' ;
1116}
1217
1318describe ( 'utils' , function ( ) {
14- let chai ;
15-
16- before ( async function ( ) {
17- chai = await import ( 'chai' ) ;
18- const chaiAsPromised = await import ( 'chai-as-promised' ) ;
19-
20- chai . should ( ) ;
21- chai . use ( chaiAsPromised . default ) ;
22- } ) ;
2319
2420 describe ( '#getXctestrunFilePath' , function ( ) {
2521 const platformVersion = '12.0' ;
2622 const sdkVersion = '12.2' ;
2723 const udid = 'xxxxxyyyyyyzzzzzz' ;
2824 const bootstrapPath = 'path/to/data' ;
2925 const platformName = PLATFORM_NAME_IOS ;
30- let sandbox ;
26+ let sandbox : sinon . SinonSandbox ;
3127
3228 beforeEach ( function ( ) {
3329 sandbox = sinon . createSandbox ( ) ;
@@ -42,9 +38,9 @@ describe('utils', function () {
4238 . withArgs ( path . resolve ( `${ bootstrapPath } /${ udid } _${ sdkVersion } .xctestrun` ) )
4339 . resolves ( true ) ;
4440 sandbox . stub ( fs , 'copyFile' ) ;
45- const deviceInfo = { isRealDevice : true , udid, platformVersion, platformName} ;
46- await getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath )
47- . should . eventually . equal ( path . resolve ( `${ bootstrapPath } /${ udid } _${ sdkVersion } .xctestrun` ) ) ;
41+ const deviceInfo : DeviceInfo = { isRealDevice : true , udid, platformVersion, platformName} ;
42+ await expect ( getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath ) )
43+ . to . eventually . equal ( path . resolve ( `${ bootstrapPath } /${ udid } _${ sdkVersion } .xctestrun` ) ) ;
4844 sandbox . assert . notCalled ( fs . copyFile ) ;
4945 } ) ;
5046
@@ -58,9 +54,9 @@ describe('utils', function () {
5854 path . resolve ( `${ bootstrapPath } /${ udid } _${ sdkVersion } .xctestrun` )
5955 )
6056 . resolves ( ) ;
61- const deviceInfo = { isRealDevice : true , udid, platformVersion} ;
62- await getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath )
63- . should . eventually . equal ( path . resolve ( `${ bootstrapPath } /${ udid } _${ sdkVersion } .xctestrun` ) ) ;
57+ const deviceInfo : DeviceInfo = { isRealDevice : true , udid, platformVersion, platformName : PLATFORM_NAME_IOS } ;
58+ await expect ( getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath ) )
59+ . to . eventually . equal ( path . resolve ( `${ bootstrapPath } /${ udid } _${ sdkVersion } .xctestrun` ) ) ;
6460 } ) ;
6561
6662 it ( 'should return platform based path' , async function ( ) {
@@ -69,9 +65,9 @@ describe('utils', function () {
6965 existsStub . withArgs ( path . resolve ( `${ bootstrapPath } /WebDriverAgentRunner_iphonesimulator${ sdkVersion } -${ get_arch ( ) } .xctestrun` ) ) . resolves ( false ) ;
7066 existsStub . withArgs ( path . resolve ( `${ bootstrapPath } /${ udid } _${ platformVersion } .xctestrun` ) ) . resolves ( true ) ;
7167 sandbox . stub ( fs , 'copyFile' ) ;
72- const deviceInfo = { isRealDevice : false , udid, platformVersion} ;
73- await getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath )
74- . should . eventually . equal ( path . resolve ( `${ bootstrapPath } /${ udid } _${ platformVersion } .xctestrun` ) ) ;
68+ const deviceInfo : DeviceInfo = { isRealDevice : false , udid, platformVersion, platformName : PLATFORM_NAME_IOS } ;
69+ await expect ( getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath ) )
70+ . to . eventually . equal ( path . resolve ( `${ bootstrapPath } /${ udid } _${ platformVersion } .xctestrun` ) ) ;
7571 sandbox . assert . notCalled ( fs . copyFile ) ;
7672 } ) ;
7773
@@ -88,38 +84,36 @@ describe('utils', function () {
8884 )
8985 . resolves ( ) ;
9086
91- const deviceInfo = { isRealDevice : false , udid, platformVersion} ;
92- await getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath )
93- . should . eventually . equal ( path . resolve ( `${ bootstrapPath } /${ udid } _${ platformVersion } .xctestrun` ) ) ;
87+ const deviceInfo : DeviceInfo = { isRealDevice : false , udid, platformVersion, platformName : PLATFORM_NAME_IOS } ;
88+ await expect ( getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath ) )
89+ . to . eventually . equal ( path . resolve ( `${ bootstrapPath } /${ udid } _${ platformVersion } .xctestrun` ) ) ;
9490 } ) ;
9591
9692 it ( 'should raise an exception because of no files' , async function ( ) {
9793 const expected = path . resolve ( `${ bootstrapPath } /WebDriverAgentRunner_iphonesimulator${ sdkVersion } -${ get_arch ( ) } .xctestrun` ) ;
9894 sandbox . stub ( fs , 'exists' ) . resolves ( false ) ;
9995
100- const deviceInfo = { isRealDevice : false , udid, platformVersion} ;
96+ const deviceInfo : DeviceInfo = { isRealDevice : false , udid, platformVersion, platformName : PLATFORM_NAME_IOS } ;
10197 try {
10298 await getXctestrunFilePath ( deviceInfo , sdkVersion , bootstrapPath ) ;
10399 fail ( ) ;
104- } catch ( err ) {
105- err . message . should . equal ( `If you are using 'useXctestrunFile' capability then you need to have a xctestrun file (expected: '${ expected } ')` ) ;
100+ } catch ( err : any ) {
101+ expect ( err . message ) . to . equal ( `If you are using 'useXctestrunFile' capability then you need to have a xctestrun file (expected: '${ expected } ')` ) ;
106102 }
107103 } ) ;
108104 } ) ;
109105
110106 describe ( '#getAdditionalRunContent' , function ( ) {
111107 it ( 'should return ios format' , function ( ) {
112108 const wdaPort = getAdditionalRunContent ( PLATFORM_NAME_IOS , 8000 ) ;
113- wdaPort . WebDriverAgentRunner
114- . EnvironmentVariables . USE_PORT
115- . should . equal ( '8000' ) ;
109+ expect ( wdaPort . WebDriverAgentRunner
110+ . EnvironmentVariables . USE_PORT ) . to . equal ( '8000' ) ;
116111 } ) ;
117112
118113 it ( 'should return tvos format' , function ( ) {
119114 const wdaPort = getAdditionalRunContent ( PLATFORM_NAME_TVOS , '9000' ) ;
120- wdaPort . WebDriverAgentRunner_tvOS
121- . EnvironmentVariables . USE_PORT
122- . should . equal ( '9000' ) ;
115+ expect ( wdaPort . WebDriverAgentRunner_tvOS
116+ . EnvironmentVariables . USE_PORT ) . to . equal ( '9000' ) ;
123117 } ) ;
124118 } ) ;
125119
@@ -129,34 +123,35 @@ describe('utils', function () {
129123
130124 it ( 'should return ios format, real device' , function ( ) {
131125 const platformName = 'iOs' ;
132- const deviceInfo = { isRealDevice : true , udid, platformVersion, platformName} ;
126+ const deviceInfo : DeviceInfo = { isRealDevice : true , udid, platformVersion, platformName} ;
133127
134- getXctestrunFileName ( deviceInfo , '10.2.0' ) . should . equal (
128+ expect ( getXctestrunFileName ( deviceInfo , '10.2.0' ) ) . to . equal (
135129 'WebDriverAgentRunner_iphoneos10.2.0-arm64.xctestrun' ) ;
136130 } ) ;
137131
138132 it ( 'should return ios format, simulator' , function ( ) {
139133 const platformName = 'ios' ;
140- const deviceInfo = { isRealDevice : false , udid, platformVersion, platformName} ;
134+ const deviceInfo : DeviceInfo = { isRealDevice : false , udid, platformVersion, platformName} ;
141135
142- getXctestrunFileName ( deviceInfo , '10.2.0' ) . should . equal (
136+ expect ( getXctestrunFileName ( deviceInfo , '10.2.0' ) ) . to . equal (
143137 `WebDriverAgentRunner_iphonesimulator10.2.0-${ get_arch ( ) } .xctestrun` ) ;
144138 } ) ;
145139
146140 it ( 'should return tvos format, real device' , function ( ) {
147141 const platformName = 'tVos' ;
148- const deviceInfo = { isRealDevice : true , udid, platformVersion, platformName} ;
142+ const deviceInfo : DeviceInfo = { isRealDevice : true , udid, platformVersion, platformName} ;
149143
150- getXctestrunFileName ( deviceInfo , '10.2.0' ) . should . equal (
144+ expect ( getXctestrunFileName ( deviceInfo , '10.2.0' ) ) . to . equal (
151145 'WebDriverAgentRunner_tvOS_appletvos10.2.0-arm64.xctestrun' ) ;
152146 } ) ;
153147
154148 it ( 'should return tvos format, simulator' , function ( ) {
155149 const platformName = 'tvOS' ;
156- const deviceInfo = { isRealDevice : false , udid, platformVersion, platformName} ;
150+ const deviceInfo : DeviceInfo = { isRealDevice : false , udid, platformVersion, platformName} ;
157151
158- getXctestrunFileName ( deviceInfo , '10.2.0' ) . should . equal (
152+ expect ( getXctestrunFileName ( deviceInfo , '10.2.0' ) ) . to . equal (
159153 `WebDriverAgentRunner_tvOS_appletvsimulator10.2.0-${ get_arch ( ) } .xctestrun` ) ;
160154 } ) ;
161155 } ) ;
162156} ) ;
157+
0 commit comments