@@ -8,29 +8,48 @@ import { PluginComparisonMessages } from "../../../lib/services/livesync/playgro
8
8
let readJsonParams : string [ ] = [ ] ;
9
9
let warnParams : string [ ] = [ ] ;
10
10
11
- function createTestInjector ( localPlugins : IStringDictionary ) : IInjector {
11
+ const deviceId = "myTestDeviceId" ;
12
+ const projectDir = "testProjectDir" ;
13
+
14
+ function createTestInjector ( localPlugins : IStringDictionary , options ?: { isNativeScriptPlugin ?: boolean , hasPluginNativeCode ?: boolean } ) : IInjector {
15
+ options = options || { } ;
12
16
const injector = new Yok ( ) ;
13
17
injector . register ( "fs" , {
14
18
readJson : ( filePath : string ) => {
15
19
readJsonParams . push ( filePath ) ;
16
- return {
20
+ const result : any = {
17
21
dependencies : localPlugins
18
22
} ;
23
+
24
+ if ( options . isNativeScriptPlugin ) {
25
+ result . nativescript = { } ;
26
+ }
27
+
28
+ return result ;
29
+ } ,
30
+ exists : ( filePath : string ) => {
31
+ return options . hasPluginNativeCode ;
32
+ } ,
33
+ isEmptyDir : ( filePath : string ) => {
34
+ return ! options . hasPluginNativeCode ;
35
+ }
36
+ } ) ;
37
+ injector . register ( "pluginsService" , {
38
+ isNativeScriptPlugin : ( ) => {
39
+ return options . isNativeScriptPlugin ;
19
40
}
20
41
} ) ;
21
42
injector . register ( "logger" , {
22
43
trace : ( ) => ( { } ) ,
23
44
warn : ( message : string ) => warnParams . push ( message )
24
45
} ) ;
25
46
injector . register ( "projectData" , {
26
- projectDir : "testProjectDir"
47
+ projectDir
27
48
} ) ;
28
49
injector . register ( "previewAppPluginsService" , PreviewAppPluginsService ) ;
29
50
return injector ;
30
51
}
31
52
32
- const deviceId = "myTestDeviceId" ;
33
-
34
53
function createDevice ( plugins : string ) : Device {
35
54
return {
36
55
id : deviceId ,
@@ -45,8 +64,20 @@ function createDevice(plugins: string): Device {
45
64
} ;
46
65
}
47
66
48
- function setup ( localPlugins : IStringDictionary , previewAppPlugins : IStringDictionary ) : any {
49
- const injector = createTestInjector ( localPlugins ) ;
67
+ function createPreviewLiveSyncData ( options ?: { bundle : boolean } ) {
68
+ return {
69
+ projectDir,
70
+ appFilesUpdaterOptions : {
71
+ release : false ,
72
+ bundle : options . bundle
73
+ } ,
74
+ env : { }
75
+ } ;
76
+ }
77
+
78
+ function setup ( localPlugins : IStringDictionary , previewAppPlugins : IStringDictionary ,
79
+ options ?: { isNativeScriptPlugin : boolean , hasPluginNativeCode : boolean } ) : any {
80
+ const injector = createTestInjector ( localPlugins , options ) ;
50
81
const previewAppPluginsService = injector . resolve ( "previewAppPluginsService" ) ;
51
82
const device = createDevice ( JSON . stringify ( previewAppPlugins ) ) ;
52
83
@@ -57,7 +88,7 @@ function setup(localPlugins: IStringDictionary, previewAppPlugins: IStringDictio
57
88
}
58
89
59
90
describe ( "previewAppPluginsService" , ( ) => {
60
- describe ( "comparePluginsOnDevice" , ( ) => {
91
+ describe ( "comparePluginsOnDevice without bundle " , ( ) => {
61
92
it ( "should persist warnings per preview app's version" , async ( ) => {
62
93
const localPlugins = {
63
94
"nativescript-facebook" : "2.2.3" ,
@@ -84,7 +115,9 @@ describe("previewAppPluginsService", () => {
84
115
return originalGetLocalPlugins . apply ( previewAppPluginsService ) ;
85
116
} ;
86
117
87
- await previewAppPluginsService . comparePluginsOnDevice ( createDevice ( JSON . stringify ( previewAppPlugins ) ) ) ;
118
+ const previewLiveSyncData = createPreviewLiveSyncData ( { bundle : false } ) ;
119
+
120
+ await previewAppPluginsService . comparePluginsOnDevice ( previewLiveSyncData , createDevice ( JSON . stringify ( previewAppPlugins ) ) ) ;
88
121
89
122
const expectedWarnings = [
90
123
util . format ( PluginComparisonMessages . PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP , "nativescript-facebook" , deviceId ) ,
@@ -98,7 +131,7 @@ describe("previewAppPluginsService", () => {
98
131
isGetLocalPluginsCalled = false ;
99
132
warnParams = [ ] ;
100
133
101
- await previewAppPluginsService . comparePluginsOnDevice ( createDevice ( JSON . stringify ( previewAppPlugins ) ) ) ;
134
+ await previewAppPluginsService . comparePluginsOnDevice ( previewLiveSyncData , createDevice ( JSON . stringify ( previewAppPlugins ) ) ) ;
102
135
103
136
assert . isFalse ( isGetDevicePluginsCalled ) ;
104
137
assert . isFalse ( isGetLocalPluginsCalled ) ;
@@ -225,13 +258,171 @@ describe("previewAppPluginsService", () => {
225
258
it ( `${ testCase . name } ` , async ( ) => {
226
259
const { previewAppPluginsService, device } = setup ( testCase . localPlugins , testCase . previewAppPlugins ) ;
227
260
228
- await previewAppPluginsService . comparePluginsOnDevice ( device ) ;
261
+ await previewAppPluginsService . comparePluginsOnDevice ( createPreviewLiveSyncData ( { bundle : false } ) , device ) ;
229
262
230
263
assert . equal ( warnParams . length , testCase . expectedWarnings . length ) ;
231
264
testCase . expectedWarnings . forEach ( warning => assert . include ( warnParams , warning ) ) ;
232
265
} ) ;
233
266
}
234
267
} ) ;
268
+ describe ( "comparePluginsOnDevice with bundle" , ( ) => {
269
+ const testCases = [
270
+ {
271
+ name : "should show warning for non nativescript plugin that has lower major version" ,
272
+ localPlugins : {
273
+ lodash : "1.2.3"
274
+ } ,
275
+ previewAppPlugins : {
276
+ lodash : "2.3.3"
277
+ } ,
278
+ isNativeScriptPlugin : false ,
279
+ hasPluginNativeCode : false ,
280
+ expectedWarnings : [
281
+ util . format ( PluginComparisonMessages . LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION , "lodash" , "1.2.3" , "2.3.3" )
282
+ ]
283
+ } ,
284
+ {
285
+ name : "should show warning for non nativescript plugin that has greather major version" ,
286
+ localPlugins : {
287
+ lodash : "3.2.3"
288
+ } ,
289
+ previewAppPlugins : {
290
+ lodash : "2.3.3"
291
+ } ,
292
+ isNativeScriptPlugin : false ,
293
+ hasPluginNativeCode : false ,
294
+ expectedWarnings : [
295
+ util . format ( PluginComparisonMessages . LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION , "lodash" , "3.2.3" , "2.3.3" )
296
+ ]
297
+ } ,
298
+ {
299
+ name : "should show warning for non nativescript plugin that has greather minor version" ,
300
+ localPlugins : {
301
+ lodash : "3.4.5"
302
+ } ,
303
+ previewAppPlugins : {
304
+ lodash : "3.3.0"
305
+ } ,
306
+ isNativeScriptPlugin : false ,
307
+ hasPluginNativeCode : false ,
308
+ expectedWarnings : [
309
+ util . format ( PluginComparisonMessages . LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION , "lodash" , "3.4.5" , "3.3.0" )
310
+ ]
311
+ } ,
312
+ {
313
+ name : "should not show warning for non nativescript plugin that has the same version" ,
314
+ localPlugins : {
315
+ lodash : "3.4.5"
316
+ } ,
317
+ previewAppPlugins : {
318
+ lodash : "3.4.5"
319
+ } ,
320
+ isNativeScriptPlugin : false ,
321
+ hasPluginNativeCode : false ,
322
+ expectedWarnings : [ ]
323
+ } ,
324
+ {
325
+ name : "should not show warning for nativescript plugin without native code that has lower major version" ,
326
+ localPlugins : {
327
+ "nativescript-theme-core" : "2.4.5"
328
+ } ,
329
+ previewAppPlugins : {
330
+ "nativescript-theme-core" : "3.4.5"
331
+ } ,
332
+ isNativeScriptPlugin : true ,
333
+ hasPluginNativeCode : false ,
334
+ expectedWarnings : < string [ ] > [ ]
335
+ } ,
336
+ {
337
+ name : "should not show warning for nativescript plugin without native code that has greather major version" ,
338
+ localPlugins : {
339
+ "nativescript-theme-core" : "4.4.5"
340
+ } ,
341
+ previewAppPlugins : {
342
+ "nativescript-theme-core" : "3.4.5"
343
+ } ,
344
+ isNativeScriptPlugin : true ,
345
+ hasPluginNativeCode : false ,
346
+ expectedWarnings : [ ]
347
+ } ,
348
+ {
349
+ name : "should not show warning for nativescript plugin without native code that has greather minor version" ,
350
+ localPlugins : {
351
+ "nativescript-theme-core" : "4.6.5"
352
+ } ,
353
+ previewAppPlugins : {
354
+ "nativescript-theme-core" : "4.4.5"
355
+ } ,
356
+ isNativeScriptPlugin : true ,
357
+ hasPluginNativeCode : false ,
358
+ expectedWarnings : [ ]
359
+ } ,
360
+ {
361
+ name : "should not show warning for nativescript plugin without native code that has the same version" ,
362
+ localPlugins : {
363
+ "nativescript-theme-core" : "4.6.5"
364
+ } ,
365
+ previewAppPlugins : {
366
+ "nativescript-theme-core" : "4.6.5"
367
+ } ,
368
+ isNativeScriptPlugin : true ,
369
+ hasPluginNativeCode : false ,
370
+ expectedWarnings : [ ]
371
+ } ,
372
+ {
373
+ name : "should show warning for nativescript plugin with native code that has lower major version" ,
374
+ localPlugins : {
375
+ "nativescript-theme-core" : "2.4.5"
376
+ } ,
377
+ previewAppPlugins : {
378
+ "nativescript-theme-core" : "3.4.5"
379
+ } ,
380
+ isNativeScriptPlugin : true ,
381
+ hasPluginNativeCode : true ,
382
+ expectedWarnings : [ util . format ( PluginComparisonMessages . LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION , "nativescript-theme-core" , "2.4.5" , "3.4.5" ) ]
383
+ } ,
384
+ {
385
+ name : "should show warning for nativescript plugin with native code that has greather major version" ,
386
+ localPlugins : {
387
+ "nativescript-theme-core" : "4.4.5"
388
+ } ,
389
+ previewAppPlugins : {
390
+ "nativescript-theme-core" : "3.4.5"
391
+ } ,
392
+ isNativeScriptPlugin : true ,
393
+ hasPluginNativeCode : true ,
394
+ expectedWarnings : [ util . format ( PluginComparisonMessages . LOCAL_PLUGIN_WITH_DIFFERENCE_IN_MAJOR_VERSION , "nativescript-theme-core" , "4.4.5" , "3.4.5" ) ]
395
+ } ,
396
+ {
397
+ name : "should show warning for nativescript plugin with native code that has greather minor version" ,
398
+ localPlugins : {
399
+ "nativescript-theme-core" : "4.4.5"
400
+ } ,
401
+ previewAppPlugins : {
402
+ "nativescript-theme-core" : "4.3.5"
403
+ } ,
404
+ isNativeScriptPlugin : true ,
405
+ hasPluginNativeCode : true ,
406
+ expectedWarnings : [ util . format ( PluginComparisonMessages . LOCAL_PLUGIN_WITH_GREATHER_MINOR_VERSION , "nativescript-theme-core" , "4.4.5" , "4.3.5" ) ]
407
+ } ,
408
+ ] ;
409
+
410
+ afterEach ( ( ) => {
411
+ warnParams = [ ] ;
412
+ readJsonParams = [ ] ;
413
+ } ) ;
414
+
415
+ _ . each ( testCases , testCase => {
416
+ it ( `${ testCase . name } ` , async ( ) => {
417
+ const { previewAppPluginsService, device } = setup ( testCase . localPlugins , testCase . previewAppPlugins , { isNativeScriptPlugin : testCase . isNativeScriptPlugin , hasPluginNativeCode : testCase . hasPluginNativeCode } ) ;
418
+
419
+ await previewAppPluginsService . comparePluginsOnDevice ( createPreviewLiveSyncData ( { bundle : true } ) , device ) ;
420
+
421
+ assert . equal ( warnParams . length , testCase . expectedWarnings . length ) ;
422
+ testCase . expectedWarnings . forEach ( warning => assert . include ( warnParams , warning ) ) ;
423
+ } ) ;
424
+ } ) ;
425
+ } ) ;
235
426
describe ( "getExternalPlugins" , ( ) => {
236
427
const testCases = [
237
428
{
0 commit comments