diff --git a/core/settings/Settings.py b/core/settings/Settings.py index 81d23956..a05b64b1 100644 --- a/core/settings/Settings.py +++ b/core/settings/Settings.py @@ -140,3 +140,4 @@ class AppName(object): DEFAULT_NG = 'TestApp' WITH_DASH = 'tns-app' WITH_SPACE = 'Test App' + WITH_NUMBER = '123' diff --git a/data/apps.py b/data/apps.py index 46cc3e9d..4974e191 100644 --- a/data/apps.py +++ b/data/apps.py @@ -54,3 +54,6 @@ class Apps(object): SCHEMATICS_SHARED = AppInfo(type=AppType.SHARED_NG, id=None, size=__shared_size, texts=['Welcome']) SCHEMATICS_SHARED_SAMPLE = AppInfo(type=AppType.SHARED_NG, id=None, size=__shared_size, texts=['Barcelona']) SCHEMATICS_NS = AppInfo(type=AppType.NG, id=None, size=__ns_only_size, texts=['Tap the button']) + HELLO_WORLD_JS = AppInfo(type=AppType.JS, id=None, size=None, texts=None) + HELLO_WORLD_TS = AppInfo(type=AppType.TS, id=None, size=None, texts=None) + HELLO_WORLD_NG = AppInfo(type=AppType.NG, id=None, size=None, texts=None) diff --git a/products/nativescript/tns_assert.py b/products/nativescript/tns_assert.py index 2e2f4d5f..ac23dc8d 100644 --- a/products/nativescript/tns_assert.py +++ b/products/nativescript/tns_assert.py @@ -3,11 +3,17 @@ from core.enums.app_type import AppType from core.settings import Settings from core.utils.file_utils import Folder +from core.utils.file_utils import File from core.utils.json_utils import JsonUtils from core.utils.perf_utils import PerfUtils +from products.nativescript.tns_helpers import TnsHelpers class TnsAssert(object): + NODE_MODULES = 'node_modules' + TNS_MODULES = os.path.join(NODE_MODULES, 'tns-core-modules') + HOOKS = 'hooks' + @staticmethod def created(app_name, output=None, app_data=None): @@ -17,18 +23,28 @@ def created(app_name, output=None, app_data=None): # Assert output if output is not None: + app = app_name.rsplit('/')[-1] assert 'Now you can navigate to your project with $ cd' in output assert 'After that you can preview it on device by executing $ tns preview' in output assert 'After that you can run it on device/emulator by executing $ tns run ' not in output + assert 'Project {0} was successfully created'.format(app) in output, 'Failed to create {0}'.format(app) # Assert app data if app_data is not None: # Assert app type + assert Folder.exists(os.path.join(app_path, TnsAssert.TNS_MODULES)) + assert Folder.exists(os.path.join(app_path, TnsAssert.NODE_MODULES, 'nativescript-theme-core')) + assert Folder.exists(os.path.join(app_path, TnsAssert.NODE_MODULES, 'nativescript-dev-webpack')) + if app_data.type is AppType.JS: pass elif app_data.type is AppType.TS: + TnsAssert.__verify_created_ts() pass elif app_data.type is AppType.NG: + TnsAssert.__verify_created_ng() + pass + elif app_data.type is AppType.VUE: pass elif app_data.type is AppType.SHARED_NG: pass @@ -77,3 +93,29 @@ def build(app_name, platform=None, release=False, provision=Settings.IOS.DEV_PRO # Assert size if app_data.size is not None: pass + + @staticmethod + def __verify_created_ts(): + app_path = TnsHelpers.get_app_path(app_name='TestAppTS') + assert File.exists(os.path.join(app_path, 'tsconfig.json')) + assert File.exists(os.path.join(app_path, 'webpack.config.js')) + assert File.exists(os.path.join(app_path, 'tsconfig.tns.json')) + assert not File.exists(os.path.join(app_path, 'references.d.ts')) + assert File.exists(os.path.join(app_path, TnsAssert.TNS_MODULES, 'tns-core-modules.d.ts')) + assert File.exists(os.path.join(app_path, TnsAssert.HOOKS, 'before-prepare', + 'nativescript-dev-typescript.js')) + assert File.exists(os.path.join(app_path, TnsAssert.HOOKS, 'before-watch', + 'nativescript-dev-typescript.js')) + + @staticmethod + def __verify_created_ng(): + app_path = TnsHelpers.get_app_path(app_name='TestAppNG') + assert File.exists(os.path.join(app_path, 'tsconfig.json')) + assert File.exists(os.path.join(app_path, 'webpack.config.js')) + assert File.exists(os.path.join(app_path, 'tsconfig.tns.json')) + assert not File.exists(os.path.join(app_path, 'references.d.ts')) + assert File.exists(os.path.join(app_path, TnsAssert.TNS_MODULES, 'tns-core-modules.d.ts')) + assert File.exists(os.path.join(app_path, TnsAssert.HOOKS, 'before-prepare', + 'nativescript-dev-typescript.js')) + assert File.exists(os.path.join(app_path, TnsAssert.HOOKS, 'before-watch', + 'nativescript-dev-typescript.js')) diff --git a/products/nativescript/tns_helpers.py b/products/nativescript/tns_helpers.py index d37a512c..573c9cfa 100644 --- a/products/nativescript/tns_helpers.py +++ b/products/nativescript/tns_helpers.py @@ -1,6 +1,15 @@ +import os + +from core.settings import Settings + class TnsHelpers(object): + @staticmethod + def get_app_path(app_name): + app_path = os.path.join(Settings.TEST_RUN_HOME, app_name) + return app_path + @staticmethod def get_apk(app_name): return '' diff --git a/tests/cli/create/create_tests.py b/tests/cli/create/create_tests.py new file mode 100644 index 00000000..00e4d4e7 --- /dev/null +++ b/tests/cli/create/create_tests.py @@ -0,0 +1,83 @@ +import os + +from core.base_test.tns_test import TnsTest +from core.utils.file_utils import Folder +from data.apps import Apps +from core.settings import Settings +from data.templates import Template +from products.nativescript.tns import Tns + + +class CreateTests(TnsTest): + app_data_JS = Apps.HELLO_WORLD_JS + app_data_TS = Apps.HELLO_WORLD_TS + app_data_NG = Apps.HELLO_WORLD_NG + + js_app = Settings.AppName.DEFAULT + 'JS' + ts_app = Settings.AppName.DEFAULT + 'TS' + ng_app = Settings.AppName.DEFAULT + 'NG' + + js_app_space = Settings.AppName.WITH_SPACE + js_app_dash = Settings.AppName.WITH_DASH + js_app_number = Settings.AppName.WITH_NUMBER + + @classmethod + def setUpClass(cls): + TnsTest.setUpClass() + + def setUp(self): + TnsTest.setUp(self) + Folder.clean(os.path.join(Settings.TEST_RUN_HOME, 'folder')) + Folder.clean(os.path.join(Settings.TEST_RUN_HOME, 'js_app_space')) + Folder.clean(os.path.join(Settings.TEST_RUN_HOME, 'js_app_dash')) + Folder.clean(os.path.join(Settings.TEST_RUN_HOME, 'js_app_number')) + + @classmethod + def tearDownClass(cls): + TnsTest.tearDownClass() + + def test_001_create_app_like_real_user(self): + Tns.create(app_name=self.js_app, app_data=None) + + def test_002_create_app_template_js(self): + """Create app with --template js project without update modules""" + Tns.create(app_name=self.js_app, template=Template.HELLO_WORLD_JS.local_package, + app_data=self.app_data_JS, update=False, verify=False) + + def test_003_create_app_template_ts(self): + """Create app with --template ts project without update modules""" + Tns.create(app_name=self.ts_app, template=Template.HELLO_WORLD_TS.local_package, + app_data=self.app_data_TS, update=False, verify=False) + + def test_004_create_app_template_ng(self): + """Create app with --template ng project without update modules""" + Tns.create(app_name=self.ng_app, template=Template.HELLO_WORLD_NG.local_package, + app_data=self.app_data_NG, update=False, verify=False) + + def test_005_create_project_with_path(self): + """Create project with --path option""" + Tns.create(app_name=self.js_app, template=Template.HELLO_WORLD_JS.local_package, + app_data=self.app_data_JS, path=os.path.join(Settings.TEST_RUN_HOME, 'folder', 'subfolder'), + update=False, verify=False) + assert Folder.exists(os.path.join(Settings.TEST_RUN_HOME, 'folder', 'subfolder', 'TestAppJS')) + + def test_006_create_project_with_space(self): + """ Create project with space is possible, but packageId will skip the space symbol""" + Tns.create(app_name=self.js_app_space, template=Template.HELLO_WORLD_JS.local_package, + app_data=self.app_data_JS, update=False, verify=False) + + def test_007_create_project_with_space(self): + """ Create project with dash is possible, but packageId will skip the dash symbol""" + Tns.create(app_name=self.js_app_dash, template=Template.HELLO_WORLD_JS.local_package, + app_data=self.app_data_JS, update=False, verify=False) + + def test_008_create_project_named_123(self): + """Create app starting with digits should not be possible without --force option""" + Tns.create(app_name=self.js_app_number, template=Template.HELLO_WORLD_JS.local_package, + app_data=self.app_data_JS, update=False, verify=False) + # TODO: package_json contains + + def test_009_create_project_with_appid(self): + """Create project with --appid option""" + Tns.create(app_name=self.js_app, template=Template.HELLO_WORLD_JS.local_package, app_data=self.app_data_JS, + update=False, verify=False, app_id='org.nativescript.MyApp')