Ejemplo n.º 1
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)
Ejemplo n.º 2
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.'
Ejemplo n.º 3
0
    def verify_installed(self, output):
        # Verify output
        assert 'Copying template files' in output
        assert 'Platform android successfully added' in output
        if Settings.HOST_OS == OSType.OSX:
            assert 'Platform ios successfully added' in output

        # Verify files
        assert Folder.exists(os.path.join(self.APP_PATH, 'node_modules', 'tns-core-modules'))
        assert Folder.exists(os.path.join(self.APP_PATH, 'platforms', 'android'))
        assert File.exists(os.path.join(self.APP_PATH, 'platforms', 'android', 'build.gradle'))
        if Settings.HOST_OS == OSType.OSX:
            assert Folder.exists(os.path.join(self.APP_PATH, 'platforms', 'ios'))
            assert Folder.exists(os.path.join(self.APP_PATH, 'platforms', 'ios', 'TestApp.xcodeproj'))
Ejemplo n.º 4
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))
Ejemplo n.º 5
0
 def archive_apps():
     if TestContext.TEST_APP_NAME is not None:
         app_path = os.path.join(Settings.TEST_RUN_HOME, TestContext.TEST_APP_NAME)
         if Folder.exists(app_path):
             archive_path = os.path.join(Settings.TEST_OUT_HOME, TestContext.CLASS_NAME, TestContext.TEST_NAME,
                                         TestContext.TEST_APP_NAME)
             Log.info('Archive app under test at: {0}'.format(archive_path))
        def start(emulator):
            # Define emulator start options and command
            emulator_path = os.path.join(ANDROID_HOME, 'emulator', 'emulator')
            options = '-port {0} -wipe-data -no-snapshot-save -no-boot-anim -no-audio -netspeed lte'.format(
                emulator.port)

            # Check if clean snapshot is available and use it
            snapshot_name = 'clean_boot'
            home = os.path.expanduser("~")
            snapshot = os.path.join(home, '.android', 'avd', '{0}.avd'.format(emulator.avd), 'snapshots', snapshot_name)
            if Folder.exists(snapshot):
                Log.info('{0} has clean boot snapshot! Will user it.'.format(emulator.avd))
                options = '-port {0} -no-snapshot-save -no-boot-anim -no-audio -snapshot {1}'.format(emulator.port,
                                                                                                     snapshot_name)

            command = '{0} @{1} {2}'.format(emulator_path, emulator.avd, options)
            Log.info('Booting {0} with cmd:'.format(emulator.avd))
            Log.info(command)
            run(cmd=command, wait=False, register=False)
            booted = Adb.wait_until_boot(device_id=emulator.emu_id)
            if booted:
                Log.info('{0} is up and running!'.format(emulator.avd))
                device = Device(id=emulator.emu_id, name=emulator.avd, type=DeviceType.EMU, version=emulator.os_version)
                TestContext.STARTED_DEVICES.append(device)
                return device
            else:
                raise Exception('Failed to boot {0}!'.format(emulator.avd))
 def test_310_build_ios_with_copy_to(self):
     Tns.platform_remove(self.app_name, platform=Platform.IOS)
     Tns.exec_command(command='build --copy-to ' + TEST_RUN_HOME, path=self.app_name,
                      platform=Platform.IOS, bundle=True)
     assert Folder.exists(os.path.join(TEST_RUN_HOME, 'TestApp.app'))
     Tns.exec_command(command='build --copy-to ' + TEST_RUN_HOME, path=self.app_name, platform=Platform.IOS,
                      bundle=True, for_device=True, release=True, provision=Settings.IOS.PROVISIONING)
     assert File.exists(os.path.join(TEST_RUN_HOME, 'TestApp.ipa'))
Ejemplo n.º 8
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'))
Ejemplo n.º 9
0
    def test_450_resources_update_android(self):
        target_app = os.path.join(self.app_name, 'app', 'App_Resources')
        source_app = os.path.join(TEST_RUN_HOME, 'assets', 'apps',
                                  'test-app-js-41', 'app', 'App_Resources')
        Folder.clean(target_app)
        Folder.copy(source_app, target_app)

        result = Tns.exec_command(command='resources update android',
                                  path=self.app_name)

        assert "Successfully updated your project's application resources '/Android' directory structure" in \
               result.output
        assert "The previous version of your Android application resources has been renamed to '/Android-Pre-v4'" in \
               result.output
        assert File.exists(
            os.path.join(TnsPaths.get_path_app_resources(self.app_name),
                         'Android-Pre-v4', 'app.gradle'))
        assert File.exists(
            os.path.join(TnsPaths.get_path_app_resources(self.app_name),
                         'Android', 'app.gradle'))
        assert File.exists(
            os.path.join(
                TnsPaths.get_path_app_resources_main_android(self.app_name),
                'AndroidManifest.xml'))
        assert Folder.exists(
            os.path.join(
                TnsPaths.get_path_app_resources_main_android(self.app_name),
                'assets'))
        assert Folder.exists(
            os.path.join(
                TnsPaths.get_path_app_resources_main_android(self.app_name),
                'java'))
        assert Folder.exists(
            os.path.join(
                TnsPaths.get_path_app_resources_main_android(self.app_name),
                'res', 'values'))

        Tns.prepare_android(self.app_name)
        assert File.exists(
            os.path.join(
                TnsPaths.get_platforms_android_src_main_path(self.app_name),
                'AndroidManifest.xml'))
Ejemplo n.º 10
0
    def build(app_name,
              platform,
              release=False,
              provision=Settings.IOS.PROVISIONING,
              for_device=False,
              bundle=True,
              aot=False,
              source_map=False,
              uglify=False,
              snapshot=False,
              log_trace=False,
              verify=True,
              app_data=None,
              aab=False,
              compile_snapshot=False):
        result = Tns.exec_command(command='build',
                                  path=app_name,
                                  platform=platform,
                                  release=release,
                                  provision=provision,
                                  for_device=for_device,
                                  bundle=bundle,
                                  aot=aot,
                                  source_map=source_map,
                                  uglify=uglify,
                                  snapshot=snapshot,
                                  wait=True,
                                  log_trace=log_trace,
                                  aab=aab,
                                  compile_snapshot=compile_snapshot)
        if verify:
            # Verify output
            assert result.exit_code == 0, 'Build failed with non zero exit code.'
            assert 'Project successfully built.' in result.output

            # Verify apk, app or ipa produced
            if platform == Platform.ANDROID:
                assert File.exists(
                    TnsPaths.get_apk_path(app_name=app_name, release=release))
            if platform == Platform.IOS:
                app_path = TnsPaths.get_ipa_path(app_name=app_name,
                                                 release=release,
                                                 for_device=for_device)
                if for_device:
                    assert File.exists(app_path)
                else:
                    assert Folder.exists(app_path)

            # Verify based on app_data
            if app_data is not None:
                pass

        return result
Ejemplo n.º 11
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
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
 def clone(repo_url, local_folder, branch='master'):
     """Clone GitHub repo to local folder.
     :param repo_url: HTTPs url of the repo.
     :param branch: Branch.
     :param local_folder: Local folder to clone the repo.
     """
     if Folder.exists(folder=local_folder):
         Folder.clean(folder=local_folder)
     repo_url = get_repo_url(repo_url=repo_url, ssh_clone=Settings.SSH_CLONE)
     command = 'git clone --depth 1 {0} -b {1} "{2}"'.format(repo_url, branch, str(local_folder))
     Log.info(command)
     result = run(cmd=command)
     assert "fatal" not in result.output, "Failed to clone: " + repo_url
     assert result.exit_code == 0, "Failed to clone: " + repo_url
Ejemplo n.º 14
0
    def create_app(app_data, shared, sample, theme, style, prefix, source_dir, webpack):
        # Create shared project with sample data
        result = NG.new(collection=NS_SCHEMATICS, project=NGNewTests.app_name, theme=theme, shared=shared,
                        sample=sample, style=style, prefix=prefix, source_dir=source_dir, webpack=webpack)

        # Verify valid {N} app is created
        # Temporary do not assert theme is created because in schematics we still use nativescript-theme-core@1
        # TODO: Replace with theme=theme when schematics use @nativescript/theme
        TnsAssert.created(app_name=NGNewTests.app_name, app_data=app_data, theme=False, webpack=webpack)
        assert 'Directory is already under version control. Skipping initialization of git.' in result.output, \
            'Git init should be skipped because app is created already existing repo (the one with tests).'

        # Check sample
        if sample:
            # TODO: Implement it
            pass

        # Check theme
        if theme:
            assert App.is_dependency(app_name=NGNewTests.app_name, dependency='@nativescript/theme')
        else:
            assert not App.is_dependency(app_name=NGNewTests.app_name, dependency='@nativescript/theme')

        # Check styling
        if style is None or style is StylingType.CSS:
            assert 'app.css' in result.output
        else:
            assert 'app.android.scss' in result.output
            assert 'app.ios.scss' in result.output
            assert '_app-common.scss' in result.output

        # Check webpack
        if webpack:
            assert App.is_dev_dependency(app_name=NGNewTests.app_name, dependency='nativescript-dev-webpack')
        else:
            assert not App.is_dev_dependency(app_name=NGNewTests.app_name, dependency='nativescript-dev-webpack')

        # Check prefix
        if prefix is None:
            prefix = 'app'
        path = os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, 'angular.json')
        actual_prefix = JsonUtils.read(file_path=path)['projects'][NGNewTests.app_name]['prefix']
        assert str(actual_prefix) == prefix, 'Prefix not set in angular.json'

        # Check source dir exists (applicable only for shared projects).
        if shared:
            if source_dir is None:
                source_dir = 'src'
            assert Folder.exists(os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, source_dir))
Ejemplo n.º 15
0
    def test_355_tns_run_android_delete_node_modules(self):
        """
        Run should not fail if node_modules folder is deleted
        https://github.com/NativeScript/nativescript-cli/issues/3944
        """
        # Run the project with --justLaunch
        run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu, just_launch=True)

        # Delete node_modules
        node_modules = os.path.join(Settings.TEST_RUN_HOME, self.app_name, 'node_modules')
        Folder.clean(node_modules)

        # Run the project again, verify it is build and node_modules folder exists
        run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu, just_launch=True)
        assert Folder.exists(node_modules)
        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
Ejemplo n.º 17
0
 def test_410_plugin_remove_should_not_fail_if_plugin_name_has_dot_android(
         self):
     """
     Test for issue https://github.com/NativeScript/nativescript-cli/issues/3451
     """
     Tns.platform_remove(app_name=self.app_name, platform=Platform.ANDROID)
     Tns.plugin_add(plugin_name='[email protected]',
                    path=self.app_name)
     assert Folder.exists(
         os.path.join(self.app_path, 'node_modules',
                      'nativescript-socket.io'))
     result = Tns.plugin_remove(plugin_name='nativescript-socket.io',
                                path=self.app_name,
                                log_trace=True)
     assert 'Successfully removed plugin nativescript-socket.io' in result.output
     assert 'stdout: removed 1 package' in result.output
     assert 'Exec npm uninstall nativescript-socket.io --save' in result.output
     output = File.read(os.path.join(self.app_path, 'package.json'))
     assert 'nativescript-socket.io' not in output
Ejemplo n.º 18
0
 def test_442_assert_arm64_is_enabled_by_default(self):
     """
      Test arm64-v8 is enabled by default
     """
     Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True)
     apk_folder = os.path.join(TEST_RUN_HOME, APP_NAME, "platforms",
                               "android", "app", "build", "outputs", "apk",
                               "debug")
     apk_file = os.path.join(apk_folder, "app-debug.apk")
     apk_folder_to_unzip = os.path.join(apk_folder, "apk")
     Folder.create(apk_folder_to_unzip)
     command = "unzip " + apk_file + " -d " + apk_folder_to_unzip
     run(command, wait=False)
     time.sleep(20)
     unzip_apk_folder = os.path.join(apk_folder, "apk")
     arm64_folder = os.path.join(unzip_apk_folder, "lib", "arm64-v8a")
     assert Folder.exists(
         arm64_folder), "arm64-v8a architecture is missing!"
     error_message = "libNativeScript.so in arm64-v8a folder is missing!"
     assert File.exists(os.path.join(arm64_folder,
                                     "libNativeScript.so")), error_message
Ejemplo n.º 19
0
 def test_101_plugin_add_prepare_verify_app_ios(self):
     Tns.plugin_add(plugin_name='tns-plugin', path=self.app_name)
     Tns.build_ios(app_name=self.app_name)
     path_app = os.path.join(TnsPaths.get_ipa_path(self.app_name))
     assert Folder.exists(path_app)
Ejemplo n.º 20
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!'