|
| 1 | +import { |
| 2 | + createMockPodfileConfig, |
| 3 | + createTestConfig, |
| 4 | + type WithIterableResult, |
| 5 | +} from '../__mocks__'; |
| 6 | +import { FMT_WORKAROUND_MARKER } from '../src/withIosFmtWorkaround'; |
| 7 | +import withIterable from '../src/withIterable'; |
| 8 | + |
| 9 | +const EXPO_PODFILE_SNIPPET = ` |
| 10 | + post_install do |installer| |
| 11 | + react_native_post_install( |
| 12 | + installer, |
| 13 | + config[:reactNativePath], |
| 14 | + :mac_catalyst_enabled => false, |
| 15 | + :ccache_enabled => podfile_properties['apple.ccacheEnabled'] == 'true', |
| 16 | + ) |
| 17 | + end |
| 18 | +`; |
| 19 | + |
| 20 | +describe('withIosFmtWorkaround', () => { |
| 21 | + it('injects the fmt workaround after react_native_post_install', async () => { |
| 22 | + const result = withIterable(createTestConfig(), {}) as WithIterableResult; |
| 23 | + const modifiedPodfile = await result.mods.ios.podfile( |
| 24 | + createMockPodfileConfig({ contents: EXPO_PODFILE_SNIPPET }) |
| 25 | + ); |
| 26 | + |
| 27 | + expect(modifiedPodfile.modResults.contents).toContain( |
| 28 | + FMT_WORKAROUND_MARKER |
| 29 | + ); |
| 30 | + expect(modifiedPodfile.modResults.contents).toContain( |
| 31 | + "config.build_settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++17'" |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + it('does not inject the workaround twice', async () => { |
| 36 | + const result = withIterable(createTestConfig(), {}) as WithIterableResult; |
| 37 | + const firstPass = await result.mods.ios.podfile( |
| 38 | + createMockPodfileConfig({ contents: EXPO_PODFILE_SNIPPET }) |
| 39 | + ); |
| 40 | + const secondPass = await result.mods.ios.podfile( |
| 41 | + createMockPodfileConfig({ contents: firstPass.modResults.contents }) |
| 42 | + ); |
| 43 | + |
| 44 | + const markerCount = ( |
| 45 | + secondPass.modResults.contents.match( |
| 46 | + new RegExp( |
| 47 | + FMT_WORKAROUND_MARKER.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), |
| 48 | + 'g' |
| 49 | + ) |
| 50 | + ) || [] |
| 51 | + ).length; |
| 52 | + |
| 53 | + expect(markerCount).toBe(1); |
| 54 | + }); |
| 55 | +}); |
0 commit comments