Skip to content

Commit b2b0797

Browse files
author
Dimitar Topuzov
committed
Update typescript test after cahgnes in nativescript-dev-typescript
1 parent c11e610 commit b2b0797

File tree

1 file changed

+86
-43
lines changed

1 file changed

+86
-43
lines changed

core/tns/tns_verifications.py

+86-43
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'''
44
import json
55
import os
6+
import re
67

78
from core.osutils.file import File
89
from core.osutils.folder import Folder
@@ -22,6 +23,36 @@ class TnsAsserts(object):
2223
PLATFORM_ANDROID_NPM_MODULES_PATH = PLATFORM_ANDROID_APP_PATH + 'tns_modules/'
2324
PLATFORM_ANDROID_TNS_MODULES_PATH = PLATFORM_ANDROID_NPM_MODULES_PATH + 'tns-core-modules/'
2425

26+
@staticmethod
27+
def __read_json(path):
28+
"""
29+
Read content of json file.
30+
:param path: Path to file.
31+
:return: Content of file as json object.
32+
"""
33+
34+
# This is to handle test for app with space.
35+
# In this case we put app name inside ''.
36+
path = path.replace('\'', '')
37+
path = path.replace('\"', '')
38+
39+
# Check if file exists
40+
assert File.exists(path), 'Failed to find file: ' + path
41+
42+
# Read it...
43+
with open(path) as json_file:
44+
data = json.load(json_file)
45+
return data
46+
47+
@staticmethod
48+
def _get_modules_version(app_name):
49+
"""
50+
Get version of `tns-core-modules` inside project
51+
:param app_name: Project name (path relative to TEST_RUN_HOME).
52+
:return: Value of `tns-core-modules`
53+
"""
54+
return TnsAsserts.get_package_json(app_name=app_name).get('dependencies').get('tns-core-modules')
55+
2556
@staticmethod
2657
def _get_ios_app_path(app_name):
2758
normalized_app_name = app_name.replace(' ', '')
@@ -83,10 +114,24 @@ def created_ts(app_name, output=None):
83114
ref_dts = os.path.join(app_name, 'references.d.ts')
84115
dts = os.path.join(app_name, TnsAsserts.TNS_MODULES, 'tns-core-modules.d.ts')
85116

117+
# Assert content of files added with TypeScript plugin.
118+
modules_version = TnsAsserts._get_modules_version(app_name=app_name)
119+
modules_version = re.sub("\D", "", modules_version)
120+
86121
File.exists(ts_config)
87122
File.exists(ref_dts)
88123
File.exists(dts)
89-
assert './node_modules/tns-core-modules/tns-core-modules.d.ts' in File.read(ref_dts)
124+
red_tds_content = File.read(ref_dts)
125+
if modules_version[0] < 3:
126+
assert './node_modules/tns-core-modules/tns-core-modules.d.ts' in red_tds_content
127+
else:
128+
assert './node_modules/tns-core-modules/tns-core-modules.d.ts' not in red_tds_content
129+
ts_config_json = TnsAsserts.get_tsconfig_json(app_name=app_name)
130+
paths = ts_config_json.get('compilerOptions').get('paths')
131+
assert paths is not None, 'Paths missing in tsconfig.json'
132+
assert '/node_modules/tns-core-modules/' in str(paths), \
133+
'"/node_modules/tns-core-modules/" not found in paths section iof tsconfig.json'
134+
90135
assert not Folder.is_empty(app_name + TnsAsserts.NODE_MODULES + '/nativescript-dev-typescript')
91136
assert File.exists(app_name + TnsAsserts.HOOKS + 'before-prepare/nativescript-dev-typescript.js')
92137
assert File.exists(app_name + TnsAsserts.HOOKS + 'before-watch/nativescript-dev-typescript.js')
@@ -164,42 +209,40 @@ def platform_list_status(output=None, prepared=Platforms.NONE, added=Platforms.N
164209

165210
@staticmethod
166211
def package_json_contains(app_name, string_list=None):
167-
'''
212+
"""
168213
Assert package.json contains list of strings.
169214
:param app_name: Application name.
170215
:param string_list: List of strings.
171-
'''
216+
"""
172217
package_json_path = app_name + '/package.json'
173218
output = File.read(package_json_path)
174219
for item in string_list:
175220
if item in output:
176221
print '{0} found in {1}.'.format(item, package_json_path)
177222
else:
178-
print 'pacakge.json:'
223+
print 'package.json:'
179224
print output
180225
assert False, '{0} NOT found in {1}.'.format(item, package_json_path)
181226

182227
@staticmethod
183228
def get_package_json(app_name):
184-
'''
229+
"""
185230
Return content of package.json as json object.
186231
:param app_name: Application name.
187232
:return: package.json as json object.
188-
'''
233+
"""
189234
path = os.path.join(app_name, 'package.json')
235+
return TnsAsserts.__read_json(path=path)
190236

191-
# This is to handle test for app with space.
192-
# In this case we put app name inside ''.
193-
path = path.replace('\'', '')
194-
path = path.replace('\"', '')
195-
196-
# Check if file exists
197-
assert File.exists(path), 'Failed to find package.json at ' + path
198-
199-
# Read it...
200-
with open(path) as json_file:
201-
data = json.load(json_file)
202-
return data
237+
@staticmethod
238+
def get_tsconfig_json(app_name):
239+
"""
240+
Return content of package.json as json object.
241+
:param app_name: Application name.
242+
:return: package.json as json object.
243+
"""
244+
path = os.path.join(app_name, 'tsconfig.json')
245+
return TnsAsserts.__read_json(path=path)
203246

204247
@staticmethod
205248
def prepared(app_name, platform=Platforms.BOTH, output=None, prepare_type=Prepare.FULL):
@@ -249,28 +292,28 @@ def _full_prepare():
249292
if platform is Platforms.IOS or platform is Platforms.BOTH:
250293
assert 'tns-ios' in output
251294

252-
# Ignore because of https://github.com/NativeScript/nativescript-cli/issues/2586
253-
# if platform is Platforms.ANDROID or platform is Platforms.BOTH:
254-
# app_path = app_name + TnsAsserts.PLATFORM_ANDROID_APP_PATH
255-
# modules_path = app_name + TnsAsserts.PLATFORM_ANDROID_TNS_MODULES_PATH
256-
# assert File.exists(app_path + 'main-view-model.js'), \
257-
# 'Application files does not exists in platforms folder.'
258-
# assert File.exists(modules_path + 'application/application.js'), \
259-
# 'Modules does not exists in platforms folder.'
260-
# assert File.exists(modules_path + 'xml/xml.js'), 'TNS Modules does not exists in platforms folder.'
261-
# assert not File.exists(modules_path + 'application/application.android.js'), \
262-
# 'Prepare does not strip \'android\' from name of js files.'
263-
# assert not File.exists(modules_path + 'application/application.ios.js'), \
264-
# 'Prepare does not skip \'ios\' specific js files.'
265-
#
266-
# if platform is Platforms.IOS or platform is Platforms.BOTH:
267-
# app_path = TnsAsserts._get_ios_app_path(app_name)
268-
# modules_path = TnsAsserts._get_ios_modules_path(app_name)
269-
# assert File.exists(app_path + 'main-view-model.js'), \
270-
# 'Application files does not exists in platforms folder.'
271-
# assert File.exists(modules_path + 'application/application.js'), \
272-
# 'Modules does not exists in platforms folder.'
273-
# assert not File.exists(modules_path + 'application/application.android.js'), \
274-
# 'Prepare does not skip \'ios\' specific js files.'
275-
# assert not File.exists(modules_path + 'application/application.ios.js'), \
276-
# 'Prepare does not strip \'ios\' from name of js files.'
295+
# Ignore because of https://github.com/NativeScript/nativescript-cli/issues/2586
296+
# if platform is Platforms.ANDROID or platform is Platforms.BOTH:
297+
# app_path = app_name + TnsAsserts.PLATFORM_ANDROID_APP_PATH
298+
# modules_path = app_name + TnsAsserts.PLATFORM_ANDROID_TNS_MODULES_PATH
299+
# assert File.exists(app_path + 'main-view-model.js'), \
300+
# 'Application files does not exists in platforms folder.'
301+
# assert File.exists(modules_path + 'application/application.js'), \
302+
# 'Modules does not exists in platforms folder.'
303+
# assert File.exists(modules_path + 'xml/xml.js'), 'TNS Modules does not exists in platforms folder.'
304+
# assert not File.exists(modules_path + 'application/application.android.js'), \
305+
# 'Prepare does not strip \'android\' from name of js files.'
306+
# assert not File.exists(modules_path + 'application/application.ios.js'), \
307+
# 'Prepare does not skip \'ios\' specific js files.'
308+
#
309+
# if platform is Platforms.IOS or platform is Platforms.BOTH:
310+
# app_path = TnsAsserts._get_ios_app_path(app_name)
311+
# modules_path = TnsAsserts._get_ios_modules_path(app_name)
312+
# assert File.exists(app_path + 'main-view-model.js'), \
313+
# 'Application files does not exists in platforms folder.'
314+
# assert File.exists(modules_path + 'application/application.js'), \
315+
# 'Modules does not exists in platforms folder.'
316+
# assert not File.exists(modules_path + 'application/application.android.js'), \
317+
# 'Prepare does not skip \'ios\' specific js files.'
318+
# assert not File.exists(modules_path + 'application/application.ios.js'), \
319+
# 'Prepare does not strip \'ios\' from name of js files.'

0 commit comments

Comments
 (0)