コード例 #1
0
    def test_398_tns_run_ios_console_time(self):
        # Delete src folder from the previous test till Folder copy strt to backup folders too
        Folder.clean(
            os.path.join(APP_PATH, 'app', 'App_Resources', 'iOS', 'src'))

        Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
        Tns.create(app_name=APP_NAME,
                   template=Template.HELLO_WORLD_NG.local_package,
                   update=True)
        Tns.platform_add_ios(APP_NAME, framework_path=IOS.FRAMEWORK_PATH)
        # Replace app.component.ts to use console.time() and console.timeEnd()

        File.copy(
            os.path.join(TEST_RUN_HOME, 'assets', 'runtime', 'ios', 'files',
                         'ios-runtime-843', 'app.component.ts'),
            os.path.join(APP_PATH, 'src', 'app', 'app.component.ts'), True)

        # `tns run ios` and wait until app is deployed
        result = Tns.run_ios(app_name=APP_NAME,
                             emulator=True,
                             wait=False,
                             verify=False)

        # Verify initial state of the app
        strings = [
            'Project successfully built',
            'Successfully installed on device with identifier', self.sim.id
        ]
        assert_result = Wait.until(lambda: all(st in File.read(result.log_file)
                                               for st in strings),
                                   timeout=200,
                                   period=5)

        assert assert_result, 'App not build correctly! Logs: ' + File.read(
            result.log_file)

        Device.wait_for_text(self.sim, text="Ter Stegen", timeout=30)

        # Verify console.time() works - issue https://github.com/NativeScript/ios-runtime/issues/843
        console_time = ['CONSOLE INFO startup:']
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=console_time)
コード例 #2
0
    def test_001_build_android(self):
        Tns.build_android(self.app_name)
        assert not File.exists(os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.plist'))
        assert not File.exists(os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.android.js'))
        assert not File.exists(os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.ios.js'))

        src = os.path.join(self.app_name, 'app', 'app.js')
        dest_1 = os.path.join(self.app_name, 'app', 'new.android.js')
        dest_2 = os.path.join(self.app_name, 'app', 'new.ios.js')
        File.copy(src, dest_1)
        File.copy(src, dest_2)

        result = Tns.build_android(self.app_name)
        assert "Gradle build..." in result.output, "Gradle build not called."
        assert result.output.count("Gradle build...") == 1, "Only one gradle build is triggered."

        assert not File.exists(os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.plist'))
        assert not File.exists(os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.android.js'))
        assert not File.exists(os.path.join(TnsPaths.get_platforms_android_folder(self.app_name), '*.ios.js'))

        # Verify apk does not contain aar files
        apk_path = TnsPaths.get_apk_path(app_name=self.app_name, release=False)
        File.unzip(apk_path, self.temp_folder)
        # Clean META-INF folder. It contains com.android.support.... files which are expected to be there due to
        # https://github.com/NativeScript/nativescript-cli/pull/3923
        Folder.clean(os.path.join(self.temp_folder, 'META-INF'))
        assert not File.pattern_exists(self.temp_folder, '*.aar')
        assert not File.pattern_exists(self.temp_folder, '*.plist')
        assert not File.pattern_exists(self.temp_folder, '*.android.*')
        assert not File.pattern_exists(self.temp_folder, '*.ios.*')

        # Verify app is built with android sdk 29 by default
        TnsAssert.string_in_android_manifest(apk_path, 'compileSdkVersion="29"')
        Folder.clean(self.temp_folder)

        # Verify incremental native build
        result = Tns.exec_command(command='build --clean', path=self.app_name,
                                  platform=Platform.ANDROID)
        assert "Gradle clean..." in result.output, "Gradle clean is not called."
        assert "Gradle build..." in result.output, "Gradle build is not called."
        assert result.output.count("Gradle build...") == 1, "More than 1 gradle build is triggered."
コード例 #3
0
    def setUpClass(cls):
        TnsRunTest.setUpClass()

        # Create app
        Tns.create(app_name=cls.app_name,
                   template=Template.HELLO_WORLD_TS.local_package,
                   update=True)
        src = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'logs',
                           'hello-world-ts', 'app.ts')
        target = os.path.join(Settings.TEST_RUN_HOME, cls.app_name, 'app')
        File.copy(source=src, target=target)
        Tns.platform_add_android(
            app_name=cls.app_name,
            framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS is OSType.OSX:
            Tns.platform_add_ios(app_name=cls.app_name,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Copy TestApp to data folder.
        Folder.copy(source=cls.source_project_dir,
                    target=cls.target_project_dir)
コード例 #4
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
コード例 #5
0
    def get_screenshots():
        # get host snapshot
        base_path = os.path.join(Settings.TEST_OUT_IMAGES, TestContext.CLASS_NAME, TestContext.TEST_NAME)
        try:
            import pyautogui
            png_path = os.path.join(base_path, 'host.png')
            File.delete(png_path)
            Folder.create(folder=os.path.dirname(png_path))
            pyautogui.screenshot().save(png_path)
            Log.info("Saved host os screen at {0}".format(png_path))
        except Exception:
            Log.warning('Failed to take screenshot of host os.')

        # get device screenshots
        for device in TestContext.STARTED_DEVICES:
            try:
                png_path = os.path.join(base_path, device.name + '.png')
                File.delete(png_path)
                device.get_screen(png_path)
            except AssertionError:
                Log.warning('Failed to take screenshot of {0}'.format(device.id))
コード例 #6
0
    def setUpClass(cls):
        TnsRunTest.setUpClass()
        Preview.install_preview_app(cls.emu, Platform.ANDROID)
        if Settings.HOST_OS is OSType.OSX:
            Preview.install_preview_app(cls.sim, Platform.IOS)
            Preview.install_playground_app(cls.sim, Platform.IOS)

        # Create app
        Tns.create(app_name=cls.app_name,
                   template=Template.VUE_BLANK.local_package,
                   update=True)
        Tns.platform_add_android(
            app_name=cls.app_name,
            framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS is OSType.OSX:
            Tns.platform_add_ios(app_name=cls.app_name,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Copy TestApp to data folder.
        Folder.copy(source=cls.source_project_dir,
                    target=cls.target_project_dir)
コード例 #7
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'))
コード例 #8
0
 def test_201_error_is_shown_when_metadata_folder_in_apk_is_missing(self):
     """
        https://github.com/NativeScript/android-runtime/issues/1471
        https://github.com/NativeScript/android-runtime/issues/1382
     """
     Adb.uninstall("org.nativescript.TestApp", self.emulator.id, True)
     Tns.build_android(os.path.join(TEST_RUN_HOME, APP_NAME), verify=True)
     apk_folder_path = os.path.join(TEST_RUN_HOME, APP_NAME, PLATFORM_ANDROID_APK_DEBUG_PATH)
     apk_path = os.path.join(apk_folder_path, "app-debug.apk")
     unzip_folder = os.path.join(apk_folder_path, "app-debug")
     File.unzip(apk_path, unzip_folder)
     Folder.clean(os.path.join(unzip_folder, "assets", "metadata"))
     File.delete(apk_path)
     File.zip(unzip_folder, apk_path)
     self.sign_apk(apk_path)
     Adb.install(apk_path, self.emulator.id, 60)
     Adb.start_application(self.emulator.id, "org.nativescript.TestApp")
     text_on_screen = "com.tns.NativescriptException: metadata folder couldn\'t be opened!"
     self.emulator.wait_for_text(text_on_screen)
     error_message = "Missing metadata in apk is not causing the correct error! Logs: "
     assert self.emulator.is_text_visible(text_on_screen), error_message + self.emulator.get_text()
コード例 #9
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
コード例 #10
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
コード例 #11
0
    def test_06_copy_to_not_existing_file_with_restore(self):
        TestContext.BACKUP_FILES.clear()
        Folder.clean(Settings.BACKUP_FOLDER)
        # Path to files
        file_name = "app.android.add_style.scss"
        folder_name = os.path.join(self.current_folder, 'resources', 'new')
        Folder.clean(folder_name)
        Folder.create(folder_name)
        old_scss = os.path.join(self.current_folder, 'resources',
                                'app.android.scss')
        new_scss = os.path.join(folder_name, file_name)

        # Test Copy
        File.copy(source=old_scss, target=new_scss, backup_files=True)
        assert File.exists(new_scss)
        assert len(File.read(
            path=new_scss).splitlines()) == 14, 'Unexpected lines count.'
        assert not File.exists(os.path.join(Settings.BACKUP_FOLDER,
                                            file_name)), "File not backup!"
        assert TestContext.BACKUP_FILES.items()[0].__getitem__(
            0) == new_scss, "File path is not correct!"
        assert TestContext.BACKUP_FILES.items()[0].__getitem__(
            1) == file_name, "File name not correct!"

        # Revert
        TnsTest.restore_files()
        assert not File.exists(new_scss)
        assert not File.exists(os.path.join(Settings.BACKUP_FOLDER,
                                            file_name)), "File not deleted!"
        assert not TestContext.BACKUP_FILES, "File object not deleted!"
コード例 #12
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)
コード例 #13
0
 def setUpClass(cls):
     TnsTest.setUpClass()
     cls.emulator = DeviceManager.Emulator.ensure_available(
         Emulators.DEFAULT)
     Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
     Tns.create(app_name=APP_NAME,
                template=Template.HELLO_WORLD_NG.local_package,
                update=True)
     json = App.get_package_json(app_name=APP_NAME)
     cls.app_id = json['nativescript']['id']
     devices = Adb.get_ids(include_emulators=False)
     device_id = None
     for device in devices:
         device_id = device
     if device_id is not None:
         cls.device = Device(id=device_id,
                             name=device_id,
                             type=DeviceType.ANDROID,
                             version=Adb.get_version(device_id))
     Adb.uninstall(cls.app_id, device_id, assert_success=False)
     Tns.platform_add_android(APP_NAME,
                              framework_path=Android.FRAMEWORK_PATH)
コード例 #14
0
    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
コード例 #15
0
    def test_102_ng_app_apk(self):
        # Extract APK
        apk = TnsPaths.get_apk_path(app_name=self.ng_app, release=True)
        extracted_apk = os.path.join(Settings.TEST_OUT_TEMP, 'ng-apk')
        File.unzip(file_path=apk, dest_dir=extracted_apk)

        assets_app = os.path.join(extracted_apk, 'assets', 'app')
        assets_snapshots = os.path.join(extracted_apk, 'assets', 'snapshots')

        # No asserts for lib and res, since it is same as JS project
        assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_app),
                                           expected=1342382,
                                           tolerance=0.1)
        assert PerfUtils.is_value_in_range(
            actual=Folder.get_size(assets_snapshots),
            expected=13157964,
            tolerance=0.1)

        # Verify final apk size
        assert PerfUtils.is_value_in_range(actual=File.get_size(apk),
                                           expected=20087522,
                                           tolerance=0.05)
コード例 #16
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)
コード例 #17
0
    def test_350_tns_run_ios_source_code_in_app_resources(self):
        """
        https://github.com/NativeScript/nativescript-cli/issues/4343
        """
        # Add plugin with source code in iOS part of the plugin
        source_path = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'issues', 'nativescript-cli-4343', 'src')
        dest_path = os.path.join(self.app_resources_ios, 'src')
        Folder.copy(source_path, dest_path, clean_target=False)

        # Call method from the source code of the plugin in main-view-model.js
        old_value = 'viewModel.counter = 42;'
        new_value = 'viewModel.counter = 42;\n var objTC = new TestClass2();\n console.log(objTC.sayHey());'
        target_js = os.path.join(Settings.TEST_RUN_HOME, self.app_name, 'app', 'main-view-model.js')
        File.replace(target_js, old_value, new_value)

        result = Tns.run_ios(self.app_name, emulator=True)
        strings = TnsLogs.run_messages(app_name=self.app_name, platform=Platform.IOS,
                                       run_type=RunType.FIRST_TIME, device=self.sim)
        strings.append('Hey Native!')
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

        # Verify app looks correct inside simulator
        self.sim.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
コード例 #18
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))
コード例 #19
0
    def setUpClass(cls):
        TnsDeviceTest.setUpClass()

        cls.emu = DeviceManager.Emulator.ensure_available(
            Settings.Emulators.DEFAULT)
        if Settings.HOST_OS is OSType.OSX:
            cls.sim = DeviceManager.Simulator.ensure_available(
                Settings.Simulators.DEFAULT)
            Simctl.uninstall_all(cls.sim)

        # Create app
        Tns.create(app_name=cls.app_name,
                   template=Template.HELLO_WORLD_JS.local_package,
                   update=True)
        Tns.platform_add_android(
            app_name=cls.app_name,
            framework_path=Settings.Android.FRAMEWORK_PATH)
        if Settings.HOST_OS is OSType.OSX:
            Tns.platform_add_ios(app_name=cls.app_name,
                                 framework_path=Settings.IOS.FRAMEWORK_PATH)

        # Copy TestApp to data folder.
        Folder.copy(source=cls.source_project_dir,
                    target=cls.target_project_dir)
コード例 #20
0
 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'))
コード例 #21
0
        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
コード例 #22
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
コード例 #23
0
    def test_07_copy_to_existing_file_with_restore(self):
        TestContext.BACKUP_FILES.clear()
        Folder.clean(Settings.BACKUP_FOLDER)

        # Path to files
        file_name = "app.android.add_style.scss"
        folder_name = os.path.join(self.current_folder, 'resources', 'new')
        Folder.clean(folder_name)
        Folder.create(folder_name)
        old_scss = os.path.join(self.current_folder, 'resources',
                                'app.android.scss')
        new_scss = os.path.join(folder_name, file_name)
        old_value = 'Android here'
        new_value = 'Android here\n.page { background-color: red;}'

        # Create new file (so we don't break original one).
        File.copy(source=old_scss, target=new_scss)
        assert len(File.read(
            path=new_scss).splitlines()) == 14, 'Unexpected lines count.'

        # Replace
        File.replace(path=new_scss, old_string=old_value, new_string=new_value)
        content = File.read(path=new_scss)
        assert 'red;' in content, 'Failed to replace string.'
        assert len(content.splitlines()) == 15, 'Unexpected lines count.'

        # Test Copy
        File.copy(source=old_scss, target=new_scss, backup_files=True)
        content = File.read(path=new_scss)
        assert 'red;' not in content, 'Failed to copy file!'
        assert len(content.splitlines()) == 14, 'Unexpected lines count.'
        assert File.exists(new_scss)
        assert File.exists(os.path.join(Settings.BACKUP_FOLDER,
                                        file_name)), "File not backup!"
        assert TestContext.BACKUP_FILES.items()[0].__getitem__(
            0) == new_scss, "File path is not correct!"
        assert TestContext.BACKUP_FILES.items()[0].__getitem__(
            1) == file_name, "File name not correct!"

        # Revert
        TnsTest.restore_files()
        assert File.exists(new_scss)
        content = File.read(path=new_scss)
        assert 'red;' in content, 'Failed to replace string.'
        assert len(content.splitlines()) == 15, 'Unexpected lines count.'
        assert not File.exists(os.path.join(Settings.BACKUP_FOLDER,
                                            file_name)), "File not deleted!"
        assert not TestContext.BACKUP_FILES, "File object not deleted!"

        File.delete(path=new_scss)
コード例 #24
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'))
コード例 #25
0
 def test_010_create_app_remove_app_resources(self):
     # creates valid project from local directory template
     Folder.clean(os.path.join("template-hello-world"))
     Folder.clean(os.path.join(Settings.AppName.DEFAULT))
     Git.clone(
         repo_url='[email protected]:NativeScript/template-hello-world.git',
         local_folder="template-hello-world")
     Folder.clean(
         os.path.join(Settings.TEST_RUN_HOME, 'template-hello-world', 'app',
                      'App_Resources'))
     file_path = os.path.join(Settings.TEST_RUN_HOME,
                              'template-hello-world', 'package.json')
     File.replace(path=file_path,
                  old_string="tns-template-hello-world",
                  new_string="test-tns-template-hello-world")
     path = os.path.join(Settings.TEST_RUN_HOME, 'template-hello-world')
     Tns.create(app_name=Settings.AppName.DEFAULT, template=path)
コード例 #26
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'))
コード例 #27
0
 def __clean_backup_folder_and_dictionary():
     TestContext.BACKUP_FILES.clear()
     Folder.clean(Settings.BACKUP_FOLDER)
コード例 #28
0
 def tearDownClass(cls):
     TnsTest.tearDownClass()
     Folder.clean(os.path.join(TEST_RUN_HOME, APP_NAME))
コード例 #29
0
 def tearDown(self):
     TnsTest.tearDown(self)
     Folder.clean(self.app_name)
コード例 #30
0
 def tearDownClass(cls):
     for app in cls.test_data:
         repo = app[0]
         Folder.clean(os.path.join(Settings.TEST_RUN_HOME, repo))
     TnsTest.tearDownClass()