Skip to content

Commit 1b9e6dd

Browse files
committed
Update build and prepare tests for iOS
- Add test for prepare with —provision - DO not pass —teamID if —provision is passed - Minor refactoring to speed up iOS build test suite
1 parent 44f4735 commit 1b9e6dd

File tree

6 files changed

+66
-59
lines changed

6 files changed

+66
-59
lines changed

core/settings/strings.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
updates_available = "Updates available"
2929
no_issues = "No issues were detected."
3030
before_prepare = "Executing before-prepare hook"
31-
peer_typeScript = "Found peer TypeScript"
3231
skipping_prepare = "Skipping prepare."
3332
building = "Building project..."
3433
build_successful = "BUILD SUCCESSFUL"

core/tns/tns.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from core.osutils.os_type import OSType
1313
from core.osutils.process import Process
1414
from core.settings.settings import COMMAND_TIMEOUT, TNS_PATH, TAG, TEST_RUN_HOME, DEVELOPMENT_TEAM, CURRENT_OS, \
15-
SUT_FOLDER
15+
SUT_FOLDER, DISTRIBUTION_PROVISIONING
1616
from core.tns.tns_platform_type import Platform
1717
from core.tns.tns_verifications import TnsAsserts
1818
from core.xcode.xcode import Xcode
@@ -61,6 +61,11 @@ def __get_app_name_from_attributes(attributes={}):
6161
app_name = v
6262
return app_name.replace('"', '')
6363

64+
@staticmethod
65+
def __get_xcode_project_file(app_name):
66+
app_id = Tns.__get_final_package_name(app_name, platform=Platform.IOS)
67+
return File.read(app_name + '/platforms/ios/' + app_id + '.xcodeproj/project.pbxproj')
68+
6469
@staticmethod
6570
def version(tns_path=None):
6671
"""
@@ -330,11 +335,15 @@ def prepare_ios(attributes={}, assert_success=True, log_trace=False, tns_path=No
330335
assert "Project successfully prepared" in output
331336

332337
# Verify TEAM_ID
338+
app_name = Tns.__get_app_name_from_attributes(attributes=attributes)
333339
if "--for-device" in attributes.keys() or "--forDevice" in attributes.keys():
334-
app_name = Tns.__get_app_name_from_attributes(attributes=attributes)
335-
app_id = Tns.__get_final_package_name(app_name, platform=Platform.IOS)
336-
output = File.read(app_name + '/platforms/ios/' + app_id + 'TestApp' + '.xcodeproj/project.pbxproj')
337-
assert DEVELOPMENT_TEAM in output, "TeamID not passed to Xcode project!"
340+
assert DEVELOPMENT_TEAM in Tns.__get_xcode_project_file(app_name), "TeamID not passed to Xcode project!"
341+
342+
# Verify PROVISIONING
343+
if "--provision" in attributes.keys():
344+
id = attributes.get("--provision")
345+
assert id in Tns.__get_xcode_project_file(app_name), \
346+
"Provisioning profile specified by --provision not passed to Xcode project!"
338347

339348
return output
340349

@@ -369,11 +378,11 @@ def build_android(attributes={}, assert_success=True, tns_path=None):
369378

370379
@staticmethod
371380
def build_ios(attributes={}, assert_success=True, tns_path=None):
372-
if "7." in Xcode.get_version():
373-
print "Xcode 7. No need to pass --teamId param!"
374-
else:
381+
382+
if "--provision" not in attributes.keys():
375383
attr = {"--teamId": DEVELOPMENT_TEAM}
376384
attributes.update(attr)
385+
377386
output = Tns.run_tns_command("build ios", attributes=attributes, tns_path=tns_path)
378387

379388
app_name = Tns.__get_app_name_from_attributes(attributes=attributes)
@@ -406,9 +415,12 @@ def build_ios(attributes={}, assert_success=True, tns_path=None):
406415
assert "EXPORT SUCCEEDED" in output
407416
assert File.exists(device_folder + app_id + ".ipa"), "IPA file not found!"
408417
bundle_content = File.read(device_folder + app_id + ".app/" + app_id)
409-
410-
output = File.read(app_name + '/platforms/ios/' + app_id + '.xcodeproj/project.pbxproj')
411-
assert DEVELOPMENT_TEAM in output, "TeamID not passed to Xcode project!"
418+
xcode_project = Tns.__get_xcode_project_file(app_name)
419+
if "--provision" not in attributes.keys():
420+
assert DEVELOPMENT_TEAM in xcode_project, "TeamID not passed to Xcode!"
421+
else:
422+
assert DEVELOPMENT_TEAM in xcode_project or DISTRIBUTION_PROVISIONING in xcode_project, \
423+
"TeamID not passed to Xcode!"
412424
else:
413425
assert "build/emulator/" + app_id + ".app" in output
414426
assert File.exists(app_name + "/platforms/ios/" + app_id + "/" + app_id + "-Prefix.pch")

tests/build/ios/build_ios_tests.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ def test_001_build_ios(self):
6161
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
6262
Tns.build_ios(attributes={"--path": self.app_name})
6363

64-
def test_002_build_ios_release_fordevice(self):
65-
Tns.create_app(self.app_name)
64+
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
65+
Tns.build_ios(attributes={"--path": self.app_name, "--release": ""})
66+
67+
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
68+
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": ""})
69+
70+
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
6671
Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_RUNTIME_PATH})
67-
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
6872
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": "", "--release": ""})
6973

7074
# Verify no aar and frameworks in platforms folder
@@ -78,16 +82,6 @@ def test_002_build_ios_release_fordevice(self):
7882
assert "armv7" in output
7983
assert "arm64" in output
8084

81-
def test_200_build_ios_release(self):
82-
Tns.create_app(self.app_name)
83-
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
84-
Tns.build_ios(attributes={"--path": self.app_name, "--release": ""})
85-
86-
def test_201_build_ios_fordevice(self):
87-
Tns.create_app(self.app_name)
88-
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
89-
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": ""})
90-
9185
def test_211_build_ios_inside_project(self):
9286
Tns.create_app(self.app_name)
9387
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
@@ -101,8 +95,6 @@ def test_211_build_ios_inside_project(self):
10195
def test_213_build_ios_platform_not_added_or_platforms_deleted(self):
10296
Tns.create_app(self.app_name_noplatform)
10397
Tns.build_ios(attributes={"--path": self.app_name_noplatform})
104-
Folder.cleanup(self.app_name_noplatform + '/platforms')
105-
Tns.build_ios(attributes={"--path": self.app_name_noplatform}, assert_success=False)
10698

10799
def test_300_build_ios_with_dash(self):
108100
Tns.create_app(self.app_name_dash)
@@ -127,15 +119,14 @@ def test_302_build_ios_with_ios_in_path(self):
127119

128120
def test_310_build_ios_with_copy_to(self):
129121
File.remove("TestApp.app")
122+
File.remove("TestApp.ipa")
123+
130124
Tns.create_app(self.app_name)
131125
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
126+
132127
Tns.build_ios(attributes={"--path": self.app_name, "--copy-to": "./"})
133128
assert File.exists("TestApp.app")
134129

135-
def test_311_build_ios_release_with_copy_to(self):
136-
File.remove("TestApp.ipa")
137-
Tns.create_app(self.app_name)
138-
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
139130
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": "", "--release": "", "--copy-to": "./"})
140131
assert File.exists("TestApp.ipa")
141132

tests/build/ios/plugin_ios_staitc_libs_tests.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from core.osutils.command import run
77
from core.osutils.file import File
88
from core.osutils.folder import Folder
9-
from core.settings.settings import IOS_RUNTIME_PATH, SUT_FOLDER, TEST_RUN_HOME
9+
from core.settings.settings import IOS_RUNTIME_PATH, TEST_RUN_HOME
1010
from core.tns.tns import Tns
1111
from core.xcode.xcode import Xcode
1212

@@ -17,30 +17,7 @@ def setUp(self):
1717
Xcode.cleanup_cache()
1818
Folder.cleanup(self.app_name)
1919

20-
def test_201_plugin_add_static_lib_universal_before_platform_add_ios(self):
21-
Tns.create_app(self.app_name)
22-
23-
plugin_path = TEST_RUN_HOME + "/data/static-lib/hello-plugin.tgz"
24-
output = Tns.plugin_add(plugin_path, attributes={"--path": self.app_name}, assert_success=False)
25-
assert "Successfully installed plugin hello." in output
26-
27-
assert File.exists(self.app_name + "/node_modules/hello/package.json")
28-
assert File.exists(self.app_name + "/node_modules/hello/hello-plugin.ios.js")
29-
assert File.exists(self.app_name + "/node_modules/hello/platforms/ios/HelloLib.a")
30-
assert File.exists(self.app_name + "/node_modules/hello/platforms/ios/include/HelloLib/Bye.h")
31-
assert File.exists(self.app_name + "/node_modules/hello/platforms/ios/include/HelloLib/Hello.h")
32-
assert "static-lib/hello-plugin" in File.read(self.app_name + "/package.json")
33-
34-
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
35-
Tns.build_ios(attributes={"--path": self.app_name})
36-
37-
assert File.exists(self.app_name + "/platforms/ios/TestApp/app/tns_modules/hello/package.json")
38-
assert File.exists(self.app_name + "/platforms/ios/TestApp/app/tns_modules/hello/hello-plugin.js")
39-
output = run(
40-
"cat " + self.app_name + "/platforms/ios/TestApp.xcodeproj/project.pbxproj | grep \"HelloLib.a\"")
41-
assert "HelloLib.a in Frameworks" in output
42-
43-
def test_202_plugin_add_static_lib_universal_after_platform_add_ios(self):
20+
def test_200_plugin_add_static_lib_universal(self):
4421
Tns.create_app(self.app_name)
4522
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
4623

@@ -70,7 +47,7 @@ def test_401_plugin_add_static_lib_non_universal(self):
7047
plugin_path = TEST_RUN_HOME + "/data/static-lib/bye-plugin.tgz"
7148
output = Tns.plugin_add(plugin_path, attributes={"--path": self.app_name}, assert_success=False)
7249
assert "Successfully installed plugin bye" in output
73-
50+
7451
output = Tns.prepare_ios(attributes={"--path": self.app_name}, assert_success=False)
7552
assert "The static library at" in output
7653
assert "ByeLib.a is not built for one or more of " + \

tests/build/ios/prepare_ios_tests.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import re
77

88
from core.base_class.BaseClass import BaseClass
9+
from core.device.simulator import Simulator
910
from core.osutils.command import run
1011
from core.osutils.file import File
1112
from core.osutils.folder import Folder
12-
from core.settings.settings import IOS_RUNTIME_PATH, CURRENT_OS, OSType, TEST_RUN_HOME, ANDROID_RUNTIME_PATH
13+
from core.settings.settings import IOS_RUNTIME_PATH, CURRENT_OS, OSType, TEST_RUN_HOME, ANDROID_RUNTIME_PATH, \
14+
PROVISIONING
1315
from core.tns.replace_helper import ReplaceHelper
1416
from core.tns.tns import Tns
1517
from core.tns.tns_platform_type import Platform
@@ -24,11 +26,16 @@ def setUpClass(cls):
2426
BaseClass.setUpClass(logfile)
2527
if CURRENT_OS != OSType.OSX:
2628
raise NameError("Can not run iOS tests on non OSX OS.")
29+
else:
30+
Simulator.stop()
2731

2832
def setUp(self):
2933
BaseClass.setUp(self)
3034
Folder.cleanup(self.app_name)
3135

36+
def tearDown(self):
37+
assert not Simulator.is_running()[0], 'iOS Simulator started after prepare!'
38+
3239
def test_100_prepare_ios(self):
3340
Tns.create_app(self.app_name)
3441
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
@@ -109,6 +116,7 @@ def test_220_build_ios_with_custom_plist(self):
109116
assert "<string>orgnativescriptTestApp</string>" in File.read(final_plist)
110117

111118
# Prepare in release
119+
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
112120
Tns.prepare_ios(attributes={"--path": self.app_name, '--release': ''})
113121
assert "<string>fbXXXXXXXXX</string>" in File.read(final_plist)
114122
assert "<string>orgnativescriptTestApp</string>" not in File.read(final_plist)
@@ -142,3 +150,23 @@ def test_301_prepare_android_does_not_prepare_ios(self):
142150
output = Tns.prepare_android(attributes={"--path": self.app_name})
143151
assert "nativescript-iqkeyboardmanager is not supported for android" in output
144152
assert "Successfully prepared plugin nativescript-social-share for android" in output
153+
154+
def test_320_prepare_ios_with_provisioning(self):
155+
Tns.create_app(self.app_name)
156+
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
157+
158+
# Prepare with --provision (debug, emulator)
159+
Tns.prepare_ios(attributes={"--path": self.app_name, "--provision": PROVISIONING})
160+
161+
# Prepare with --provision (release, emulator)
162+
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
163+
Tns.prepare_ios(attributes={"--path": self.app_name, "--release": "", "--provision": PROVISIONING})
164+
165+
# Prepare with --provision (debug, device)
166+
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
167+
Tns.prepare_ios(attributes={"--path": self.app_name, "--forDevice": "", "--provision": PROVISIONING})
168+
169+
# Prepare with --provision (release, device)
170+
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
171+
Tns.prepare_ios(
172+
attributes={"--path": self.app_name, "--release": "", "--forDevice": "", "--provision": PROVISIONING})

tests/device/run_ios_device_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_001_tns_run_ios_js_css_xml(self):
8181
"""Make valid changes in JS,CSS and XML"""
8282

8383
# `tns run ios` and wait until app is deployed
84-
log = Tns.run_ios(attributes={'--path': self.app_name}, log_trace=True, wait=False, assert_success=False)
84+
log = Tns.run_ios(attributes={'--path': self.app_name}, wait=False, assert_success=False)
8585
strings = ['Project successfully built',
8686
'Successfully installed on device with identifier', self.DEVICE_ID,
8787
'Successfully synced application']

0 commit comments

Comments
 (0)