-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhello_world_ng_tests.py
297 lines (247 loc) · 16.2 KB
/
hello_world_ng_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
import os
import unittest
from core.base_class.BaseClass import BaseClass
from core.device.device import Device
from core.device.emulator import Emulator
from core.device.simulator import Simulator
from core.npm.npm import Npm
from core.osutils.file import File
from core.osutils.folder import Folder
from core.osutils.os_type import OSType
from core.settings.settings import ANDROID_KEYSTORE_PATH, \
ANDROID_KEYSTORE_PASS, ANDROID_KEYSTORE_ALIAS, ANDROID_KEYSTORE_ALIAS_PASS, EMULATOR_ID, CURRENT_OS, \
IOS_PACKAGE, ANDROID_PACKAGE, SIMULATOR_NAME, WEBPACK_PACKAGE, TYPESCRIPT_PACKAGE
from core.tns.replace_helper import ReplaceHelper
from core.tns.tns import Tns
from core.tns.tns_platform_type import Platform
from tests.webpack.helpers.helpers import Helpers
class WebPackHelloWorldNG(BaseClass):
SIMULATOR_ID = ""
image_original = 'hello-world-ng'
image_change = 'hello-world-ng-js-css-xml'
html_change = ['app/item/items.component.html', '[text]="item.name"', '[text]="item.id"']
ts_change = ['app/item/item.service.ts', 'Ter Stegen', 'Stegen Ter']
css_change = ['app/app.css', 'core.light.css', 'core.dark.css']
@classmethod
def setUpClass(cls):
BaseClass.setUpClass(cls.__name__)
Emulator.stop()
Emulator.ensure_available()
Tns.create_app_ng(cls.app_name, update_modules=True)
Npm.uninstall(package="nativescript-dev-typescript", option='--save-dev', folder=cls.app_name)
Npm.install(package=TYPESCRIPT_PACKAGE, option='--save-dev', folder=cls.app_name)
Tns.install_npm(package=WEBPACK_PACKAGE, option='--save-dev', folder=cls.app_name)
Tns.platform_add_android(attributes={"--path": cls.app_name, "--frameworkPath": ANDROID_PACKAGE})
if CURRENT_OS == OSType.OSX:
Simulator.stop()
cls.SIMULATOR_ID = Simulator.ensure_available(simulator_name=SIMULATOR_NAME)
Tns.platform_add_ios(attributes={'--path': cls.app_name, '--frameworkPath': IOS_PACKAGE})
def setUp(self):
Tns.kill()
Helpers.emulator_cleanup(app_name=self.app_name)
BaseClass.setUp(self)
def tearDown(self):
BaseClass.tearDown(self)
Tns.kill()
@classmethod
def tearDownClass(cls):
BaseClass.tearDownClass()
@staticmethod
def apply_changes(app_name, log, platform, aot=False):
# Change JS, XML and CSS
ReplaceHelper.replace(app_name, WebPackHelloWorldNG.ts_change, sleep=10)
Tns.wait_for_log(log_file=log, string_list=['item.service.'], clean_log=False)
if platform == Platform.ANDROID:
text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='Stegen Ter', timeout=20)
assert text_changed, 'Changes in JS file not applied (UI is not refreshed).'
plugin_path = os.path.join(app_name, 'node_modules', 'nativescript-camera')
if Folder.exists(plugin_path):
assert "Building project" not in log, "Unexpected build was triggered."
assert "Gradle build" not in log, "Unexpected gradle build was triggered."
ReplaceHelper.replace(app_name, WebPackHelloWorldNG.html_change, sleep=10)
if aot:
Tns.wait_for_log(log_file=log, string_list=['main.aot.ts'], clean_log=False)
else:
Tns.wait_for_log(log_file=log, string_list=['items.component.html'], clean_log=False)
ReplaceHelper.replace(app_name, WebPackHelloWorldNG.css_change, sleep=10)
Tns.wait_for_log(log_file=log, string_list=['app.css'], clean_log=False)
Tns.wait_for_log(log_file=log, string_list=Helpers.wp_sync, not_existing_string_list=Helpers.wp_errors,
timeout=120)
# Verify application looks correct
if platform == Platform.ANDROID:
Helpers.android_screen_match(image=WebPackHelloWorldNG.image_change, timeout=120)
if platform == Platform.IOS:
Helpers.ios_screen_match(sim_id=WebPackHelloWorldNG.SIMULATOR_ID, image=WebPackHelloWorldNG.image_change,
timeout=120)
@staticmethod
def revert_changes(app_name, log, platform, aot=False):
# Clean old logs
if CURRENT_OS is not OSType.WINDOWS:
File.write(file_path=log, text="")
# Revert changes
ReplaceHelper.rollback(app_name, WebPackHelloWorldNG.html_change, sleep=20)
if aot:
Tns.wait_for_log(log_file=log, string_list=['main.aot.ts'], clean_log=False)
else:
Tns.wait_for_log(log_file=log, string_list=['items.component.html'], clean_log=False)
ReplaceHelper.rollback(app_name, WebPackHelloWorldNG.ts_change, sleep=10)
Tns.wait_for_log(log_file=log, string_list=['item.service.'], clean_log=False)
if platform == Platform.ANDROID:
text_changed = Device.wait_for_text(device_id=EMULATOR_ID, text='Ter Stegen', timeout=20)
assert text_changed, 'Changes in TS file not applied (UI is not refreshed).'
ReplaceHelper.rollback(app_name, WebPackHelloWorldNG.css_change, sleep=10)
Tns.wait_for_log(log_file=log, string_list=['app.css'], clean_log=False)
# Verify application looks correct
Tns.wait_for_log(log_file=log, string_list=Helpers.wp_sync, not_existing_string_list=Helpers.wp_errors,
timeout=60)
if platform == Platform.ANDROID:
Helpers.android_screen_match(image=WebPackHelloWorldNG.image_original, timeout=120)
if platform == Platform.IOS:
Helpers.ios_screen_match(sim_id=WebPackHelloWorldNG.SIMULATOR_ID, image=WebPackHelloWorldNG.image_original,
timeout=120)
def test_001_android_build_release_with_bundle(self):
Tns.build_android(attributes={"--path": self.app_name,
"--keyStorePath": ANDROID_KEYSTORE_PATH,
"--keyStorePassword": ANDROID_KEYSTORE_PASS,
"--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
"--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
"--release": "",
"--bundle": ""})
verification_errors = Helpers.verify_size(app_name=self.app_name, config="ng-android-bundle")
Helpers.run_android_via_adb(app_name=self.app_name, image=self.image_original)
self.assertEqual([], verification_errors)
@unittest.skipIf(CURRENT_OS != OSType.OSX, "Run only on macOS.")
def test_001_ios_build_release_with_bundle(self):
Tns.build_ios(attributes={"--path": self.app_name, "--release": "", "--for-device": "", "--bundle": ""})
verification_errors = Helpers.verify_size(app_name=self.app_name, config="ng-ios-bundle")
self.assertEqual([], verification_errors)
def test_100_android_build_release_with_bundle_and_uglify(self):
Tns.build_android(attributes={"--path": self.app_name,
"--keyStorePath": ANDROID_KEYSTORE_PATH,
"--keyStorePassword": ANDROID_KEYSTORE_PASS,
"--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
"--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
"--release": "",
"--bundle": "",
"--env.uglify": "",
"--env.aot": ""})
verification_errors = Helpers.verify_size(app_name=self.app_name, config="ng-android-bundle-uglify")
Helpers.run_android_via_adb(app_name=self.app_name, image=self.image_original)
self.assertEqual([], verification_errors)
@unittest.skipIf(CURRENT_OS != OSType.OSX, "Run only on macOS.")
def test_100_ios_build_release_with_bundle_and_uglify(self):
# Hack to workaround https://github.com/NativeScript/nativescript-dev-webpack/issues/602
Tns.build_ios(attributes={"--path": self.app_name, "--release": "", "--for-device": "", "--bundle": ""})
# ...remove the live above when the issues is fixed.
Tns.build_ios(attributes={"--path": self.app_name, "--release": "", "--for-device": "", "--bundle": "",
"--env.uglify": "", "--env.aot": ""})
verification_errors = Helpers.verify_size(app_name=self.app_name, config="ng-ios-bundle-uglify")
self.assertEqual([], verification_errors)
@unittest.skipIf(CURRENT_OS == OSType.WINDOWS, "Windows can't build with snapshot.")
def test_110_android_build_release_with_bundle_and_snapshot(self):
Tns.build_android(attributes={"--path": self.app_name,
"--keyStorePath": ANDROID_KEYSTORE_PATH,
"--keyStorePassword": ANDROID_KEYSTORE_PASS,
"--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
"--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
"--release": "",
"--bundle": "",
"--env.snapshot": ""})
verification_errors = Helpers.verify_size(app_name=self.app_name, config="ng-android-bundle-snapshot",
check_embedded_script_size=True)
Helpers.run_android_via_adb(app_name=self.app_name, image=self.image_original)
self.assertEqual([], verification_errors)
@unittest.skipIf(CURRENT_OS == OSType.WINDOWS, "Windows can't build with snapshot.")
def test_120_android_build_release_with_bundle_and_snapshot_and_uglify(self):
Tns.build_android(attributes={"--path": self.app_name,
"--keyStorePath": ANDROID_KEYSTORE_PATH,
"--keyStorePassword": ANDROID_KEYSTORE_PASS,
"--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
"--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
"--release": "",
"--bundle": "",
"--env.uglify": "",
"--env.aot": "",
"--env.snapshot": ""})
verification_errors = Helpers.verify_size(app_name=self.app_name, config="ng-android-bundle-uglify-snapshot",
check_embedded_script_size=True)
Helpers.run_android_via_adb(app_name=self.app_name, image=self.image_original)
self.assertEqual([], verification_errors)
def test_200_run_android_with_bundle_sync_changes(self):
log = Tns.run_android(attributes={'--path': self.app_name,
"--bundle": "",
'--device': EMULATOR_ID}, wait=False, assert_success=False)
Tns.wait_for_log(log_file=log, string_list=Helpers.wp_run, not_existing_string_list=Helpers.wp_errors,
timeout=240, check_interval=10)
Helpers.android_screen_match(image=self.image_original, timeout=120)
Helpers.wait_webpack_watcher()
self.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
self.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
@unittest.skipIf(CURRENT_OS != OSType.OSX, "Run only on macOS.")
def test_200_run_ios_with_bundle_sync_changes(self):
log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--bundle': ''}, wait=False,
assert_success=False)
Tns.wait_for_log(log_file=log, string_list=Helpers.wp_run, not_existing_string_list=Helpers.wp_errors,
timeout=180)
Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=self.image_original, timeout=120)
Helpers.wait_webpack_watcher()
self.apply_changes(app_name=self.app_name, log=log, platform=Platform.IOS)
self.revert_changes(app_name=self.app_name, log=log, platform=Platform.IOS)
def test_210_run_android_with_bundle_uglify_sync_changes(self):
log = Tns.run_android(attributes={'--path': self.app_name,
"--bundle": "",
"--env.uglify": "",
'--device': EMULATOR_ID}, wait=False, assert_success=False)
Tns.wait_for_log(log_file=log, string_list=Helpers.wp_run, not_existing_string_list=Helpers.wp_errors,
timeout=180)
Helpers.android_screen_match(image=self.image_original, timeout=120)
Helpers.wait_webpack_watcher()
self.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
self.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
@unittest.skipIf(CURRENT_OS != OSType.OSX, "Run only on macOS.")
def test_210_run_ios_with_bundle_uglify_sync_changes(self):
log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': '', '--bundle': '', '--env.uglify': ''},
wait=False, assert_success=False)
Tns.wait_for_log(log_file=log, string_list=Helpers.wp, not_existing_string_list=Helpers.wp_errors,
timeout=240)
Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=self.image_original, timeout=120)
Helpers.wait_webpack_watcher()
self.apply_changes(app_name=self.app_name, log=log, platform=Platform.IOS)
self.revert_changes(app_name=self.app_name, log=log, platform=Platform.IOS)
def test_220_run_android_with_bundle_uglify_aot_sync_changes(self):
log = Tns.run_android(attributes={'--path': self.app_name,
"--bundle": "",
"--env.uglify": "",
"--env.aot": "",
'--device': EMULATOR_ID}, wait=False, assert_success=False)
Tns.wait_for_log(log_file=log, string_list=Helpers.wp_run, not_existing_string_list=Helpers.wp_errors,
timeout=180)
Helpers.android_screen_match(image=self.image_original, timeout=120)
Helpers.wait_webpack_watcher()
self.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID, aot=True)
self.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID, aot=True)
@unittest.skipIf(CURRENT_OS != OSType.OSX, "Run only on macOS.")
def test_220_run_ios_with_bundle_uglify_aot_sync_changes(self):
log = Tns.run_ios(
attributes={'--path': self.app_name, '--emulator': '', '--bundle': '', '--env.uglify': '', '--env.aot': ''},
wait=False, assert_success=False)
Tns.wait_for_log(log_file=log, string_list=Helpers.wp, not_existing_string_list=Helpers.wp_errors,
timeout=240)
Helpers.ios_screen_match(sim_id=self.SIMULATOR_ID, image=self.image_original, timeout=120)
Helpers.wait_webpack_watcher()
self.apply_changes(app_name=self.app_name, log=log, platform=Platform.IOS, aot=True)
self.revert_changes(app_name=self.app_name, log=log, platform=Platform.IOS, aot=True)
def test_230_run_android_with_bundle_add_plugin_sync_changes(self):
"""
https://github.com/NativeScript/nativescript-cli/issues/3707
"""
Tns.plugin_add("nativescript-camera", attributes={"--path": self.app_name})
log = Tns.run_android(attributes={'--path': self.app_name,
"--bundle": "",
'--device': EMULATOR_ID}, wait=False, assert_success=False)
Tns.wait_for_log(log_file=log, string_list=Helpers.wp_run, not_existing_string_list=Helpers.wp_errors,
timeout=240, check_interval=10)
Helpers.android_screen_match(image=self.image_original, timeout=120)
Helpers.wait_webpack_watcher()
self.apply_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)
self.revert_changes(app_name=self.app_name, log=log, platform=Platform.ANDROID)