Skip to content

Commit ea8e143

Browse files
committedDec 10, 2019
chore: re-write tests to be data driven
1 parent 1106223 commit ea8e143

File tree

1 file changed

+46
-31
lines changed

1 file changed

+46
-31
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,66 @@
1+
"""
2+
Tests for tns run on project without tns-core-modules package.
3+
See https://github.com/NativeScript/nativescript-dev-webpack/issues/1089
4+
"""
15
import os
2-
import unittest
6+
7+
from parameterized import parameterized
38

49
from core.base_test.tns_run_test import TnsRunTest
510
from core.enums.os_type import OSType
611
from core.enums.platform_type import Platform
712
from core.settings import Settings
13+
from core.utils.device.simctl import Simctl
14+
from core.utils.file_utils import Folder
815
from core.utils.npm import Npm
9-
from data.changes import Changes
1016
from data.templates import Template
1117
from products.nativescript.run_type import RunType
1218
from products.nativescript.tns import Tns
1319
from products.nativescript.tns_logs import TnsLogs
1420

1521

16-
class TestRunWithScopePackageOnly(TnsRunTest):
17-
app_name = Settings.AppName.DEFAULT
18-
app_path = os.path.join(Settings.TEST_RUN_HOME, Settings.AppName.DEFAULT)
22+
# noinspection PyUnusedLocal
23+
# noinspection PyMethodMayBeStatic
24+
class TestRunWithScopedPackages(TnsRunTest):
25+
test_data = [
26+
[Template.HELLO_WORLD_JS.name.replace('template-', ''), Template.HELLO_WORLD_JS],
27+
# Skip TS projects because on TS projects we need to update all requires in the app in order to make it work.
28+
# [Template.HELLO_WORLD_TS.name.replace('template-', ''), Template.HELLO_WORLD_TS],
29+
[Template.HELLO_WORLD_NG.name.replace('template-', ''), Template.HELLO_WORLD_NG],
30+
# Skip MasterDetailNG, it fails, need to be investigated.
31+
# [Template.MASTER_DETAIL_NG.name.replace('template-', ''), Template.MASTER_DETAIL_NG],
32+
]
1933

20-
@classmethod
21-
def setUpClass(cls):
22-
TnsRunTest.setUpClass()
34+
@parameterized.expand(test_data)
35+
def test_scoped_package_only(self, app_name, template_info):
36+
TnsRunTest.setUp(self)
2337

2438
# Create app
25-
Tns.create(app_name=cls.app_name, template=Template.HELLO_WORLD_NG.local_package, update=True)
26-
Npm.uninstall(package='tns-core-modules', option='--save', folder=cls.app_path)
27-
Npm.install(package=Settings.Packages.NATIVESCRIPT_CORE, option='--save --save-exact', folder=cls.app_path)
28-
Tns.platform_add_android(app_name=cls.app_name, framework_path=Settings.Android.FRAMEWORK_PATH)
39+
app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
40+
Tns.create(app_name=app_name, template=template_info.local_package, update=True)
41+
Npm.uninstall(package='tns-core-modules', option='--save', folder=app_path)
42+
Npm.install(package=Settings.Packages.NATIVESCRIPT_CORE, option='--save --save-exact', folder=app_path)
43+
Tns.platform_add_android(app_name=app_name, framework_path=Settings.Android.FRAMEWORK_PATH)
2944
if Settings.HOST_OS is OSType.OSX:
30-
Tns.platform_add_ios(app_name=cls.app_name, framework_path=Settings.IOS.FRAMEWORK_PATH)
31-
32-
def setUp(self):
33-
TnsRunTest.setUp(self)
34-
35-
@classmethod
36-
def tearDownClass(cls):
37-
TnsRunTest.tearDownClass()
45+
Tns.platform_add_ios(app_name=app_name, framework_path=Settings.IOS.FRAMEWORK_PATH)
3846

39-
def test_100_run_android(self):
40-
self.run_app(Platform.ANDROID, self.emu)
47+
# Run Android
48+
result = Tns.run_android(app_name=app_name, device=self.emu.id)
49+
strings = TnsLogs.run_messages(app_name=app_name, run_type=RunType.UNKNOWN, platform=Platform.ANDROID)
50+
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
51+
for text in template_info.texts:
52+
self.emu.wait_for_text(text=text, timeout=60)
4153

42-
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
43-
def test_100_run_ios(self):
44-
self.run_app(Platform.IOS, self.sim)
54+
# Run iOS
55+
Tns.kill()
56+
if Settings.HOST_OS is OSType.OSX:
57+
Simctl.uninstall_all(simulator_info=self.sim)
58+
result = Tns.run_ios(app_name=app_name, device=self.sim.id)
59+
strings = TnsLogs.run_messages(app_name=app_name, run_type=RunType.UNKNOWN, platform=Platform.IOS)
60+
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
61+
for text in template_info.texts:
62+
self.sim.wait_for_text(text=text, timeout=60)
4563

46-
def run_app(self, platform, device):
47-
result = Tns.run(app_name=self.app_name, platform=platform, emulator=True, wait=False)
48-
strings = TnsLogs.run_messages(app_name=self.app_name, platform=platform, run_type=RunType.UNKNOWN,
49-
device=device)
50-
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=240)
51-
device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
64+
# Cleanup
65+
Folder.clean(os.path.join(Settings.TEST_RUN_HOME, app_name))
66+
TnsRunTest.tearDown(self)

0 commit comments

Comments
 (0)
Please sign in to comment.