def test_401_plugin_add_invalid_pod(self):
            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'CocoaPods',
                                       'invalidpod.tgz')
            result = Tns.plugin_add(plugin_path, path=Settings.AppName.DEFAULT)
            assert "Successfully installed plugin invalidpod." in result.output
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'invalidpod', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'invalidpod', 'platforms', 'ios', 'Podfile'))

            output = File.read(os.path.join(self.app_name, 'package.json'))
            assert "invalidpod" in output

            result = Tns.prepare_ios(self.app_name, verify=False)
            assert "Installing pods..." in result.output
            assert "'pod install' command failed" in result.output
            assert "pod 'InvalidPod'" in File.read(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'Podfile'))

            assert not File.exists(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'TestApp.xcworkspace'))
            assert not File.exists(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'Pods', 'Pods.xcodeproj'))
    def test_320_build_ios_with_custom_entitlements(self):
        # Add entitlements in app/App_Resources/iOS/app.entitlements
        source = os.path.join(TEST_RUN_HOME, 'assets', 'entitlements', 'app.entitlements')
        target = os.path.join(self.app_name, 'app', 'App_Resources', 'iOS', 'app.entitlements')
        File.copy(source, target)

        # Build again and verify entitlements are merged
        Tns.build_ios(self.app_name)
        entitlements_path = os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name), self.app_name,
                                         'TestApp.entitlements')
        assert File.exists(entitlements_path), "Entitlements file is missing!"
        entitlements_content = File.read(entitlements_path)
        assert '<key>aps-environment</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<string>development</string>' in entitlements_content, "Entitlements file content is wrong!"

        # Install plugin with entitlements, build again and verify entitlements are merged
        plugin_path = os.path.join(TEST_RUN_HOME, 'assets', 'plugins', 'nativescript-test-entitlements-1.0.0.tgz')
        Npm.install(package=plugin_path, option='--save', folder=self.app_name)

        Tns.build_ios(self.app_name)
        entitlements_content = File.read(entitlements_path)
        assert '<key>aps-environment</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<string>development</string>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<key>inter-app-audio</key>' in entitlements_content, "Entitlements file content is wrong!"
        assert '<true/>' in entitlements_content, "Entitlements file content is wrong!"

        # Build in release, for device (provision without entitlements)
        result = Tns.build_ios(self.app_name, for_device=True, release=True, verify=False)
        assert "Provisioning profile" in result.output
        assert "doesn't include the aps-environment and inter-app-audio entitlements" in result.output
Example #3
0
 def test_311_plugin_platforms_should_not_exist_in_tnsmodules_ios(self):
     """
     Test for issue https://github.com/NativeScript/nativescript-cli/issues/3932
     """
     Tns.platform_remove(app_name=self.app_name, platform=Platform.IOS)
     Tns.plugin_add(plugin_name='nativescript-ui-listview',
                    path=self.app_name)
     Folder.clean(os.path.join(self.app_name, 'node_modules'))
     File.delete(os.path.join(self.app_name, 'package.json'))
     copy = os.path.join('assets', 'issues', 'nativescript-cli-3932',
                         'nativescript-ui-listview')
     paste = os.path.join(self.app_name, 'nativescript-ui-listview')
     Folder.copy(copy, paste)
     copy = os.path.join('assets', 'issues', 'nativescript-cli-3932',
                         'package.json')
     paste = os.path.join(self.app_name)
     File.copy(copy, paste)
     Tns.platform_add_ios(app_name=self.app_name,
                          framework_path=Settings.IOS.FRAMEWORK_PATH)
     folder_path = os.path.join(self.app_name, 'nativescript-ui-listview')
     Npm.install(option='--ignore-scripts', folder=folder_path)
     Tns.build_ios(app_name=self.app_name, bundle=False)
     app_path = os.path.join(
         TnsPaths.get_platforms_ios_folder(self.app_name))
     assert not File.exists(
         os.path.join(app_path, 'nativescript-ui-listview', 'node_modules',
                      'nativescript-ui-core', 'platforms'))
Example #4
0
 def platform_added(app_name, platform, output, version=None):
     platform_string = str(platform)
     # Verify output
     assert 'Platform {0} successfully added'.format(
         platform_string) in output
     # Verify platform folder
     if platform == Platform.ANDROID:
         assert Folder.exists(
             TnsPaths.get_platforms_android_folder(app_name))
     else:
         assert Folder.exists(TnsPaths.get_platforms_ios_folder(app_name))
     # Verify package.json
     app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
     package_json = os.path.join(app_path, 'package.json')
     json = JsonUtils.read(package_json)
     if version is not None:
         if 'next' in version:
             assert json['nativescript'][
                 'tns-' + platform_string]['version'] is not None
         if 'rc' in version:
             assert 'rc' in json['nativescript']['tns-' +
                                                 platform_string]['version']
         else:
             assert version in json['nativescript'][
                 'tns-' + platform_string]['version']
     else:
         assert json['nativescript']['tns-' + platform_string]['version'] is not None, \
             'tns-' + platform_string + ' not available in package.json of the app.'
        def test_202_plugin_add_pod_google_maps_after_platform_add_ios(self):
            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'CocoaPods', 'googlesdk.tgz')
            result = Tns.plugin_add(plugin_path, path=Settings.AppName.DEFAULT)
            assert "Successfully installed plugin googlesdk." in result.output
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'googlesdk', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'googlesdk', 'platforms', 'ios', 'Podfile'))

            output = File.read(os.path.join(self.app_name, 'package.json'))
            assert self.app_identifier in output.lower()
            assert "dependencies" in output
            assert "googlesdk" in output

            result = Tns.build_ios(self.app_name)
            assert "Installing pods..." in result.output

            output = File.read(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'Podfile'))
            assert "source 'https://github.com/CocoaPods/Specs.git'" in output
            assert "platform :ios, '8.1'" in output
            assert "pod 'GoogleMaps'" in output
            assert "use_frameworks!" in output

            output = File.read(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'TestApp.xcworkspace',
                             'contents.xcworkspacedata'))
            assert "location = \"group:TestApp.xcodeproj\">" in output
            assert "location = \"group:Pods/Pods.xcodeproj\">" in output
            assert Folder.exists(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'Pods', 'Pods.xcodeproj'))

            # This deployment target comes from the CLI
            output = File.read(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'TestApp.xcodeproj', 'project.pbxproj'))
            assert "IPHONEOS_DEPLOYMENT_TARGET = 9.0;" in output
        def test_210_plugin_add_static_lib_universal(self):
            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'hello-plugin.tgz')
            result = Tns.plugin_add(plugin_path,
                                    path=Settings.AppName.DEFAULT,
                                    verify=False)
            assert "Successfully installed plugin hello." in result.output

            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'hello', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'hello', 'hello-plugin.ios.js'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'hello', 'platforms', 'ios', 'HelloLib.a'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'hello', 'platforms', 'ios', 'include',
                             'HelloLib', 'Bye.h'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'hello', 'platforms', 'ios', 'include',
                             'HelloLib', 'Hello.h'))
            output = File.read(os.path.join(self.app_name, 'package.json'))
            assert "plugins/hello-plugin" in output

            # Require the plugin so webpack can pick it up
            main_js_file = os.path.join(Settings.TEST_RUN_HOME, self.app_name,
                                        'app', 'main-page.js')
            File.append(main_js_file, 'const hello = require("hello");')

            Tns.prepare_ios(self.app_name)

            bundle_js = File.read(
                os.path.join(
                    TnsPaths.get_platforms_ios_app_path(self.app_name),
                    'bundle.js'))
            vendor_js = File.read(
                os.path.join(
                    TnsPaths.get_platforms_ios_app_path(self.app_name),
                    'vendor.js'))
            assert '__webpack_require__("../node_modules/hello/hello-plugin.js")' in bundle_js
            assert 'hello = Hello.alloc().init();' in vendor_js

            result = run("cat " + os.path.join(
                TnsPaths.get_platforms_ios_folder(self.app_name),
                'TestApp.xcodeproj', 'project.pbxproj | grep \"HelloLib.a\"'))
            assert "HelloLib.a in Frameworks" in result.output
    def test_200_prepare_additional_appresources(self):
        Tns.prepare_ios(self.app_name)

        # Create new files in AppResources
        File.copy(os.path.join(TnsPaths.get_path_app_resources(self.app_name), 'iOS', 'Assets.xcassets',
                               'AppIcon.appiconset', 'icon-76.png'),
                  os.path.join(TnsPaths.get_path_app_resources(self.app_name), 'iOS', 'newDefault.png'))

        Tns.prepare_ios(self.app_name)

        # Verify XCode Project include files from App Resources folder
        result = run("cat " + os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name), 'TestApp.xcodeproj',
                                           'project.pbxproj | grep newDefault.png'))
        assert "newDefault.png" in result.output
Example #8
0
 def test_320_cfbundleurltypes_overridden_from_plugin_ios(self):
     """
     Test for issue https://github.com/NativeScript/nativescript-cli/issues/2936
     """
     Tns.platform_remove(app_name=self.app_name, platform=Platform.IOS)
     plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'plugins',
                                'CFBundleURLName-Plugin.tgz')
     Tns.plugin_add(plugin_path, path=self.app_name)
     Tns.prepare_ios(app_name=self.app_name)
     plist = File.read(
         os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                      self.app_name, self.app_name + '-Info.plist'))
     assert '<key>NSAllowsArbitraryLoads</key>' in plist, \
         'NSAppTransportSecurity from plugin is not found in final Info.plist'
     assert '<string>bar</string>' in plist, 'CFBundleURLTypes from plugin is not found in final Info.plist'
    def test_001_build_ios(self):
        Tns.platform_remove(self.app_name, platform=Platform.ANDROID)
        Tns.build_ios(self.app_name)
        Tns.build_ios(self.app_name, release=True)
        Tns.build_ios(self.app_name, for_device=True)
        Tns.build_ios(self.app_name, for_device=True, release=True)
        assert not File.exists(os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name), '*.aar'))
        assert not File.exists(os.path.join(TnsPaths.get_platforms_ios_npm_modules(self.app_name), '*.framework'))

        # Verify ipa has both armv7 and arm64 archs
        ipa_path = TnsPaths.get_ipa_path(app_name=self.app_name, release=True, for_device=True)
        run("mv " + ipa_path + " TestApp-ipa.tgz")
        run("unzip -o TestApp-ipa.tgz")
        result = run("lipo -info Payload/TestApp.app/TestApp")
        Folder.clean("Payload")
        assert "Architectures in the fat file: Payload/TestApp.app/TestApp are: armv7 arm64" in result.output
Example #10
0
 def platform_removed(app_name, platform, output):
     platform_string = str(platform)
     # Verify output
     assert 'Platform {0} successfully removed'.format(
         platform_string) in output
     # Verify package.json
     app_path = TnsPaths.get_app_path(app_name)
     package_json = os.path.join(app_path, 'package.json')
     json = JsonUtils.read(package_json)
     assert not 'tns-' + platform_string in json
     if platform == Platform.ANDROID:
         assert not Folder.exists(
             TnsPaths.get_platforms_android_folder(app_name))
     else:
         assert not Folder.exists(
             TnsPaths.get_platforms_ios_folder(app_name))
        def test_100_plugin_add_multiple_pods(self):
            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'CocoaPods', 'carousel.tgz')
            result = Tns.plugin_add(plugin_path, path=Settings.AppName.DEFAULT)
            assert "Successfully installed plugin carousel." in result.output
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'carousel', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'carousel', 'platforms', 'ios', 'Podfile'))
            assert "carousel" in File.read(
                os.path.join(Settings.TEST_RUN_HOME, self.app_name,
                             'package.json'))

            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'CocoaPods', 'keychain.tgz')
            result = Tns.plugin_add(plugin_path, path=Settings.AppName.DEFAULT)
            assert "Successfully installed plugin keychain." in result.output
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'keychain', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'keychain', 'platforms', 'ios', 'Podfile'))
            assert "keychain" in File.read(
                os.path.join(Settings.TEST_RUN_HOME, self.app_name,
                             'package.json'))

            result = Tns.prepare_ios(self.app_name)
            assert "Installing pods..." in result.output
            # These asserts will be available again after we merge the webpack only branch for 6.0.0 release
            # assert "Successfully prepared plugin carousel for ios." in result.output
            # assert "Successfully prepared plugin keychain for ios." in result.output

            output = File.read(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'Podfile'))
            assert "use_frameworks!" in output
            assert "pod 'iCarousel'" in output
            assert "pod 'AFNetworking'" in output
            assert "pod 'UICKeyChainStore'" in output
    def test_100_prepare_ios(self):
        Tns.prepare_ios(self.app_name)
        result = Tns.prepare_ios(self.app_name)
        # assert "Skipping prepare" in result.output
        Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
        result = Tns.prepare_ios(self.app_name)
        assert "Preparing project..." in result.output

        # Verify Xcode Schemes
        result = run("xcodebuild -project " + os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                                                           'TestApp.xcodeproj', ' -list'))
        assert "This project contains no schemes." not in result.output
        result1 = re.search(r"Targets:\n\s*TestApp", result.output)
        assert result1 is not None
        result1 = re.search(r"Schemes:\n\s*TestApp", result.output)
        assert result1 is not None

        Tns.prepare_android(self.app_name)
        Tns.prepare_ios(self.app_name)
        result = Tns.prepare_ios(self.app_name)
Example #13
0
 def platform_clean(app_name, platform=Platform.NONE, verify=True):
     platform_string = str(platform)
     command = 'platform clean ' + platform_string
     result = Tns.exec_command(command=command, path=app_name)
     if verify:
         assert "Platform {0} successfully removed".format(
             platform_string) in result.output
         assert "error" not in result.output
         if platform is Platform.ANDROID:
             assert Folder.exists(
                 TnsPaths.get_platforms_android_folder(app_name))
         if platform is Platform.IOS:
             assert Folder.exists(
                 TnsPaths.get_platforms_ios_folder(app_name))
         assert "Platform {0} successfully added".format(
             platform_string) in result.output
         package_json = os.path.join(TnsPaths.get_app_path(app_name),
                                     'package.json')
         json = JsonUtils.read(package_json)
         assert json['nativescript']['tns-' +
                                     platform_string]['version'] is not None
Example #14
0
    def test_401_plugin_add_invalid_plugin(self):
        Tns.platform_remove(app_name=self.app_name, platform=Platform.IOS)
        Tns.platform_remove(app_name=self.app_name, platform=Platform.ANDROID)
        result = Tns.plugin_add(plugin_name='wd',
                                path=self.app_name,
                                verify=False)
        assert 'wd is not a valid NativeScript plugin' in result.output
        assert 'Verify that the plugin package.json file ' + \
               'contains a nativescript key and try again' in result.output
        Tns.platform_add_android(
            self.app_name, framework_path=Settings.Android.FRAMEWORK_PATH)
        Tns.platform_add_ios(self.app_name,
                             framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Verify iOS only plugin
        result = Tns.plugin_add(plugin_name='[email protected]',
                                path=self.app_name)
        assert 'tns-plugin is not supported for android' in result.output
        assert 'Successfully installed plugin tns-plugin' in result.output

        # Verify Android only plugin
        result = Tns.plugin_add(plugin_name='acra-telerik-analytics',
                                path=self.app_name)
        assert 'acra-telerik-analytics is not supported for ios' in result.output
        assert 'Successfully installed plugin acra-telerik-analytics' in result.output

        Tns.build_ios(app_name=self.app_name, bundle=False)
        ios_path = os.path.join(
            TnsPaths.get_platforms_ios_folder(self.app_name))
        assert not File.pattern_exists(ios_path, pattern='*.aar')
        assert not File.pattern_exists(ios_path, pattern='*acra*')

        Tns.build_android(app_name=self.app_name, bundle=False)
        android_path = os.path.join(
            TnsPaths.get_platforms_android_folder(self.app_name))
        assert File.pattern_exists(android_path, pattern='*.aar')
        assert File.pattern_exists(android_path, pattern='*acra*')