@@ -590,7 +590,83 @@ describe('lib/main', function () {
590590 } )
591591 } )
592592
593- describe ( '_npmInstall' , function ( ) {
593+ describe ( '_getNpmInstallCommand' , ( ) => {
594+ describe ( 'when package-lock.json exists' , ( ) => {
595+ const codeDirectory = '.'
596+
597+ it ( 'npm ci' , ( ) => {
598+ const { packageManager, installOptions } = lambda . _getNpmInstallCommand ( program , codeDirectory )
599+ assert . equal ( packageManager , 'npm' )
600+ assert . deepEqual ( installOptions , [ '-s' , 'ci' , '--production' , '--no-audit' , '--prefix' , codeDirectory ] )
601+ } )
602+
603+ it ( 'npm ci with "--no-optional"' , ( ) => {
604+ const { packageManager, installOptions } = lambda . _getNpmInstallCommand (
605+ {
606+ ...program ,
607+ optionalDependencies : false
608+ } ,
609+ codeDirectory
610+ )
611+ assert . equal ( packageManager , 'npm' )
612+ assert . deepEqual (
613+ installOptions ,
614+ [ '-s' , 'ci' , '--production' , '--no-audit' , '--no-optional' , '--prefix' , codeDirectory ]
615+ )
616+ } )
617+
618+ it ( 'npm ci on docker' , ( ) => {
619+ const { packageManager, installOptions } = lambda . _getNpmInstallCommand (
620+ {
621+ ...program ,
622+ dockerImage : 'test'
623+ } ,
624+ codeDirectory
625+ )
626+ assert . equal ( packageManager , 'npm' )
627+ assert . deepEqual ( installOptions , [ '-s' , 'ci' , '--production' , '--no-audit' ] )
628+ } )
629+ } )
630+
631+ describe ( 'when package-lock.json does not exist' , ( ) => {
632+ const codeDirectory = './test'
633+
634+ it ( 'npm install' , ( ) => {
635+ const { packageManager, installOptions } = lambda . _getNpmInstallCommand ( program , './test' )
636+ assert . equal ( packageManager , 'npm' )
637+ assert . deepEqual ( installOptions , [ '-s' , 'install' , '--production' , '--no-audit' , '--prefix' , './test' ] )
638+ } )
639+
640+ it ( 'npm install with "--no-optional"' , ( ) => {
641+ const { packageManager, installOptions } = lambda . _getNpmInstallCommand (
642+ {
643+ ...program ,
644+ optionalDependencies : false
645+ } ,
646+ codeDirectory
647+ )
648+ assert . equal ( packageManager , 'npm' )
649+ assert . deepEqual (
650+ installOptions ,
651+ [ '-s' , 'install' , '--production' , '--no-audit' , '--no-optional' , '--prefix' , codeDirectory ]
652+ )
653+ } )
654+
655+ it ( 'npm install on docker' , ( ) => {
656+ const { packageManager, installOptions } = lambda . _getNpmInstallCommand (
657+ {
658+ ...program ,
659+ dockerImage : 'test'
660+ } ,
661+ codeDirectory
662+ )
663+ assert . equal ( packageManager , 'npm' )
664+ assert . deepEqual ( installOptions , [ '-s' , 'install' , '--production' , '--no-audit' ] )
665+ } )
666+ } )
667+ } )
668+
669+ describe ( '_packageInstall using "npm"' , function ( ) {
594670 _timeout ( { this : this , sec : 60 } ) // ci should be faster than install
595671
596672 // npm treats files as packages when installing, and so removes them.
@@ -605,7 +681,7 @@ describe('lib/main', function () {
605681 describe ( 'when package-lock.json does exist' , ( ) => {
606682 it ( 'should use "npm ci"' , ( ) => {
607683 const beforeAwsSdkStat = fs . statSync ( path . join ( codeDirectory , 'node_modules' , 'aws-sdk' ) )
608- return lambda . _npmInstall ( program , codeDirectory ) . then ( ( ) => {
684+ return lambda . _packageInstall ( program , codeDirectory ) . then ( ( ) => {
609685 const contents = fs . readdirSync ( path . join ( codeDirectory , 'node_modules' ) )
610686 assert . include ( contents , 'dotenv' )
611687
@@ -627,7 +703,7 @@ describe('lib/main', function () {
627703
628704 it ( 'should use "npm install"' , ( ) => {
629705 const beforeAwsSdkStat = fs . statSync ( path . join ( codeDirectory , 'node_modules' , 'aws-sdk' ) )
630- return lambda . _npmInstall ( program , codeDirectory ) . then ( ( ) => {
706+ return lambda . _packageInstall ( program , codeDirectory ) . then ( ( ) => {
631707 const contents = fs . readdirSync ( path . join ( codeDirectory , 'node_modules' ) )
632708 assert . include ( contents , 'dotenv' )
633709
@@ -652,7 +728,7 @@ describe('lib/main', function () {
652728
653729 describe ( 'No `--no-optionalDependencies`' , ( ) => {
654730 it ( 'optionalDependencies is installed' , ( ) => {
655- return lambda . _npmInstall ( program , codeDirectory ) . then ( ( ) => {
731+ return lambda . _packageInstall ( program , codeDirectory ) . then ( ( ) => {
656732 const contents = fs . readdirSync ( path . join ( codeDirectory , 'node_modules' ) )
657733 assert . include ( contents , 'npm' )
658734 } )
@@ -665,7 +741,7 @@ describe('lib/main', function () {
665741 ...program ,
666742 optionalDependencies : false
667743 }
668- return lambda . _npmInstall ( params , codeDirectory ) . then ( ( ) => {
744+ return lambda . _packageInstall ( params , codeDirectory ) . then ( ( ) => {
669745 const contents = fs . readdirSync ( path . join ( codeDirectory , 'node_modules' ) )
670746 assert . notInclude ( contents , 'npm' )
671747 } )
@@ -674,7 +750,7 @@ describe('lib/main', function () {
674750 } )
675751 } )
676752
677- describe ( '_npmInstall (When codeDirectory contains characters to be escaped)' , ( ) => {
753+ describe ( '_packageInstall using "npm" (When codeDirectory contains characters to be escaped)' , ( ) => {
678754 beforeEach ( ( ) => {
679755 // Since '\' can not be included in the file or directory name in Windows
680756 const directoryName = process . platform === 'win32'
@@ -694,7 +770,7 @@ describe('lib/main', function () {
694770 it ( '_npm adds node_modules' , function ( ) {
695771 _timeout ( { this : this , sec : 30 } ) // give it time to build the node modules
696772
697- return lambda . _npmInstall ( program , codeDirectory ) . then ( ( ) => {
773+ return lambda . _packageInstall ( program , codeDirectory ) . then ( ( ) => {
698774 const contents = fs . readdirSync ( codeDirectory )
699775 assert . include ( contents , 'node_modules' )
700776 } )
@@ -768,15 +844,15 @@ describe('lib/main', function () {
768844 } )
769845 } )
770846
771- describe ( '_zip' , ( ) => {
847+ describe ( '_zip using "npm" ' , ( ) => {
772848 beforeEach ( function ( ) {
773849 _timeout ( { this : this , sec : 30 } ) // give it time to build the node modules
774850 return Promise . resolve ( ) . then ( ( ) => {
775851 return lambda . _cleanDirectory ( codeDirectory )
776852 } ) . then ( ( ) => {
777853 return lambda . _fileCopy ( program , '.' , codeDirectory , true )
778854 } ) . then ( ( ) => {
779- return lambda . _npmInstall ( program , codeDirectory )
855+ return lambda . _packageInstall ( program , codeDirectory )
780856 } ) . then ( ( ) => {
781857 if ( process . platform !== 'win32' ) {
782858 fs . symlinkSync (
0 commit comments