Skip to content

Commit a4d3465

Browse files
Merge pull request #11 from NativeScript/mivanova/create_tests
feat: tests for `tns create`
2 parents 1f6cd2c + 86c2740 commit a4d3465

File tree

5 files changed

+138
-0
lines changed

5 files changed

+138
-0
lines changed

core/settings/Settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ class AppName(object):
140140
DEFAULT_NG = 'TestApp'
141141
WITH_DASH = 'tns-app'
142142
WITH_SPACE = 'Test App'
143+
WITH_NUMBER = '123'

data/apps.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ class Apps(object):
5454
SCHEMATICS_SHARED = AppInfo(type=AppType.SHARED_NG, id=None, size=__shared_size, texts=['Welcome'])
5555
SCHEMATICS_SHARED_SAMPLE = AppInfo(type=AppType.SHARED_NG, id=None, size=__shared_size, texts=['Barcelona'])
5656
SCHEMATICS_NS = AppInfo(type=AppType.NG, id=None, size=__ns_only_size, texts=['Tap the button'])
57+
HELLO_WORLD_JS = AppInfo(type=AppType.JS, id=None, size=None, texts=None)
58+
HELLO_WORLD_TS = AppInfo(type=AppType.TS, id=None, size=None, texts=None)
59+
HELLO_WORLD_NG = AppInfo(type=AppType.NG, id=None, size=None, texts=None)

products/nativescript/tns_assert.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
from core.enums.app_type import AppType
44
from core.settings import Settings
55
from core.utils.file_utils import Folder
6+
from core.utils.file_utils import File
67
from core.utils.json_utils import JsonUtils
78
from core.utils.perf_utils import PerfUtils
9+
from products.nativescript.tns_helpers import TnsHelpers
810

911

1012
class TnsAssert(object):
13+
NODE_MODULES = 'node_modules'
14+
TNS_MODULES = os.path.join(NODE_MODULES, 'tns-core-modules')
15+
HOOKS = 'hooks'
16+
1117
@staticmethod
1218
def created(app_name, output=None, app_data=None):
1319

@@ -17,18 +23,28 @@ def created(app_name, output=None, app_data=None):
1723

1824
# Assert output
1925
if output is not None:
26+
app = app_name.rsplit('/')[-1]
2027
assert 'Now you can navigate to your project with $ cd' in output
2128
assert 'After that you can preview it on device by executing $ tns preview' in output
2229
assert 'After that you can run it on device/emulator by executing $ tns run <platform>' not in output
30+
assert 'Project {0} was successfully created'.format(app) in output, 'Failed to create {0}'.format(app)
2331

2432
# Assert app data
2533
if app_data is not None:
2634
# Assert app type
35+
assert Folder.exists(os.path.join(app_path, TnsAssert.TNS_MODULES))
36+
assert Folder.exists(os.path.join(app_path, TnsAssert.NODE_MODULES, 'nativescript-theme-core'))
37+
assert Folder.exists(os.path.join(app_path, TnsAssert.NODE_MODULES, 'nativescript-dev-webpack'))
38+
2739
if app_data.type is AppType.JS:
2840
pass
2941
elif app_data.type is AppType.TS:
42+
TnsAssert.__verify_created_ts()
3043
pass
3144
elif app_data.type is AppType.NG:
45+
TnsAssert.__verify_created_ng()
46+
pass
47+
elif app_data.type is AppType.VUE:
3248
pass
3349
elif app_data.type is AppType.SHARED_NG:
3450
pass
@@ -77,3 +93,29 @@ def build(app_name, platform=None, release=False, provision=Settings.IOS.DEV_PRO
7793
# Assert size
7894
if app_data.size is not None:
7995
pass
96+
97+
@staticmethod
98+
def __verify_created_ts():
99+
app_path = TnsHelpers.get_app_path(app_name='TestAppTS')
100+
assert File.exists(os.path.join(app_path, 'tsconfig.json'))
101+
assert File.exists(os.path.join(app_path, 'webpack.config.js'))
102+
assert File.exists(os.path.join(app_path, 'tsconfig.tns.json'))
103+
assert not File.exists(os.path.join(app_path, 'references.d.ts'))
104+
assert File.exists(os.path.join(app_path, TnsAssert.TNS_MODULES, 'tns-core-modules.d.ts'))
105+
assert File.exists(os.path.join(app_path, TnsAssert.HOOKS, 'before-prepare',
106+
'nativescript-dev-typescript.js'))
107+
assert File.exists(os.path.join(app_path, TnsAssert.HOOKS, 'before-watch',
108+
'nativescript-dev-typescript.js'))
109+
110+
@staticmethod
111+
def __verify_created_ng():
112+
app_path = TnsHelpers.get_app_path(app_name='TestAppNG')
113+
assert File.exists(os.path.join(app_path, 'tsconfig.json'))
114+
assert File.exists(os.path.join(app_path, 'webpack.config.js'))
115+
assert File.exists(os.path.join(app_path, 'tsconfig.tns.json'))
116+
assert not File.exists(os.path.join(app_path, 'references.d.ts'))
117+
assert File.exists(os.path.join(app_path, TnsAssert.TNS_MODULES, 'tns-core-modules.d.ts'))
118+
assert File.exists(os.path.join(app_path, TnsAssert.HOOKS, 'before-prepare',
119+
'nativescript-dev-typescript.js'))
120+
assert File.exists(os.path.join(app_path, TnsAssert.HOOKS, 'before-watch',
121+
'nativescript-dev-typescript.js'))

products/nativescript/tns_helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
import os
2+
3+
from core.settings import Settings
4+
15

26
class TnsHelpers(object):
37

8+
@staticmethod
9+
def get_app_path(app_name):
10+
app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
11+
return app_path
12+
413
@staticmethod
514
def get_apk(app_name):
615
return ''

tests/cli/create/create_tests.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import os
2+
3+
from core.base_test.tns_test import TnsTest
4+
from core.utils.file_utils import Folder
5+
from data.apps import Apps
6+
from core.settings import Settings
7+
from data.templates import Template
8+
from products.nativescript.tns import Tns
9+
10+
11+
class CreateTests(TnsTest):
12+
app_data_JS = Apps.HELLO_WORLD_JS
13+
app_data_TS = Apps.HELLO_WORLD_TS
14+
app_data_NG = Apps.HELLO_WORLD_NG
15+
16+
js_app = Settings.AppName.DEFAULT + 'JS'
17+
ts_app = Settings.AppName.DEFAULT + 'TS'
18+
ng_app = Settings.AppName.DEFAULT + 'NG'
19+
20+
js_app_space = Settings.AppName.WITH_SPACE
21+
js_app_dash = Settings.AppName.WITH_DASH
22+
js_app_number = Settings.AppName.WITH_NUMBER
23+
24+
@classmethod
25+
def setUpClass(cls):
26+
TnsTest.setUpClass()
27+
28+
def setUp(self):
29+
TnsTest.setUp(self)
30+
Folder.clean(os.path.join(Settings.TEST_RUN_HOME, 'folder'))
31+
Folder.clean(os.path.join(Settings.TEST_RUN_HOME, 'js_app_space'))
32+
Folder.clean(os.path.join(Settings.TEST_RUN_HOME, 'js_app_dash'))
33+
Folder.clean(os.path.join(Settings.TEST_RUN_HOME, 'js_app_number'))
34+
35+
@classmethod
36+
def tearDownClass(cls):
37+
TnsTest.tearDownClass()
38+
39+
def test_001_create_app_like_real_user(self):
40+
Tns.create(app_name=self.js_app, app_data=None)
41+
42+
def test_002_create_app_template_js(self):
43+
"""Create app with --template js project without update modules"""
44+
Tns.create(app_name=self.js_app, template=Template.HELLO_WORLD_JS.local_package,
45+
app_data=self.app_data_JS, update=False, verify=False)
46+
47+
def test_003_create_app_template_ts(self):
48+
"""Create app with --template ts project without update modules"""
49+
Tns.create(app_name=self.ts_app, template=Template.HELLO_WORLD_TS.local_package,
50+
app_data=self.app_data_TS, update=False, verify=False)
51+
52+
def test_004_create_app_template_ng(self):
53+
"""Create app with --template ng project without update modules"""
54+
Tns.create(app_name=self.ng_app, template=Template.HELLO_WORLD_NG.local_package,
55+
app_data=self.app_data_NG, update=False, verify=False)
56+
57+
def test_005_create_project_with_path(self):
58+
"""Create project with --path option"""
59+
Tns.create(app_name=self.js_app, template=Template.HELLO_WORLD_JS.local_package,
60+
app_data=self.app_data_JS, path=os.path.join(Settings.TEST_RUN_HOME, 'folder', 'subfolder'),
61+
update=False, verify=False)
62+
assert Folder.exists(os.path.join(Settings.TEST_RUN_HOME, 'folder', 'subfolder', 'TestAppJS'))
63+
64+
def test_006_create_project_with_space(self):
65+
""" Create project with space is possible, but packageId will skip the space symbol"""
66+
Tns.create(app_name=self.js_app_space, template=Template.HELLO_WORLD_JS.local_package,
67+
app_data=self.app_data_JS, update=False, verify=False)
68+
69+
def test_007_create_project_with_space(self):
70+
""" Create project with dash is possible, but packageId will skip the dash symbol"""
71+
Tns.create(app_name=self.js_app_dash, template=Template.HELLO_WORLD_JS.local_package,
72+
app_data=self.app_data_JS, update=False, verify=False)
73+
74+
def test_008_create_project_named_123(self):
75+
"""Create app starting with digits should not be possible without --force option"""
76+
Tns.create(app_name=self.js_app_number, template=Template.HELLO_WORLD_JS.local_package,
77+
app_data=self.app_data_JS, update=False, verify=False)
78+
# TODO: package_json contains
79+
80+
def test_009_create_project_with_appid(self):
81+
"""Create project with --appid option"""
82+
Tns.create(app_name=self.js_app, template=Template.HELLO_WORLD_JS.local_package, app_data=self.app_data_JS,
83+
update=False, verify=False, app_id='org.nativescript.MyApp')

0 commit comments

Comments
 (0)