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)
        TnsAssert.created(app_name=cls.app_name, app_data=None)
    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)
示例#3
0
 def test_200_create_project_with_template(self, template_source):
     """Create app should be possible with --template and npm packages, git repos and aliases"""
     result = Tns.create(app_name=Settings.AppName.DEFAULT,
                         template=template_source,
                         update=False,
                         verify=False)
     TnsAssert.created(app_name=Settings.AppName.DEFAULT,
                       output=result.output,
                       theme=False)
    def test_301_tns_resources_generate_icons_old_template_structure(self):
        # Create nativescript@4 app
        result = Tns.create(app_name=APP_NAME,
                            template='[email protected]',
                            verify=False)
        TnsAssert.created(app_name=APP_NAME,
                          output=result.output,
                          webpack=False)

        # Generate icons with nativescript
        self.test_001_tns_resources_generate_icons()
 def test_301_tns_resources_update_on_updated_project(self):
     result = Tns.create(app_name=APP_NAME,
                         template=Template.HELLO_WORLD_JS.local_package,
                         verify=False,
                         update=False)
     TnsAssert.created(app_name=APP_NAME,
                       output=result.output,
                       webpack=False,
                       theme=False)
     result = Tns.exec_command(command='resources update', path=APP_NAME)
     assert 'The App_Resources have already been updated for the Android platform.' in result.output
示例#6
0
 def test_400_invalid_framework_name(self):
     result = Tns.create(app_name=APP_NAME,
                         template=Template.HELLO_WORLD_JS.local_package,
                         update=False,
                         verify=False)
     TnsAssert.created(app_name=APP_NAME,
                       output=result.output,
                       theme=False,
                       webpack=False)
     result = Tns.test_init(app_name=APP_NAME,
                            framework='jasmin',
                            verify=False)
     assert 'Unknown or unsupported unit testing framework: jasmin' in result.output
示例#7
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))
    def test_300_tns_resources_update(self):
        # Create nativescript@3 app
        result = Tns.create(app_name=APP_NAME,
                            template='[email protected]',
                            verify=False,
                            update=False)
        TnsAssert.created(app_name=APP_NAME,
                          output=result.output,
                          webpack=False)

        # Update resources
        out = Tns.exec_command(command='resources update',
                               path=APP_NAME).output
        assert "Successfully updated your project's application resources '/Android' directory structure." in out
        assert "The previous version of your Android application resources has been renamed to '/Android-Pre-v4'" in out
示例#9
0
    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)
示例#10
0
    def test_200_doctor_show_warning_when_new_components_are_available(self):
        result = Tns.create(app_name=self.APP_NAME, template=Template.HELLO_WORLD_JS.local_package,
                            update=False, verify=False)
        TnsAssert.created(app_name=self.APP_NAME, output=result.output, theme=False, webpack=False)
        Tns.platform_add_android(app_name=self.APP_NAME, version='4')
        App.install_dependency(app_name=self.APP_NAME, dependency='tns-core-modules', version='4')

        doctor_result = Tns.doctor(app_name=self.APP_NAME)
        doctor_output = doctor_result.output

        info_result = Tns.info(app_name=self.APP_NAME)
        info_output = info_result.output

        for output in (doctor_output, info_output):
            assert 'Update available for component tns-core-modules' in output
            assert 'Update available for component tns-android' in output
    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!')
示例#12
0
    def create(app_name=Settings.AppName.DEFAULT,
               template=None,
               path=None,
               app_id=None,
               force=False,
               default=False,
               update=True,
               force_clean=True,
               log_trace=False,
               verify=True,
               app_data=None):
        """
        Create {N} application.
        :param app_name: Application name (TestApp by default).
        :param template: Template string (it can be everything that can be npm installed - npm package, git url ...)
        :param path: Path where app to be created (Passes `--path <value>` to tns command. None by default).
        :param app_id: Application identifier.
        :param force: If true passes '--force' to tns command.
        :param default: If true passes '--default' to tns command.
        :param update: If True update the app (modules and plugins).
        :param force_clean: If True clean app folder before creating a project.
        :param log_trace: If True runs tns command with '--log trace'.
        :param verify: If True assert app is created properly.
        :param app_data: AppInfo object with expected data (used to verify app is created properly).
        """

        # Cleanup app folder
        if force_clean:
            Folder.clean(TnsPaths.get_app_path(app_name=app_name))

        # Create app
        normalized_app_name = app_name
        if ' ' in app_name:
            normalized_app_name = '"' + app_name + '"'
        command = 'create ' + normalized_app_name
        if template is not None:
            command = command + ' --template ' + template
        if path is not None:
            command = command + ' --path ' + path
        if app_id is not None:
            # noinspection SpellCheckingInspection
            command = command + ' --appid ' + app_id
        if force:
            command += ' --force'
        if default:
            command += ' --default'
        result = Tns.exec_command(command, log_trace=log_trace)

        # Update the app (if specified)
        if update:
            App.update(app_name=app_name)

        # Let TestContext know app is created
        TestContext.TEST_APP_NAME = app_name

        # Verify app is created properly
        if verify is not False:
            # Usually we do not pass path on tns create, which actually equals to cwd.
            # In such cases pass correct path to TnsAssert.created()
            if path is None:
                path = Settings.TEST_RUN_HOME
            TnsAssert.created(app_name=app_name,
                              output=result.output,
                              app_data=app_data,
                              path=path)

        return result