Skip to content

Commit e015d68

Browse files
Vasil ChimevVasil Chimev
Vasil Chimev
authored and
Vasil Chimev
committed
Merge pull request #14 from NativeScript/templ-ng
Add angular/ng template tests
2 parents 4b3a734 + 2342658 commit e015d68

File tree

7 files changed

+274
-57
lines changed

7 files changed

+274
-57
lines changed

core/tns/tns.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ def create_app(app_name, path=None, app_id=None, copy_from=None, template=None,
3636
if app_id is not None:
3737
command += " --appid " + app_id
3838

39-
# By default --copy-from template-hello-world
40-
if copy_from is not None:
41-
command += " --copy-from " + copy_from
42-
else:
43-
command += " --copy-from " + SUT_ROOT_FOLDER + os.path.sep + "template-hello-world"
39+
if template is None:
40+
# By default --copy-from template-hello-world
41+
if copy_from is not None:
42+
command += " --copy-from " + copy_from
43+
else:
44+
command += " --copy-from " + SUT_ROOT_FOLDER + os.path.sep + "template-hello-world"
4445

4546
if template is not None:
4647
command += " --template " + template

tests/build/build_android_ng.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import unittest
2+
3+
from core.osutils.command import run
4+
from core.osutils.file import File
5+
from core.osutils.folder import Folder
6+
from core.settings.settings import ANDROID_RUNTIME_PATH, TNS_PATH, \
7+
ANDROID_KEYSTORE_PASS, ANDROID_KEYSTORE_ALIAS, ANDROID_KEYSTORE_PATH, ANDROID_KEYSTORE_ALIAS_PASS
8+
from core.tns.tns import Tns
9+
10+
11+
class BuildAndroidNG(unittest.TestCase):
12+
13+
@classmethod
14+
def setUpClass(cls):
15+
Folder.cleanup('./TNS_App')
16+
output = run(TNS_PATH + " create TNS_App --ng")
17+
assert "successfully created" in output
18+
Tns.platform_add(
19+
platform="android",
20+
path="TNS_App",
21+
framework_path=ANDROID_RUNTIME_PATH)
22+
23+
def setUp(self):
24+
25+
print ""
26+
print "#####"
27+
print self.id()
28+
print "#####"
29+
print ""
30+
31+
def tearDown(self):
32+
pass
33+
34+
@classmethod
35+
def tearDownClass(cls):
36+
Folder.cleanup('./TNS_App')
37+
38+
def test_010_build_android_ng_project(self):
39+
Tns.build(platform="android", path="TNS_App")
40+
assert File.exists("TNS_App/platforms/android/build/outputs/apk/TNSApp-debug.apk")
41+
42+
def test_210_build_android_ng_project(self):
43+
output = run(TNS_PATH + " build android --keyStorePath " + ANDROID_KEYSTORE_PATH +
44+
" --keyStorePassword " + ANDROID_KEYSTORE_PASS +
45+
" --keyStoreAlias " + ANDROID_KEYSTORE_ALIAS +
46+
" --keyStoreAliasPassword " + ANDROID_KEYSTORE_ALIAS_PASS +
47+
" --release --path TNS_App")
48+
49+
assert "Project successfully prepared" in output
50+
assert "BUILD SUCCESSFUL" in output
51+
52+
assert "Project successfully built" in output
53+
assert File.exists("TNS_App/platforms/android/build/outputs/apk/TNSApp-release.apk")

tests/build/build_ios_ng.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import unittest
2+
3+
from core.osutils.command import run
4+
from core.osutils.file import File
5+
from core.osutils.folder import Folder
6+
from core.settings.settings import IOS_RUNTIME_SYMLINK_PATH, TNS_PATH
7+
from core.tns.tns import Tns
8+
from core.xcode.xcode import Xcode
9+
10+
11+
class BuildiOSNG(unittest.TestCase):
12+
13+
@classmethod
14+
def setUpClass(cls):
15+
Xcode.cleanup_cache()
16+
Folder.cleanup('./TNS_App')
17+
18+
output = run(TNS_PATH + " create TNS_App --ng")
19+
assert "successfully created" in output
20+
Tns.platform_add(
21+
platform="ios",
22+
path="TNS_App",
23+
framework_path=IOS_RUNTIME_SYMLINK_PATH, symlink=True)
24+
25+
def setUp(self):
26+
print ""
27+
print "#####"
28+
print self.id()
29+
print "#####"
30+
print ""
31+
32+
def tearDown(self):
33+
pass
34+
35+
@classmethod
36+
def tearDownClass(cls):
37+
Folder.cleanup('./TNS_App')
38+
39+
def test_010_build_ios_ng_project(self):
40+
output = run(TNS_PATH + " build ios --path TNS_App")
41+
assert "Project successfully prepared" in output
42+
assert "build/emulator/TNSApp.app" in output
43+
assert "** BUILD SUCCEEDED **" in output
44+
assert "Project successfully built" in output
45+
assert File.exists("TNS_App/platforms/ios/build/emulator/TNSApp.app")
46+
47+
def test_210_build_ios_ng_project_release_fordevice(self):
48+
output = run(TNS_PATH +
49+
" build ios --path TNS_App --for-device --release")
50+
assert "Project successfully prepared" in output
51+
assert "CONFIGURATION Release" in output
52+
assert "CodeSign" in output
53+
assert "build/device/TNSApp.app" in output
54+
assert "** BUILD SUCCEEDED **" in output
55+
assert "Project successfully built" in output
56+
assert File.exists("TNS_App/platforms/ios/build/device/TNSApp.ipa")

tests/build/create_ng.py

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import unittest
2+
3+
from nose_parameterized import parameterized
4+
5+
from core.osutils.command import run
6+
from core.osutils.folder import Folder
7+
from core.settings.settings import TNS_PATH
8+
from core.tns.tns import Tns
9+
10+
11+
class CreateNG(unittest.TestCase):
12+
13+
def setUp(self):
14+
print ""
15+
print "#####"
16+
print self.id()
17+
print "#####"
18+
print ""
19+
20+
Folder.cleanup('./TNS_App')
21+
22+
def tearDown(self):
23+
Folder.cleanup('./TNS_App')
24+
25+
def assert_angular_project(self):
26+
output = run("cat TNS_App/package.json")
27+
assert "angular2" in output
28+
assert "nativescript-angular" in output
29+
assert "tns-core-modules" in output
30+
assert "nativescript-dev-typescript" in output
31+
32+
assert Folder.exists("TNS_App/node_modules/angular2")
33+
assert Folder.exists("TNS_App/node_modules/nativescript-angular")
34+
assert Folder.exists("TNS_App/node_modules/nativescript-dev-typescript")
35+
assert Folder.exists("TNS_App/node_modules/tns-core-modules")
36+
37+
assert Folder.exists("TNS_App/hooks")
38+
assert Folder.exists("TNS_App/app/App_Resources")
39+
40+
def test_101_create_ng_project(self):
41+
output = run(TNS_PATH + " create TNS_App --ng")
42+
assert "successfully created" in output
43+
self.assert_angular_project()
44+
45+
@parameterized.expand([
46+
"tns-template-hello-world-ng",
47+
"https://github.com/NativeScript/template-hello-world-ng.git",
48+
"angular",
49+
"ng",
50+
])
51+
def test_102_create_project_with_template_ng(self, template_source):
52+
Tns.create_app(app_name="TNS_App", template=template_source)
53+
self.assert_angular_project()
54+
55+
def test_401_create_project_with_template_no_value(self):
56+
output = run(TNS_PATH + " create TNS_App --template")
57+
assert "successfully created" not in output
58+
assert "requires non-empty value" in output
59+
60+
def test_402_create_project_with_template_and_ng(self):
61+
output = run(TNS_PATH + " create TNS_App --template --ng")
62+
assert "successfully created" not in output
63+
assert "requires non-empty value" in output

tests/build/prepare_android.py

+35-20
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class PrepareAndroid(unittest.TestCase):
15+
1516
def setUp(self):
1617
print ""
1718
print "#####"
@@ -66,7 +67,40 @@ def test_002_prepare_android_inside_project(self):
6667
assert not File.exists(
6768
'TNS_App/platforms/android/src/main/assets/app/tns_modules/application/application.ios.js')
6869

69-
def test_010_prepare_android_tns_core_modules(self):
70+
def test_010_prepare_android_ng_project(self):
71+
output = run(TNS_PATH + " create TNS_App --ng")
72+
assert "successfully created" in output
73+
Tns.platform_add(
74+
platform="android",
75+
path="TNS_App",
76+
framework_path=ANDROID_RUNTIME_PATH)
77+
Tns.prepare(platform="android", path="TNS_App")
78+
79+
assert Folder.exists(
80+
'TNS_App/platforms/android/src/main/assets/app/tns_modules/angular2')
81+
assert Folder.exists(
82+
'TNS_App/platforms/android/src/main/assets/app/tns_modules/nativescript-angular')
83+
84+
def test_200_prepare_android_patform_not_added(self):
85+
Tns.create_app(app_name="TNS_App")
86+
output = run(TNS_PATH + " prepare android --path TNS_App")
87+
assert "Copying template files..." in output
88+
assert "Project successfully created." in output
89+
assert "Project successfully prepared" in output
90+
assert File.exists(
91+
'TNS_App/platforms/android/src/main/assets/app/tns_modules/xml/xml.js')
92+
93+
def test_201_prepare_xml_error(self):
94+
Tns.create_app(app_name="TNS_App")
95+
File.replace("TNS_App/app/main-page.xml", "</Page>", "</Page")
96+
output = run(TNS_PATH + " prepare android --path TNS_App")
97+
assert "Copying template files..." in output
98+
assert "Project successfully created." in output
99+
assert "Project successfully prepared" in output
100+
assert "main-page.xml has syntax errors." in output
101+
assert "unclosed xml attribute" in output
102+
103+
def test_210_prepare_android_tns_core_modules(self):
70104
Tns.create_app(
71105
app_name="TNS_App",
72106
copy_from=SUT_ROOT_FOLDER + "/QA-TestApps/tns-modules-app/app")
@@ -108,25 +142,6 @@ def test_010_prepare_android_tns_core_modules(self):
108142
"tns_modules/application/application-common.js")
109143
assert "require(\"globals\"); // test" in output
110144

111-
def test_200_prepare_android_patform_not_added(self):
112-
Tns.create_app(app_name="TNS_App")
113-
output = run(TNS_PATH + " prepare android --path TNS_App")
114-
assert "Copying template files..." in output
115-
assert "Project successfully created." in output
116-
assert "Project successfully prepared" in output
117-
assert File.exists(
118-
'TNS_App/platforms/android/src/main/assets/app/tns_modules/xml/xml.js')
119-
120-
def test_201_prepare_xml_error(self):
121-
Tns.create_app(app_name="TNS_App")
122-
File.replace("TNS_App/app/main-page.xml", "</Page>", "</Page")
123-
output = run(TNS_PATH + " prepare android --path TNS_App")
124-
assert "Copying template files..." in output
125-
assert "Project successfully created." in output
126-
assert "Project successfully prepared" in output
127-
assert "main-page.xml has syntax errors." in output
128-
assert "unclosed xml attribute" in output
129-
130145
def test_300_prepare_android_remove_old_files(self):
131146
Tns.create_app_platform_add(
132147
app_name="TNS_App",

tests/build/prepare_ios.py

+47-32
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
class PrepareiOS(unittest.TestCase):
15+
1516
@classmethod
1617
def setUpClass(cls):
1718
if CURRENT_OS != OSType.OSX:
@@ -28,7 +29,7 @@ def setUp(self):
2829
Folder.cleanup('./TNS_App')
2930

3031
def tearDown(self):
31-
pass
32+
Folder.cleanup('./TNS_App')
3233

3334
def test_001_prepare_ios(self):
3435
Tns.create_app_platform_add(app_name="TNS_App", platform="ios",
@@ -47,38 +48,19 @@ def test_001_prepare_ios(self):
4748
assert not File.exists(
4849
'TNS_App/platforms/ios/TNSApp/app/tns_modules/application/application.ios.js')
4950

50-
def test_010_prepare_ios_tns_core_modules(self):
51-
Tns.create_app(app_name="TNS_App", copy_from="data/projects/helloworld-1.2.1/app")
52-
Tns.platform_add(platform="ios", path="TNS_App",
53-
framework_path=IOS_RUNTIME_SYMLINK_PATH, symlink=True)
54-
55-
# Make a change in tns-core-modules to verify they are not overwritten.
56-
File.replace("TNS_App/node_modules/tns-core-modules/application/application-common.js",
57-
"(\"globals\");",
58-
"(\"globals\"); // test")
59-
60-
# Verify tns-core-modules are copied to the native project, not app's tns_modules.
61-
for i in range(1, 3):
62-
print "prepare number: " + str(i)
63-
64-
output = run(TNS_PATH + " prepare ios --path TNS_App")
65-
assert "You have tns_modules dir in your app folder" in output
66-
assert "Project successfully prepared" in output
67-
68-
output = run("cat TNS_App/app/tns_modules/package.json")
69-
assert "\"version\": \"1.2.1\"," in output
70-
71-
output = run("cat TNS_App/node_modules/tns-core-modules/package.json")
72-
assert "\"version\": \"1.2.1\"," not in output
73-
output = run("cat TNS_App/node_modules/" +
74-
"tns-core-modules/application/application-common.js")
75-
assert "require(\"globals\"); // test" in output
51+
def test_010_prepare_android_ng_project(self):
52+
output = run(TNS_PATH + " create TNS_App --ng")
53+
assert "successfully created" in output
54+
Tns.platform_add(
55+
platform="ios",
56+
path="TNS_App",
57+
framework_path=IOS_RUNTIME_SYMLINK_PATH, symlink=True)
58+
Tns.prepare(platform="ios", path="TNS_App")
7659

77-
output = run("cat TNS_App/platforms/ios/TNSApp/app/tns_modules/package.json")
78-
assert "\"version\": \"1.2.1\"," not in output
79-
output = run("cat TNS_App/platforms/ios/" +
80-
"TNSApp/app/tns_modules/application/application-common.js")
81-
assert "require(\"globals\"); // test" in output
60+
assert Folder.exists(
61+
'TNS_App/platforms/ios/TNSApp/app/tns_modules/angular2')
62+
assert Folder.exists(
63+
'TNS_App/platforms/ios/TNSApp/app/tns_modules/nativescript-angular')
8264

8365
def test_200_prepare_additional_appresources(self):
8466
Tns.create_app_platform_add(app_name="TNS_App", platform="ios",
@@ -119,6 +101,39 @@ def test_201_prepare_ios_platform_not_added(self):
119101
assert File.exists(
120102
'TNS_App/platforms/ios/TNSApp/app/tns_modules/application/application.js')
121103

104+
def test_210_prepare_ios_tns_core_modules(self):
105+
Tns.create_app(app_name="TNS_App", copy_from="data/projects/helloworld-1.2.1/app")
106+
Tns.platform_add(platform="ios", path="TNS_App",
107+
framework_path=IOS_RUNTIME_SYMLINK_PATH, symlink=True)
108+
109+
# Make a change in tns-core-modules to verify they are not overwritten.
110+
File.replace("TNS_App/node_modules/tns-core-modules/application/application-common.js",
111+
"(\"globals\");",
112+
"(\"globals\"); // test")
113+
114+
# Verify tns-core-modules are copied to the native project, not app's tns_modules.
115+
for i in range(1, 3):
116+
print "prepare number: " + str(i)
117+
118+
output = run(TNS_PATH + " prepare ios --path TNS_App")
119+
assert "You have tns_modules dir in your app folder" in output
120+
assert "Project successfully prepared" in output
121+
122+
output = run("cat TNS_App/app/tns_modules/package.json")
123+
assert "\"version\": \"1.2.1\"," in output
124+
125+
output = run("cat TNS_App/node_modules/tns-core-modules/package.json")
126+
assert "\"version\": \"1.2.1\"," not in output
127+
output = run("cat TNS_App/node_modules/" +
128+
"tns-core-modules/application/application-common.js")
129+
assert "require(\"globals\"); // test" in output
130+
131+
output = run("cat TNS_App/platforms/ios/TNSApp/app/tns_modules/package.json")
132+
assert "\"version\": \"1.2.1\"," not in output
133+
output = run("cat TNS_App/platforms/ios/" +
134+
"TNSApp/app/tns_modules/application/application-common.js")
135+
assert "require(\"globals\"); // test" in output
136+
122137
def test_300_prepare_ios_preserve_case(self):
123138
Tns.create_app_platform_add(app_name="TNS_App", platform="ios",
124139
framework_path=IOS_RUNTIME_SYMLINK_PATH, symlink=True)

0 commit comments

Comments
 (0)