Skip to content

feat: tests for tns create #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/settings/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,4 @@ class AppName(object):
DEFAULT_NG = 'TestApp'
WITH_DASH = 'tns-app'
WITH_SPACE = 'Test App'
WITH_NUMBER = '123'
3 changes: 3 additions & 0 deletions data/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
42 changes: 42 additions & 0 deletions products/nativescript/tns_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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 <platform>' 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
Expand Down Expand Up @@ -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'))
9 changes: 9 additions & 0 deletions products/nativescript/tns_helpers.py
Original file line number Diff line number Diff line change
@@ -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 ''
Expand Down
83 changes: 83 additions & 0 deletions tests/cli/create/create_tests.py
Original file line number Diff line number Diff line change
@@ -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')