|
| 1 | +import addBroadcastExtensionXcodeTarget, { |
| 2 | + MIN_DEPLOYMENT_TARGET, |
| 3 | + resolveDeploymentTarget, |
| 4 | +} from '../src/withIosScreenCapture/addBroadcastExtensionXcodeTarget'; |
| 5 | + |
| 6 | +const DEVELOPMENT_TEAM_ID = 'ABCDE12345'; |
| 7 | + |
| 8 | +type StubOptions = { |
| 9 | + /** Deployment targets on the host app target's own configurations. */ |
| 10 | + appTargets?: (string | number | undefined)[]; |
| 11 | + /** Deployment targets on the project-level configurations. */ |
| 12 | + projectTargets?: (string | number | undefined)[]; |
| 13 | + /** |
| 14 | + * Deployment targets belonging to targets other than the host app (widgets, |
| 15 | + * other extensions). These must never influence the resolved value. |
| 16 | + */ |
| 17 | + otherTargets?: (string | number | undefined)[]; |
| 18 | +}; |
| 19 | + |
| 20 | +/** |
| 21 | + * Minimal stand-in for the parts of the `xcode` project object that |
| 22 | + * addBroadcastExtensionXcodeTarget touches. Captures the build configurations |
| 23 | + * it generates so they can be asserted on. |
| 24 | + * |
| 25 | + * Models real project structure: configurations live in the flat |
| 26 | + * XCBuildConfiguration section, and each target reaches its own subset through |
| 27 | + * an XCConfigurationList. |
| 28 | + */ |
| 29 | +const createProjectStub = ( |
| 30 | + options: StubOptions | (string | number | undefined)[], |
| 31 | +) => { |
| 32 | + const { |
| 33 | + appTargets = [], |
| 34 | + projectTargets = [], |
| 35 | + otherTargets = [], |
| 36 | + } = Array.isArray(options) ? { appTargets: options } : options; |
| 37 | + |
| 38 | + const buildConfigurationSection: Record<string, any> = {}; |
| 39 | + const configurationLists: Record<string, any> = {}; |
| 40 | + |
| 41 | + const addList = ( |
| 42 | + listUuid: string, |
| 43 | + targets: (string | number | undefined)[], |
| 44 | + prefix: string, |
| 45 | + ) => { |
| 46 | + const buildConfigurations = targets.map((target, index) => { |
| 47 | + const uuid = `${prefix}${index}`; |
| 48 | + buildConfigurationSection[uuid] = { |
| 49 | + isa: 'XCBuildConfiguration', |
| 50 | + buildSettings: |
| 51 | + target === undefined ? {} : { IPHONEOS_DEPLOYMENT_TARGET: target }, |
| 52 | + }; |
| 53 | + buildConfigurationSection[`${uuid}_comment`] = 'Debug'; |
| 54 | + return { value: uuid, comment: 'Debug' }; |
| 55 | + }); |
| 56 | + configurationLists[listUuid] = { buildConfigurations }; |
| 57 | + }; |
| 58 | + |
| 59 | + addList('APP_LIST', appTargets, 'APP'); |
| 60 | + addList('PROJECT_LIST', projectTargets, 'PROJ'); |
| 61 | + // reachable in the flat section but not from the app or project lists |
| 62 | + addList('OTHER_LIST', otherTargets, 'OTHER'); |
| 63 | + |
| 64 | + let uuidCounter = 0; |
| 65 | + |
| 66 | + // the module mutates this in place, so every call must see the same object |
| 67 | + const projectSection: Record<string, any> = { |
| 68 | + PROJECT_UUID: { attributes: {} }, |
| 69 | + }; |
| 70 | + |
| 71 | + return { |
| 72 | + addedConfigurations: [] as any[], |
| 73 | + pbxXCBuildConfigurationSection: () => buildConfigurationSection, |
| 74 | + pbxXCConfigurationList: () => configurationLists, |
| 75 | + generateUuid: () => `GENERATED${uuidCounter++}`, |
| 76 | + getFirstProject: () => ({ |
| 77 | + uuid: 'PROJECT_UUID', |
| 78 | + firstProject: { targets: [], buildConfigurationList: 'PROJECT_LIST' }, |
| 79 | + }), |
| 80 | + getFirstTarget: () => ({ |
| 81 | + firstTarget: { name: 'TestApp', buildConfigurationList: 'APP_LIST' }, |
| 82 | + }), |
| 83 | + addXCConfigurationList(configurations: any[]) { |
| 84 | + this.addedConfigurations = configurations; |
| 85 | + return { uuid: 'CONFIG_LIST_UUID' }; |
| 86 | + }, |
| 87 | + updateBuildProperty: () => undefined, |
| 88 | + addFramework: () => ({ path: 'ReplayKit.framework' }), |
| 89 | + addToPbxFileReferenceSection: () => undefined, |
| 90 | + addToPbxBuildFileSection: () => undefined, |
| 91 | + addToPbxNativeTargetSection: () => undefined, |
| 92 | + addToPbxProjectSection: () => undefined, |
| 93 | + addTargetDependency: () => undefined, |
| 94 | + addBuildPhase: () => ({ buildPhase: {} }), |
| 95 | + addToPbxGroup: () => undefined, |
| 96 | + addPbxGroup: () => ({ uuid: 'GROUP_UUID' }), |
| 97 | + pbxProjectSection: () => projectSection, |
| 98 | + hash: { project: { objects: { PBXGroup: {} } as Record<string, any> } }, |
| 99 | + }; |
| 100 | +}; |
| 101 | + |
| 102 | +describe('resolveDeploymentTarget', () => { |
| 103 | + it('falls back to the minimum when the project declares no target', () => { |
| 104 | + const proj = createProjectStub([]); |
| 105 | + expect(resolveDeploymentTarget(proj as any)).toBe(MIN_DEPLOYMENT_TARGET); |
| 106 | + }); |
| 107 | + |
| 108 | + it('never lowers the target below the extension minimum', () => { |
| 109 | + const proj = createProjectStub(['12.0', '13.4']); |
| 110 | + expect(resolveDeploymentTarget(proj as any)).toBe(MIN_DEPLOYMENT_TARGET); |
| 111 | + }); |
| 112 | + |
| 113 | + // An app may pin ios.deploymentTarget to the toolchain minimum via |
| 114 | + // expo-build-properties. The extension must not land above it, or screen |
| 115 | + // share becomes unavailable on the oldest devices the app still supports. |
| 116 | + it('does not exceed a host app pinned to the toolchain minimum', () => { |
| 117 | + const proj = createProjectStub(['15.0', '15.0']); |
| 118 | + expect(resolveDeploymentTarget(proj as any)).toBe('15.0'); |
| 119 | + }); |
| 120 | + |
| 121 | + it("raises the target to match the host app's deployment target", () => { |
| 122 | + const proj = createProjectStub(['16.4', '16.4']); |
| 123 | + expect(resolveDeploymentTarget(proj as any)).toBe('16.4'); |
| 124 | + }); |
| 125 | + |
| 126 | + it('picks the highest target when configurations disagree', () => { |
| 127 | + const proj = createProjectStub(['15.1', '16.4', '14.0']); |
| 128 | + expect(resolveDeploymentTarget(proj as any)).toBe('16.4'); |
| 129 | + }); |
| 130 | + |
| 131 | + it('compares versions numerically rather than lexically', () => { |
| 132 | + // lexically '9.0' sorts above '16.0' |
| 133 | + const proj = createProjectStub(['9.0', '16.0']); |
| 134 | + expect(resolveDeploymentTarget(proj as any)).toBe('16.0'); |
| 135 | + }); |
| 136 | + |
| 137 | + it('ignores quoted values and non-version placeholders', () => { |
| 138 | + const proj = createProjectStub(['"16.4"', '$(inherited)', undefined]); |
| 139 | + expect(resolveDeploymentTarget(proj as any)).toBe('16.4'); |
| 140 | + }); |
| 141 | + |
| 142 | + it('rejects versions with a non-numeric suffix', () => { |
| 143 | + // Number.parseInt('4beta') is 4, so a naive parse would adopt "16.4beta" |
| 144 | + // verbatim and write an invalid value into the build setting. |
| 145 | + const proj = createProjectStub(['16.4beta']); |
| 146 | + expect(resolveDeploymentTarget(proj as any)).toBe(MIN_DEPLOYMENT_TARGET); |
| 147 | + |
| 148 | + const withValid = createProjectStub(['16.4beta', '16.1']); |
| 149 | + expect(resolveDeploymentTarget(withValid as any)).toBe('16.1'); |
| 150 | + }); |
| 151 | + |
| 152 | + it('reads the project-level target when the app target inherits it', () => { |
| 153 | + const proj = createProjectStub({ |
| 154 | + appTargets: ['$(inherited)'], |
| 155 | + projectTargets: ['16.4'], |
| 156 | + }); |
| 157 | + expect(resolveDeploymentTarget(proj as any)).toBe('16.4'); |
| 158 | + }); |
| 159 | + |
| 160 | + // The extension must never require a newer iOS than the app it ships inside: |
| 161 | + // a widget or notification-service extension on a higher target would |
| 162 | + // otherwise silently drop screen share on devices in between. |
| 163 | + it('ignores deployment targets belonging to unrelated targets', () => { |
| 164 | + const proj = createProjectStub({ |
| 165 | + appTargets: ['16.1', '16.1'], |
| 166 | + projectTargets: ['16.1'], |
| 167 | + otherTargets: ['17.0', '18.0'], |
| 168 | + }); |
| 169 | + expect(resolveDeploymentTarget(proj as any)).toBe('16.1'); |
| 170 | + }); |
| 171 | + |
| 172 | + // Xcode 27 errors out on anything below 15.0, so even the fallback taken when |
| 173 | + // the host app's target cannot be read has to clear that bar. |
| 174 | + it('always resolves to a target Xcode 27 accepts', () => { |
| 175 | + const projects = [ |
| 176 | + createProjectStub([]), |
| 177 | + createProjectStub(['13.4']), |
| 178 | + createProjectStub(['16.4']), |
| 179 | + ]; |
| 180 | + projects.forEach((proj) => { |
| 181 | + const [major, minor = 0] = resolveDeploymentTarget(proj as any) |
| 182 | + .split('.') |
| 183 | + .map(Number); |
| 184 | + expect(major * 100 + minor).toBeGreaterThanOrEqual(15 * 100); |
| 185 | + }); |
| 186 | + }); |
| 187 | +}); |
| 188 | + |
| 189 | +describe('addBroadcastExtensionXcodeTarget', () => { |
| 190 | + const addTarget = (deploymentTargets: string[]) => { |
| 191 | + const proj = createProjectStub(deploymentTargets); |
| 192 | + addBroadcastExtensionXcodeTarget(proj as any, { |
| 193 | + appName: 'TestApp', |
| 194 | + extensionName: 'broadcast', |
| 195 | + extensionBundleIdentifier: 'io.getstream.test.broadcast', |
| 196 | + currentProjectVersion: '1', |
| 197 | + marketingVersion: '1.0.0', |
| 198 | + developmentTeamId: DEVELOPMENT_TEAM_ID, |
| 199 | + }); |
| 200 | + return proj.addedConfigurations; |
| 201 | + }; |
| 202 | + |
| 203 | + it('writes DEVELOPMENT_TEAM into every build configuration', () => { |
| 204 | + const configurations = addTarget(['16.4']); |
| 205 | + |
| 206 | + expect(configurations).toHaveLength(2); |
| 207 | + expect(configurations.map((c) => c.name)).toEqual(['Debug', 'Release']); |
| 208 | + configurations.forEach((configuration) => { |
| 209 | + expect(configuration.buildSettings.DEVELOPMENT_TEAM).toBe( |
| 210 | + DEVELOPMENT_TEAM_ID, |
| 211 | + ); |
| 212 | + }); |
| 213 | + }); |
| 214 | + |
| 215 | + it('applies the resolved deployment target to every build configuration', () => { |
| 216 | + const configurations = addTarget(['16.4']); |
| 217 | + |
| 218 | + configurations.forEach((configuration) => { |
| 219 | + expect(configuration.buildSettings.IPHONEOS_DEPLOYMENT_TARGET).toBe( |
| 220 | + '16.4', |
| 221 | + ); |
| 222 | + }); |
| 223 | + }); |
| 224 | + |
| 225 | + it('falls back to the minimum deployment target for older host apps', () => { |
| 226 | + const configurations = addTarget(['13.4']); |
| 227 | + |
| 228 | + configurations.forEach((configuration) => { |
| 229 | + expect(configuration.buildSettings.IPHONEOS_DEPLOYMENT_TARGET).toBe( |
| 230 | + MIN_DEPLOYMENT_TARGET, |
| 231 | + ); |
| 232 | + }); |
| 233 | + }); |
| 234 | +}); |
0 commit comments