@@ -27,6 +27,7 @@ var events = require('cordova-common').events;
27
27
var plugman = require ( '../../src/plugman/plugman' ) ;
28
28
var platforms = require ( '../../src/plugman/platforms/common' ) ;
29
29
var knownPlatforms = require ( '../../src/platforms/platforms' ) ;
30
+ var cordovaUtil = require ( '../../src/cordova/util' ) ;
30
31
var common = require ( '../common' ) ;
31
32
var fs = require ( 'fs' ) ;
32
33
var os = require ( 'os' ) ;
@@ -287,15 +288,12 @@ describe('install', function () {
287
288
. fin ( function ( ) {
288
289
var plugmanVersion = require ( '../../package.json' ) . version . replace ( / - d e v | - n i g h t l y .* $ / , '' ) ;
289
290
var cordovaVersion = require ( '../../package.json' ) . version . replace ( / - d e v | - n i g h t l y .* $ / , '' ) ;
290
- expect ( satisfies . calls . count ( ) ) . toBe ( 4 ) ;
291
+ // var megaFun = require('../../package.json').version.replace(/-dev|-nightly.*$/, '');
292
+ expect ( satisfies . calls . count ( ) ) . toBe ( 2 ) ;
291
293
// <engine name="cordova" version=">=2.3.0"/>
292
294
expect ( satisfies . calls . argsFor ( 0 ) ) . toEqual ( [ cordovaVersion , '>=2.3.0' , true ] ) ;
293
295
// <engine name="cordova-plugman" version=">=0.10.0" />
294
296
expect ( satisfies . calls . argsFor ( 1 ) ) . toEqual ( [ plugmanVersion , '>=0.10.0' , true ] ) ;
295
- // <engine name="mega-fun-plugin" version=">=1.0.0" scriptSrc="megaFunVersion" platform="*" />
296
- expect ( satisfies . calls . argsFor ( 2 ) ) . toEqual ( [ null , '>=1.0.0' , true ] ) ;
297
- // <engine name="mega-boring-plugin" version=">=3.0.0" scriptSrc="megaBoringVersion" platform="ios|android" />
298
- expect ( satisfies . calls . argsFor ( 3 ) ) . toEqual ( [ null , '>=3.0.0' , true ] ) ;
299
297
done ( ) ;
300
298
} ) ;
301
299
} , TIMEOUT ) ;
@@ -543,3 +541,67 @@ describe('end', function () {
543
541
shell . rm ( '-rf' , temp_dir ) ;
544
542
} , TIMEOUT ) ;
545
543
} ) ;
544
+
545
+ describe ( 'unit tests for checkEngines' , function ( ) {
546
+ var fail ;
547
+ var engine = [ { platform : 'android' ,
548
+ minVersion : '>=3.6.0' ,
549
+ currentVersion : '6.2.3' } ] ;
550
+ beforeEach ( function ( ) {
551
+ spyOn ( semver , 'satisfies' ) ;
552
+ } ) ;
553
+
554
+ it ( 'checkEngines should return true' , function ( ) {
555
+ spyOn ( fs , 'existsSync' ) . and . returnValue ( false ) ;
556
+ semver . satisfies . and . returnValue ( true ) ;
557
+ install . checkEngines ( engine , 'pluginDir' )
558
+ . then ( function ( res ) {
559
+ expect ( res ) . toBe ( true ) ;
560
+ } ) . fail ( function err ( errMsg ) {
561
+ fail ( 'fail handler unexpectedly invoked' ) ;
562
+ console . error ( errMsg ) ;
563
+ } ) ;
564
+ } ) ;
565
+
566
+ it ( 'checkEngines should check cordovaDependencies' , function ( ) {
567
+ var pkgJson = { engines : { cordovaDependencies : { '9.0.0' : [ Object ] , '2.0.0' : [ Object ] } } } ;
568
+ spyOn ( fs , 'existsSync' ) . and . returnValue ( true ) ;
569
+ spyOn ( cordovaUtil , 'requireNoCache' ) . and . returnValue ( pkgJson ) ;
570
+ semver . satisfies . and . callThrough ( ) ;
571
+ install . checkEngines ( engine , 'pluginDir' )
572
+ . then ( function ( res ) {
573
+ expect ( res ) . toBe ( true ) ;
574
+ expect ( semver . satisfies ) . toHaveBeenCalledWith ( '6.2.3' , '>=3.6.0' , true ) ;
575
+ } ) . fail ( function err ( errMsg ) {
576
+ fail ( 'fail handler unexpectedly invoked' ) ;
577
+ console . error ( errMsg ) ;
578
+ } ) ;
579
+ } ) ;
580
+
581
+ it ( 'checkEngines should check if plugin version is supported' , function ( ) {
582
+ spyOn ( fs , 'existsSync' ) . and . returnValue ( true ) ;
583
+ spyOn ( cordovaUtil , 'requireNoCache' ) . and . returnValue ( true ) ;
584
+ semver . satisfies . and . callThrough ( ) ;
585
+ install . checkEngines ( engine , 'pluginDir' )
586
+ . then ( function ( res ) {
587
+ expect ( res ) . toBe ( true ) ;
588
+ expect ( semver . satisfies ) . toHaveBeenCalledWith ( '6.2.3' , '>=3.6.0' , true ) ;
589
+ } ) . fail ( function err ( errMsg ) {
590
+ fail ( 'fail handler unexpectedly invoked' ) ;
591
+ console . error ( errMsg ) ;
592
+ } ) ;
593
+ } ) ;
594
+
595
+ it ( 'checkEngines should warn if plugin is not supported' , function ( ) {
596
+ spyOn ( events , 'emit' ) ;
597
+ spyOn ( Q , 'reject' ) . and . callThrough ( ) ;
598
+ semver . satisfies . and . returnValue ( false ) ;
599
+ install . checkEngines ( engine , 'pluginDir' )
600
+ . then ( function ( res ) {
601
+ fail ( 'success handler unexpectedly invoked' ) ;
602
+ } ) . fail ( function err ( errMsg ) {
603
+ expect ( errMsg ) . toBe ( 'skip' ) ;
604
+ expect ( events . emit ) . toHaveBeenCalledWith ( 'warn' , jasmine . stringMatching ( / f a i l e d v e r s i o n r e q u i r e m e n t / ) ) ;
605
+ } ) ;
606
+ } ) ;
607
+ } ) ;
0 commit comments