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.signable).toBe(true); 35 expect(applicationTarget.dependencies?.length).toBe(1); 36 expect(applicationTarget.dependencies?.[0].name).toBe('shareextension'); 37 expect(applicationTarget.dependencies?.[0].type).toBe(TargetType.EXTENSION); 38 expect(applicationTarget.dependencies?.[0].signable).toBe(true); 39 }); 40 41 it('also reads dependency dependencies', async () => { 42 vol.fromJSON( 43 { 44 'ios/easwatchtest.xcodeproj/project.pbxproj': originalFs.readFileSync( 45 path.join(__dirname, 'fixtures/watch.pbxproj'), 46 'utf-8' 47 ), 48 'ios/easwatchtest.xcodeproj/xcshareddata/xcschemes/easwatchtest.xcscheme': 49 originalFs.readFileSync(path.join(__dirname, 'fixtures/watch.xcscheme'), 'utf-8'), 50 }, 51 projectRoot 52 ); 53 54 const applicationTarget = await findApplicationTargetWithDependenciesAsync( 55 projectRoot, 56 'easwatchtest' 57 ); 58 expect(applicationTarget.name).toBe('easwatchtest'); 59 expect(applicationTarget.type).toBe(TargetType.APPLICATION); 60 expect(applicationTarget.dependencies?.length).toBe(1); 61 expect(applicationTarget.dependencies?.[0].name).toBe('eas-watch-test'); 62 expect(applicationTarget.dependencies?.[0].type).toBe(TargetType.OTHER); 63 expect(applicationTarget.dependencies?.[0].dependencies?.[0].name).toBe( 64 'eas-watch-test WatchKit Extension' 65 ); 66 expect(applicationTarget.dependencies?.[0].dependencies?.[0].type).toBe(TargetType.OTHER); 67 }); 68 69 it('marks framework targets as non-signable', async () => { 70 vol.fromJSON( 71 { 72 'ios/myapp.xcodeproj/project.pbxproj': originalFs.readFileSync( 73 path.join(__dirname, 'fixtures/project-with-framework.pbxproj'), 74 'utf-8' 75 ), 76 'ios/myapp.xcodeproj/xcshareddata/xcschemes/myapp.xcscheme': originalFs.readFileSync( 77 path.join(__dirname, 'fixtures/framework.xcscheme'), 78 'utf-8' 79 ), 80 }, 81 projectRoot 82 ); 83 84 const applicationTarget = await findApplicationTargetWithDependenciesAsync( 85 projectRoot, 86 'myapp' 87 ); 88 expect(applicationTarget.signable).toBe(true); 89 expect(applicationTarget.dependencies?.[0].signable).toBe(false); 90 }); 91}); 92