Skip to content

Commit 931472d

Browse files
authored
Enable --provision tests for Xcode9 and address output changes in NativeScript/nativescript-cli#3070
- Enable —provision tests for Xcode9 - Update tests after changes in output introduced with NativeScript/nativescript-cli#3070 - Add test for NativeScript/nativescript-cli#3080
1 parent 38cf463 commit 931472d

14 files changed

+85
-82
lines changed

core/tns/angular_helper.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

core/tns/tns.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ def create_app_ng(app_name, attributes={}, log_trace=False, assert_success=True,
221221
if Npm.version() < 5:
222222
assert "nativescript-angular" in output
223223
assert File.exists(os.path.join(app_name, 'node_modules', 'nativescript-theme-core'))
224+
package_json = File.read(os.path.join(app_name, 'package.json'))
225+
assert "tns-core-modules" in package_json
226+
assert "nativescript-angular" in package_json
227+
assert "nativescript-dev-typescript" in package_json
224228

225229
return output
226230

@@ -348,13 +352,17 @@ def prepare_ios(attributes={}, assert_success=True, log_trace=False, tns_path=No
348352
return output
349353

350354
@staticmethod
351-
def build_android(attributes={}, assert_success=True, tns_path=None):
352-
output = Tns.run_tns_command("build android", attributes=attributes, tns_path=tns_path)
355+
def build_android(attributes={}, assert_success=True, tns_path=None, log_trace=False):
356+
output = Tns.run_tns_command("build android", attributes=attributes, tns_path=tns_path, log_trace=log_trace)
353357
if assert_success:
354358
# Verify output of build command
355-
assert "BUILD SUCCESSFUL" in output, "Build failed!" + os.linesep + output
356359
assert "Project successfully built" in output, "Build failed!" + os.linesep + output
360+
assert "FAILURE" not in output
357361
assert "NOT FOUND" not in output # Test for https://github.com/NativeScript/android-runtime/issues/390
362+
if log_trace:
363+
assert "BUILD SUCCESSFUL" in output, "Build failed!" + os.linesep + output
364+
else:
365+
assert "BUILD SUCCESSFUL" not in output, "Native build out is displayed even without --log trace"
358366

359367
# Verify apk packages
360368
app_name = Tns.__get_app_name_from_attributes(attributes=attributes)
@@ -377,24 +385,29 @@ def build_android(attributes={}, assert_success=True, tns_path=None):
377385
return output
378386

379387
@staticmethod
380-
def build_ios(attributes={}, assert_success=True, tns_path=None):
388+
def build_ios(attributes={}, assert_success=True, tns_path=None, log_trace=False):
381389

382390
if "--provision" not in attributes.keys():
383391
attr = {"--teamId": DEVELOPMENT_TEAM}
384392
attributes.update(attr)
385393

386-
output = Tns.run_tns_command("build ios", attributes=attributes, tns_path=tns_path)
394+
output = Tns.run_tns_command("build ios", attributes=attributes, tns_path=tns_path, log_trace=log_trace)
387395

388396
app_name = Tns.__get_app_name_from_attributes(attributes=attributes)
389397
app_name = app_name.replace("\"", "") # Handle projects with space
390398
app_id = Tns.__get_final_package_name(app_name, platform=Platform.IOS)
391399

392400
if assert_success:
393-
assert "BUILD SUCCEEDED" in output
394401
assert "Project successfully built" in output
395402
assert "ERROR" not in output
396403
assert "malformed" not in output
397-
assert "CodeSign" in output
404+
405+
if log_trace:
406+
assert "BUILD SUCCEEDED" in output
407+
assert "CodeSign" in output
408+
else:
409+
assert "BUILD SUCCEEDED" not in output, "Native build out is displayed even without --log trace"
410+
assert "CodeSign" not in output, "Native build out is displayed even without --log trace"
398411

399412
# Verify release/debug builds
400413
if "--release" in attributes.keys():
@@ -410,9 +423,13 @@ def build_ios(attributes={}, assert_success=True, tns_path=None):
410423
device_folder = app_name + "/platforms/ios/build/device/"
411424
emu_folder = app_name + "/platforms/ios/build/emulator/"
412425
if "--forDevice" in attributes.keys() or "--for-device" in attributes.keys():
413-
assert "build/device/" + app_id + ".app" in output
414-
assert "ARCHIVE SUCCEEDED" in output
415-
assert "EXPORT SUCCEEDED" in output
426+
if log_trace:
427+
assert "build/device/" + app_id + ".app" in output
428+
assert "ARCHIVE SUCCEEDED" in output
429+
assert "EXPORT SUCCEEDED" in output
430+
else:
431+
assert "ARCHIVE SUCCEEDED" not in output, "Native build out is displayed even without --log trace"
432+
assert "EXPORT SUCCEEDED" not in output, "Native build out is displayed even without --log trace"
416433
assert File.exists(device_folder + app_id + ".ipa"), "IPA file not found!"
417434
bundle_content = File.read(device_folder + app_id + ".app/" + app_id)
418435
xcode_project = Tns.__get_xcode_project_file(app_name)
@@ -422,7 +439,11 @@ def build_ios(attributes={}, assert_success=True, tns_path=None):
422439
assert DEVELOPMENT_TEAM in xcode_project or DISTRIBUTION_PROVISIONING in xcode_project, \
423440
"TeamID not passed to Xcode!"
424441
else:
425-
assert "build/emulator/" + app_id + ".app" in output
442+
if log_trace:
443+
assert "build/emulator/" + app_id + ".app" in output
444+
else:
445+
assert "build/emulator/" + app_id + ".app" not in output, \
446+
"Native build out is displayed even without --log trace"
426447
assert File.exists(app_name + "/platforms/ios/" + app_id + "/" + app_id + "-Prefix.pch")
427448
assert File.exists(emu_folder + app_id + ".app")
428449
bundle_content = File.read(emu_folder + app_id + ".app/" + app_id)
Loading
Binary file not shown.
737 Bytes
Loading
Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
import os
22

33
from core.base_class.BaseClass import BaseClass
4-
from core.osutils.file import File
54
from core.osutils.folder import Folder
65
from core.settings.settings import ANDROID_RUNTIME_PATH, \
76
ANDROID_KEYSTORE_PASS, ANDROID_KEYSTORE_ALIAS, ANDROID_KEYSTORE_PATH, ANDROID_KEYSTORE_ALIAS_PASS
87
from core.tns.tns import Tns
9-
from core.tns import angular_helper as angular
10-
from core.settings.strings import *
118

129

1310
class BuildAndroidNGTests(BaseClass):
@@ -25,21 +22,13 @@ def tearDownClass(cls):
2522
Folder.cleanup(cls.app_name)
2623

2724
def test_001_build_android_ng_project(self):
28-
angular.assert_angular_project(self.app_name)
2925
Tns.build_android(attributes={"--path": self.app_name})
30-
assert File.exists(os.path.join(self.app_name, debug_apk_path))
3126

3227
def test_200_build_android_ng_project_release(self):
33-
print ANDROID_KEYSTORE_PATH
34-
output = Tns.build_android(attributes={"--keyStorePath": ANDROID_KEYSTORE_PATH,
35-
"--keyStorePassword": ANDROID_KEYSTORE_PASS,
36-
"--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
37-
"--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
38-
"--release": "",
39-
"--path": self.app_name
40-
})
41-
assert successfully_prepared in output
42-
assert build_successful in output
43-
44-
assert successfully_built in output
45-
assert File.exists(os.path.join(self.app_name, release_apk_path))
28+
Tns.build_android(attributes={"--keyStorePath": ANDROID_KEYSTORE_PATH,
29+
"--keyStorePassword": ANDROID_KEYSTORE_PASS,
30+
"--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
31+
"--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
32+
"--release": "",
33+
"--path": self.app_name
34+
})

tests/build/android/build_android_tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ def test_002_build_android_release(self):
105105
"--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
106106
"--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
107107
"--release": ""
108-
})
108+
}, log_trace=True)
109109

110110
# Configs are respected
111111
assert 'release' in File.read(os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, 'config.json'))
112112

113113
def test_200_build_android_inside_project_folder(self):
114114
Folder.navigate_to(self.app_name)
115115
output = Tns.build_android(tns_path=os.path.join("..", TNS_PATH), attributes={"--path": self.app_name},
116-
assert_success=False)
116+
assert_success=False, log_trace=True)
117117
Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False)
118118
assert successfully_prepared in output
119119
assert build_successful in output
@@ -130,7 +130,7 @@ def test_201_build_android_with_additional_prepare(self):
130130
def test_202_build_android_with_log_trace_and_platform_not_added_or_empty(self):
131131
"""'tns build android' with log trace options should output more logs."""
132132
Tns.create_app(self.app_no_platform)
133-
output = Tns.build_android(attributes={"--path": self.app_no_platform, "--log trace": ""})
133+
output = Tns.build_android(attributes={"--path": self.app_no_platform}, log_trace=True)
134134

135135
# Assert log trace show gradle logs
136136
assert "[DEBUG]" in output
@@ -311,8 +311,8 @@ def test_390_build_project_with_foursquare_android_oauth(self):
311311
Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_RUNTIME_PATH})
312312

313313
# Add foursquare native library as dependency
314-
source = os.path.join('data','issues','android-runtime-755','app.gradle')
315-
target = os.path.join(self.app_name, 'app','App_Resources','Android','app.gradle')
314+
source = os.path.join('data', 'issues', 'android-runtime-755', 'app.gradle')
315+
target = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'app.gradle')
316316
File.copy(src=source, dest=target)
317317

318318
# Build the project

tests/build/android/plugin_android_tests.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,7 @@ def test_200_build_app_with_plugin_added_inside_project(self):
113113
os.chdir(current_dir)
114114
assert "Successfully installed plugin tns-plugin" in output
115115

116-
output = Tns.build_android(attributes={"--path": self.app_name})
117-
assert successfully_prepared in output
118-
119-
assert build_successful in output
120-
assert successfully_built in output
121-
assert error not in output.lower()
122-
assert "FAILURE" not in output
123-
116+
Tns.build_android(attributes={"--path": self.app_name}, log_trace=True)
124117
assert File.exists(self.app_name + "/platforms/android/build/outputs/apk/TestApp-debug.apk")
125118
assert File.exists(self.app_name + "/platforms/android/src/main/assets/app/tns_modules/tns-plugin/index.js")
126119

tests/build/android/prepare_android_tests.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import unittest
77

88
from core.base_class.BaseClass import BaseClass
9+
from core.git.git import Git
910
from core.npm.npm import Npm
11+
from core.osutils.command import run
1012
from core.osutils.file import File
1113
from core.osutils.folder import Folder
1214
from core.osutils.os_type import OSType
@@ -21,6 +23,7 @@
2123
class PrepareAndroidTests(BaseClass):
2224
def setUp(self):
2325
BaseClass.setUp(self)
26+
Folder.navigate_to(folder=TEST_RUN_HOME, relative_from_current_folder=False)
2427

2528
def test_101_prepare_android(self):
2629
Tns.create_app(self.app_name, update_modules=False)
@@ -129,14 +132,29 @@ def test_310_prepare_should_flatten_scoped_dependencies(self):
129132
ng_path = os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_NPM_MODULES_PATH, '@angular', 'core')
130133
assert File.exists(ng_path), "Scoped dependencies are flattened, please see #1783!"
131134

132-
@unittest.skip("TODO: Fix the test")
133-
def test_320_unmet_peer_dependencies_do_not_stop_prepare(self):
134-
Tns.create_app_ng(self.app_name, update_modules=True)
135-
# Cleanup node_modules and let CLI install npm dependencies
136-
Folder.cleanup(os.path.join(TEST_RUN_HOME, self.app_name, 'node_modules'))
137-
output = Tns.prepare_android(attributes={"--path": self.app_name})
138-
assert "requires a peer of tns-core-modules" in output, "No npm warning for unmet peer dependencies."
139-
assert "but none was installed" in output, "No npm warning for unmet peer dependencies."
135+
@unittest.skipIf(CURRENT_OS == OSType.WINDOWS, "Skip on Windows")
136+
def test_320_prepare_scoped_plugins(self):
137+
"""
138+
Test for https://github.com/NativeScript/nativescript-cli/pull/3080
139+
140+
Before this change we copied all NG components at following location (js demo of nativescript-facebook):
141+
platforms/android/src/main/assets/app/tns_modules/nativescript-facebook/node_modules/@angular
142+
143+
Now folder above should be empty (or not existing at all).
144+
"""
145+
146+
Folder.cleanup("nativescript-facebook")
147+
Git.clone_repo(repo_url='git@github.com:NativeScript/nativescript-facebook.git',
148+
local_folder="nativescript-facebook")
149+
Folder.navigate_to(folder="nativescript-facebook/src")
150+
output = run(command="npm run build")
151+
Folder.navigate_to(folder=TEST_RUN_HOME, relative_from_current_folder=False)
152+
assert "tsc" in output
153+
assert "ERR" not in output
154+
Tns.prepare_android(attributes={"--path": "nativescript-facebook/demo"})
155+
output = run(command="find nativescript-facebook/demo/platforms/android/ | grep @")
156+
assert "@angular/core" not in output, "@angular/* should not be in platforms folder."
157+
assert "@angular/router" not in output, "@angular/* should not be in platforms folder."
140158

141159
def test_400_prepare_missing_or_missing_platform(self):
142160
Tns.create_app(self.app_name, update_modules=False)

tests/build/ios/build_ios_provision_tests.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Test for --provision options
33
"""
44
import os
5-
import unittest
65

76
from core.base_class.BaseClass import BaseClass
87
from core.device.simulator import Simulator
@@ -47,14 +46,10 @@ def test_200_build_ios_list_provisions(self):
4746
assert DISTRIBUTION_PROVISIONING in output
4847
assert DEVELOPMENT_TEAM in output
4948

50-
@unittest.skipIf("9." in Xcode.get_version(),
51-
"Skip on Xcode 9 because of https://github.com/NativeScript/nativescript-cli/issues/3046")
5249
def test_201_build_ios_with_provision(self):
5350
build_attributes = {"--path": self.app_name, "--forDevice": "", "--release": "", "--provision": PROVISIONING}
5451
Tns.build_ios(attributes=build_attributes)
5552

56-
@unittest.skipIf("9." in Xcode.get_version(),
57-
"Skip on Xcode 9 because of https://github.com/NativeScript/nativescript-cli/issues/3046")
5853
def test_202_build_ios_with_distribution_provision(self):
5954
build_attributes = {"--path": self.app_name, "--forDevice": "", "--release": "",
6055
"--provision": DISTRIBUTION_PROVISIONING}

tests/build/ios/build_ios_tests.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ def tearDownClass(cls):
5959
def test_001_build_ios(self):
6060
Tns.create_app(self.app_name)
6161
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
62-
Tns.build_ios(attributes={"--path": self.app_name})
62+
Tns.build_ios(attributes={"--path": self.app_name}, log_trace=True)
6363

6464
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
65-
Tns.build_ios(attributes={"--path": self.app_name, "--release": ""})
65+
Tns.build_ios(attributes={"--path": self.app_name, "--release": ""}, log_trace=True)
6666

6767
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
68-
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": ""})
68+
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": ""}, log_trace=True)
6969

7070
Folder.cleanup(os.path.join(self.app_name, 'platforms', 'ios'))
7171
Tns.platform_add_android(attributes={"--path": self.app_name, "--frameworkPath": ANDROID_RUNTIME_PATH})
72-
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": "", "--release": ""})
72+
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": "", "--release": ""}, log_trace=True)
7373

7474
# Verify no aar and frameworks in platforms folder
7575
assert not File.pattern_exists(self.app_name + "/platforms/ios", "*.aar")
@@ -82,17 +82,17 @@ def test_001_build_ios(self):
8282
assert "armv7" in output
8383
assert "arm64" in output
8484

85-
def test_211_build_ios_inside_project(self):
85+
def test_200_build_ios_inside_project(self):
8686
Tns.create_app(self.app_name)
8787
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
8888
Folder.navigate_to(self.app_name)
8989
output = Tns.build_ios(tns_path=os.path.join("..", TNS_PATH), attributes={"--path": self.app_name},
90-
assert_success=False)
90+
assert_success=False, log_trace=True)
9191
Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False)
9292
assert "build/emulator/TestApp.app" in output
9393
assert File.exists(self.app_name + "/platforms/ios/build/emulator/TestApp.app")
9494

95-
def test_213_build_ios_platform_not_added_or_platforms_deleted(self):
95+
def test_210_build_ios_platform_not_added_or_platforms_deleted(self):
9696
Tns.create_app(self.app_name_noplatform)
9797
Tns.build_ios(attributes={"--path": self.app_name_noplatform})
9898

@@ -124,10 +124,11 @@ def test_310_build_ios_with_copy_to(self):
124124
Tns.create_app(self.app_name)
125125
Tns.platform_add_ios(attributes={"--path": self.app_name, "--frameworkPath": IOS_RUNTIME_PATH})
126126

127-
Tns.build_ios(attributes={"--path": self.app_name, "--copy-to": "./"})
127+
Tns.build_ios(attributes={"--path": self.app_name, "--copy-to": "./"}, log_trace=True)
128128
assert File.exists("TestApp.app")
129129

130-
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": "", "--release": "", "--copy-to": "./"})
130+
Tns.build_ios(attributes={"--path": self.app_name, "--forDevice": "", "--release": "", "--copy-to": "./"},
131+
log_trace=True)
131132
assert File.exists("TestApp.ipa")
132133

133134
def test_320_build_ios_with_custom_entitlements(self):

tests/device/run_ios_device_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def test_330_tns_run_ios_after_rebuild_of_native_project(self):
232232

233233
# `tns run ios` and wait until app is deployed
234234
log = Tns.run_ios(attributes={'--path': self.app_name, '--device': self.DEVICE_ID}, wait=False,
235-
assert_success=False)
235+
assert_success=False, log_trace=True)
236236
strings = [self.DEVICE_ID, 'Successfully synced application']
237237
Tns.wait_for_log(log_file=log, string_list=strings, timeout=120, check_interval=10)
238238

tests/emulator/run_android_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ def test_390_tns_run_android_should_warn_if_package_ids_do_not_match(self):
519519
output = Tns.run_android(attributes={'--path': self.app_name, '--justlaunch': ''})
520520
assert "The Application identifier is different from the one inside 'package.json' file." in output
521521
assert "NativeScript CLI might not work properly." in output
522-
assert "BUILD SUCCESSFUL" in output
522+
assert "Project successfully built" in output
523523

524524
@unittest.skipIf(CURRENT_OS == OSType.LINUX, "`shell cp -r` fails for some reason on emulators on Linux.")
525525
def test_400_tns_run_android_respect_adb_errors(self):

0 commit comments

Comments
 (0)