@@ -43,31 +43,46 @@ describe('NodeVersionValidator', function () {
4343 } ) ;
4444
4545 it ( 'should run the script WITH error if the patch version is lower' , function ( done ) {
46- testValidateNodeVersion ( done , requiredNodeVersionWithDiff ( 0 , 0 , - 1 ) , true ) ;
46+ var lowerPatchversion = requiredNodeVersionWithDiff ( 0 , 0 , - 1 ) ;
47+ testValidateNodeVersion (
48+ done ,
49+ lowerPatchversion ,
50+ REQUIRED_NODE_JS_VERSION !== lowerPatchversion
51+ ) ;
4752 } ) ;
4853
4954 it ( 'should run the script WITH error if the major version is higher' , function ( done ) {
5055 testValidateNodeVersion ( done , requiredNodeVersionWithDiff ( + 1 , 0 , 0 ) , true ) ;
5156 } ) ;
5257
5358 it ( 'should run the script WITH error if the major version is lower' , function ( done ) {
54- testValidateNodeVersion ( done , requiredNodeVersionWithDiff ( - 1 , 0 , 0 ) , true ) ;
59+ var lowerMajorVersion = requiredNodeVersionWithDiff ( - 1 , 0 , 0 ) ;
60+ testValidateNodeVersion (
61+ done ,
62+ lowerMajorVersion ,
63+ REQUIRED_NODE_JS_VERSION !== lowerMajorVersion
64+ ) ;
5565 } ) ;
5666
5767 it ( 'should run the script WITH error if the minor version is higher' , function ( done ) {
5868 testValidateNodeVersion ( done , requiredNodeVersionWithDiff ( 0 , + 1 , 0 ) , true ) ;
5969 } ) ;
6070
6171 it ( 'should run the script WITH error if the minor version is lower' , function ( done ) {
62- testValidateNodeVersion ( done , requiredNodeVersionWithDiff ( 0 , - 1 , 0 ) , true ) ;
72+ var lowerMinorVersion = requiredNodeVersionWithDiff ( 0 , - 1 , 0 ) ;
73+ testValidateNodeVersion (
74+ done ,
75+ lowerMinorVersion ,
76+ REQUIRED_NODE_JS_VERSION !== lowerMinorVersion
77+ ) ;
6378 } ) ;
6479} ) ;
6580
6681function requiredNodeVersionWithDiff ( majorDiff , minorDiff , patchDiff ) {
6782 var matches = REQUIRED_NODE_JS_VERSION . match ( / ^ v ( \d + ) \. ( \d + ) \. ( \d + ) / ) ;
68- var major = parseInt ( matches [ 1 ] ) + majorDiff ;
69- var minor = parseInt ( matches [ 2 ] ) + minorDiff ;
70- var patch = parseInt ( matches [ 3 ] ) + patchDiff ;
83+ var major = Math . max ( parseInt ( matches [ 1 ] , 10 ) + majorDiff , 0 ) ;
84+ var minor = Math . max ( parseInt ( matches [ 2 ] , 10 ) + minorDiff , 0 ) ;
85+ var patch = Math . max ( parseInt ( matches [ 3 ] , 10 ) + patchDiff , 0 ) ;
7186
7287 return `v${ major } .${ minor } .${ patch } ` ;
7388}
0 commit comments