1import { vol } from 'memfs'; 2import path from 'path'; 3 4import { findApplicationTargetWithDependenciesAsync, TargetType } from '../Target'; 5 6jest.mock('fs'); 7 8const originalFs = jest.requireActual('fs'); 9 10describe(findApplicationTargetWithDependenciesAsync, () => { 11 const projectRoot = '/app'; 12 13 afterEach(() => vol.reset()); 14 15 it('reads the application target and its dependencies', async () => { 16 vol.fromJSON( 17 { 18 'ios/testproject.xcodeproj/project.pbxproj': originalFs.readFileSync( 19 path.join(__dirname, 'fixtures/project-multitarget.pbxproj'), 20 'utf-8' 21 ), 22 'ios/testproject.xcodeproj/xcshareddata/xcschemes/multitarget.xcscheme': 23 originalFs.readFileSync(path.join(__dirname, 'fixtures/multitarget.xcscheme'), 'utf-8'), 24 }, 25 projectRoot 26 ); 27 28 const applicationTarget = await findApplicationTargetWithDependenciesAsync( 29 projectRoot, 30 'multitarget' 31 ); 32 expect(applicationTarget.name).toBe('multitarget'); 33 expect(applicationTarget.type).toBe(TargetType.APPLICATION); 34 expect(applicationTarget.dependencies.length).toBe(1); 35 expect(applicationTarget.dependencies[0].name).toBe('shareextension'); 36 expect(applicationTarget.dependencies[0].type).toBe(TargetType.EXTENSION); 37 }); 38 39 it('also reads dependency dependencies', async () => { 40 vol.fromJSON( 41 { 42 'ios/easwatchtest.xcodeproj/project.pbxproj': originalFs.readFileSync( 43 path.join(__dirname, 'fixtures/watch.pbxproj'), 44 'utf-8' 45 ), 46 'ios/easwatchtest.xcodeproj/xcshareddata/xcschemes/easwatchtest.xcscheme': 47 originalFs.readFileSync(path.join(__dirname, 'fixtures/watch.xcscheme'), 'utf-8'), 48 }, 49 projectRoot 50 ); 51 52 const applicationTarget = await findApplicationTargetWithDependenciesAsync( 53 projectRoot, 54 'easwatchtest' 55 ); 56 expect(applicationTarget.name).toBe('easwatchtest'); 57 expect(applicationTarget.type).toBe(TargetType.APPLICATION); 58 expect(applicationTarget.dependencies.length).toBe(1); 59 expect(applicationTarget.dependencies[0].name).toBe('eas-watch-test'); 60 expect(applicationTarget.dependencies[0].type).toBe(TargetType.OTHER); 61 expect(applicationTarget.dependencies[0].dependencies[0].name).toBe( 62 'eas-watch-test WatchKit Extension' 63 ); 64 expect(applicationTarget.dependencies[0].dependencies[0].type).toBe(TargetType.OTHER); 65 }); 66}); 67