1import path from 'path'; 2 3import { 4 extractEnvVariableFromBuild, 5 getProcessOptions, 6 getXcodeBuildArgsAsync, 7 _assertXcodeBuildResults, 8} from '../XcodeBuild'; 9import { ensureDeviceIsCodeSignedForDeploymentAsync } from '../codeSigning/configureCodeSigning'; 10 11jest.mock('../codeSigning/configureCodeSigning'); 12 13const fs = jest.requireActual('fs') as typeof import('fs'); 14 15const asMock = <T extends (...args: any[]) => any>(fn: T): jest.MockedFunction<T> => 16 fn as jest.MockedFunction<T>; 17 18describe(getXcodeBuildArgsAsync, () => { 19 it(`returns fully qualified arguments for a build`, async () => { 20 asMock(ensureDeviceIsCodeSignedForDeploymentAsync).mockResolvedValueOnce('my-dev-team'); 21 await expect( 22 getXcodeBuildArgsAsync({ 23 projectRoot: '/path/to/project', 24 buildCache: false, 25 configuration: 'Debug', 26 isSimulator: false, 27 scheme: 'project-with-build-configurations', 28 device: { udid: 'demo-udid', name: 'foobar' }, 29 xcodeProject: { 30 isWorkspace: true, 31 name: 'demo-project', 32 }, 33 }) 34 ).resolves.toEqual([ 35 '-workspace', 36 'demo-project', 37 '-configuration', 38 'Debug', 39 '-scheme', 40 'project-with-build-configurations', 41 '-destination', 42 'id=demo-udid', 43 'DEVELOPMENT_TEAM=my-dev-team', 44 '-allowProvisioningUpdates', 45 '-allowProvisioningDeviceRegistration', 46 'clean', 47 'build', 48 ]); 49 }); 50 it(`returns standard simulator arguments`, async () => { 51 await expect( 52 getXcodeBuildArgsAsync({ 53 projectRoot: '/path/to/project', 54 buildCache: true, 55 configuration: 'Release', 56 isSimulator: true, 57 scheme: 'project-with-build-configurations', 58 device: { udid: 'demo-udid', name: 'foobar' }, 59 xcodeProject: { 60 isWorkspace: false, 61 name: 'demo-project', 62 }, 63 }) 64 ).resolves.toEqual([ 65 '-project', 66 'demo-project', 67 '-configuration', 68 'Release', 69 '-scheme', 70 'project-with-build-configurations', 71 '-destination', 72 'id=demo-udid', 73 ]); 74 expect(ensureDeviceIsCodeSignedForDeploymentAsync).toBeCalledTimes(0); 75 }); 76}); 77 78describe(extractEnvVariableFromBuild, () => { 79 const fixture = fs.readFileSync(path.join(__dirname, 'fixtures/xcodebuild.log'), 'utf8'); 80 it(`gets env variables from build results`, async () => { 81 expect(extractEnvVariableFromBuild(fixture, 'APPLE_INTERNAL_LIBRARY_DIR')).toEqual([ 82 '/AppleInternal/Library', 83 ]); 84 expect(extractEnvVariableFromBuild(fixture, 'AVAILABLE_PLATFORMS')[0]).toEqual( 85 'appletvos\\ appletvsimulator\\ driverkit\\ iphoneos\\ iphonesimulator\\ macosx\\ watchos\\ watchsimulator' 86 ); 87 expect( 88 extractEnvVariableFromBuild(fixture, 'CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING')[0] 89 ).toEqual('YES'); 90 expect(extractEnvVariableFromBuild(fixture, 'CONFIGURATION_BUILD_DIR')[0]).toEqual( 91 '/Users/evanbacon/Library/Developer/Xcode/DerivedData/basicexpoapp-bhxfzfgdguosemfinvpzbtpjpnji/Build/Products/Debug-iphonesimulator/expo-dev-launcher' 92 ); 93 expect(extractEnvVariableFromBuild(fixture, 'UNLOCALIZED_RESOURCES_FOLDER_PATH')[0]).toEqual( 94 'basicexpoapp.app' 95 ); 96 }); 97}); 98 99xdescribe(getProcessOptions, () => { 100 it(`gets process option when a packager is enabled`, async () => { 101 expect( 102 getProcessOptions({ 103 packager: true, 104 shouldSkipInitialBundling: true, 105 terminal: 'foobar', 106 port: 3000, 107 }) 108 ).toEqual({ 109 env: {}, 110 }); 111 }); 112}); 113 114describe(_assertXcodeBuildResults, () => { 115 it(`asserts invalid Xcode version`, () => { 116 expect(() => 117 _assertXcodeBuildResults( 118 70, 119 'foobar', 120 fs.readFileSync(path.resolve(__dirname, './fixtures/outdated-xcode-error.log'), 'utf8'), 121 { name: 'name' }, 122 './output.log' 123 ) 124 ).toThrow( 125 'This operation can fail if the version of the OS on the device is newer than the version of Xcode that is running.' 126 ); 127 }); 128}); 129