Exemplo n.º 1
0
    def test_101(self, title, framework, template, platform):
        # Create app
        Tns.create(app_name=APP_NAME, template=template.local_package)

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

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

        # Run Tests
        result = Tns.test(app_name=APP_NAME,
                          platform=platform,
                          emulator=True,
                          just_launch=False,
                          wait=False)
        test_change = None
        if framework == FrameworkType.JASMINE:
            test_change = Changes.JSHelloWord.TEST
        if framework == FrameworkType.MOCHA:
            test_change = Changes.NGHelloWorld.TEST
        Sync.replace(app_name=APP_NAME, change_set=test_change)
        strings = ["log for test"]
        TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
Exemplo n.º 2
0
 def test_init(app_name, framework, update=True, verify=True):
     """
     Execute `tns test init` command.
     :param app_name: App name (passed as --path <App name>)
     :param framework: Unit testing framework as string (jasmin, mocha, quinit).
     :param update: Update nativescript-unit-test-runner if True.
     :param verify: Verify command was executed successfully.
     :return: Result of `tns test init` command.
     """
     app_path = TnsPaths.get_app_path(app_name=app_name)
     command = 'test init --framework {0}'.format(str(framework))
     result = Tns.exec_command(command=command, path=app_name, timeout=300)
     if verify:
         TnsAssert.test_initialized(app_name=app_name,
                                    framework=framework,
                                    output=result.output)
     if update:
         Npm.uninstall(package='nativescript-unit-test-runner',
                       option='--save',
                       folder=app_path)
         Npm.install(package='nativescript-unit-test-runner@next',
                     option='--save --save-exact',
                     folder=app_path)
     return result
Exemplo n.º 3
0
    def test_100(self, title, framework, template, platform):
        # Create app
        Tns.create(app_name=APP_NAME, template=template.local_package)

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

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

        # Run Tests
        Tns.test(app_name=APP_NAME,
                 platform=platform,
                 emulator=True,
                 just_launch=True)