Skip to content

Commit 177c6f0

Browse files
authored
feat: add webpack param to TnsAssert.created() (#24)
Introduce `webpack` param in TnsAssert.created(). Fix code sharing tests.
1 parent 688a96a commit 177c6f0

File tree

2 files changed

+35
-25
lines changed

2 files changed

+35
-25
lines changed

products/nativescript/tns_assert.py

+19-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class TnsAssert(object):
1313

1414
@staticmethod
15-
def created(app_name, output=None, app_data=None, path=Settings.TEST_RUN_HOME, theme=True):
15+
def created(app_name, output=None, app_data=None, path=Settings.TEST_RUN_HOME, webpack=True, theme=True):
1616
"""
1717
Verify app is created properly.
1818
:param app_name: Name of the app.
@@ -33,31 +33,33 @@ def created(app_name, output=None, app_data=None, path=Settings.TEST_RUN_HOME, t
3333
assert 'After that you can run it on device/emulator by executing $ tns run <platform>' not in output
3434
assert 'Project {0} was successfully created'.format(app) in output, 'Failed to create {0}'.format(app)
3535

36-
# Assert app data
37-
if app_data is not None:
38-
# Verify modules installed
39-
node_path = TnsHelpers.get_app_node_modules_path(app_name=app_name, path=path)
40-
assert Folder.exists(os.path.join(node_path, 'tns-core-modules')), '{N} theme do not exists in app.'
41-
assert File.exists(os.path.join(node_path, 'tns-core-modules', 'tns-core-modules.d.ts'))
36+
# Verify modules installed
37+
node_path = TnsHelpers.get_app_node_modules_path(app_name=app_name, path=path)
38+
assert Folder.exists(os.path.join(node_path, 'tns-core-modules')), '{N} theme do not exists in app.'
39+
assert File.exists(os.path.join(node_path, 'tns-core-modules', 'tns-core-modules.d.ts'))
4240

43-
# Verify {N} core theme is installed
44-
if theme:
45-
assert Folder.exists(os.path.join(node_path, 'nativescript-theme-core')), '{N} theme do not exists.'
41+
# Verify {N} core theme is installed
42+
if theme:
43+
assert Folder.exists(os.path.join(node_path, 'nativescript-theme-core')), '{N} theme do not exists.'
4644

47-
# Verify webpack is installed
45+
# Verify webpack is installed
46+
if webpack:
4847
before_watch_hooks = os.path.join(app_path, 'hooks', 'before-watch')
4948
assert Folder.exists(os.path.join(node_path, 'nativescript-dev-webpack')), 'Webpack not installed in app.'
5049
assert File.exists(os.path.join(app_path, 'webpack.config.js')), 'Missing webpack config.'
5150
assert File.exists(os.path.join(before_watch_hooks, 'nativescript-dev-webpack.js')), 'Hooks not installed.'
5251

53-
# Verify typescript in TS and NG apps:
54-
if app_data.app_type in {AppType.TS, AppType.NG, AppType.SHARED_NG}:
55-
assert Folder.exists(os.path.join(node_path, 'nativescript-dev-typescript')), 'TS not installed in app.'
56-
assert File.exists(os.path.join(app_path, 'tsconfig.json')), 'Missing config.'
52+
# Verify typescript in TS and NG apps:
53+
if app_data.app_type in {AppType.TS, AppType.NG, AppType.SHARED_NG}:
54+
assert Folder.exists(os.path.join(node_path, 'nativescript-dev-typescript')), 'TS not installed in app.'
55+
assert File.exists(os.path.join(app_path, 'tsconfig.json')), 'Missing config.'
56+
if webpack:
5757
assert File.exists(os.path.join(app_path, 'tsconfig.tns.json')), 'Missing config.'
58-
assert File.exists(os.path.join(before_watch_hooks, 'nativescript-dev-typescript.js')), \
59-
'Hooks not installed.'
58+
assert File.exists(os.path.join(before_watch_hooks, 'nativescript-dev-typescript.js')), \
59+
'Hooks not installed.'
6060

61+
# Assert app data
62+
if app_data is not None:
6163
# Assert app id
6264
if app_data.bundle_id is not None:
6365
pass

tests/code_sharing/ng_new_tests.py

+16-8
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,25 @@ def create_and_run(shared=True, sample=False, theme=True, style=None, prefix=Non
101101
else:
102102
app_data = Apps.SCHEMATICS_SHARED
103103

104+
# Create app
105+
NGNewTests.create_app(app_data=app_data, shared=shared, sample=sample, theme=theme, style=style,
106+
prefix=prefix, source_dir=source_dir, webpack=webpack)
107+
108+
# Update the app
109+
if Settings.ENV != EnvironmentType.LIVE:
110+
App.update(app_name=NGNewTests.app_name, modules=True, angular=True, typescript=False, web_pack=False)
111+
112+
# Run the app
113+
NGNewTests.run_bundle(app_data=app_data, webpack=webpack, shared=shared, theme=theme)
114+
115+
@staticmethod
116+
def create_app(app_data, shared, sample, theme, style, prefix, source_dir, webpack):
104117
# Create shared project with sample data
105118
result = NG.new(collection=NS_SCHEMATICS, project=NGNewTests.app_name, theme=theme, shared=shared,
106119
sample=sample, style=style, prefix=prefix, source_dir=source_dir, webpack=webpack)
107120

108121
# Verify valid {N} app is created
109-
theme = True
110-
if style is None:
111-
theme = False
112-
TnsAssert.created(app_name=NGNewTests.app_name, app_data=app_data, theme=theme)
122+
TnsAssert.created(app_name=NGNewTests.app_name, app_data=app_data, theme=theme, webpack=webpack)
113123
assert 'Directory is already under version control. Skipping initialization of git.' in result.output, \
114124
'Git init should be skipped because app is created already existing repo (the one with tests).'
115125

@@ -152,10 +162,8 @@ def create_and_run(shared=True, sample=False, theme=True, style=None, prefix=Non
152162
source_dir = 'src'
153163
assert Folder.exists(os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, source_dir))
154164

155-
# Update the app
156-
if Settings.ENV != EnvironmentType.LIVE:
157-
App.update(app_name=NGNewTests.app_name, modules=True, angular=True, typescript=False, web_pack=False)
158-
165+
@staticmethod
166+
def run_bundle(app_data, webpack, shared, theme):
159167
# Run android (if webpack is available -> use --bundle)
160168
Tns.run(app_name=NGNewTests.app_name, platform=Platform.ANDROID, emulator=True, bundle=webpack)
161169
for text in app_data.texts:

0 commit comments

Comments
 (0)