@@ -8,29 +8,43 @@ import { PluginComparisonMessages } from "../../../lib/services/livesync/playgro
88let readJsonParams : string [ ] = [ ] ;
99let warnParams : string [ ] = [ ] ;
1010
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 || { } ;
1216 const injector = new Yok ( ) ;
1317 injector . register ( "fs" , {
1418 readJson : ( filePath : string ) => {
1519 readJsonParams . push ( filePath ) ;
16- return {
20+ const result : any = {
1721 dependencies : localPlugins
1822 } ;
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 ;
1935 }
2036 } ) ;
2137 injector . register ( "logger" , {
2238 trace : ( ) => ( { } ) ,
2339 warn : ( message : string ) => warnParams . push ( message )
2440 } ) ;
2541 injector . register ( "projectData" , {
26- projectDir : "testProjectDir"
42+ projectDir
2743 } ) ;
2844 injector . register ( "previewAppPluginsService" , PreviewAppPluginsService ) ;
2945 return injector ;
3046}
3147
32- const deviceId = "myTestDeviceId" ;
33-
3448function createDevice ( plugins : string ) : Device {
3549 return {
3650 id : deviceId ,
@@ -45,8 +59,20 @@ function createDevice(plugins: string): Device {
4559 } ;
4660}
4761
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 ) ;
5076 const previewAppPluginsService = injector . resolve ( "previewAppPluginsService" ) ;
5177 const device = createDevice ( JSON . stringify ( previewAppPlugins ) ) ;
5278
@@ -57,7 +83,7 @@ function setup(localPlugins: IStringDictionary, previewAppPlugins: IStringDictio
5783}
5884
5985describe ( "previewAppPluginsService" , ( ) => {
60- describe ( "comparePluginsOnDevice" , ( ) => {
86+ describe ( "comparePluginsOnDevice without bundle " , ( ) => {
6187 it ( "should persist warnings per preview app's version" , async ( ) => {
6288 const localPlugins = {
6389 "nativescript-facebook" : "2.2.3" ,
@@ -84,7 +110,9 @@ describe("previewAppPluginsService", () => {
84110 return originalGetLocalPlugins . apply ( previewAppPluginsService ) ;
85111 } ;
86112
87- await previewAppPluginsService . comparePluginsOnDevice ( createDevice ( JSON . stringify ( previewAppPlugins ) ) ) ;
113+ const previewLiveSyncData = createPreviewLiveSyncData ( { bundle : false } ) ;
114+
115+ await previewAppPluginsService . comparePluginsOnDevice ( previewLiveSyncData , createDevice ( JSON . stringify ( previewAppPlugins ) ) ) ;
88116
89117 const expectedWarnings = [
90118 util . format ( PluginComparisonMessages . PLUGIN_NOT_INCLUDED_IN_PREVIEW_APP , "nativescript-facebook" , deviceId ) ,
@@ -98,7 +126,7 @@ describe("previewAppPluginsService", () => {
98126 isGetLocalPluginsCalled = false ;
99127 warnParams = [ ] ;
100128
101- await previewAppPluginsService . comparePluginsOnDevice ( createDevice ( JSON . stringify ( previewAppPlugins ) ) ) ;
129+ await previewAppPluginsService . comparePluginsOnDevice ( previewLiveSyncData , createDevice ( JSON . stringify ( previewAppPlugins ) ) ) ;
102130
103131 assert . isFalse ( isGetDevicePluginsCalled ) ;
104132 assert . isFalse ( isGetLocalPluginsCalled ) ;
@@ -225,13 +253,171 @@ describe("previewAppPluginsService", () => {
225253 it ( `${ testCase . name } ` , async ( ) => {
226254 const { previewAppPluginsService, device } = setup ( testCase . localPlugins , testCase . previewAppPlugins ) ;
227255
228- await previewAppPluginsService . comparePluginsOnDevice ( device ) ;
256+ await previewAppPluginsService . comparePluginsOnDevice ( createPreviewLiveSyncData ( { bundle : false } ) , device ) ;
229257
230258 assert . equal ( warnParams . length , testCase . expectedWarnings . length ) ;
231259 testCase . expectedWarnings . forEach ( warning => assert . include ( warnParams , warning ) ) ;
232260 } ) ;
233261 }
234262 } ) ;
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+ } ) ;
235421 describe ( "getExternalPlugins" , ( ) => {
236422 const testCases = [
237423 {
0 commit comments