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