1import { compileMockModWithResultsAsync } from '../../plugins/__tests__/mockMods'; 2import { withPodfileProperties } from '../../plugins/ios-plugins'; 3import { 4 updateIosBuildPropertiesFromConfig, 5 updateIosBuildProperty, 6 withJsEnginePodfileProps, 7} from '../BuildProperties'; 8 9jest.mock('../../plugins/ios-plugins'); 10 11describe(withJsEnginePodfileProps, () => { 12 const JS_ENGINE_PROP_KEY = 'expo.jsEngine'; 13 14 it('set the property from shared `jsEngine` config', async () => { 15 const { modResults } = await compileMockModWithResultsAsync( 16 { jsEngine: 'hermes' }, 17 { 18 plugin: withJsEnginePodfileProps, 19 mod: withPodfileProperties, 20 modResults: {}, 21 } 22 ); 23 expect(modResults).toMatchObject({ 24 [JS_ENGINE_PROP_KEY]: 'hermes', 25 }); 26 }); 27 28 it('set the property from platform override `jsEngine`', async () => { 29 const { modResults } = await compileMockModWithResultsAsync( 30 { jsEngine: 'hermes', ios: { jsEngine: 'jsc' } }, 31 { 32 plugin: withJsEnginePodfileProps, 33 mod: withPodfileProperties, 34 modResults: {}, 35 } 36 ); 37 expect(modResults).toMatchObject({ 38 [JS_ENGINE_PROP_KEY]: 'jsc', 39 }); 40 }); 41 42 it('overwrite the property if an old property is existed', async () => { 43 const { modResults } = await compileMockModWithResultsAsync( 44 { jsEngine: 'hermes' }, 45 { 46 plugin: withJsEnginePodfileProps, 47 mod: withPodfileProperties, 48 modResults: { [JS_ENGINE_PROP_KEY]: 'jsc' } as Record<string, string>, 49 } 50 ); 51 expect(modResults).toMatchObject({ 52 [JS_ENGINE_PROP_KEY]: 'hermes', 53 }); 54 }); 55}); 56 57describe(updateIosBuildPropertiesFromConfig, () => { 58 it('should respect `propValueGetter` order', () => { 59 const podfileProperties = {}; 60 const configToPropertyRules = [ 61 { 62 propName: 'expo.jsEngine', 63 propValueGetter: (config) => config.ios?.jsEngine ?? config.jsEngine ?? 'NOTFOUND', 64 }, 65 ]; 66 67 expect( 68 updateIosBuildPropertiesFromConfig( 69 { jsEngine: 'hermes', ios: { jsEngine: 'jsc' } }, 70 podfileProperties, 71 configToPropertyRules 72 ) 73 ).toMatchObject({ 74 'expo.jsEngine': 'jsc', 75 }); 76 77 expect( 78 updateIosBuildPropertiesFromConfig( 79 { jsEngine: 'jsc' }, 80 podfileProperties, 81 configToPropertyRules 82 ) 83 ).toMatchObject({ 84 'expo.jsEngine': 'jsc', 85 }); 86 87 expect( 88 updateIosBuildPropertiesFromConfig({}, podfileProperties, configToPropertyRules) 89 ).toMatchObject({ 90 'expo.jsEngine': 'NOTFOUND', 91 }); 92 }); 93}); 94 95describe(updateIosBuildProperty, () => { 96 it('should merge properties', () => { 97 const podfileProperties = { 98 foo: 'foo', 99 bar: 'bar', 100 name: 'oldName', 101 }; 102 expect(updateIosBuildProperty(podfileProperties, 'name', 'newName')).toEqual({ 103 foo: 'foo', 104 bar: 'bar', 105 name: 'newName', 106 }); 107 }); 108 109 it('should keep original property when `value` is null by default', () => { 110 const podfileProperties = { 111 foo: 'foo', 112 bar: 'bar', 113 }; 114 expect(updateIosBuildProperty(podfileProperties, 'bar', null)).toEqual({ 115 foo: 'foo', 116 bar: 'bar', 117 }); 118 }); 119 120 it('should remove original property when `value` is null when `removePropWhenValueIsNull` is true', () => { 121 const podfileProperties = { 122 foo: 'foo', 123 bar: 'bar', 124 }; 125 expect( 126 updateIosBuildProperty(podfileProperties, 'bar', null, { removePropWhenValueIsNull: true }) 127 ).toEqual({ 128 foo: 'foo', 129 }); 130 }); 131}); 132