From 234265855847e650d5a76297cb90418d9ed8b190 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Thu, 24 Mar 2016 17:33:04 +0200 Subject: [PATCH] Add angular/ng template tests --- core/tns/tns.py | 11 ++--- tests/build/build_android_ng.py | 53 ++++++++++++++++++++++ tests/build/build_ios_ng.py | 56 +++++++++++++++++++++++ tests/build/create_ng.py | 63 ++++++++++++++++++++++++++ tests/build/prepare_android.py | 55 ++++++++++++++--------- tests/build/prepare_ios.py | 79 ++++++++++++++++++++------------- tns_tests_runner.py | 14 ++++++ 7 files changed, 274 insertions(+), 57 deletions(-) create mode 100644 tests/build/build_android_ng.py create mode 100644 tests/build/build_ios_ng.py create mode 100644 tests/build/create_ng.py diff --git a/core/tns/tns.py b/core/tns/tns.py index 3e65ebc2..0cd5a9be 100644 --- a/core/tns/tns.py +++ b/core/tns/tns.py @@ -36,11 +36,12 @@ def create_app(app_name, path=None, app_id=None, copy_from=None, template=None, if app_id is not None: command += " --appid " + app_id - # By default --copy-from template-hello-world - if copy_from is not None: - command += " --copy-from " + copy_from - else: - command += " --copy-from " + SUT_ROOT_FOLDER + os.path.sep + "template-hello-world" + if template is None: + # By default --copy-from template-hello-world + if copy_from is not None: + command += " --copy-from " + copy_from + else: + command += " --copy-from " + SUT_ROOT_FOLDER + os.path.sep + "template-hello-world" if template is not None: command += " --template " + template diff --git a/tests/build/build_android_ng.py b/tests/build/build_android_ng.py new file mode 100644 index 00000000..ba477c65 --- /dev/null +++ b/tests/build/build_android_ng.py @@ -0,0 +1,53 @@ +import unittest + +from core.osutils.command import run +from core.osutils.file import File +from core.osutils.folder import Folder +from core.settings.settings import ANDROID_RUNTIME_PATH, TNS_PATH, \ + ANDROID_KEYSTORE_PASS, ANDROID_KEYSTORE_ALIAS, ANDROID_KEYSTORE_PATH, ANDROID_KEYSTORE_ALIAS_PASS +from core.tns.tns import Tns + + +class BuildAndroidNG(unittest.TestCase): + + @classmethod + def setUpClass(cls): + Folder.cleanup('./TNS_App') + output = run(TNS_PATH + " create TNS_App --ng") + assert "successfully created" in output + Tns.platform_add( + platform="android", + path="TNS_App", + framework_path=ANDROID_RUNTIME_PATH) + + def setUp(self): + + print "" + print "#####" + print self.id() + print "#####" + print "" + + def tearDown(self): + pass + + @classmethod + def tearDownClass(cls): + Folder.cleanup('./TNS_App') + + def test_010_build_android_ng_project(self): + Tns.build(platform="android", path="TNS_App") + assert File.exists("TNS_App/platforms/android/build/outputs/apk/TNSApp-debug.apk") + + def test_210_build_android_ng_project(self): + output = run(TNS_PATH + " build android --keyStorePath " + ANDROID_KEYSTORE_PATH + + " --keyStorePassword " + ANDROID_KEYSTORE_PASS + + " --keyStoreAlias " + ANDROID_KEYSTORE_ALIAS + + " --keyStoreAliasPassword " + ANDROID_KEYSTORE_ALIAS_PASS + + " --release --path TNS_App") + + assert "Project successfully prepared" in output + assert "BUILD SUCCESSFUL" in output + + assert "Project successfully built" in output + assert File.exists("TNS_App/platforms/android/build/outputs/apk/TNSApp-release.apk") diff --git a/tests/build/build_ios_ng.py b/tests/build/build_ios_ng.py new file mode 100644 index 00000000..6cba770b --- /dev/null +++ b/tests/build/build_ios_ng.py @@ -0,0 +1,56 @@ +import unittest + +from core.osutils.command import run +from core.osutils.file import File +from core.osutils.folder import Folder +from core.settings.settings import IOS_RUNTIME_SYMLINK_PATH, TNS_PATH +from core.tns.tns import Tns +from core.xcode.xcode import Xcode + + +class BuildiOSNG(unittest.TestCase): + + @classmethod + def setUpClass(cls): + Xcode.cleanup_cache() + Folder.cleanup('./TNS_App') + + output = run(TNS_PATH + " create TNS_App --ng") + assert "successfully created" in output + Tns.platform_add( + platform="ios", + path="TNS_App", + framework_path=IOS_RUNTIME_SYMLINK_PATH, symlink=True) + + def setUp(self): + print "" + print "#####" + print self.id() + print "#####" + print "" + + def tearDown(self): + pass + + @classmethod + def tearDownClass(cls): + Folder.cleanup('./TNS_App') + + def test_010_build_ios_ng_project(self): + output = run(TNS_PATH + " build ios --path TNS_App") + assert "Project successfully prepared" in output + assert "build/emulator/TNSApp.app" in output + assert "** BUILD SUCCEEDED **" in output + assert "Project successfully built" in output + assert File.exists("TNS_App/platforms/ios/build/emulator/TNSApp.app") + + def test_210_build_ios_ng_project_release_fordevice(self): + output = run(TNS_PATH + + " build ios --path TNS_App --for-device --release") + assert "Project successfully prepared" in output + assert "CONFIGURATION Release" in output + assert "CodeSign" in output + assert "build/device/TNSApp.app" in output + assert "** BUILD SUCCEEDED **" in output + assert "Project successfully built" in output + assert File.exists("TNS_App/platforms/ios/build/device/TNSApp.ipa") diff --git a/tests/build/create_ng.py b/tests/build/create_ng.py new file mode 100644 index 00000000..3e00b36f --- /dev/null +++ b/tests/build/create_ng.py @@ -0,0 +1,63 @@ +import unittest + +from nose_parameterized import parameterized + +from core.osutils.command import run +from core.osutils.folder import Folder +from core.settings.settings import TNS_PATH +from core.tns.tns import Tns + + +class CreateNG(unittest.TestCase): + + def setUp(self): + print "" + print "#####" + print self.id() + print "#####" + print "" + + Folder.cleanup('./TNS_App') + + def tearDown(self): + Folder.cleanup('./TNS_App') + + def assert_angular_project(self): + output = run("cat TNS_App/package.json") + assert "angular2" in output + assert "nativescript-angular" in output + assert "tns-core-modules" in output + assert "nativescript-dev-typescript" in output + + assert Folder.exists("TNS_App/node_modules/angular2") + assert Folder.exists("TNS_App/node_modules/nativescript-angular") + assert Folder.exists("TNS_App/node_modules/nativescript-dev-typescript") + assert Folder.exists("TNS_App/node_modules/tns-core-modules") + + assert Folder.exists("TNS_App/hooks") + assert Folder.exists("TNS_App/app/App_Resources") + + def test_101_create_ng_project(self): + output = run(TNS_PATH + " create TNS_App --ng") + assert "successfully created" in output + self.assert_angular_project() + + @parameterized.expand([ + "tns-template-hello-world-ng", + "https://github.com/NativeScript/template-hello-world-ng.git", + "angular", + "ng", + ]) + def test_102_create_project_with_template_ng(self, template_source): + Tns.create_app(app_name="TNS_App", template=template_source) + self.assert_angular_project() + + def test_401_create_project_with_template_no_value(self): + output = run(TNS_PATH + " create TNS_App --template") + assert "successfully created" not in output + assert "requires non-empty value" in output + + def test_402_create_project_with_template_and_ng(self): + output = run(TNS_PATH + " create TNS_App --template --ng") + assert "successfully created" not in output + assert "requires non-empty value" in output diff --git a/tests/build/prepare_android.py b/tests/build/prepare_android.py index 951710cc..144ce642 100644 --- a/tests/build/prepare_android.py +++ b/tests/build/prepare_android.py @@ -12,6 +12,7 @@ class PrepareAndroid(unittest.TestCase): + def setUp(self): print "" print "#####" @@ -66,7 +67,40 @@ def test_002_prepare_android_inside_project(self): assert not File.exists( 'TNS_App/platforms/android/src/main/assets/app/tns_modules/application/application.ios.js') - def test_010_prepare_android_tns_core_modules(self): + def test_010_prepare_android_ng_project(self): + output = run(TNS_PATH + " create TNS_App --ng") + assert "successfully created" in output + Tns.platform_add( + platform="android", + path="TNS_App", + framework_path=ANDROID_RUNTIME_PATH) + Tns.prepare(platform="android", path="TNS_App") + + assert Folder.exists( + 'TNS_App/platforms/android/src/main/assets/app/tns_modules/angular2') + assert Folder.exists( + 'TNS_App/platforms/android/src/main/assets/app/tns_modules/nativescript-angular') + + def test_200_prepare_android_patform_not_added(self): + Tns.create_app(app_name="TNS_App") + output = run(TNS_PATH + " prepare android --path TNS_App") + assert "Copying template files..." in output + assert "Project successfully created." in output + assert "Project successfully prepared" in output + assert File.exists( + 'TNS_App/platforms/android/src/main/assets/app/tns_modules/xml/xml.js') + + def test_201_prepare_xml_error(self): + Tns.create_app(app_name="TNS_App") + File.replace("TNS_App/app/main-page.xml", "", "", "