|
| 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 | +""" |
1 | 5 | import os
|
2 |
| -import unittest |
| 6 | + |
| 7 | +from parameterized import parameterized |
3 | 8 |
|
4 | 9 | from core.base_test.tns_run_test import TnsRunTest
|
5 | 10 | from core.enums.os_type import OSType
|
6 | 11 | from core.enums.platform_type import Platform
|
7 | 12 | from core.settings import Settings
|
| 13 | +from core.utils.device.simctl import Simctl |
| 14 | +from core.utils.file_utils import Folder |
8 | 15 | from core.utils.npm import Npm
|
9 |
| -from data.changes import Changes |
10 | 16 | from data.templates import Template
|
11 | 17 | from products.nativescript.run_type import RunType
|
12 | 18 | from products.nativescript.tns import Tns
|
13 | 19 | from products.nativescript.tns_logs import TnsLogs
|
14 | 20 |
|
15 | 21 |
|
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 | + ] |
19 | 33 |
|
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) |
23 | 37 |
|
24 | 38 | # 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) |
29 | 44 | 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) |
38 | 46 |
|
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) |
41 | 53 |
|
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) |
45 | 63 |
|
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