3
3
'''
4
4
import json
5
5
import os
6
+ import re
6
7
7
8
from core .osutils .file import File
8
9
from core .osutils .folder import Folder
@@ -22,6 +23,36 @@ class TnsAsserts(object):
22
23
PLATFORM_ANDROID_NPM_MODULES_PATH = PLATFORM_ANDROID_APP_PATH + 'tns_modules/'
23
24
PLATFORM_ANDROID_TNS_MODULES_PATH = PLATFORM_ANDROID_NPM_MODULES_PATH + 'tns-core-modules/'
24
25
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
+
25
56
@staticmethod
26
57
def _get_ios_app_path (app_name ):
27
58
normalized_app_name = app_name .replace (' ' , '' )
@@ -83,10 +114,24 @@ def created_ts(app_name, output=None):
83
114
ref_dts = os .path .join (app_name , 'references.d.ts' )
84
115
dts = os .path .join (app_name , TnsAsserts .TNS_MODULES , 'tns-core-modules.d.ts' )
85
116
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
+
86
121
File .exists (ts_config )
87
122
File .exists (ref_dts )
88
123
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
+
90
135
assert not Folder .is_empty (app_name + TnsAsserts .NODE_MODULES + '/nativescript-dev-typescript' )
91
136
assert File .exists (app_name + TnsAsserts .HOOKS + 'before-prepare/nativescript-dev-typescript.js' )
92
137
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
164
209
165
210
@staticmethod
166
211
def package_json_contains (app_name , string_list = None ):
167
- '''
212
+ """
168
213
Assert package.json contains list of strings.
169
214
:param app_name: Application name.
170
215
:param string_list: List of strings.
171
- '''
216
+ """
172
217
package_json_path = app_name + '/package.json'
173
218
output = File .read (package_json_path )
174
219
for item in string_list :
175
220
if item in output :
176
221
print '{0} found in {1}.' .format (item , package_json_path )
177
222
else :
178
- print 'pacakge .json:'
223
+ print 'package .json:'
179
224
print output
180
225
assert False , '{0} NOT found in {1}.' .format (item , package_json_path )
181
226
182
227
@staticmethod
183
228
def get_package_json (app_name ):
184
- '''
229
+ """
185
230
Return content of package.json as json object.
186
231
:param app_name: Application name.
187
232
:return: package.json as json object.
188
- '''
233
+ """
189
234
path = os .path .join (app_name , 'package.json' )
235
+ return TnsAsserts .__read_json (path = path )
190
236
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 )
203
246
204
247
@staticmethod
205
248
def prepared (app_name , platform = Platforms .BOTH , output = None , prepare_type = Prepare .FULL ):
@@ -249,28 +292,28 @@ def _full_prepare():
249
292
if platform is Platforms .IOS or platform is Platforms .BOTH :
250
293
assert 'tns-ios' in output
251
294
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