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_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
Ejemplo n.º 3
0
    def test_100_plugin_add_after_platform_add_android(self):
        result = Tns.plugin_add(plugin_name='tns-plugin', path=self.app_name)
        assert 'Successfully installed plugin tns-plugin' in result.output
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'index.js'))
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'package.json'))

        output = File.read(os.path.join(self.app_path, 'package.json'))
        assert 'org.nativescript.TestApp' in output
        assert 'dependencies' in output
        assert 'tns-plugin' in output
        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_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
Ejemplo n.º 6
0
    def test_201_build_app_for_both_platforms(self):
        Tns.plugin_add(plugin_name='tns-plugin', path=self.app_name)

        # Verify files of the plugin
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'index.js'))
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'package.json'))
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'test.android.js'))
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'test.ios.js'))
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'test2.android.xml'))
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'test2.ios.xml'))

        Tns.build_ios(app_name=self.app_name)
        Tns.build_android(app_name=self.app_name)

        apk_path = os.path.join(TnsPaths.get_apk_path(self.app_name))
        output = Adb.get_package_permission(apk_path)
        assert 'android.permission.READ_EXTERNAL_STORAGE' in output
        assert 'android.permission.WRITE_EXTERNAL_STORAGE' in output
        assert 'android.permission.INTERNET' in output
Ejemplo n.º 7
0
 def test_201_create_project_with_local_directory_template(self):
     """--template should install all packages from package.json"""
     template_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                  'myCustomTemplate')
     Tns.create(app_name=Settings.AppName.DEFAULT,
                template=template_path,
                update=False)
     node_modules = TnsPaths.get_app_node_modules_path(
         app_name=Settings.AppName.DEFAULT)
     assert not Folder.is_empty(os.path.join(node_modules, 'lodash'))
     assert not Folder.is_empty(os.path.join(node_modules, 'minimist'))
     assert not Folder.is_empty(
         os.path.join(node_modules, 'tns-core-modules'))
     assert not Folder.is_empty(
         os.path.join(node_modules, 'tns-core-modules-widgets'))
Ejemplo n.º 8
0
    def created(app_name,
                output=None,
                app_data=None,
                path=Settings.TEST_RUN_HOME,
                webpack=True,
                theme=True):
        """
        Verify app is created properly.
        :param app_name: Name of the app.
        :param output: Console output of `tns create` command.
        :param app_data: AppInfo object.
        :param path: Base path where app is created.
        :param webpack: If true it will verify webpack plugin is installed.
        :param theme: If true it will verify default {N} theme is installed.
        """
        # Assert app exists
        app_path = os.path.join(path, app_name)
        assert Folder.exists(
            app_path
        ), 'Failed to create app. ' + os.linesep + app_path + ' do not exists!'

        # Assert output
        if output is not None:
            assert 'Now you can navigate to your project with $ cd' in output
            assert 'After that you can preview it on device by executing $ tns preview' in output
            assert 'After that you can run it on device/emulator by executing $ tns run <platform>' not in output
            assert 'Project {0} was successfully created'.format(app_name) in output, \
                'Failed to create {0}'.format(app_name)

        # Verify modules installed
        node_path = TnsPaths.get_app_node_modules_path(app_name=app_name,
                                                       path=path)
        assert Folder.exists(os.path.join(
            node_path, 'tns-core-modules')), '{N} theme do not exists in app.'
        assert File.exists(
            os.path.join(node_path, 'tns-core-modules',
                         'tns-core-modules.d.ts'))

        # Verify {N} core theme is installed
        if theme:
            assert Folder.exists(
                os.path.join(
                    node_path,
                    'nativescript-theme-core')), '{N} theme do not exists.'

        # Verify webpack is installed
        before_watch_hooks = os.path.join(app_path, 'hooks', 'before-watch')
        if webpack:
            assert Folder.exists(
                os.path.join(node_path, 'nativescript-dev-webpack')
            ), 'Webpack not installed in app.'
            assert File.exists(os.path.join(
                app_path, 'webpack.config.js')), 'Missing webpack config.'

        # Assert app data
        if app_data is not None:
            # Verify typescript in TS and NG apps:
            if app_data.app_type in {
                    AppType.TS, AppType.NG, AppType.SHARED_NG
            }:
                assert not Folder.exists(os.path.join(node_path, 'nativescript-dev-typescript')), \
                    'TS not installed in app.'
                assert File.exists(os.path.join(
                    app_path, 'tsconfig.json')), 'Missing config.'
                if webpack:
                    assert File.exists(
                        os.path.join(app_path,
                                     'tsconfig.tns.json')), 'Missing config.'
                assert not File.exists(os.path.join(before_watch_hooks, 'nativescript-dev-typescript.js')), \
                    'Hooks not installed.'

            # Assert app id
            if app_data.bundle_id is not None:
                pass

            # Assert size
            if app_data.size is not None:
                app_size = Folder.get_size(app_path)
                assert PerfUtils.is_value_in_range(
                    actual=app_size,
                    expected=app_data.size.init,
                    tolerance=0.25), 'Actual project size is not expected!'