11import path from 'path' ;
2+ import { promises as fs } from 'fs' ;
23import execa , { ExecaReturnValue } from 'execa' ;
34
45import { CliRunOptions , Config } from '../types' ;
@@ -12,12 +13,19 @@ describe('run.ts', () => {
1213 const bundleIdIOS = 'org.reactjs.native.example.RNDemo' ;
1314 const mockBundleIdResponse = { stdout : bundleIdIOS } as ExecaReturnValue < any > ;
1415
16+ const mkdirMock = jest . spyOn ( fs , 'mkdir' ) ;
17+
18+ jest
19+ . spyOn ( process , 'cwd' )
20+ . mockReturnValue ( '/Users/johndoe/Projects/my-project' ) ;
21+
1522 const execKillMock = {
1623 kill : jest . fn ( ) ,
1724 } as unknown as execa . ExecaChildProcess < any > ;
1825 const execMock = jest . spyOn ( execa , 'command' ) . mockImplementation ( ) ;
1926
2027 beforeEach ( ( ) => {
28+ mkdirMock . mockReset ( ) ;
2129 execMock . mockReset ( ) . mockReturnValue ( execKillMock ) ;
2230 } ) ;
2331
@@ -208,11 +216,13 @@ describe('run.ts', () => {
208216 } ,
209217 } ;
210218
211- const expectedJestCommand = `jest --config=${ path . join (
212- process . cwd ( ) ,
213- 'lib' ,
214- 'jest-config.json'
215- ) } --roots=${ path . join ( process . cwd ( ) ) } --runInBand`;
219+ const jestConfigPath = path . join ( __dirname , '..' , 'jest-config.json' ) ;
220+
221+ const expectedJestCommand = `jest --config=${ jestConfigPath } --roots=${ path . join (
222+ process . cwd ( )
223+ ) } --runInBand`;
224+
225+ const expectedJestCommandWithReport = `${ expectedJestCommand } --json --outputFile=/Users/johndoe/Projects/my-project/.owl/report/jest-report.json` ;
216226
217227 const commandSyncMock = jest . spyOn ( execa , 'commandSync' ) ;
218228 const mockGenerateReport = jest . spyOn ( reportHelpers , 'generateReport' ) ;
@@ -225,25 +235,33 @@ describe('run.ts', () => {
225235 } ) ;
226236
227237 it ( 'runs an iOS project' , async ( ) => {
228- jest . spyOn ( configHelpers , 'getConfig' ) . mockResolvedValueOnce ( config ) ;
238+ jest
239+ . spyOn ( configHelpers , 'getConfig' )
240+ . mockResolvedValueOnce ( { ...config , report : true } ) ;
229241 const mockRunIOS = jest . spyOn ( run , 'runIOS' ) . mockResolvedValueOnce ( ) ;
230242 const mockRestoreIOSUI = jest
231243 . spyOn ( run , 'restoreIOSUI' )
232244 . mockResolvedValueOnce ( ) ;
233245
246+ mkdirMock . mockResolvedValue ( undefined ) ;
247+
234248 await run . runHandler ( args ) ;
235249
250+ await expect ( mkdirMock ) . toHaveBeenCalled ( ) ;
236251 await expect ( mockRunIOS ) . toHaveBeenCalled ( ) ;
237252 await expect ( commandSyncMock ) . toHaveBeenCalledTimes ( 1 ) ;
238- await expect ( commandSyncMock ) . toHaveBeenCalledWith ( expectedJestCommand , {
239- env : {
240- OWL_DEBUG : 'false' ,
241- OWL_IOS_SIMULATOR : 'iPhone Simulator' ,
242- OWL_PLATFORM : 'ios' ,
243- OWL_UPDATE_BASELINE : 'false' ,
244- } ,
245- stdio : 'inherit' ,
246- } ) ;
253+ await expect ( commandSyncMock ) . toHaveBeenCalledWith (
254+ expectedJestCommandWithReport ,
255+ {
256+ env : {
257+ OWL_DEBUG : 'false' ,
258+ OWL_IOS_SIMULATOR : 'iPhone Simulator' ,
259+ OWL_PLATFORM : 'ios' ,
260+ OWL_UPDATE_BASELINE : 'false' ,
261+ } ,
262+ stdio : 'inherit' ,
263+ }
264+ ) ;
247265 await expect ( mockRestoreIOSUI ) . toHaveBeenCalled ( ) ;
248266 } ) ;
249267
@@ -329,10 +347,23 @@ describe('run.ts', () => {
329347 commandSyncMock . mockRejectedValueOnce ( undefined ! ) ;
330348
331349 try {
332- await run . runHandler ( { ...args , update : true } ) ;
350+ await run . runHandler ( { ...args } ) ;
333351 } catch {
352+ await expect ( commandSyncMock ) . toHaveBeenCalledWith (
353+ expectedJestCommand ,
354+ {
355+ env : {
356+ OWL_DEBUG : 'false' ,
357+ OWL_IOS_SIMULATOR : 'iPhone Simulator' ,
358+ OWL_PLATFORM : 'ios' ,
359+ OWL_UPDATE_BASELINE : 'false' ,
360+ } ,
361+ stdio : 'inherit' ,
362+ }
363+ ) ;
334364 await expect ( mockRunIOS ) . toHaveBeenCalled ( ) ;
335365 await expect ( commandSyncMock ) . toHaveBeenCalledTimes ( 1 ) ;
366+ await expect ( mkdirMock ) . not . toHaveBeenCalled ( ) ;
336367 await expect ( mockGenerateReport ) . not . toHaveBeenCalled ( ) ;
337368 }
338369 } ) ;
0 commit comments