UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

35 lines (34 loc) 2.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); require('../../../../mocks/mockAll'); const path_1 = __importDefault(require("path")); const getProjectPath_1 = require("../../../../../utils/getProjectPath"); const importIosAssets_1 = require("../../../../../utils/upgrade/ios/importIosAssets"); const mockFs_1 = require("../../../../mocks/mockFs"); describe('importIosAssets', () => { it('should get launch icon', async () => { mockFs_1.mockFs.writeFileSync('/oldProject/ios/test/Images.xcassets/someImage.png', 'old image data'); mockFs_1.mockFs.writeFileSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'ios/test/Images.xcassets/newImage.png'), 'existing image data'); mockFs_1.mockFs.writeFileSync('/oldProject/ios/test/LaunchScreen.storyboard', 'old launch screen'); mockFs_1.mockFs.writeFileSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'ios/test/LaunchScreen.storyboard'), 'existing launch screen'); const importGetter = (0, importIosAssets_1.importIosAssets)('/oldProject'); expect(importGetter).toBeTruthy(); expect(importGetter.value).toEqual('Images.xcassets, LaunchScreen.storyboard'); await importGetter.apply(); expect(mockFs_1.mockFs.existsSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'ios/test/Images.xcassets/newImage.png'))).toBeFalsy(); expect(mockFs_1.mockFs.existsSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'ios/test/Images.xcassets/someImage.png'))).toBeTruthy(); expect(mockFs_1.mockFs.readFileSync(path_1.default.join((0, getProjectPath_1.getProjectPath)(), 'ios/test/LaunchScreen.storyboard'))).toBe('old launch screen'); }); it('should handle errors', () => { mockFs_1.mockFs.setReadPermission(false); const importGetter = (0, importIosAssets_1.importIosAssets)('/oldProject'); expect(importGetter).toBeNull(); }); it('should handle not finding assets', () => { const importGetter = (0, importIosAssets_1.importIosAssets)('/oldProject'); expect(importGetter).toBeNull(); }); });