Esempio n. 1
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.'
Esempio n. 2
0
    def test_002_build_android_release_uglify_snapshot_sourcemap(self):
        # https://github.com/NativeScript/nativescript-dev-webpack/issues/920
        result = Tns.build_android(self.app_name,
                                   release=True,
                                   uglify=True,
                                   snapshot=True,
                                   source_map=True)
        assert "ERROR in NativeScriptSnapshot. Snapshot generation failed!" not in result.output
        assert "Target architecture: arm64-v8a" not in result.output

        # Verify snapshot files in the built .apk
        apk_path = TnsPaths.get_apk_path(app_name=self.app_name, release=True)
        if Settings.HOST_OS != OSType.WINDOWS:
            TnsAssert.snapshot_build(apk_path, self.temp_folder)

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

        # Configs are respected
        assert File.exists(TnsPaths.get_apk_path(self.app_name, release=True))

        # Create zip
        command = "tar -czf " + self.app_name + "/app/app.tar.gz " + self.app_name + "/app/app.js"
        run(cmd=command, cwd=Settings.TEST_RUN_HOME, wait=True)
        assert File.exists(os.path.join(self.app_path, 'app', 'app.tar.gz'))
        def test_401_plugin_add_invalid_pod(self):
            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'CocoaPods',
                                       'invalidpod.tgz')
            result = Tns.plugin_add(plugin_path, path=Settings.AppName.DEFAULT)
            assert "Successfully installed plugin invalidpod." in result.output
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'invalidpod', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'invalidpod', 'platforms', 'ios', 'Podfile'))

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

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

            assert not File.exists(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'TestApp.xcworkspace'))
            assert not File.exists(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'Pods', 'Pods.xcodeproj'))
Esempio n. 4
0
def run_hello_world_js_ts(app_name, platform, device, bundle=True, hmr=True, uglify=False, release=False,
                          aot=False, snapshot=False, instrumented=False, sync_all_files=False, just_launch=False,
                          default_andr_sdk='29', timeout=240):
    # Execute `tns run` and wait until logs are OK
    result = Tns.run(app_name=app_name, platform=platform, emulator=True, wait=False, bundle=bundle, hmr=hmr,
                     release=release, uglify=uglify, aot=aot, snapshot=snapshot, sync_all_files=sync_all_files,
                     just_launch=just_launch)

    strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.UNKNOWN, bundle=bundle,
                                   hmr=hmr, instrumented=instrumented, device=device, release=release,
                                   snapshot=snapshot)
    TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=timeout)

    # Verify it looks properly
    device.wait_for_text(text=Changes.JSHelloWord.JS.old_text)
    device.wait_for_text(text=Changes.JSHelloWord.XML.old_text)
    blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE)
    assert blue_count > 100, 'Failed to find blue color on {0}'.format(device.name)
    initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png')
    device.get_screen(path=initial_state)
    if platform == Platform.ANDROID:
        # Verify android sdk the app is built with
        if release:
            apk_path = TnsPaths.get_apk_path(app_name=app_name, release=True)
        else:
            apk_path = TnsPaths.get_apk_path(app_name=app_name, release=False)
        TnsAssert.string_in_android_manifest(apk_path, 'compileSdkVersion="{0}"'.format(default_andr_sdk))
    if snapshot and Settings.HOST_OS != OSType.WINDOWS:
        TnsAssert.snapshot_build(TnsPaths.get_apk_path(app_name=app_name, release=True), Settings.TEST_OUT_TEMP)
    return result
    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
Esempio n. 6
0
    def test_100_plugin_add_after_platform_add_android(self):
        result = Tns.plugin_add(plugin_name='tns-plugin', path=self.app_name)
        assert 'Successfully installed plugin tns-plugin' in result.output
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'index.js'))
        assert File.exists(
            os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                         'tns-plugin', 'package.json'))

        output = File.read(os.path.join(self.app_path, 'package.json'))
        assert 'org.nativescript.TestApp' in output
        assert 'dependencies' in output
        assert 'tns-plugin' in output
    def test_200_prepare_additional_appresources(self):
        Tns.prepare_ios(self.app_name)

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

        Tns.prepare_ios(self.app_name)

        # Verify XCode Project include files from App Resources folder
        result = run("cat " + os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name), 'TestApp.xcodeproj',
                                           'project.pbxproj | grep newDefault.png'))
        assert "newDefault.png" in result.output
    def test_003_js_app_apk(self):
        # Extract APK
        apk = TnsPaths.get_apk_path(app_name=self.js_app, release=True)
        extracted_apk = os.path.join(Settings.TEST_OUT_TEMP, 'js-apk')
        File.unzip(file_path=apk, dest_dir=extracted_apk)

        res = os.path.join(extracted_apk, 'res')
        assets_app = os.path.join(extracted_apk, 'assets', 'app')
        assets_snapshots = os.path.join(extracted_apk, 'assets', 'snapshots')
        lib = os.path.join(extracted_apk, 'lib')
        run(cmd='du -hs *', cwd=lib, wait=True, log_level=logging.INFO)

        # Verify content of APK
        assert PerfUtils.is_value_in_range(actual=Folder.get_size(lib),
                                           expected=38724352,
                                           tolerance=0.1)
        assert PerfUtils.is_value_in_range(actual=Folder.get_size(res),
                                           expected=843827,
                                           tolerance=0.1)
        assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_app),
                                           expected=641606,
                                           tolerance=0.1)
        assert PerfUtils.is_value_in_range(
            actual=Folder.get_size(assets_snapshots),
            expected=5811260,
            tolerance=0.1)

        # Verify final apk size
        assert PerfUtils.is_value_in_range(actual=File.get_size(apk),
                                           expected=18216351,
                                           tolerance=0.05)
Esempio n. 9
0
class TnsRunJSTestsApi28(TnsRunAndroidTest):
    app_name = Settings.AppName.DEFAULT
    source_project_dir = TnsPaths.get_app_path(app_name)
    target_project_dir = os.path.join(Settings.TEST_RUN_HOME, 'data', 'temp',
                                      app_name)

    @classmethod
    def setUpClass(cls):
        TnsRunAndroidTest.setUpClass()
        Docker.start()

        # Create app
        result = Tns.create(app_name=cls.app_name,
                            template='[email protected]',
                            verify=False)
        TnsAssert.created(app_name=cls.app_name,
                          output=result.output,
                          path=Settings.TEST_RUN_HOME,
                          theme=False)

        # Copy TestApp to data folder.
        Folder.copy(source=cls.source_project_dir,
                    target=cls.target_project_dir)

    def setUp(self):
        TnsRunAndroidTest.setUp(self)

        # "src" folder of TestApp will be restored before each test.
        # This will ensure failures in one test do not cause common failures.
        source_src = os.path.join(self.target_project_dir, 'app')
        target_src = os.path.join(self.source_project_dir, 'app')
        Folder.clean(target_src)
        Folder.copy(source=source_src, target=target_src)

    @classmethod
    def tearDownClass(cls):
        TnsRunAndroidTest.tearDownClass()
        Docker.stop()

    def test_100_run_android(self):
        """
            Run android, verify app is built with api28 and verify livesync
        """
        # Run app and verify on emulator
        sync_hello_world_js(self.app_name,
                            Platform.ANDROID,
                            self.emu,
                            default_andr_sdk='28')

    def test_200_run_android_release_snapshot(self):
        """
            Run android, verify app is built with api28
        """
        # Run app and verify on emulator
        run_hello_world_js_ts(self.app_name,
                              Platform.ANDROID,
                              self.emu,
                              default_andr_sdk='28',
                              release=True,
                              snapshot=True)
 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
Esempio n. 11
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_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
    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
Esempio n. 14
0
 def platform_removed(app_name, platform, output):
     platform_string = str(platform)
     # Verify output
     assert 'Platform {0} successfully removed'.format(
         platform_string) in output
     # Verify package.json
     app_path = TnsPaths.get_app_path(app_name)
     package_json = os.path.join(app_path, 'package.json')
     json = JsonUtils.read(package_json)
     assert not 'tns-' + platform_string in json
     if platform == Platform.ANDROID:
         assert not Folder.exists(
             TnsPaths.get_platforms_android_folder(app_name))
     else:
         assert not Folder.exists(
             TnsPaths.get_platforms_ios_folder(app_name))
 def test_102_ng_app_ipa(self):
     ipa = TnsPaths.get_ipa_path(app_name=self.ng_app,
                                 release=True,
                                 for_device=True)
     assert PerfUtils.is_value_in_range(actual=File.get_size(ipa),
                                        expected=16226626,
                                        tolerance=0.05)
Esempio n. 16
0
    def test_201_build_app_for_both_platforms(self):
        Tns.plugin_add(plugin_name='tns-plugin', path=self.app_name)

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

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

        apk_path = os.path.join(TnsPaths.get_apk_path(self.app_name))
        output = Adb.get_package_permission(apk_path)
        assert 'android.permission.READ_EXTERNAL_STORAGE' in output
        assert 'android.permission.WRITE_EXTERNAL_STORAGE' in output
        assert 'android.permission.INTERNET' in output
Esempio n. 17
0
    def test_100_run_android_app_bundle_compile_snapshot(self):
        """Run app on android with --aab option with optimisations for snapshot.
           Verify the output(app.aab)."""

        path_to_aab = os.path.join(TnsPaths.get_app_path(self.app_name),
                                   "platforms", "android", "app", "build",
                                   "outputs", "bundle", "release",
                                   "app-release.aab")
        path_to_apks = os.path.join(TnsPaths.get_app_path(self.app_name),
                                    "platforms", "android", "app", "build",
                                    "outputs", "bundle", "release",
                                    "app-release.apks")

        # env.snapshot is applicable only in release build
        result = Tns.run_android(self.app_path,
                                 aab=True,
                                 release=True,
                                 snapshot=True,
                                 uglify=True,
                                 verify=False,
                                 compile_snapshot=True)
        strings = [
            'Successfully generated snapshots',
            'The build result is located at: {0}'.format(path_to_aab)
        ]
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=strings,
                             timeout=300)

        # Verify app can be deployed on emulator via nativescript
        # Verify app looks correct inside emulator
        self.emu.wait_for_text(text='TAP', timeout=60)

        # Verify that the correct .so file is included in the package
        File.unzip(path_to_apks, os.path.join(self.app_name, 'apks'))
        File.unzip(
            os.path.join(self.app_name, 'apks', 'standalones',
                         'standalone-arm64_v8a_hdpi.apk'),
            os.path.join(self.app_name, 'standalone-arm64'))
        assert File.exists(
            os.path.join(self.app_name, 'standalone-arm64', 'lib', 'arm64-v8a',
                         'libNativeScript.so'))
        assert not File.exists(
            os.path.join(self.app_name, 'standalone-arm64', 'assets',
                         'snapshots', 'x86_64', 'snapshot.blob'))
Esempio n. 18
0
    def test_300_deploy_list_and_run_applications(self):
        # Deploy test application
        app_id = TnsPaths.get_bundle_id(app_name=APP_NAME)
        result = Tns.deploy(app_name=APP_NAME,
                            platform=Platform.ANDROID,
                            just_launch=True,
                            wait=True)
        for device in self.ANDROID_DEVICES:
            assert device.id in result.output
        if Settings.HOST_OS == OSType.OSX:
            result = Tns.deploy(app_name=APP_NAME,
                                platform=Platform.IOS,
                                just_launch=True,
                                wait=True)
            for device in self.IOS_DEVICES:
                assert device.id in result.output

        # Verify list-applications command list default android apps and the app we've just deployed
        for device in self.ANDROID_DEVICES:
            result = Tns.exec_command(
                'device list-applications --device {0}'.format(device.id))
            assert 'com.android' in result.output
            assert app_id in result.output

        # Verify `device run <bundle-id>` will start the app
        device = self.ANDROID_DEVICES[0]
        Adb.stop_application(device_id=device.id, app_id=app_id)
        assert not device.is_text_visible(
            text=Changes.JSHelloWord.JS.old_value), 'Failed to stop the app.'
        Tns.exec_command(command='device run {0}'.format(app_id),
                         device=device.id,
                         wait=True,
                         just_launch=True)
        device.wait_for_text(text=Changes.JSHelloWord.JS.old_value)

        # Get Android device logs
        result = Tns.exec_command(command='device log',
                                  device=device.id,
                                  wait=False)
        TnsLogs.wait_for_log(log_file=result.log_file,
                             string_list=['beginning of'],
                             timeout=120)
        assert 'I' or 'D' or 'W' in File.read(
            result.log_file
        ), 'Log does not contain INFO, DEBUG or WARN messages.'

        # Get iOS device logs
        if Settings.HOST_OS == OSType.OSX:
            device = self.IOS_DEVICES[0]
            result = Tns.exec_command(command='device log',
                                      device=device.id,
                                      wait=False)
            TnsLogs.wait_for_log(log_file=result.log_file,
                                 string_list=['>:'],
                                 timeout=120)
            assert "<Notice>:" or "<Error>:" in File.read(
                result.log_file), 'tns device log fails to get ios logs.'
Esempio n. 19
0
    def test_002_build_android_release(self):
        Tns.build_android(self.app_name, release=True)

        # Configs are respected
        assert File.exists(TnsPaths.get_apk_path(self.app_name, release=True))

        # Create zip
        command = "tar -czf " + self.app_name + "/app/app.tar.gz " + self.app_name + "/app/app.js"
        run(cmd=command, cwd=Settings.TEST_RUN_HOME, wait=True)
        assert File.exists(os.path.join(self.app_path, 'app', 'app.tar.gz'))
        def test_100_plugin_add_multiple_pods(self):
            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'CocoaPods', 'carousel.tgz')
            result = Tns.plugin_add(plugin_path, path=Settings.AppName.DEFAULT)
            assert "Successfully installed plugin carousel." in result.output
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'carousel', 'package.json'))
            assert File.exists(
                os.path.join(TnsPaths.get_app_node_modules_path(self.app_name),
                             'carousel', 'platforms', 'ios', 'Podfile'))
            assert "carousel" in File.read(
                os.path.join(Settings.TEST_RUN_HOME, self.app_name,
                             'package.json'))

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

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

            output = File.read(
                os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                             'Podfile'))
            assert "use_frameworks!" in output
            assert "pod 'iCarousel'" in output
            assert "pod 'AFNetworking'" in output
            assert "pod 'UICKeyChainStore'" in output
Esempio n. 21
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."
Esempio n. 22
0
 def __app_restart_messages(app_name, platform, instrumented, app_type, device, just_launch=False):
     logs = ['Restarting application on device']
     if platform == Platform.ANDROID:
         app_id = TnsPaths.get_bundle_id(app_name)
         if device is not None and device.version < 7.0 and just_launch is False:
             logs.append('ActivityManager: Start proc')
             logs.append('activity {0}/com.tns.NativeScriptActivity'.format(app_id))
     if instrumented:
         logs.append('QA: Application started')
         if app_type == AppType.NG:
             logs.append('QA: items component on init')
     return logs
Esempio n. 23
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
        def test_210_plugin_add_static_lib_universal(self):
            plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                       'plugins', 'hello-plugin.tgz')
            result = Tns.plugin_add(plugin_path,
                                    path=Settings.AppName.DEFAULT,
                                    verify=False)
            assert "Successfully installed plugin hello." in result.output

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

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

            Tns.prepare_ios(self.app_name)

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

            result = run("cat " + os.path.join(
                TnsPaths.get_platforms_ios_folder(self.app_name),
                'TestApp.xcodeproj', 'project.pbxproj | grep \"HelloLib.a\"'))
            assert "HelloLib.a in Frameworks" in result.output
class NGGenerateNGTests(TnsTest):
    app_name = Settings.AppName.DEFAULT
    app_path = TnsPaths.get_app_path(app_name=app_name)

    @classmethod
    def setUpClass(cls):
        TnsTest.setUpClass()
        NG.kill()
        Folder.clean(cls.app_path)

        # Create app
        NG.new(collection=NS_SCHEMATICS, project=cls.app_name, shared=False)
        # TODO: Rollback theme=False when schematics use @nativescript/theme
        TnsAssert.created(app_name=cls.app_name, app_data=None, theme=False)

    def setUp(self):
        TnsTest.setUpClass()
        NG.kill()

    def tearDown(self):
        NG.kill()
        TnsTest.tearDown(self)

    def test_001_generate_component(self):
        result = NG.exec_command(command='g c component-test', cwd=self.app_path)
        assert 'CREATE app/component-test/component-test.component.html' in result.output
        assert 'CREATE app/component-test/component-test.component.ts' in result.output
        assert 'CREATE app/component-test/component-test.component.css' in result.output
        assert 'UPDATE app/app.module.ts' in result.output

    def test_002_generate_module(self):
        result = NG.exec_command(command='g m module-test', cwd=self.app_path)
        assert 'CREATE app/module-test/module-test.module.ts' in result.output

    def test_003_generate_component_in_existing_modules(self):
        result = NG.exec_command(command='g m module-test2', cwd=self.app_path)
        assert 'CREATE app/module-test2/module-test2.module.ts' in result.output

        result = NG.exec_command(command='g c module-test2/component-name', cwd=self.app_path)
        assert 'CREATE app/module-test2/component-name/component-name.component.html' in result.output
        assert 'CREATE app/module-test2/component-name/component-name.component.ts' in result.output
        assert 'CREATE app/module-test2/component-name/component-name.component.css' in result.output
        assert 'UPDATE app/module-test2/module-test2.module.ts' in result.output

    @unittest.skip('Skip because of https://github.com/NativeScript/nativescript-schematics/issues/194')
    def test_004_generate_master_detail(self):
        result = NG.exec_command(command='g master-detail --master=dogs --detail=dog', cwd=self.app_path)
        assert 'CREATE app/dogs/dog-detail/dog-detail.component.html' in result.output
        assert 'CREATE app/dogs/dogs/dogs.component.html' in result.output
        assert 'data.service.ts' in result.output
        assert 'dogs.module.ts' in result.output
Esempio n. 26
0
    def test_401_plugin_add_invalid_plugin(self):
        Tns.platform_remove(app_name=self.app_name, platform=Platform.IOS)
        Tns.platform_remove(app_name=self.app_name, platform=Platform.ANDROID)
        result = Tns.plugin_add(plugin_name='wd',
                                path=self.app_name,
                                verify=False)
        assert 'wd is not a valid NativeScript plugin' in result.output
        assert 'Verify that the plugin package.json file ' + \
               'contains a nativescript key and try again' in result.output
        Tns.platform_add_android(
            self.app_name, framework_path=Settings.Android.FRAMEWORK_PATH)
        Tns.platform_add_ios(self.app_name,
                             framework_path=Settings.IOS.FRAMEWORK_PATH)

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

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

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

        Tns.build_android(app_name=self.app_name, bundle=False)
        android_path = os.path.join(
            TnsPaths.get_platforms_android_folder(self.app_name))
        assert File.pattern_exists(android_path, pattern='*.aar')
        assert File.pattern_exists(android_path, pattern='*acra*')
Esempio n. 27
0
 def test_320_cfbundleurltypes_overridden_from_plugin_ios(self):
     """
     Test for issue https://github.com/NativeScript/nativescript-cli/issues/2936
     """
     Tns.platform_remove(app_name=self.app_name, platform=Platform.IOS)
     plugin_path = os.path.join(Settings.TEST_RUN_HOME, 'assets', 'plugins',
                                'CFBundleURLName-Plugin.tgz')
     Tns.plugin_add(plugin_path, path=self.app_name)
     Tns.prepare_ios(app_name=self.app_name)
     plist = File.read(
         os.path.join(TnsPaths.get_platforms_ios_folder(self.app_name),
                      self.app_name, self.app_name + '-Info.plist'))
     assert '<key>NSAllowsArbitraryLoads</key>' in plist, \
         'NSAppTransportSecurity from plugin is not found in final Info.plist'
     assert '<string>bar</string>' in plist, 'CFBundleURLTypes from plugin is not found in final Info.plist'
Esempio n. 28
0
 def test_201_create_project_with_local_directory_template(self):
     """--template should install all packages from package.json"""
     template_path = os.path.join(Settings.TEST_RUN_HOME, 'assets',
                                  'myCustomTemplate')
     Tns.create(app_name=Settings.AppName.DEFAULT,
                template=template_path,
                update=False)
     node_modules = TnsPaths.get_app_node_modules_path(
         app_name=Settings.AppName.DEFAULT)
     assert not Folder.is_empty(os.path.join(node_modules, 'lodash'))
     assert not Folder.is_empty(os.path.join(node_modules, 'minimist'))
     assert not Folder.is_empty(
         os.path.join(node_modules, 'tns-core-modules'))
     assert not Folder.is_empty(
         os.path.join(node_modules, 'tns-core-modules-widgets'))
    def test_301_build_project_with_space_release(self):

        # Ensure ANDROID_KEYSTORE_PATH contain spaces (verification for CLI issue 2650)
        Folder.create("with space")
        file_name = os.path.basename(Settings.Android.ANDROID_KEYSTORE_PATH)
        cert_with_space_path = os.path.join("with space", file_name)
        File.copy(Settings.Android.ANDROID_KEYSTORE_PATH, cert_with_space_path)

        Tns.build_android(app_name='"' + self.app_name_with_space + '"', release=True)
        output = File.read(os.path.join(self.app_name_with_space, "package.json"))
        assert self.app_identifier in output.lower()

        output = File.read(os.path.join(TnsPaths.get_platforms_android_src_main_path(self.app_name_with_space),
                                        'AndroidManifest.xml'))
        assert self.app_identifier in output.lower()
    def workflow(app_name, device, platform, shared):
        # Create an app
        app_path = TnsPaths.get_app_path(app_name=app_name)
        Folder.clean(app_path)
        NG.new(collection=NS_SCHEMATICS, project=app_name, shared=shared)
        TnsAssert.created(app_name=app_name, app_data=None)

        # Run app initially
        text = 'TAP'
        if shared:
            text = 'Welcome to'
        result = Tns.run(app_name=app_name, platform=platform, emulator=True, hmr=True)
        strings = TnsLogs.run_messages(app_name=app_name, platform=platform, bundle=True, hmr=True, app_type=AppType.NG)
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
        device.wait_for_text(text=text)

        # Generate module and component
        NG.exec_command(command='g m module-test', cwd=app_path)
        NG.exec_command(command='g c module-test/component-test', cwd=app_path)

        # Update app.modules.ts
        app_module_name = 'app.module.ts'
        app_module_path = os.path.join(app_path, 'app', app_module_name)
        if shared:
            app_module_name = 'app.module.tns.ts'
            app_module_path = os.path.join(app_path, 'src', 'app', app_module_name)
        old_string = "import { HomeComponent } from './home/home.component';"
        new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
        File.replace(path=app_module_path, old_string=old_string, new_string=new_string)
        File.replace(path=app_module_path, old_string='HomeComponent,', new_string='ComponentTestComponent,')

        # Update app-routing.module.ts
        app_routing_module_name = 'app-routing.module.ts'
        app_routing_module_path = os.path.join(app_path, 'app', app_routing_module_name)
        if shared:
            app_routing_module_name = 'app.routes.ts'
            app_routing_module_path = os.path.join(app_path, 'src', 'app', app_routing_module_name)
        old_string = "import { HomeComponent } from './home/home.component';"
        new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
        File.replace(path=app_routing_module_path, old_string=old_string, new_string=new_string)
        File.replace(path=app_routing_module_path, old_string='HomeComponent', new_string='ComponentTestComponent')

        # Verify app is updated
        logs = [app_module_name.replace('.tns', ''), app_routing_module_name.replace('.tns', ''),
                'Successfully synced application']
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs, timeout=120)
        device.wait_for_text(text='component-test works!')