-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtest_ng_generate_e2e.py
97 lines (81 loc) · 4.5 KB
/
test_ng_generate_e2e.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
"""
Tests for `ng g` during livesync.
"""
import os
import unittest
from core.base_test.tns_run_test import TnsRunTest
from core.enums.app_type import AppType
from core.enums.os_type import OSType
from core.enums.platform_type import Platform
from core.settings import Settings
from core.utils.file_utils import Folder, File
from products.angular.ng import NG, NS_SCHEMATICS
from products.nativescript.tns import Tns
from products.nativescript.tns_assert import TnsAssert
from products.nativescript.tns_logs import TnsLogs
from products.nativescript.tns_paths import TnsPaths
class NGGenE2ETestsNS(TnsRunTest):
ns_app_name = Settings.AppName.DEFAULT
shared_app_name = 'SharedApp'
ns_app_path = TnsPaths.get_app_path(app_name=ns_app_name)
shared_app_path = TnsPaths.get_app_path(app_name=shared_app_name)
@classmethod
def setUpClass(cls):
TnsRunTest.setUpClass()
NG.kill()
def setUp(self):
TnsRunTest.setUpClass()
NG.kill()
def tearDown(self):
NG.kill()
TnsRunTest.tearDown(self)
def test_100_ns_generate_during_run_android(self):
NGGenE2ETestsNS.workflow(app_name=self.ns_app_name, device=self.emu, platform=Platform.ANDROID, shared=False)
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Skip iOS tests on non macOS machines.')
def test_100_ns_generate_during_run_ios(self):
NGGenE2ETestsNS.workflow(app_name=self.ns_app_name, device=self.sim, platform=Platform.IOS, shared=False)
def test_200_shared_generate_during_run_android(self):
NGGenE2ETestsNS.workflow(app_name=self.ns_app_name, device=self.emu, platform=Platform.ANDROID, shared=True)
@unittest.skipIf(Settings.HOST_OS != OSType.OSX, 'Skip iOS tests on non macOS machines.')
def test_200_shared_generate_during_run_ios(self):
NGGenE2ETestsNS.workflow(app_name=self.ns_app_name, device=self.sim, platform=Platform.IOS, shared=True)
@staticmethod
def workflow(app_name, device, platform, shared):
# Create an app
app_path = TnsPaths.get_app_path(app_name=app_name)
Folder.clean(app_path)
NG.new(collection=NS_SCHEMATICS, project=app_name, shared=shared)
TnsAssert.created(app_name=app_name, app_data=None)
# Run app initially
result = Tns.run(app_name=app_name, platform=platform, emulator=True, hmr=True)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, bundle=True, hmr=True, app_type=AppType.NG)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)
device.wait_for_text(text='TAP')
# Generate module and component
NG.exec_command(command='g m module-test', cwd=app_path)
NG.exec_command(command='g c module-test/component-test', cwd=app_path)
# Update app.modules.ts
app_module_name = 'app.module.ts'
app_module_path = os.path.join(app_path, 'app', app_module_name)
if shared:
app_module_name = 'app.module.tns.ts'
app_module_path = os.path.join(app_path, 'src', 'app', app_module_name)
old_string = "import { HomeComponent } from './home/home.component';"
new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
File.replace(path=app_module_path, old_string=old_string, new_string=new_string)
File.replace(path=app_module_path, old_string='HomeComponent,', new_string='ComponentTestComponent,')
# Update app-routing.module.ts
app_routing_module_name = 'app-routing.module.ts'
app_routing_module_path = os.path.join(app_path, 'app', app_routing_module_name)
if shared:
app_routing_module_name = 'app.routes.ts'
app_routing_module_path = os.path.join(app_path, 'src', 'app', app_routing_module_name)
old_string = "import { HomeComponent } from './home/home.component';"
new_string = "import { ComponentTestComponent } from './module-test/component-test/component-test.component';"
File.replace(path=app_routing_module_path, old_string=old_string, new_string=new_string)
File.replace(path=app_routing_module_path, old_string='HomeComponent', new_string='ComponentTestComponent')
# Verify app is updated
logs = [app_module_name.replace('.tns', ''), app_routing_module_name.replace('.tns', ''),
'Successfully synced application']
TnsLogs.wait_for_log(log_file=result.log_file, string_list=logs, timeout=120)
device.wait_for_text(text='component-test works!')