1import { IOSConfig } from '@expo/config-plugins'; 2import { fs, vol } from 'memfs'; 3import * as path from 'path'; 4 5import { setNotificationSounds } from '../withNotificationsIOS'; 6import { getDirFromFS } from './withNotificationsAndroid-test'; 7 8jest.mock('fs'); 9 10const fsReal = jest.requireActual('fs') as typeof fs; 11 12const LIST_OF_GENERATED_FILES = [ 13 'assets/notificationSound.wav', 14 'ios/testproject/notificationSound.wav', 15 'ios/testproject.xcodeproj/project.pbxproj', 16 'ios/testproject/AppDelegate.m', 17]; 18 19const soundPath = path.resolve(__dirname, './fixtures/cat.wav'); 20 21const projectRoot = '/app'; 22 23describe('iOS notifications configuration', () => { 24 beforeAll(async () => { 25 jest.mock('fs'); 26 const sound = fsReal.readFileSync(soundPath); 27 vol.fromJSON({ 'ios/testproject/AppDelegate.m': '' }, projectRoot); 28 vol.mkdirpSync('/app/assets'); 29 vol.mkdirpSync('/app/ios/testproject.xcodeproj/'); 30 vol.writeFileSync('/app/assets/notificationSound.wav', sound); 31 vol.writeFileSync( 32 '/app/ios/testproject.xcodeproj/project.pbxproj', 33 fsReal.readFileSync(path.join(__dirname, 'fixtures/project.pbxproj'), 'utf-8') 34 ); 35 }); 36 37 afterAll(() => { 38 jest.unmock('fs'); 39 vol.reset(); 40 }); 41 42 it('writes all the asset files (sounds and images) as expected', async () => { 43 const project = IOSConfig.XcodeUtils.getPbxproj(projectRoot); 44 // TODO: test pbxproj result via snapshot 45 setNotificationSounds(projectRoot, { 46 sounds: ['/app/assets/notificationSound.wav'], 47 project, 48 projectName: 'testproject', 49 }); 50 51 const after = getDirFromFS(vol.toJSON(), projectRoot); 52 expect(Object.keys(after).sort()).toEqual(LIST_OF_GENERATED_FILES.sort()); 53 }); 54}); 55