@@ -30,6 +30,10 @@ const spawnMock = test.mock.method(childProcess, 'spawnSync');
3030
3131const devicectl = require ( '../lib/devicectl' ) ;
3232
33+ test . beforeEach ( ( ) => {
34+ spawnMock . mock . resetCalls ( ) ;
35+ } ) ;
36+
3337test ( 'exports' , ( t ) => {
3438 t . assert ||= require ( 'node:assert' ) ;
3539
@@ -38,6 +42,9 @@ test('exports', (t) => {
3842 t . assert . equal ( typeof devicectl . xcode_version , 'function' ) ;
3943 t . assert . equal ( typeof devicectl . help , 'function' ) ;
4044 t . assert . equal ( typeof devicectl . list , 'function' ) ;
45+ t . assert . equal ( typeof devicectl . diagnose , 'function' ) ;
46+ t . assert . equal ( typeof devicectl . install , 'function' ) ;
47+ t . assert . equal ( typeof devicectl . launch , 'function' ) ;
4148} ) ;
4249
4350test ( 'check_prerequisites fail' , ( t ) => {
@@ -86,10 +93,6 @@ test('devicectl version', (t) => {
8693} ) ;
8794
8895test ( 'devicectl help' , async ( ctx ) => {
89- ctx . beforeEach ( ( t ) => {
90- spawnMock . mock . resetCalls ( ) ;
91- } ) ;
92-
9396 await ctx . test ( 'with no arguments' , ( t ) => {
9497 t . assert ||= require ( 'node:assert' ) ;
9598
@@ -115,12 +118,10 @@ test('devicectl help', async (ctx) => {
115118
116119test ( 'devicectl list' , async ( ctx ) => {
117120 ctx . beforeEach ( ( t ) => {
118- spawnMock . mock . resetCalls ( ) ;
119-
120121 t . mock . method ( console , 'error' , ( ) => { } ) ;
121122 } ) ;
122123
123- await ctx . test ( 'with a successful response ' , ( t ) => {
124+ await ctx . test ( 'with no arguments ' , ( t ) => {
124125 t . assert ||= require ( 'node:assert' ) ;
125126
126127 spawnMock . mock . mockImplementationOnce ( ( ) => {
@@ -132,6 +133,18 @@ test('devicectl list', async (ctx) => {
132133 t . assert . deepEqual ( retObj . json , { result : { devices : [ ] } } ) ;
133134 } ) ;
134135
136+ await ctx . test ( 'with preferredDDI argument' , ( t ) => {
137+ t . assert ||= require ( 'node:assert' ) ;
138+
139+ spawnMock . mock . mockImplementationOnce ( ( ) => {
140+ return { status : 0 , stdout : '{"result":{"platforms":[]}}' } ;
141+ } ) ;
142+
143+ const retObj = devicectl . list ( 'preferredDDI' ) ;
144+ t . assert . deepEqual ( spawnMock . mock . calls [ 0 ] . arguments [ 1 ] , [ 'devicectl' , 'list' , 'preferredDDI' , '--quiet' , '--json-output' , '/dev/stdout' ] ) ;
145+ t . assert . deepEqual ( retObj . json , { result : { platforms : [ ] } } ) ;
146+ } ) ;
147+
135148 await ctx . test ( 'with parsing error' , ( t ) => {
136149 t . assert ||= require ( 'node:assert' ) ;
137150
@@ -144,3 +157,90 @@ test('devicectl list', async (ctx) => {
144157 t . assert . equal ( retObj . json , undefined ) ;
145158 } ) ;
146159} ) ;
160+
161+ test ( 'devicectl diagnose' , async ( ctx ) => {
162+ ctx . beforeEach ( ( t ) => {
163+ t . mock . method ( console , 'error' , ( ) => { } ) ;
164+ } ) ;
165+
166+ await ctx . test ( 'with a successful response' , ( t ) => {
167+ t . assert ||= require ( 'node:assert' ) ;
168+
169+ spawnMock . mock . mockImplementationOnce ( ( ) => {
170+ return { status : 0 , stdout : '{"result":{}}' } ;
171+ } ) ;
172+
173+ const retObj = devicectl . diagnose ( 'device_id' ) ;
174+ t . assert . deepEqual ( spawnMock . mock . calls [ 0 ] . arguments [ 1 ] , [ 'devicectl' , 'diagnose' , '--device' , 'device_id' , '--no-finder' , '--quiet' , '--json-output' , '/dev/stdout' ] ) ;
175+ t . assert . deepEqual ( retObj . json , { result : { } } ) ;
176+ } ) ;
177+
178+ await ctx . test ( 'with parsing error' , ( t ) => {
179+ t . assert ||= require ( 'node:assert' ) ;
180+
181+ spawnMock . mock . mockImplementationOnce ( ( ) => {
182+ return { status : 0 , stdout : 'This is not valid JSON' } ;
183+ } ) ;
184+
185+ const retObj = devicectl . diagnose ( 'device_id' ) ;
186+ t . assert . match ( console . error . mock . calls [ 0 ] . arguments [ 0 ] , / S y n t a x E r r o r : U n e x p e c t e d t o k e n / ) ;
187+ t . assert . equal ( retObj . json , undefined ) ;
188+ } ) ;
189+ } ) ;
190+
191+ test ( 'devicectl install' , ( t ) => {
192+ t . assert ||= require ( 'node:assert' ) ;
193+
194+ spawnMock . mock . mockImplementationOnce ( ( ) => {
195+ return { status : 0 , stdout : '' } ;
196+ } ) ;
197+
198+ devicectl . install ( 'device_id' , 'path/to/bundle.app' ) ;
199+ t . assert . deepEqual ( spawnMock . mock . calls [ 0 ] . arguments [ 1 ] , [ 'devicectl' , 'device' , 'install' , 'app' , '--device' , 'device_id' , 'path/to/bundle.app' ] ) ;
200+ } ) ;
201+
202+ test ( 'devicectl launch' , async ( ctx ) => {
203+ await ctx . test ( 'with no argv arguments' , ( t ) => {
204+ t . assert ||= require ( 'node:assert' ) ;
205+
206+ spawnMock . mock . mockImplementationOnce ( ( ) => {
207+ return { status : 0 , stdout : '' } ;
208+ } ) ;
209+
210+ devicectl . launch ( 'device_id' , 'com.example.myapp' ) ;
211+ t . assert . deepEqual ( spawnMock . mock . calls [ 0 ] . arguments [ 1 ] , [ 'devicectl' , 'device' , 'process' , 'launch' , '--device' , 'device_id' , 'com.example.myapp' ] ) ;
212+ } ) ;
213+
214+ await ctx . test ( 'with argv arguments' , ( t ) => {
215+ t . assert ||= require ( 'node:assert' ) ;
216+
217+ spawnMock . mock . mockImplementationOnce ( ( ) => {
218+ return { status : 0 , stdout : '' } ;
219+ } ) ;
220+
221+ devicectl . launch ( 'device_id' , 'com.example.myapp' , [ 'https://example.com' ] ) ;
222+ t . assert . deepEqual ( spawnMock . mock . calls [ 0 ] . arguments [ 1 ] , [ 'devicectl' , 'device' , 'process' , 'launch' , '--device' , 'device_id' , 'com.example.myapp' , 'https://example.com' ] ) ;
223+ } ) ;
224+
225+ await ctx . test ( 'with startStopped option' , ( t ) => {
226+ t . assert ||= require ( 'node:assert' ) ;
227+
228+ spawnMock . mock . mockImplementationOnce ( ( ) => {
229+ return { status : 0 , stdout : '' } ;
230+ } ) ;
231+
232+ devicectl . launch ( 'device_id' , 'com.example.myapp' , [ ] , { startStopped : true } ) ;
233+ t . assert . deepEqual ( spawnMock . mock . calls [ 0 ] . arguments [ 1 ] , [ 'devicectl' , 'device' , 'process' , 'launch' , '--device' , 'device_id' , '--start-stopped' , 'com.example.myapp' ] ) ;
234+ } ) ;
235+
236+ await ctx . test ( 'with console option' , ( t ) => {
237+ t . assert ||= require ( 'node:assert' ) ;
238+
239+ spawnMock . mock . mockImplementationOnce ( ( ) => {
240+ return { status : 0 , stdout : '' } ;
241+ } ) ;
242+
243+ devicectl . launch ( 'device_id' , 'com.example.myapp' , [ ] , { console : true } ) ;
244+ t . assert . deepEqual ( spawnMock . mock . calls [ 0 ] . arguments [ 1 ] , [ 'devicectl' , 'device' , 'process' , 'launch' , '--device' , 'device_id' , '--console' , 'com.example.myapp' ] ) ;
245+ } ) ;
246+ } ) ;
0 commit comments