@@ -153,7 +153,10 @@ describe('lib/main', function () {
153153
154154 describe ( '_codeDirectory' , ( ) => {
155155 it ( 'Working directory in the /tmp directory' , ( ) => {
156- assert . equal ( lambda . _codeDirectory ( ) , path . join ( os . tmpdir ( ) , 'node-lambda-lambda' ) )
156+ assert . equal (
157+ lambda . _codeDirectory ( ) ,
158+ path . join ( fs . realpathSync ( os . tmpdir ( ) ) , 'node-lambda-lambda' )
159+ )
157160 } )
158161 } )
159162
@@ -586,25 +589,34 @@ describe('lib/main', function () {
586589 } )
587590 } )
588591
589- describe ( '_npmInstall' , ( ) => {
592+ describe ( '_npmInstall' , function ( ) {
593+ _timeout ( { this : this , sec : 30 } ) // ci should be faster than install
594+
590595 // npm treats files as packages when installing, and so removes them.
591596 // Test with `devDependencies` packages that are not installed with the `--production` option.
592597 const nodeModulesMocha = path . join ( codeDirectory , 'node_modules' , 'mocha' )
593598
594599 beforeEach ( ( ) => {
595600 return lambda . _cleanDirectory ( codeDirectory ) . then ( ( ) => {
596- fs . ensureDirSync ( nodeModulesMocha )
601+ fs . copySync (
602+ path . join ( 'node_modules' , 'aws-sdk' ) ,
603+ path . join ( codeDirectory , 'node_modules' , 'aws-sdk' )
604+ )
597605 return lambda . _fileCopy ( program , '.' , codeDirectory , true )
598606 } )
599607 } )
600608
601609 describe ( 'when package-lock.json does exist' , ( ) => {
602- it ( 'should use "npm ci"' , function ( ) {
603- _timeout ( { this : this , sec : 30 } ) // ci should be faster than install
604-
610+ it ( 'should use "npm ci"' , ( ) => {
611+ const beforeAwsSdkStat = fs . statSync ( path . join ( codeDirectory , 'node_modules' , 'aws-sdk' ) )
605612 return lambda . _npmInstall ( program , codeDirectory ) . then ( ( ) => {
606- const contents = fs . readdirSync ( codeDirectory )
607- assert . include ( contents , 'node_modules' )
613+ const contents = fs . readdirSync ( path . join ( codeDirectory , 'node_modules' ) )
614+ assert . include ( contents , 'dotenv' )
615+
616+ // To remove and then install.
617+ // beforeAwsSdkStat.ctimeMs < afterAwsSdkStat.ctimeMs
618+ const afterAwsSdkStat = fs . statSync ( path . join ( codeDirectory , 'node_modules' , 'aws-sdk' ) )
619+ assert . isBelow ( beforeAwsSdkStat . ctimeMs , afterAwsSdkStat . ctimeMs )
608620
609621 // Not installed with the `--production` option.
610622 assert . isFalse ( fs . existsSync ( nodeModulesMocha ) )
@@ -617,15 +629,19 @@ describe('lib/main', function () {
617629 return fs . removeSync ( path . join ( codeDirectory , 'package-lock.json' ) )
618630 } )
619631
620- it ( 'should use "npm install"' , function ( ) {
621- _timeout ( { this : this , sec : 60 } ) // install should be slower than ci
622-
632+ it ( 'should use "npm install"' , ( ) => {
633+ const beforeAwsSdkStat = fs . statSync ( path . join ( codeDirectory , 'node_modules' , 'aws-sdk' ) )
623634 return lambda . _npmInstall ( program , codeDirectory ) . then ( ( ) => {
624- const contents = fs . readdirSync ( codeDirectory )
625- assert . include ( contents , 'node_modules ' )
635+ const contents = fs . readdirSync ( path . join ( codeDirectory , 'node_modules' ) )
636+ assert . include ( contents , 'dotenv ' )
626637
627- // It remains because it is not erased before installation.
628- assert . isTrue ( fs . existsSync ( nodeModulesMocha ) )
638+ // Installed packages will remain intact.
639+ // beforeAwsSdkStat.ctimeMs === afterAwsSdkStat.ctimeMs
640+ const afterAwsSdkStat = fs . statSync ( path . join ( codeDirectory , 'node_modules' , 'aws-sdk' ) )
641+ assert . equal ( beforeAwsSdkStat . ctimeMs , afterAwsSdkStat . ctimeMs )
642+
643+ // Not installed with the `--production` option.
644+ assert . isFalse ( fs . existsSync ( nodeModulesMocha ) )
629645 } )
630646 } )
631647 } )
0 commit comments