Skip to content

Commit e725295

Browse files
authored
chore: address changes caused by new templates (#426)
- Fix create tests - Fix preview tests - Fix run `run_tests.py` and `run_tests_api_28.py` - Fix resource update and generate tests - Fix schematics tests - Address changes in app size - Add `Test App` in .gitignore - Fix flaky unit test causing PRs in this repo to fail. - Enable `nativescript-marketplace-demo` ignored tests
1 parent 70caaa3 commit e725295

File tree

19 files changed

+45
-41
lines changed

19 files changed

+45
-41
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package-lock.json
99
nosetests.*
1010
node_modules
11+
Test App
1112
TestApp*
1213
out/*
1314
/data/temp

assets/myCustomTemplate/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
"version": "1.0.0",
44
"dependencies": {
55
"lodash": "3.10.1",
6-
"nativescript-theme-core": "~1.0.2"
6+
"@nativescript/theme": "~2.2.0"
77
},
88
"devDependencies": {
99
"minimist": "1.2.0",
10-
"nativescript-dev-android-snapshot": "^0.*.*",
1110
"nativescript-dev-webpack": "^0.20.0"
1211
},
1312
"description": "dummy",

core_tests/unit/utils/wait_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_10_wait(self):
2121
@timed(5)
2222
def test_20_get_average_time(self):
2323
ls_time = PerfUtils.get_average_time(lambda: run(cmd='ifconfig'), retry_count=5)
24-
assert 0.003 <= ls_time <= 0.03, "Command not executed in acceptable time. Actual value: " + str(ls_time)
24+
assert 0.005 <= ls_time <= 0.05, "Command not executed in acceptable time. Actual value: " + str(ls_time)
2525

2626
@staticmethod
2727
def seconds_are_odd():

data/changes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class JSHelloWord(object):
3636
CSS = ChangeSet(file_path=os.path.join('app', 'app.css'),
3737
old_value='font-size: 18',
3838
new_value='font-size: 18;\nbackground-color: red;',
39-
old_color=None, new_color=None)
39+
old_color=None, new_color=Colors.RED)
4040
XML = ChangeSet(file_path=os.path.join('app', 'main-page.xml'),
4141
old_value='TAP', new_value='HIT',
4242
old_text='TAP', new_text='HIT')
@@ -56,7 +56,7 @@ class TSHelloWord(object):
5656
CSS = ChangeSet(file_path=os.path.join('app', 'app.css'),
5757
old_value='font-size: 18',
5858
new_value='font-size: 18;\nbackground-color: red;',
59-
old_color=None, new_color=None)
59+
old_color=None, new_color=Colors.RED)
6060
XML = ChangeSet(file_path=os.path.join('app', 'main-page.xml'),
6161
old_value='TAP', new_value='HIT',
6262
old_text='TAP', new_text='HIT')

data/sync/hello_world_js.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from products.nativescript.preview_helpers import Preview
1414
from products.nativescript.run_type import RunType
1515
from products.nativescript.tns import Tns
16-
from products.nativescript.tns_logs import TnsLogs
1716
from products.nativescript.tns_assert import TnsAssert
17+
from products.nativescript.tns_logs import TnsLogs
1818
from products.nativescript.tns_paths import TnsPaths
1919

2020

@@ -185,6 +185,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=
185185
else:
186186
raise ValueError('Invalid app_type value.')
187187

188+
not_existing_string_list = None
188189
if hmr and instrumented:
189190
not_existing_string_list = ['QA: Application started']
190191

@@ -197,7 +198,7 @@ def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=
197198
not_existing_string_list=not_existing_string_list)
198199
else:
199200
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=90)
200-
device.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count * 2, delta=25)
201+
device.wait_for_color(color=css_change.new_color, pixel_count=blue_count, delta=25)
201202

202203
# Edit JS file and verify changes are applied
203204
Sync.replace(app_name=app_name, change_set=js_change)

data/sync/hello_world_ng.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def sync_hello_world_ng(app_name, platform, device, bundle=True, uglify=False, a
9090
device=device)
9191
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
9292
not_existing_string_list=not_existing_string_list)
93-
device.wait_for_main_color(color=Colors.PINK)
93+
device.wait_for_main_color(color=Changes.NGHelloWorld.CSS.new_color)
9494

9595
# Revert changes
9696
Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
@@ -175,7 +175,7 @@ def preview_sync_hello_world_ng(app_name, platform, device, bundle=True, hmr=Tru
175175
hmr=hmr, instrumented=instrumented)
176176
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180,
177177
not_existing_string_list=not_existing_string_list)
178-
device.wait_for_main_color(color=Colors.DARK)
178+
device.wait_for_main_color(color=Changes.NGHelloWorld.CSS.new_color)
179179
if platform == Platform.IOS:
180180
for number in ["10", "1"]:
181181
device.wait_for_text(text=number)

products/nativescript/tns.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def create(app_name=Settings.AppName.DEFAULT, template=None, path=None, app_id=N
165165
TestContext.TEST_APP_NAME = app_name
166166

167167
# Verify app is created properly
168-
if verify is not False:
168+
if verify:
169169
# Usually we do not pass path on tns create, which actually equals to cwd.
170170
# In such cases pass correct path to TnsAssert.created()
171171
if path is None:

tests/apps/apps_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class SampleAppsTests(TnsTest):
2525
('nativescript-sdk-examples-ng', 'NativeScript', 'NativeScript Code Samples'),
2626
('nativescript-sdk-examples-js', 'NativeScript', 'Cookbook'),
2727
('sample-Groceries', 'NativeScript', 'Login'),
28-
# ('nativescript-marketplace-demo', 'NativeScript', 'GET STARTED'),
29-
# Ignored because of https://github.com/NativeScript/nativescript-marketplace-demo/issues/301
28+
('nativescript-marketplace-demo', 'NativeScript', 'GET STARTED'),
3029
]
3130

3231
@classmethod

tests/cli/create/create.md

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

tests/cli/create/create_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from data.templates import Template
1010
from products.nativescript.app import App
1111
from products.nativescript.tns import Tns
12+
from products.nativescript.tns_assert import TnsAssert
1213

1314

1415
# noinspection PyMethodMayBeStatic
@@ -29,9 +30,7 @@ def tearDownClass(cls):
2930

3031
def test_001_create_app_like_real_user(self):
3132
"""Create app with no any params"""
32-
# webpack - remove template after merge
33-
Tns.create(app_name=Settings.AppName.DEFAULT, app_data=Apps.HELLO_WORLD_JS,
34-
template=Template.HELLO_WORLD_JS.local_package, update=False)
33+
Tns.create(app_name=Settings.AppName.DEFAULT, app_data=Apps.HELLO_WORLD_JS, update=False)
3534

3635
def test_002_create_app_template_js(self):
3736
"""Create app with --template js project"""
@@ -117,7 +116,8 @@ def test_012_create_project_with_named_app(self):
117116
])
118117
def test_200_create_project_with_template(self, template_source):
119118
"""Create app should be possible with --template and npm packages, git repos and aliases"""
120-
Tns.create(app_name=Settings.AppName.DEFAULT, template=template_source, update=False)
119+
result = Tns.create(app_name=Settings.AppName.DEFAULT, template=template_source, update=False, verify=False)
120+
TnsAssert.created(app_name=Settings.AppName.DEFAULT, output=result.output, theme=False)
121121

122122
def test_201_create_project_with_local_directory_template(self):
123123
"""--template should install all packages from package.json"""

tests/cli/resources/test_resource_generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_300_tns_resources_generate_icons_apetools(self):
5353
def test_301_tns_resources_generate_icons_old_template_structure(self):
5454
# Create nativescript@4 app
5555
result = Tns.create(app_name=APP_NAME, template='tns-template-hello-world@4.0', verify=False)
56-
TnsAssert.created(app_name=APP_NAME, output=result.output, webpack=False)
56+
TnsAssert.created(app_name=APP_NAME, output=result.output, webpack=False, theme=False)
5757

5858
# Generate icons with nativescript
5959
self.test_001_tns_resources_generate_icons()

tests/cli/resources/test_resource_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ResourcesUpdateTests(TnsTest):
1717
def test_300_tns_resources_update(self):
1818
# Create nativescript@3 app
1919
result = Tns.create(app_name=APP_NAME, template='tns-template-hello-world@3.0', verify=False, update=False)
20-
TnsAssert.created(app_name=APP_NAME, output=result.output, webpack=False)
20+
TnsAssert.created(app_name=APP_NAME, output=result.output, webpack=False, theme=False)
2121

2222
# Update resources
2323
out = Tns.exec_command(command='resources update', path=APP_NAME).output

tests/cli/run/tests/run_tests.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,17 @@ def test_110_tns_run_android_release(self):
237237
assert blue_count > 100, 'Failed to find blue color on {0}'.format(self.emu.name)
238238

239239
Tns.kill()
240+
240241
# Make changes in js, css and xml files
241242
Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.JS)
242243
Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.XML)
243244
Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.CSS)
244245

245246
# Run with --release again and verify changes are deployed on device
246-
result = Tns.run_android(app_name=self.app_name, release=True, verify=True, emulator=True)
247+
Tns.run_android(app_name=self.app_name, release=True, verify=True, emulator=True)
247248
self.emu.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
248249
self.emu.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
249-
self.emu.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count * 2, delta=25)
250+
self.emu.wait_for_color(color=Colors.RED, pixel_count=blue_count, delta=25)
250251

251252
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'iOS tests can be executed only on macOS.')
252253
def test_110_tns_run_ios_release(self):
@@ -269,10 +270,10 @@ def test_110_tns_run_ios_release(self):
269270
Sync.replace(app_name=self.app_name, change_set=Changes.JSHelloWord.CSS)
270271

271272
# Run with --release again and verify changes are deployed on device
272-
result = Tns.run_ios(app_name=self.app_name, release=True, verify=True, emulator=True)
273+
Tns.run_ios(app_name=self.app_name, release=True, verify=True, emulator=True)
273274
self.sim.wait_for_text(text=Changes.JSHelloWord.JS.new_text)
274275
self.sim.wait_for_text(text=Changes.JSHelloWord.XML.new_text)
275-
self.sim.wait_for_color(color=Colors.LIGHT_BLUE, pixel_count=blue_count * 2, delta=25)
276+
self.sim.wait_for_color(color=Colors.RED, pixel_count=blue_count, delta=25)
276277

277278
@unittest.skipIf(Settings.HOST_OS == OSType.WINDOWS, 'skip on windows untill we fix wait_rof_log method')
278279
def test_115_tns_run_android_add_remove_files_and_folders(self):
@@ -425,8 +426,8 @@ def test_120_tns_run_ios_just_launch(self):
425426
3. Incremental prepare is triggered if js, xml and css files are changed.
426427
"""
427428
# Run app with --justlaunch and verify on device
428-
result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, just_launch=True)
429-
# On some machines it takes time for thr process to die
429+
run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, just_launch=True)
430+
# On some machines it takes time for the process to die
430431
time.sleep(5)
431432
assert not Process.is_running_by_commandline(Settings.Executables.TNS)
432433

@@ -528,7 +529,7 @@ def test_300_tns_run_ios_clean(self):
528529
If set --clean rebuilds the native project
529530
"""
530531
# Run the project once so it is build for the first time
531-
result = run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, just_launch=True)
532+
run_hello_world_js_ts(self.app_name, Platform.IOS, self.sim, just_launch=True)
532533

533534
# Verify run --clean without changes rebuilds native project
534535
result = Tns.run_ios(app_name=self.app_name, verify=True, device=self.sim.id, clean=True, just_launch=True)
@@ -763,7 +764,7 @@ def test_365_tns_run_android_should_respect_adb_errors(self):
763764
https://github.com/NativeScript/nativescript-cli/issues/2170
764765
"""
765766
# Deploy the app to make sure we have something at /data/data/org.nativescript.TestApp
766-
result = run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu, just_launch=True)
767+
run_hello_world_js_ts(self.app_name, Platform.ANDROID, self.emu, just_launch=True)
767768

768769
# Use all the disk space on emulator
769770
dest_file = '/data/data/' + TnsPaths.get_bundle_id(self.app_name)

tests/cli/run/tests/run_tests_api_28.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
from core.base_test.tns_run_android_test import TnsRunAndroidTest
44
from core.enums.platform_type import Platform
55
from core.settings import Settings
6-
from core.utils.file_utils import Folder
76
from core.utils.docker import Docker
7+
from core.utils.file_utils import Folder
88
from data.sync.hello_world_js import sync_hello_world_js, run_hello_world_js_ts
99
from products.nativescript.tns import Tns
10+
from products.nativescript.tns_assert import TnsAssert
1011
from products.nativescript.tns_paths import TnsPaths
1112

1213
Settings.Emulators.DEFAULT = Settings.Emulators.EMU_API_28
1314

1415

15-
class TnsRunJSTests(TnsRunAndroidTest):
16+
class TnsRunJSTestsApi28(TnsRunAndroidTest):
1617
app_name = Settings.AppName.DEFAULT
1718
source_project_dir = TnsPaths.get_app_path(app_name)
1819
target_project_dir = os.path.join(Settings.TEST_RUN_HOME, 'data', 'temp', app_name)
@@ -23,7 +24,8 @@ def setUpClass(cls):
2324
Docker.start()
2425

2526
# Create app
26-
Tns.create(app_name=cls.app_name, template='tns-template-hello-world@6.0')
27+
result = Tns.create(app_name=cls.app_name, template='tns-template-hello-world@6.0', verify=False)
28+
TnsAssert.created(app_name=cls.app_name, output=result.output, path=Settings.TEST_RUN_HOME, theme=False)
2729

2830
# Copy TestApp to data folder.
2931
Folder.copy(source=cls.source_project_dir, target=cls.target_project_dir)

tests/code_sharing/ng_new_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ def create_app(app_data, shared, sample, theme, style, prefix, source_dir, webpa
115115
sample=sample, style=style, prefix=prefix, source_dir=source_dir, webpack=webpack)
116116

117117
# Verify valid {N} app is created
118-
TnsAssert.created(app_name=NGNewTests.app_name, app_data=app_data, theme=theme, webpack=webpack)
118+
# Temporary do not assert theme is created because in schematics we still use nativescript-theme-core@1
119+
# TODO: Replace with theme=theme when schematics use @nativescript/theme
120+
TnsAssert.created(app_name=NGNewTests.app_name, app_data=app_data, theme=False, webpack=webpack)
119121
assert 'Directory is already under version control. Skipping initialization of git.' in result.output, \
120122
'Git init should be skipped because app is created already existing repo (the one with tests).'
121123

tests/code_sharing/test_ng_generate_e2e.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def workflow(app_name, device, platform, shared):
5555
app_path = TnsPaths.get_app_path(app_name=app_name)
5656
Folder.clean(app_path)
5757
NG.new(collection=NS_SCHEMATICS, project=app_name, shared=shared)
58-
TnsAssert.created(app_name=app_name, app_data=None)
58+
# TODO: Rollback theme=False when schematics use @nativescript/theme
59+
TnsAssert.created(app_name=app_name, app_data=None, theme=False)
5960

6061
# Run app initially
6162
text = 'TAP'

tests/code_sharing/test_ng_generate_ns.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def setUpClass(cls):
2424

2525
# Create app
2626
NG.new(collection=NS_SCHEMATICS, project=cls.app_name, shared=False)
27-
TnsAssert.created(app_name=cls.app_name, app_data=None)
27+
# TODO: Rollback theme=False when schematics use @nativescript/theme
28+
TnsAssert.created(app_name=cls.app_name, app_data=None, theme=False)
2829

2930
def setUp(self):
3031
TnsTest.setUpClass()

tests/code_sharing/test_ng_generate_shared.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ def setUpClass(cls):
2424

2525
# Create app
2626
NG.new(collection=NS_SCHEMATICS, project=cls.app_name, shared=True)
27-
TnsAssert.created(app_name=cls.app_name, app_data=None)
27+
# TODO: Rollback theme=False when schematics use @nativescript/theme
28+
TnsAssert.created(app_name=cls.app_name, app_data=None, theme=False)
2829

2930
def setUp(self):
3031
TnsTest.setUpClass()

tests/perf/app_size/test_app_size.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def test_003_js_app_apk(self):
7373
# Verify content of APK
7474
assert PerfUtils.is_value_in_range(actual=Folder.get_size(lib), expected=51266016, tolerance=0.05)
7575
assert PerfUtils.is_value_in_range(actual=Folder.get_size(res), expected=796627, tolerance=0.05)
76-
assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_app), expected=779471, tolerance=0.05)
77-
assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_snapshots), expected=9042404, tolerance=0.05)
76+
assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_app), expected=839462, tolerance=0.05)
77+
assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_snapshots), expected=10621384, tolerance=0.05)
7878

7979
# Verify final apk size
8080
assert PerfUtils.is_value_in_range(actual=File.get_size(apk), expected=24304589, tolerance=0.03)
@@ -102,8 +102,8 @@ def test_102_ng_app_apk(self):
102102
assets_snapshots = os.path.join(extracted_apk, 'assets', 'snapshots')
103103

104104
# No asserts for lib and res, since it is same as JS project
105-
assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_app), expected=1538681, tolerance=0.05)
106-
assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_snapshots), expected=19890584, tolerance=0.05)
105+
assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_app), expected=1636691, tolerance=0.05)
106+
assert PerfUtils.is_value_in_range(actual=Folder.get_size(assets_snapshots), expected=21822104, tolerance=0.05)
107107

108108
# Verify final apk size
109109
assert PerfUtils.is_value_in_range(actual=File.get_size(apk), expected=26988067, tolerance=0.03)

0 commit comments

Comments
 (0)