UNPKG

react-native-integrate

Version:

Automate integration of additional code into React Native projects

106 lines (105 loc) 5.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require('../mocks/mockAll'); const getIosProjectPath_1 = require("../../utils/getIosProjectPath"); const variables_1 = require("../../variables"); const mockFs_1 = require("../mocks/mockFs"); const mockPbxProjTemplate_1 = require("../mocks/mockPbxProjTemplate"); describe('variables', () => { beforeEach(() => { variables_1.variables.clear(); }); it('should get store', () => { variables_1.variables.set('test', 'value'); const obj = variables_1.variables.getStore(); expect(obj['test']).toEqual('value'); }); it('should get ios project name', () => { const iosProjectName = variables_1.variables.get('IOS_PROJECT_NAME'); expect(iosProjectName).toEqual('test'); }); it('should get ios bundle id', () => { const pbxFilePath = (0, getIosProjectPath_1.getPbxProjectPath)(); mockFs_1.mockFs.writeFileSync(pbxFilePath, mockPbxProjTemplate_1.mockPbxProjTemplate); const iosBundleId = variables_1.variables.get('IOS_BUNDLE_ID'); expect(iosBundleId).toEqual('org.reactjs.native.example.ReactNativeCliTemplates'); }); it('should get ios bundle id as null when no project exists', () => { const iosBundleId = variables_1.variables.get('IOS_BUNDLE_ID'); expect(iosBundleId).toEqual(null); }); it('should get ios deployment version', () => { const pbxFilePath = (0, getIosProjectPath_1.getPbxProjectPath)(); mockFs_1.mockFs.writeFileSync(pbxFilePath, mockPbxProjTemplate_1.mockPbxProjTemplate); const iosDeploymentVersion = variables_1.variables.get('IOS_DEPLOYMENT_VERSION'); expect(iosDeploymentVersion).toEqual('10.0'); }); it('should get ios bundle id as null when no project exists', () => { const iosBundleId = variables_1.variables.get('IOS_BUNDLE_ID'); expect(iosBundleId).toEqual(null); }); it('should get ios deployment version as null when no project exists', () => { const iosBundleId = variables_1.variables.get('IOS_DEPLOYMENT_VERSION'); expect(iosBundleId).toEqual(null); }); it('should get null ios project name when no project', () => { const mock = jest.spyOn(mockFs_1.mockFs, 'readdirSync'); mock.mockImplementationOnce(() => ['random']); const iosProjectName = variables_1.variables.get('IOS_PROJECT_NAME'); expect(iosProjectName).toEqual(null); mock.mockRestore(); }); it('should get and set the default value', () => { variables_1.variables.set('test', 'value'); expect(variables_1.variables.get('test')).toEqual('value'); }); describe('getText', () => { it('should return text', () => { const replaced = (0, variables_1.getText)('this has no var'); expect(replaced).toEqual('this has no var'); }); it('should replace variables', () => { variables_1.variables.set('test', 'value'); const replaced = (0, variables_1.getText)('this is $[test]'); expect(replaced).toEqual('this is value'); }); it('should not replace escaped variables', () => { variables_1.variables.set('test', 'value'); const replaced = (0, variables_1.getText)('this is \\$[test]'); expect(replaced).toEqual('this is $[test]'); }); it('should replace double escaped variables', () => { variables_1.variables.set('test', 'value'); const replaced = (0, variables_1.getText)('this is \\\\$[test]'); expect(replaced).toEqual('this is \\value'); }); it('should not replace triple escaped variables', () => { variables_1.variables.set('test', 'value'); const replaced = (0, variables_1.getText)('this is \\\\\\$[test]'); expect(replaced).toEqual('this is \\$[test]'); }); it('should replace with name for non existing variables', () => { const replaced = (0, variables_1.getText)('this is $[test]'); expect(replaced).toEqual('this is test'); }); it('should replace with description for non existing variables', () => { const replaced = (0, variables_1.getText)('this is $[get("nonExisting") ?? "description"]'); expect(replaced).toEqual('this is description'); }); it('should process script', () => { const replaced = (0, variables_1.getText)(`this is $[ var result = true; set("test2", result); result; ]`); expect(replaced).toEqual('this is true'); expect(variables_1.variables.get('test2')).toEqual(true); }); }); describe('transformTextInObject', () => { it('should return null', () => { const replaced = (0, variables_1.transformTextInObject)(null); expect(replaced).toBeNull(); }); }); });