def test_302_build_project_with_space_debug_with_plugin(self):
     # skip remove platform because androidx is not released official
     app_space_path = TnsPaths.get_app_path(app_name=self.app_name_with_space)
     # Tns.platform_remove(app_name='"' + self.app_name_with_space + '"', platform=Platform.ANDROID)
     Npm.install(package='nativescript-mapbox', option='--save', folder=app_space_path)
     result = Tns.build_android(app_name='"' + self.app_name_with_space + '"')
     assert "Project successfully built" in result.output
Example #2
0
 def test_200_plugin_platforms_should_not_exist_in_tns_modules_android(
         self):
     """
     Test for issue https://github.com/NativeScript/nativescript-cli/issues/3932
     """
     issue_path = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'issues',
                               'nativescript-cli-3932')
     Tns.platform_remove(app_name=self.app_name, platform=Platform.ANDROID)
     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(issue_path, 'nativescript-ui-listview')
     paste = os.path.join(self.app_path, 'nativescript-ui-listview')
     Folder.copy(copy, paste)
     copy = os.path.join(issue_path, 'package.json')
     paste = os.path.join(self.app_name)
     File.copy(copy, paste)
     Tns.platform_add_android(
         app_name=self.app_name,
         framework_path=Settings.Android.FRAMEWORK_PATH)
     folder_path = os.path.join(self.app_path, 'nativescript-ui-listview')
     Npm.install(option='--ignore-scripts', folder=folder_path)
     Tns.build_android(app_name=self.app_name, bundle=False)
     app_path = os.path.join(
         TnsPaths.get_platforms_android_npm_modules(self.app_name))
     assert not File.exists(
         os.path.join(app_path, 'nativescript-ui-listview', 'node_modules',
                      'nativescript-ui-core', 'platforms'))
    def test_201_test_init_mocha_js_stacktrace(self):
        # https://github.com/NativeScript/ios-runtime/issues/565
        Npm.install(package='mocha', folder=APP_PATH)
        Tns.exec_command("test init --framework",
                         cwd=APP_PATH,
                         platform='mocha')

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-565', 'example.js'),
            os.path.join(APP_PATH, 'app', 'tests'), True)

        result = File.read(os.path.join(APP_PATH, 'app', 'tests',
                                        'example.js'))
        assert "Mocha test" in result
        assert "Test" in result
        assert "Array" not in result

        result = Tns.exec_command("test ios",
                                  cwd=APP_PATH,
                                  emulator=True,
                                  wait=False)
        # TODO: Bundle: Add path to stack trace assert, (e.g. @file:///app/tests/example.js:5:25')
        # https://github.com/NativeScript/nativescript-cli/issues/4524
        strings = [
            'JavaScript stack trace',
            'JS ERROR AssertionError: expected -1 to equal 1'
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=90)
    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 #5
0
    def test_300_install_packages_and_prepare_after_install(self):
        Tns.create(app_name=self.app_name,
                   template=Template.HELLO_WORLD_JS.local_package,
                   update=True)
        Tns.platform_add_android(
            app_name=self.app_name,
            framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS == OSType.OSX:
            Tns.platform_add_ios(app_name=self.app_name,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Add packages
        Npm.install(package='lodash', option='--save', folder=self.APP_PATH)
        Npm.install(package='gulp', option='--save-dev', folder=self.APP_PATH)
        assert App.is_dependency(app_name=self.app_name, dependency='lodash')
        assert App.is_dev_dependency(app_name=self.app_name, dependency='gulp')

        # Clean node modules
        Folder.clean(os.path.join(self.APP_PATH, 'node_modules'))
        Folder.clean(os.path.join(self.APP_PATH, 'platforms'))

        # Install and verify common packages
        result = Tns.exec_command(command='install', path=self.APP_PATH)
        self.verify_installed(output=result.output)

        # Verify external packages are also installed
        assert Folder.exists(
            os.path.join(self.APP_PATH, 'node_modules', 'lodash'))
        assert Folder.exists(
            os.path.join(self.APP_PATH, 'node_modules', 'gulp'))

        # Prepare project
        Tns.prepare_android(app_name=self.app_name)
        if Settings.HOST_OS == OSType.OSX:
            Tns.prepare_ios(app_name=self.app_name)
Example #6
0
 def create(app_name, app_type):
     """
      Create hello-world app based on {N} 4.2
     :param app_name: App name.
     :param app_type: AppType enum value.
     """
     template = 'tns-template-hello-world'
     if app_type == AppType.NG:
         template = template + '-ng'
     if app_type == AppType.TS:
         template = template + '-ts'
     Tns.create(app_name=app_name,
                template='{0}@4.2'.format(template),
                update=False,
                verify=False)
     assert '~4.2.' in App.get_package_json(
         app_name=app_name).get('dependencies').get('tns-core-modules')
     if app_type == AppType.NG:
         assert '~6.1.' in App.get_package_json(app_name=app_name).get(
             'dependencies').get('nativescript-angular')
         assert '~6.1.' in App.get_package_json(
             app_name=app_name).get('dependencies').get('@angular/core')
     # Add platforms
     Tns.platform_add_android(app_name=app_name, version='4.2')
     if Settings.HOST_OS == OSType.OSX:
         Tns.platform_add_ios(app_name=app_name, version='4.2')
     # Install webpack (it was not included in {N} 4.2 templates)
     Npm.install(package='[email protected]',
                 option='--save-dev',
                 folder=os.path.join(Settings.TEST_RUN_HOME, app_name))
     Npm.install(folder=os.path.join(Settings.TEST_RUN_HOME, app_name))
Example #7
0
    def test_443_build_app_and_assert_that_tns_core_modules_could_be_updated(
            self):
        """
         Test update of tns-core-modules works correctly if you have build the app first
         https://github.com/NativeScript/android-runtime/issues/1257
        """
        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(app_name=APP_NAME,
                   template=Template.HELLO_WORLD_JS.local_package)
        Tns.platform_add_android(APP_NAME,
                                 framework_path=Android.FRAMEWORK_PATH)
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=240,
                                 period=5)
        assert test_result, "App not build correctly ! Logs: " + File.read(
            log.log_file)
        Npm.install(package=Packages.MODULES,
                    folder=os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.plugin_add(plugin_name="[email protected]",
                       path=os.path.join(TEST_RUN_HOME, APP_NAME))
        log = Tns.run_android(APP_NAME,
                              device=self.emulator.id,
                              wait=False,
                              verify=False)

        strings = [
            'Successfully synced application', 'on device', self.emulator.id
        ]

        test_result = Wait.until(lambda: all(string in File.read(log.log_file)
                                             for string in strings),
                                 timeout=120,
                                 period=5)
        assert test_result, "App not build correctly after updating tns-core modules! Logs: " + File.read(
            log.log_file)
        test_result = Wait.until(
            lambda: Device.is_text_visible(self.emulator, "TAP", True),
            timeout=90,
            period=5)
        assert test_result, "TAP Button is missing on the device! Update of tns-core-modules not successful!"
Example #8
0
    def test_101(self, title, framework, template, platform):
        # Create app
        Tns.create(app_name=APP_NAME, template=template.local_package)

        # Add platforms
        if platform == Platform.ANDROID:
            Tns.platform_add_android(
                app_name=APP_NAME,
                framework_path=Settings.Android.FRAMEWORK_PATH)
        elif platform == Platform.IOS:
            Tns.platform_add_ios(app_name=APP_NAME,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)
        else:
            raise Exception('Unknown platform: ' + str(platform))

        # Init tests and run tests
        if Settings.HOST_OS == OSType.WINDOWS and framework == FrameworkType.QUNIT:
            # Hack for qunit on windows (see https://github.com/NativeScript/nativescript-cli/issues/4333)
            Npm.install(package='qunit@2',
                        option='--save-dev',
                        folder=os.path.join(Settings.TEST_RUN_HOME, APP_NAME))
            # Tns test init will still fail with exit code 1, so we use `verify=False` and then assert logs.
            result = Tns.test_init(app_name=APP_NAME,
                                   framework=framework,
                                   verify=False)
            TnsAssert.test_initialized(app_name=APP_NAME,
                                       framework=framework,
                                       output=result.output)
        else:
            Tns.test_init(app_name=APP_NAME, framework=framework)

        # Run Tests
        result = Tns.test(app_name=APP_NAME,
                          platform=platform,
                          emulator=True,
                          just_launch=False,
                          wait=False)
        test_change = None
        if framework == FrameworkType.JASMINE:
            test_change = Changes.JSHelloWord.TEST
        if framework == FrameworkType.MOCHA:
            test_change = Changes.NGHelloWorld.TEST
        Sync.replace(app_name=APP_NAME, change_set=test_change)
        strings = ["log for test"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
Example #9
0
    def test_205_install_external_packages(self):
        Tns.create(app_name=self.app_name, template=Template.HELLO_WORLD_JS.local_package, update=True)
        # Add packages
        Npm.install(package='lodash', option='--save', folder=self.APP_PATH)
        Npm.install(package='gulp', option='--save-dev', folder=self.APP_PATH)
        assert App.is_dependency(app_name=self.app_name, dependency='lodash')
        assert App.is_dev_dependency(app_name=self.app_name, dependency='gulp')

        # Clean node modules
        Folder.clean(os.path.join(self.APP_PATH, 'node_modules'))
        Folder.clean(os.path.join(self.APP_PATH, 'platforms'))

        # Install and verify common packages
        result = Tns.exec_command(command='install', path=self.APP_PATH)
        self.verify_installed(output=result.output)

        # Verify external packages are also installed
        assert Folder.exists(os.path.join(self.APP_PATH, 'node_modules', 'lodash'))
        assert Folder.exists(os.path.join(self.APP_PATH, 'node_modules', 'gulp'))
Example #10
0
    def test_302_plugin_and_npm_modules_in_same_project_android(self):
        Tns.plugin_add(plugin_name='nativescript-social-share',
                       path=self.app_name)
        output = Npm.install(package='nativescript-appversion',
                             option='--save',
                             folder=self.app_path)
        assert 'ERR!' not in output
        assert 'nativescript-appversion@' in output

        Tns.build_android(app_name=self.app_name, verify=False)
Example #11
0
    def test_300_install_and_prepare(self):
        Tns.create(app_name=self.app_name, template=Template.HELLO_WORLD_JS.local_package, update=True)
        # Add packages
        Npm.install(package='lodash', option='--save', folder=self.APP_PATH)
        Npm.install(package='gulp', option='--save-dev', folder=self.APP_PATH)
        assert App.is_dependency(app_name=self.app_name, dependency='lodash')
        assert App.is_dev_dependency(app_name=self.app_name, dependency='gulp')

        # Call install and verify it do not fail if everything is already installed
        result = Tns.exec_command(command='install', path=self.APP_PATH)
        self.verify_installed(output=result.output)
        assert Folder.exists(os.path.join(self.APP_PATH, 'node_modules', 'lodash'))
        assert Folder.exists(os.path.join(self.APP_PATH, 'node_modules', 'gulp'))

        # Copy app folder and app resources
        Folder.copy(source=os.path.join(Settings.TEST_RUN_HOME, 'assets', 'apps', 'test-app-js-41', 'app'),
                    target=os.path.join(self.APP_PATH, 'app'))

        # Prepare project
        Tns.prepare_android(app_name=self.app_name)
        if Settings.HOST_OS == OSType.OSX:
            Tns.prepare_ios(app_name=self.app_name)
Example #12
0
    def test_100(self, title, framework, template, platform):
        # Create app
        Tns.create(app_name=APP_NAME, template=template.local_package)

        # Add platforms
        if platform == Platform.ANDROID:
            Tns.platform_add_android(
                app_name=APP_NAME,
                framework_path=Settings.Android.FRAMEWORK_PATH)
        elif platform == Platform.IOS:
            Tns.platform_add_ios(app_name=APP_NAME,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)
        else:
            raise Exception('Unknown platform: ' + str(platform))

        # Init tests and run tests
        if Settings.HOST_OS == OSType.WINDOWS and framework == FrameworkType.QUNIT:
            # Hack for qunit on windows (see https://github.com/NativeScript/nativescript-cli/issues/4333)
            Npm.install(package='qunit@2',
                        option='--save-dev',
                        folder=os.path.join(Settings.TEST_RUN_HOME, APP_NAME))
            # Tns test init will still fail with exit code 1, so we use `verify=False` and then assert logs.
            result = Tns.test_init(app_name=APP_NAME,
                                   framework=framework,
                                   verify=False)
            TnsAssert.test_initialized(app_name=APP_NAME,
                                       framework=framework,
                                       output=result.output)
        else:
            Tns.test_init(app_name=APP_NAME, framework=framework)

        # Run Tests
        Tns.test(app_name=APP_NAME,
                 platform=platform,
                 emulator=True,
                 just_launch=True)
Example #13
0
 def test_init(app_name, framework, update=True, verify=True):
     """
     Execute `tns test init` command.
     :param app_name: App name (passed as --path <App name>)
     :param framework: Unit testing framework as string (jasmin, mocha, quinit).
     :param update: Update nativescript-unit-test-runner if True.
     :param verify: Verify command was executed successfully.
     :return: Result of `tns test init` command.
     """
     app_path = TnsPaths.get_app_path(app_name=app_name)
     command = 'test init --framework {0}'.format(str(framework))
     result = Tns.exec_command(command=command, path=app_name, timeout=300)
     if verify:
         TnsAssert.test_initialized(app_name=app_name,
                                    framework=framework,
                                    output=result.output)
     if update:
         Npm.uninstall(package='nativescript-unit-test-runner',
                       option='--save',
                       folder=app_path)
         Npm.install(package='nativescript-unit-test-runner@next',
                     option='--save --save-exact',
                     folder=app_path)
     return result
Example #14
0
def __install_ns_cli():
    """
    Install NativeScript CLI locally.
    """

    # Copy NativeScript CLI (if used from local package)
    if '.tgz' in Settings.Packages.NS_CLI:
        cli_package = os.path.join(Settings.TEST_SUT_HOME, 'nativescript.tgz')
        File.copy(source=Settings.Packages.NS_CLI, target=cli_package)
        Settings.Packages.NS_CLI = cli_package

    # Install NativeScript CLI
    output = Npm.install(package=Settings.Packages.NS_CLI,
                         folder=Settings.TEST_RUN_HOME)

    # Verify executable exists after install
    path = os.path.join(Settings.TEST_RUN_HOME, 'node_modules', '.bin', 'tns')
    assert File.exists(path), 'NativeScript executable not found at ' + path
    Settings.Executables.TNS = path

    # Verify installation output
    # noinspection SpellCheckingInspection
    assert 'postinstall.js' in output, 'Post install scripts not executed.'
    assert 'dev-post-install' not in output, 'Dev post install executed on installation.'
Example #15
0
    def update(app_name,
               modules=True,
               angular=True,
               typescript=False,
               web_pack=True,
               vue=True,
               theme=True):
        app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
        modules_path = os.path.join(app_path, 'node_modules')
        if modules and App.is_dependency(app_name=app_name,
                                         dependency='tns-core-modules'):
            Npm.uninstall(package='tns-core-modules',
                          option='--save',
                          folder=app_path)
            Npm.install(package=Settings.Packages.MODULES,
                        option='--save --save-exact',
                        folder=app_path)
        if theme and App.is_dependency(app_name=app_name,
                                       dependency='@nativescript/theme'):
            Npm.uninstall(package='@nativescript/theme',
                          option='--save',
                          folder=app_path)
            Npm.install(package='@nativescript/theme@next',
                        option='--save --save-exact',
                        folder=app_path)
        if angular and App.is_dependency(app_name=app_name,
                                         dependency='nativescript-angular'):
            Npm.uninstall(package='nativescript-angular',
                          option='--save',
                          folder=app_path)
            Npm.install(package=Settings.Packages.ANGULAR,
                        option='--save --save-exact',
                        folder=app_path)
            update_script = os.path.join(modules_path, '.bin',
                                         'update-app-ng-deps')
            result = run(cmd=update_script, log_level=logging.INFO)
            assert 'Angular dependencies updated' in result.output, 'Angular dependencies not updated.'
            Npm.install(folder=app_path)
        if typescript and App.is_dev_dependency(
                app_name=app_name, dependency='nativescript-dev-typescript'):
            Npm.uninstall(package='nativescript-dev-typescript',
                          option='--save-dev',
                          folder=app_path)
            Npm.install(package=Settings.Packages.TYPESCRIPT,
                        option='--save-dev --save-exact',
                        folder=app_path)
            update_script = os.path.join(modules_path,
                                         'nativescript-dev-typescript', 'bin',
                                         'ns-upgrade-tsconfig')
            result = run(cmd=update_script, log_level=logging.INFO)
            assert "Adding 'es6' lib to tsconfig.json..." in result.output
            assert "Adding 'dom' lib to tsconfig.json..." in result.output
            assert 'Adding tns-core-modules path mappings lib' in result.output
        if web_pack and App.is_dev_dependency(
                app_name=app_name, dependency='nativescript-dev-webpack'):
            Npm.uninstall(package='nativescript-dev-webpack',
                          option='--save-dev',
                          folder=app_path)
            Npm.install(package=Settings.Packages.WEBPACK,
                        option='--save-dev --save-exact',
                        folder=app_path)
            Folder.clean(os.path.join(app_name, 'hooks'))
            Folder.clean(os.path.join(app_name, 'node_modules'))
            Npm.install(folder=app_path)
            path_script = '"' + os.path.join(modules_path, '.bin',
                                             'update-ns-webpack') + '"'
            update_script = path_script + ' --deps --configs'
            result = run(cmd=update_script, log_level=logging.INFO)
            assert 'Updating dev dependencies...' in result.output, 'Webpack dependencies not updated.'
            assert 'Updating configuration files...' in result.output, 'Webpack configs not updated.'

        if vue and App.is_dependency(app_name=app_name,
                                     dependency='nativescript-vue'):
            Npm.uninstall(package='nativescript-vue',
                          option='--save',
                          folder=app_path)
            Npm.install(package='nativescript-vue',
                        option='--save --save-exact',
                        folder=app_path)
        # on win when `npm i` is executed with path to .tgz it saves in package.json unix style path
        # which cannot be resolved on win
        if Settings.HOST_OS == OSType.WINDOWS:
            package_json = os.path.join(Settings.TEST_RUN_HOME, app_name,
                                        'package.json')
            File.replace(package_json, 'file://', '\\\\\\\\', fail_safe=True)
Example #16
0
    def test_scoped_package_only(self, app_name, template_info):
        TnsRunTest.setUp(self)

        # Create app
        app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
        Tns.create(app_name=app_name,
                   template=template_info.local_package,
                   update=True)
        Npm.uninstall(package='tns-core-modules',
                      option='--save',
                      folder=app_path)
        Npm.install(package=Settings.Packages.NATIVESCRIPT_CORE,
                    option='--save --save-exact',
                    folder=app_path)

        # Replace imports
        if template_info == Template.HELLO_WORLD_TS:
            files = File.find_by_extension(folder=os.path.join(
                app_path, 'app'),
                                           extension='ts')
            for file in files:
                File.replace(path=file,
                             old_string='tns-core-modules',
                             new_string='@nativescript/core',
                             fail_safe=True)
        if template_info == Template.MASTER_DETAIL_NG:
            files = File.find_by_extension(folder=os.path.join(
                app_path, 'src'),
                                           extension='ts')
            for file in files:
                File.replace(path=file,
                             old_string='tns-core-modules',
                             new_string='@nativescript/core',
                             fail_safe=True)

        Tns.platform_add_android(
            app_name=app_name, framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS is OSType.OSX:
            Tns.platform_add_ios(app_name=app_name,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Run Android
        result = Tns.run_android(app_name=app_name,
                                 device=self.emu.id,
                                 aot=True,
                                 uglify=True)
        strings = TnsLogs.run_messages(app_name=app_name,
                                       run_type=RunType.UNKNOWN,
                                       platform=Platform.ANDROID)
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=300)
        for text in template_info.texts:
            self.emu.wait_for_text(text=text, timeout=60)

        # Run iOS
        Tns.kill()
        if Settings.HOST_OS is OSType.OSX:
            Simctl.uninstall_all(simulator_info=self.sim)
            result = Tns.run_ios(app_name=app_name,
                                 device=self.sim.id,
                                 aot=True,
                                 uglify=True)
            strings = TnsLogs.run_messages(app_name=app_name,
                                           run_type=RunType.UNKNOWN,
                                           platform=Platform.IOS)
            TnsLogs.wait_for_log(log_file=result.log_file,
                                 string_list=strings,
                                 timeout=300)
            for text in template_info.texts:
                self.sim.wait_for_text(text=text, timeout=60)

        # Cleanup
        Folder.clean(os.path.join(Settings.TEST_RUN_HOME, app_name))
        TnsRunTest.tearDown(self)
Example #17
0
    def update(app_name,
               modules=True,
               angular=True,
               typescript=False,
               web_pack=True,
               vue=True):
        app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
        modules_path = os.path.join(app_path, 'node_modules')
        if modules and App.is_dependency(app_name=app_name,
                                         dependency='tns-core-modules'):
            Npm.uninstall(package='tns-core-modules',
                          option='--save',
                          folder=app_path)
            Npm.install(package=Settings.Packages.MODULES,
                        option='--save --save-exact',
                        folder=app_path)
        if angular and App.is_dependency(app_name=app_name,
                                         dependency='nativescript-angular'):
            Npm.uninstall(package='nativescript-angular',
                          option='--save',
                          folder=app_path)
            Npm.install(package=Settings.Packages.ANGULAR,
                        option='--save --save-exact',
                        folder=app_path)
            update_script = os.path.join(modules_path, '.bin',
                                         'update-app-ng-deps')
            result = run(cmd=update_script, log_level=logging.INFO)
            assert 'Angular dependencies updated' in result.output, 'Angular dependencies not updated.'
            Npm.install(folder=app_path)
        if typescript and App.is_dev_dependency(
                app_name=app_name, dependency='nativescript-dev-typescript'):
            Npm.uninstall(package='nativescript-dev-typescript',
                          option='--save-dev',
                          folder=app_path)
            Npm.install(package=Settings.Packages.TYPESCRIPT,
                        option='--save-dev --save-exact',
                        folder=app_path)
            update_script = os.path.join(modules_path,
                                         'nativescript-dev-typescript', 'bin',
                                         'ns-upgrade-tsconfig')
            result = run(cmd=update_script, log_level=logging.INFO)
            assert "Adding 'es6' lib to tsconfig.json..." in result.output
            assert "Adding 'dom' lib to tsconfig.json..." in result.output
            assert 'Adding tns-core-modules path mappings lib' in result.output
        if web_pack and App.is_dev_dependency(
                app_name=app_name, dependency='nativescript-dev-webpack'):
            Npm.uninstall(package='nativescript-dev-webpack',
                          option='--save-dev',
                          folder=app_path)
            Npm.install(package=Settings.Packages.WEBPACK,
                        option='--save-dev --save-exact',
                        folder=app_path)
            Folder.clean(os.path.join(app_name, 'hooks'))
            Folder.clean(os.path.join(app_name, 'node_modules'))
            Npm.install(folder=app_path)
            path_script = '"' + os.path.join(modules_path, '.bin',
                                             'update-ns-webpack') + '"'
            update_script = path_script + ' --deps --configs'
            result = run(cmd=update_script, log_level=logging.INFO)
            assert 'Updating dev dependencies...' in result.output, 'Webpack dependencies not updated.'
            assert 'Updating configuration files...' in result.output, 'Webpack configs not updated.'

        if vue and App.is_dependency(app_name=app_name,
                                     dependency='nativescript-vue'):
            Npm.uninstall(package='nativescript-vue',
                          option='--save',
                          folder=app_path)
            Npm.install(package='nativescript-vue@next',
                        option='--save --save-exact',
                        folder=app_path)
Example #18
0
 def install_dev_dependency(app_name, dependency, version='latest'):
     app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
     Npm.uninstall(package=dependency, option='--save-dev', folder=app_path)
     Npm.install(package='{0}@{1}'.format(dependency, version),
                 option='--save-dev --save-exact',
                 folder=app_path)
Example #19
0
    def new(collection=NS_SCHEMATICS,
            project=Settings.AppName.DEFAULT,
            shared=False,
            sample=False,
            prefix=None,
            source_dir=None,
            theme=True,
            style=None,
            webpack=True):
        """
        Execute `ng new`
        :param collection: Schematics collection.
        :param project: Project name.
        :param shared: If true pass --shared flag.
        :param sample: If true pass --sample flag.
        :param prefix: The prefix to apply to generated selectors (default value is `app`)
        :param source_dir: The name of the source directory (default value is `src`)
        :param theme: If false pass --no-theme flag.
        :param style: If style is not None pass --style flag (default value is `css`)
        :param webpack: If false pass --no-webpack flag.
        :return: ProcessInfo object.
        :rtype: core.utils.process_info.ProcessInfo
        """

        # Ensure old app do not exists
        project_path = os.path.join(Settings.TEST_RUN_HOME, project)
        Folder.clean(project_path)

        # Generate ng new command
        command = 'new'
        if collection is not None:
            command = command + ' --collection={0}'.format(collection)
        command = command + ' ' + project
        if shared:
            command = command + ' --shared'
        if sample:
            command = command + ' --sample'
        if prefix is not None:
            command = command + ' --prefix={0}'.format(str(prefix))
        if source_dir is not None:
            command = command + ' --sourceDir={0}'.format(str(source_dir))
        if style is not None:
            command = command + ' --style={0}'.format(str(style))
        if not webpack:
            command = command + ' --no-webpack'
        if not theme:
            command = command + ' --no-theme'

        # Add skip install due to the fact we relay on package not published in npm.
        # See https://github.com/NativeScript/nativescript-schematics/pull/220
        command = command + ' --skip-install'

        # Execute the command and add current app to context
        TestContext.TEST_APP_NAME = project

        # Execute the command
        result = NG.exec_command(command)

        # Manually run npm install if skip_install detected.
        # See https://github.com/NativeScript/nativescript-schematics/pull/220
        Npm.install(
            package=Settings.Packages.NS_SCHEMATICS,
            option='--save-dev --save-exact',
            folder=project_path)
        Npm.install(folder=project_path)

        # Return result
        return result
Example #20
0
def __install_schematics():
    """
    Install NativeScript Schematics globally.
    """
    Npm.uninstall(package='@nativescript/schematics', option='-g')
    Npm.install(package=Settings.Packages.NS_SCHEMATICS, option='-g')
Example #21
0
def __install_ng_cli():
    """
    Install Angular CLI globally.
    """
    Npm.uninstall(package='@angular/cli', option='-g')
    Npm.install(package=Settings.Packages.NG_CLI, option='-g')