diff --git a/bin/lib/create.js b/bin/lib/create.js index a96227ba8..fee726a99 100755 --- a/bin/lib/create.js +++ b/bin/lib/create.js @@ -136,7 +136,7 @@ function copyTemplateFiles (project_path, project_name, project_template_dir, pa shell.mv('-f', path.join(r, '__PROJECT_NAME__-Prefix.pch'), path.join(r, project_name + '-Prefix.pch')); shell.mv('-f', path.join(r, 'gitignore'), path.join(r, '.gitignore')); - /* replace __PROJECT_NAME__ and --ID-- with ACTIVITY and ID strings, respectively, in: + /* replace __PROJECT_NAME__ and __PROJECT_ID__ with ACTIVITY and ID strings, respectively, in: * * - ./__PROJECT_NAME__.xcodeproj/project.pbxproj * - ./__PROJECT_NAME__/Classes/AppDelegate.h @@ -155,6 +155,7 @@ function copyTemplateFiles (project_path, project_name, project_template_dir, pa var project_name_esc = project_name.replace(/&/g, '\\&'); shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r + '.xcodeproj', 'project.pbxproj')); + shell.sed('-i', /__PROJECT_ID__/g, package_name, path.join(r + '.xcodeproj', 'project.pbxproj')); shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'AppDelegate.h')); shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'AppDelegate.m')); shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'Classes', 'MainViewController.h')); @@ -162,7 +163,6 @@ function copyTemplateFiles (project_path, project_name, project_template_dir, pa shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, 'main.m')); shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, project_name + '-Info.plist')); shell.sed('-i', /__PROJECT_NAME__/g, project_name_esc, path.join(r, project_name + '-Prefix.pch')); - shell.sed('-i', /--ID--/g, package_name, path.join(r, project_name + '-Info.plist')); } function AbsParentPath (_path) { diff --git a/bin/templates/project/__PROJECT_NAME__/__PROJECT_NAME__-Info.plist b/bin/templates/project/__PROJECT_NAME__/__PROJECT_NAME__-Info.plist index 30bada686..5e3dee602 100644 --- a/bin/templates/project/__PROJECT_NAME__/__PROJECT_NAME__-Info.plist +++ b/bin/templates/project/__PROJECT_NAME__/__PROJECT_NAME__-Info.plist @@ -3,21 +3,17 @@ CFBundleDevelopmentRegion - English + en_US CFBundleDisplayName - ${PRODUCT_NAME} + $(PRODUCT_NAME) CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIcons - - CFBundleIcons~ipad - + $(EXECUTABLE_NAME) CFBundleIdentifier - --ID-- + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName - ${PRODUCT_NAME} + $(PRODUCT_NAME) CFBundlePackageType APPL CFBundleShortVersionString @@ -25,13 +21,15 @@ CFBundleSignature ???? CFBundleVersion - 1.0 + 1 LSRequiresIPhoneOS NSMainNibFile NSMainNibFile~ipad + UIRequiresFullScreen + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait @@ -45,7 +43,5 @@ UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeRight - UIRequiresFullScreen - diff --git a/bin/templates/project/__TEMP__.xcodeproj/project.pbxproj b/bin/templates/project/__TEMP__.xcodeproj/project.pbxproj index 9c2a71ffd..0e332d0fe 100755 --- a/bin/templates/project/__TEMP__.xcodeproj/project.pbxproj +++ b/bin/templates/project/__TEMP__.xcodeproj/project.pbxproj @@ -214,7 +214,7 @@ }; }; }; - buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__NON-CLI__" */; + buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__PROJECT_NAME__" */; compatibilityVersion = "Xcode 3.2"; developmentRegion = English; hasScannedForEncodings = 1; @@ -322,8 +322,9 @@ INFOPLIST_FILE = "__PROJECT_NAME__/__PROJECT_NAME__-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "__PROJECT_ID__"; + PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; - PRODUCT_NAME = "__PROJECT_NAME__"; }; name = Debug; }; @@ -344,8 +345,9 @@ INFOPLIST_FILE = "__PROJECT_NAME__/__PROJECT_NAME__-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "__PROJECT_ID__"; + PRODUCT_NAME = "$(TARGET_NAME)"; TARGETED_DEVICE_FAMILY = "1,2"; - PRODUCT_NAME = "__PROJECT_NAME__"; }; name = Release; }; @@ -441,7 +443,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__NON-CLI__" */ = { + C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__PROJECT_NAME__" */ = { isa = XCConfigurationList; buildConfigurations = ( C01FCF4F08A954540054247B /* Debug */, diff --git a/bin/templates/scripts/cordova/lib/prepare.js b/bin/templates/scripts/cordova/lib/prepare.js index 860b6e4c8..5fd4ea1ea 100644 --- a/bin/templates/scripts/cordova/lib/prepare.js +++ b/bin/templates/scripts/cordova/lib/prepare.js @@ -189,7 +189,6 @@ function updateProject (platformConfig, locations) { // because node and shell scripts handles unicode symbols differently // We need to normalize the name to NFD form since iOS uses NFD unicode form var name = unorm.nfd(platformConfig.name()); - var pkg = platformConfig.getAttribute('ios-CFBundleIdentifier') || platformConfig.packageName(); var version = platformConfig.version(); var displayName = platformConfig.shortName && platformConfig.shortName(); @@ -198,7 +197,6 @@ function updateProject (platformConfig, locations) { // Update package id (bundle id) var plistFile = path.join(locations.xcodeCordovaProj, originalName + '-Info.plist'); var infoPlist = plist.parse(fs.readFileSync(plistFile, 'utf8')); - infoPlist['CFBundleIdentifier'] = pkg; // Update version (bundle version) infoPlist['CFBundleShortVersionString'] = version; @@ -224,10 +222,14 @@ function updateProject (platformConfig, locations) { handleOrientationSettings(platformConfig, infoPlist); updateProjectPlistForLaunchStoryboard(platformConfig, infoPlist); - var info_contents = plist.build(infoPlist); + /* eslint-disable no-tabs */ + // Write out the plist file with the same formatting as Xcode does + var info_contents = plist.build(infoPlist, { indent: ' ', offset: -1 }); + /* eslint-enable no-tabs */ + info_contents = info_contents.replace(/[\s\r\n]*<\/string>/g, ''); fs.writeFileSync(plistFile, info_contents, 'utf-8'); - events.emit('verbose', 'Wrote out iOS Bundle Identifier "' + pkg + '" and iOS Bundle Version "' + version + '" to ' + plistFile); + events.emit('verbose', 'Wrote out iOS Bundle Version "' + version + '" to ' + plistFile); return handleBuildSettings(platformConfig, locations, infoPlist).then(function () { if (name === originalName) { @@ -274,23 +276,31 @@ function handleOrientationSettings (platformConfig, infoPlist) { } function handleBuildSettings (platformConfig, locations, infoPlist) { + var pkg = platformConfig.getAttribute('ios-CFBundleIdentifier') || platformConfig.packageName(); var targetDevice = parseTargetDevicePreference(platformConfig.getPreference('target-device', 'ios')); var deploymentTarget = platformConfig.getPreference('deployment-target', 'ios'); var needUpdatedBuildSettingsForLaunchStoryboard = checkIfBuildSettingsNeedUpdatedForLaunchStoryboard(platformConfig, infoPlist); var swiftVersion = platformConfig.getPreference('SwiftVersion', 'ios'); - // no build settings provided and we don't need to update build settings for launch storyboards, - // then we don't need to parse and update .pbxproj file - if (!targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion) { - return Q(); - } - var proj = new xcode.project(locations.pbxproj); /* eslint new-cap : 0 */ try { proj.parseSync(); } catch (err) { - return Q.reject(new CordovaError('Could not parse project.pbxproj: ' + err)); + return Q.reject(new CordovaError('Could not parse ' + locations.pbxproj + ': ' + err)); + } + + var origPkg = proj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER'); + + // no build settings provided and we don't need to update build settings for launch storyboards, + // then we don't need to parse and update .pbxproj file + if (origPkg === pkg && !targetDevice && !deploymentTarget && !needUpdatedBuildSettingsForLaunchStoryboard && !swiftVersion) { + return Q(); + } + + if (origPkg !== pkg) { + events.emit('verbose', 'Set PRODUCT_BUNDLE_IDENTIFIER to ' + pkg + '.'); + proj.updateBuildProperty('PRODUCT_BUNDLE_IDENTIFIER', pkg); } if (targetDevice) { diff --git a/tests/spec/unit/fixtures/ios-config-xml/SampleApp.xcodeproj/project.pbxproj b/tests/spec/unit/fixtures/ios-config-xml/SampleApp.xcodeproj/project.pbxproj index bc7d96c76..f014f46e4 100755 --- a/tests/spec/unit/fixtures/ios-config-xml/SampleApp.xcodeproj/project.pbxproj +++ b/tests/spec/unit/fixtures/ios-config-xml/SampleApp.xcodeproj/project.pbxproj @@ -9,7 +9,7 @@ 0207DA581B56EA530066E2B4 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0207DA571B56EA530066E2B4 /* Images.xcassets */; }; 1D3623260D0F684500981E51 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D3623250D0F684500981E51 /* AppDelegate.m */; }; 1D60589B0D05DD56006BFB54 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; }; - 301BF552109A68D80062928A /* libCordova.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF535109A57CC0062928A /* libCordova.a */; }; + 301BF552109A68D80062928A /* libCordova.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 301BF535109A57CC0062928A /* libCordova.a */; settings = {ATTRIBUTES = (Required, ); }; }; 302D95F114D2391D003F00A1 /* MainViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 302D95EF14D2391D003F00A1 /* MainViewController.m */; }; 302D95F214D2391D003F00A1 /* MainViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 302D95F014D2391D003F00A1 /* MainViewController.xib */; }; 3047A5121AB8059700498E2A /* build-debug.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 3047A50F1AB8059700498E2A /* build-debug.xcconfig */; }; @@ -33,6 +33,13 @@ remoteGlobalIDString = D2AAC07D0554694100DB518D; remoteInfo = CordovaLib; }; + 907D8123214C687600058A10 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 301BF52D109A57CC0062928A /* CordovaLib.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = C0C01EB21E3911D50056E6CB; + remoteInfo = Cordova; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -54,8 +61,8 @@ 8D1107310486CEB800E47090 /* SampleApp-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "SampleApp-Info.plist"; path = "SampleApp/SampleApp-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = SOURCE_ROOT; }; EB87FDF31871DA8E0020F90C /* www */ = {isa = PBXFileReference; lastKnownFileType = folder; name = www; path = ../../www; sourceTree = ""; }; EB87FDF41871DAF40020F90C /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = ../../config.xml; sourceTree = ""; }; - F840E1F0165FE0F500CFE078 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = "SampleApp/config.xml"; sourceTree = ""; }; ED33DF2A687741AEAF9F8254 /* Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "Bridging-Header.h"; path = "Bridging-Header.h"; sourceTree = ""; }; + F840E1F0165FE0F500CFE078 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = "SampleApp/config.xml"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -142,6 +149,7 @@ isa = PBXGroup; children = ( 301BF535109A57CC0062928A /* libCordova.a */, + 907D8124214C687600058A10 /* Cordova.framework */, ); name = Products; sourceTree = ""; @@ -201,7 +209,12 @@ 29B97313FDCFA39411CA2CEA /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 510; + LastUpgradeCheck = 0510; + TargetAttributes = { + 1D6058900D05DD3D006BFB54 = { + ProvisioningStyle = Automatic; + }; + }; }; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__NON-CLI__" */; compatibilityVersion = "Xcode 3.2"; @@ -230,6 +243,13 @@ remoteRef = 301BF534109A57CC0062928A /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; + 907D8124214C687600058A10 /* Cordova.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = Cordova.framework; + remoteRef = 907D8123214C687600058A10 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; /* End PBXReferenceProxy section */ /* Begin PBXResourcesBuildPhase section */ @@ -304,8 +324,9 @@ INFOPLIST_FILE = "SampleApp/SampleApp-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; - TARGETED_DEVICE_FAMILY = "1,2"; + PRODUCT_BUNDLE_IDENTIFIER = "com.example.friendstring"; PRODUCT_NAME = "SampleApp"; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -326,8 +347,9 @@ INFOPLIST_FILE = "SampleApp/SampleApp-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks"; - TARGETED_DEVICE_FAMILY = "1,2"; + PRODUCT_BUNDLE_IDENTIFIER = "com.example.friendstring"; PRODUCT_NAME = "SampleApp"; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; @@ -337,15 +359,30 @@ buildSettings = { CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = c99; + GCC_NO_COMMON_BLOCKS = YES; GCC_THUMB_SUPPORT = NO; GCC_VERSION = ""; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; @@ -363,15 +400,29 @@ buildSettings = { CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = c99; + GCC_NO_COMMON_BLOCKS = YES; GCC_THUMB_SUPPORT = NO; GCC_VERSION = ""; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; @@ -394,7 +445,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - C01FCF4E08A954540054247B /* Build configuration list for PBXProject "__NON-CLI__" */ = { + C01FCF4E08A954540054247B /* Build configuration list for PBXProject "SampleApp" */ = { isa = XCConfigurationList; buildConfigurations = ( C01FCF4F08A954540054247B /* Debug */, diff --git a/tests/spec/unit/prepare.spec.js b/tests/spec/unit/prepare.spec.js index 4705d715f..55a3e7a77 100644 --- a/tests/spec/unit/prepare.spec.js +++ b/tests/spec/unit/prepare.spec.js @@ -671,9 +671,14 @@ describe('prepare', function () { } return orig.call(this, name); }; + writeFileSyncSpy.and.callThrough(); wrapper(updateProject(cfg, p.locations), done, function () { - expect(plist.build.calls.mostRecent().args[0].CFBundleIdentifier).toEqual('testpkg'); + var xcode = require('xcode'); + var proj = new xcode.project(p.locations.pbxproj); /* eslint new-cap : 0 */ + proj.parseSync(); + var prop = proj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER'); + expect(prop).toEqual('testpkg'); }); }); it('Test#003 : should write out the app id to info plist as CFBundleIdentifier with ios-CFBundleIdentifier', function (done) { @@ -685,8 +690,14 @@ describe('prepare', function () { return orig.call(this, name); }; + writeFileSyncSpy.and.callThrough(); + wrapper(updateProject(cfg, p.locations), done, function () { - expect(plist.build.calls.mostRecent().args[0].CFBundleIdentifier).toEqual('testpkg_ios'); + var xcode = require('xcode'); + var proj = new xcode.project(p.locations.pbxproj); /* eslint new-cap : 0 */ + proj.parseSync(); + var prop = proj.getBuildProperty('PRODUCT_BUNDLE_IDENTIFIER'); + expect(prop).toEqual('testpkg_ios'); }); }); it('Test#004 : should write out the app version to info plist as CFBundleVersion', function (done) { @@ -765,11 +776,18 @@ describe('prepare', function () { it(' - should handle wildcard, with NSAllowsArbitraryLoadsInWebContent', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); @@ -785,11 +803,18 @@ describe('prepare', function () { it(' - should handle wildcard, with NSAllowsArbitraryLoadsForMedia set (fixed allows-arbitrary-loads-for-media)', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); wrapper(updateProject(my_config, p.locations), done, function () { @@ -804,11 +829,18 @@ describe('prepare', function () { it(' - should handle wildcard, with NSAllowsArbitraryLoadsForMedia not set (fixed allows-arbitrary-loads-for-media)', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); wrapper(updateProject(my_config, p.locations), done, function () { @@ -823,11 +855,18 @@ describe('prepare', function () { it(' - should handle wildcard, with NSAllowsArbitraryLoadsForMedia set (deprecated allows-arbitrary-loads-in-media)', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); wrapper(updateProject(my_config, p.locations), done, function () { @@ -842,11 +881,18 @@ describe('prepare', function () { it(' - should handle wildcard, with NSAllowsArbitraryLoadsForMedia not set (deprecated allows-arbitrary-loads-in-media)', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); wrapper(updateProject(my_config, p.locations), done, function () { @@ -861,11 +907,18 @@ describe('prepare', function () { it(' - should handle wildcard, with NSAllowsLocalNetworking', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); @@ -881,11 +934,18 @@ describe('prepare', function () { it(' - should handle wildcard, with NSAllowsArbitraryLoadsInWebContent, NSAllowsArbitraryLoadsForMedia, NSAllowsLocalNetworking', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); @@ -900,11 +960,18 @@ describe('prepare', function () { }); it(' - sanity check - no wildcard but has NSAllowsArbitraryLoadsInWebContent, NSAllowsArbitraryLoadsForMedia, NSAllowsLocalNetworking', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); @@ -1170,11 +1237,18 @@ describe('prepare', function () { it(' - should handle wildcard', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path'); @@ -1190,11 +1264,18 @@ describe('prepare', function () { it(' - sanity check - no wildcard but has NSAllowsArbitraryLoadsInWebContent, NSAllowsArbitraryLoadsForMedia, NSAllowsLocalNetworking', function (done) { + const origReadFile = fs.readFileSync; var readFile = spyOn(fs, 'readFileSync'); var configXml = 'SampleApp' + '' + ''; - readFile.and.returnValue(configXml); + + readFile.and.callFake(function (...args) { + if (args[0] === 'fake/path') { + return configXml; + } + return origReadFile(...args); + }); var my_config = new ConfigParser('fake/path');