|
| 1 | +# pylint: disable=redefined-builtin |
| 2 | +""" |
| 3 | +Tests for tns run on project without tns-core-modules package. |
| 4 | +See https://github.com/NativeScript/nativescript-dev-webpack/issues/1089 |
| 5 | +""" |
| 6 | +import os |
| 7 | + |
| 8 | +from parameterized import parameterized |
| 9 | + |
| 10 | +from core.base_test.tns_run_test import TnsRunTest |
| 11 | +from core.enums.os_type import OSType |
| 12 | +from core.enums.platform_type import Platform |
| 13 | +from core.settings import Settings |
| 14 | +from core.utils.device.simctl import Simctl |
| 15 | +from core.utils.file_utils import Folder, File |
| 16 | +from core.utils.npm import Npm |
| 17 | +from data.templates import Template |
| 18 | +from products.nativescript.run_type import RunType |
| 19 | +from products.nativescript.tns import Tns |
| 20 | +from products.nativescript.tns_logs import TnsLogs |
| 21 | + |
| 22 | + |
| 23 | +# noinspection PyUnusedLocal |
| 24 | +# noinspection PyMethodMayBeStatic |
| 25 | +class TestRunWithScopedPackages(TnsRunTest): |
| 26 | + test_data = [ |
| 27 | + [Template.HELLO_WORLD_JS.name.replace('template-', ''), Template.HELLO_WORLD_JS], |
| 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 | + [Template.MASTER_DETAIL_NG.name.replace('template-', ''), Template.MASTER_DETAIL_NG], |
| 31 | + ] |
| 32 | + |
| 33 | + @parameterized.expand(test_data) |
| 34 | + def test_scoped_package_only(self, app_name, template_info): |
| 35 | + TnsRunTest.setUp(self) |
| 36 | + |
| 37 | + # Create app |
| 38 | + app_path = os.path.join(Settings.TEST_RUN_HOME, app_name) |
| 39 | + Tns.create(app_name=app_name, template=template_info.local_package, update=True) |
| 40 | + Npm.uninstall(package='tns-core-modules', option='--save', folder=app_path) |
| 41 | + Npm.install(package=Settings.Packages.NATIVESCRIPT_CORE, option='--save --save-exact', folder=app_path) |
| 42 | + |
| 43 | + # Replace imports |
| 44 | + if template_info == Template.HELLO_WORLD_TS: |
| 45 | + files = File.find_by_extension(folder=os.path.join(app_path, 'app'), extension='ts') |
| 46 | + for file in files: |
| 47 | + File.replace(path=file, old_string='tns-core-modules', new_string='@nativescript/core', fail_safe=True) |
| 48 | + if template_info == Template.MASTER_DETAIL_NG: |
| 49 | + files = File.find_by_extension(folder=os.path.join(app_path, 'src'), extension='ts') |
| 50 | + for file in files: |
| 51 | + File.replace(path=file, old_string='tns-core-modules', new_string='@nativescript/core', fail_safe=True) |
| 52 | + |
| 53 | + Tns.platform_add_android(app_name=app_name, framework_path=Settings.Android.FRAMEWORK_PATH) |
| 54 | + if Settings.HOST_OS is OSType.OSX: |
| 55 | + Tns.platform_add_ios(app_name=app_name, framework_path=Settings.IOS.FRAMEWORK_PATH) |
| 56 | + |
| 57 | + # Run Android |
| 58 | + result = Tns.run_android(app_name=app_name, device=self.emu.id) |
| 59 | + strings = TnsLogs.run_messages(app_name=app_name, run_type=RunType.UNKNOWN, platform=Platform.ANDROID) |
| 60 | + TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300) |
| 61 | + for text in template_info.texts: |
| 62 | + self.emu.wait_for_text(text=text, timeout=60) |
| 63 | + |
| 64 | + # Run iOS |
| 65 | + Tns.kill() |
| 66 | + if Settings.HOST_OS is OSType.OSX: |
| 67 | + Simctl.uninstall_all(simulator_info=self.sim) |
| 68 | + result = Tns.run_ios(app_name=app_name, device=self.sim.id) |
| 69 | + strings = TnsLogs.run_messages(app_name=app_name, run_type=RunType.UNKNOWN, platform=Platform.IOS) |
| 70 | + TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300) |
| 71 | + for text in template_info.texts: |
| 72 | + self.sim.wait_for_text(text=text, timeout=60) |
| 73 | + |
| 74 | + # Cleanup |
| 75 | + Folder.clean(os.path.join(Settings.TEST_RUN_HOME, app_name)) |
| 76 | + TnsRunTest.tearDown(self) |
0 commit comments