@@ -27,6 +27,7 @@ var events = require('cordova-common').events;
2727var plugman = require ( '../../src/plugman/plugman' ) ;
2828var platforms = require ( '../../src/plugman/platforms/common' ) ;
2929var knownPlatforms = require ( '../../src/platforms/platforms' ) ;
30+ var cordovaUtil = require ( '../../src/cordova/util' ) ;
3031var common = require ( '../common' ) ;
3132var fs = require ( 'fs' ) ;
3233var os = require ( 'os' ) ;
@@ -287,15 +288,12 @@ describe('install', function () {
287288 . fin ( function ( ) {
288289 var plugmanVersion = require ( '../../package.json' ) . version . replace ( / - d e v | - n i g h t l y .* $ / , '' ) ;
289290 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 ) ;
291293 // <engine name="cordova" version=">=2.3.0"/>
292294 expect ( satisfies . calls . argsFor ( 0 ) ) . toEqual ( [ cordovaVersion , '>=2.3.0' , true ] ) ;
293295 // <engine name="cordova-plugman" version=">=0.10.0" />
294296 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 ] ) ;
299297 done ( ) ;
300298 } ) ;
301299 } , TIMEOUT ) ;
@@ -543,3 +541,67 @@ describe('end', function () {
543541 shell . rm ( '-rf' , temp_dir ) ;
544542 } , TIMEOUT ) ;
545543} ) ;
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