|
| 1 | +# pylint: disable=unused-argument |
| 2 | +# pylint: disable=undefined-variable |
| 3 | + |
| 4 | +import os |
| 5 | + |
| 6 | +from parameterized import parameterized |
| 7 | + |
| 8 | +from core.base_test.tns_test import TnsTest |
| 9 | +from core.enums.os_type import OSType |
| 10 | +from core.enums.platform_type import Platform |
| 11 | +from core.log.log import Log |
| 12 | +from core.settings import Settings |
| 13 | +from core.utils.device.device_manager import DeviceManager |
| 14 | +from core.utils.npm import Npm |
| 15 | +from data.templates import Template |
| 16 | +from products.nativescript.tns import Tns |
| 17 | +from products.nativescript.tns_assert import TnsAssert |
| 18 | + |
| 19 | +APP_NAME = Settings.AppName.DEFAULT |
| 20 | + |
| 21 | +TEST_DATA = [ |
| 22 | + ('jasmine-js-android', 'jasmine', Template.HELLO_WORLD_JS, Platform.ANDROID), |
| 23 | + ('jasmine-ng-android', 'jasmine', Template.HELLO_WORLD_NG, Platform.ANDROID), |
| 24 | + ('mocha-js-android', 'mocha', Template.HELLO_WORLD_JS, Platform.ANDROID), |
| 25 | + ('mocha-ng-android', 'mocha', Template.HELLO_WORLD_NG, Platform.ANDROID), |
| 26 | + ('qunit-js-android', 'qunit', Template.HELLO_WORLD_JS, Platform.ANDROID), |
| 27 | +] |
| 28 | + |
| 29 | +TEST_DATA_OSX = [ |
| 30 | + ('jasmine-js-android', 'jasmine', Template.HELLO_WORLD_JS, Platform.ANDROID), |
| 31 | + ('jasmine-js-ios', 'jasmine', Template.HELLO_WORLD_JS, Platform.IOS), |
| 32 | + ('jasmine-ng-android', 'jasmine', Template.HELLO_WORLD_NG, Platform.ANDROID), |
| 33 | + ('jasmine-ng-ios', 'jasmine', Template.HELLO_WORLD_NG, Platform.IOS), |
| 34 | + ('mocha-js-android', 'mocha', Template.HELLO_WORLD_JS, Platform.ANDROID), |
| 35 | + ('mocha-js-ios', 'mocha', Template.HELLO_WORLD_JS, Platform.IOS), |
| 36 | + ('mocha-ng-android', 'mocha', Template.HELLO_WORLD_NG, Platform.ANDROID), |
| 37 | + ('mocha-ng-ios', 'mocha', Template.HELLO_WORLD_NG, Platform.IOS), |
| 38 | + ('qunit-js-android', 'qunit', Template.HELLO_WORLD_JS, Platform.ANDROID), |
| 39 | + ('qunit-js-ios', 'qunit', Template.HELLO_WORLD_JS, Platform.IOS), |
| 40 | +] |
| 41 | + |
| 42 | + |
| 43 | +def get_data(): |
| 44 | + if Settings.HOST_OS == OSType.OSX: |
| 45 | + return TEST_DATA_OSX |
| 46 | + else: |
| 47 | + return TEST_DATA |
| 48 | + |
| 49 | + |
| 50 | +# noinspection PyMethodMayBeStatic,PyUnusedLocal |
| 51 | +class PrepareAndBuildPerfTests(TnsTest): |
| 52 | + |
| 53 | + @classmethod |
| 54 | + def setUpClass(cls): |
| 55 | + TnsTest.setUpClass() |
| 56 | + cls.emu = DeviceManager.Emulator.ensure_available(Settings.Emulators.DEFAULT) |
| 57 | + if Settings.HOST_OS is OSType.OSX: |
| 58 | + cls.sim = DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT) |
| 59 | + |
| 60 | + def setUp(self): |
| 61 | + TnsTest.setUp(self) |
| 62 | + |
| 63 | + @classmethod |
| 64 | + def tearDownClass(cls): |
| 65 | + TnsTest.tearDownClass() |
| 66 | + |
| 67 | + @parameterized.expand(get_data()) |
| 68 | + def test_100(self, title, framework, template, platform): |
| 69 | + # Create app |
| 70 | + Tns.create(app_name=APP_NAME, template=template.local_package) |
| 71 | + |
| 72 | + # Add platforms |
| 73 | + if platform == Platform.ANDROID: |
| 74 | + Tns.platform_add_android(app_name=APP_NAME, framework_path=Settings.Android.FRAMEWORK_PATH) |
| 75 | + elif platform == Platform.IOS: |
| 76 | + Tns.platform_add_ios(app_name=APP_NAME, framework_path=Settings.IOS.FRAMEWORK_PATH) |
| 77 | + else: |
| 78 | + raise Exception('Unknown platform: ' + str(platform)) |
| 79 | + |
| 80 | + # Init tests and run tests |
| 81 | + if Settings.HOST_OS == OSType.WINDOWS and framework == 'qunit': |
| 82 | + # Hack for qunit on windows (see https://github.com/NativeScript/nativescript-cli/issues/4333) |
| 83 | + Npm.install(package='qunit@2', option='--save-dev', folder=os.path.join(Settings.TEST_RUN_HOME, APP_NAME)) |
| 84 | + # Tns test init will still fail with exit code 1, so we use `verify=False` and then assert logs. |
| 85 | + result = Tns.test_init(app_name=APP_NAME, framework=framework, verify=False) |
| 86 | + TnsAssert.test_initialized(app_name=APP_NAME, framework=framework, output=result.output) |
| 87 | + else: |
| 88 | + Tns.test_init(app_name=APP_NAME, framework=framework) |
| 89 | + |
| 90 | + # Run Tests |
| 91 | + if Settings.HOST_OS != OSType.WINDOWS: |
| 92 | + Tns.test(app_name=APP_NAME, platform=Platform.ANDROID, emulator=True, justlaunch=True) |
| 93 | + # TODO: Modify hello-world test with some real test (importing modules) and run the test again. |
| 94 | + else: |
| 95 | + Log.info('Due to unknown issues --justlauch do not exit on Windows when tests are executed on Jenkins!') |
| 96 | + # TODO: Fix it! |
| 97 | + |
| 98 | + def test_400_invalid_framework_name(self): |
| 99 | + Tns.create(app_name=APP_NAME, template=Template.HELLO_WORLD_JS.local_package) |
| 100 | + result = Tns.test_init(app_name=APP_NAME, framework='jasmin', verify=False) |
| 101 | + assert 'Unknown or unsupported unit testing framework: jasmin' in result.output |
0 commit comments