@@ -55,6 +55,14 @@ const _timeout = function (params) {
5555 }
5656}
5757
58+ const forceRemoveSync = ( targetPath ) => {
59+ if ( typeof fs . rmSync === 'function' ) {
60+ fs . rmSync ( targetPath , { recursive : true , force : true } )
61+ return
62+ }
63+ fs . removeSync ( targetPath )
64+ }
65+
5866// It does not completely reproduce the response of the actual API.
5967const lambdaMockSettings = {
6068 addPermission : { } ,
@@ -140,8 +148,8 @@ const _awsRestore = () => {
140148describe ( 'lib/main' , function ( ) {
141149 if ( [ 'win32' , 'darwin' ] . includes ( process . platform ) ) {
142150 // It seems that it takes time for file operation in Windows and Mac.
143- // So set `timeout(120000 )` for the whole test.
144- this . timeout ( 120000 )
151+ // So set `timeout(180000 )` for the whole test.
152+ this . timeout ( 180000 )
145153 }
146154
147155 let aws = null // mock
@@ -478,8 +486,8 @@ describe('lib/main', function () {
478486 fs . writeFileSync ( 'fuga' , '' )
479487 } )
480488 after ( ( ) => {
481- [ 'fuga' , '__unittest' ] . forEach ( ( path ) => {
482- fs . removeSync ( path )
489+ [ 'fuga' , '__unittest' ] . forEach ( ( targetPath ) => {
490+ forceRemoveSync ( targetPath )
483491 } )
484492 } )
485493
@@ -560,7 +568,7 @@ describe('lib/main', function () {
560568
561569 it ( '_fileCopy should not include package.json when --prebuiltDirectory is set' , ( ) => {
562570 const buildDir = '.build_' + Date . now ( )
563- after ( ( ) => fs . removeSync ( buildDir ) )
571+ after ( ( ) => forceRemoveSync ( buildDir ) )
564572
565573 fs . mkdirSync ( buildDir )
566574 fs . writeFileSync ( path . join ( buildDir , 'testa' ) , '' )
@@ -594,7 +602,7 @@ describe('lib/main', function () {
594602
595603 describe ( 'when package-lock.json does not exist' , ( ) => {
596604 beforeEach ( ( ) => {
597- fs . removeSync ( path . join ( codeDirectory , 'package-lock.json' ) )
605+ forceRemoveSync ( path . join ( codeDirectory , 'package-lock.json' ) )
598606 } )
599607
600608 it ( 'returns false' , ( ) => {
@@ -717,7 +725,7 @@ describe('lib/main', function () {
717725 } )
718726
719727 describe ( '_packageInstall' , function ( ) {
720- _timeout ( { this : this , sec : 60 } ) // ci should be faster than install
728+ _timeout ( { this : this , sec : 180 } ) // ci should be faster than install
721729
722730 // npm treats files as packages when installing, and so removes them.
723731 // Test with `devDependencies` packages that are not installed with the `--production` option.
@@ -754,7 +762,7 @@ describe('lib/main', function () {
754762 fs . writeFileSync ( packageJsonPath , JSON . stringify ( packageJson ) )
755763
756764 // Remove package-lock.json because it does not match the package.json to which optionalDependencies was added.
757- fs . removeSync ( path . join ( codeDirectory , 'package-lock.json' ) )
765+ forceRemoveSync ( path . join ( codeDirectory , 'package-lock.json' ) )
758766 }
759767
760768 const testOptionalDependenciesIsInstalled = async ( packageManager ) => {
@@ -796,7 +804,7 @@ describe('lib/main', function () {
796804
797805 describe ( 'when package-lock.json does not exist' , ( ) => {
798806 beforeEach ( ( ) => {
799- return fs . removeSync ( path . join ( codeDirectory , 'package-lock.json' ) )
807+ forceRemoveSync ( path . join ( codeDirectory , 'package-lock.json' ) )
800808 } )
801809
802810 it ( 'should use "npm install"' , ( ) => {
@@ -849,7 +857,7 @@ describe('lib/main', function () {
849857 } )
850858
851859 describe ( '_packageInstall (When codeDirectory contains characters to be escaped)' , function ( ) {
852- _timeout ( { this : this , sec : 30 } ) // give it time to build the node modules
860+ _timeout ( { this : this , sec : 180 } ) // give it time to build the node modules
853861
854862 beforeEach ( ( ) => {
855863 // Since '\' can not be included in the file or directory name in Windows
@@ -863,7 +871,7 @@ describe('lib/main', function () {
863871 } )
864872
865873 afterEach ( ( ) => {
866- fs . removeSync ( codeDirectory )
874+ forceRemoveSync ( codeDirectory )
867875 codeDirectory = lambda . _codeDirectory ( )
868876 } )
869877
@@ -952,7 +960,7 @@ describe('lib/main', function () {
952960 } )
953961
954962 describe ( '_zip' , function ( ) {
955- _timeout ( { this : this , sec : 60 } ) // give it time to zip
963+ _timeout ( { this : this , sec : 180 } ) // give it time to zip
956964
957965 const beforeTask = async ( packageManager ) => {
958966 await lambda . _cleanDirectory ( codeDirectory )
@@ -1022,7 +1030,7 @@ describe('lib/main', function () {
10221030 describe ( '_archive' , ( ) => {
10231031 // archive.files's name is a slash delimiter regardless of platform.
10241032 it ( 'installs and zips with an index.js file and node_modules/dotenv (It is also a test of `_buildAndArchive`)' , function ( ) {
1025- _timeout ( { this : this , sec : 30 } ) // give it time to zip
1033+ _timeout ( { this : this , sec : 180 } ) // give it time to zip
10261034
10271035 return lambda . _archive ( { ...program , sourceDirectory : sourceDirectoryForTest } ) . then ( ( data ) => {
10281036 const archive = new Zip ( data )
@@ -1035,9 +1043,9 @@ describe('lib/main', function () {
10351043 } )
10361044
10371045 it ( 'packages a prebuilt module without installing (It is also a test of `_archivePrebuilt`)' , function ( ) {
1038- _timeout ( { this : this , sec : 30 } ) // give it time to zip
1046+ _timeout ( { this : this , sec : 180 } ) // give it time to zip
10391047 const buildDir = '.build_' + Date . now ( )
1040- after ( ( ) => fs . removeSync ( buildDir ) )
1048+ after ( ( ) => forceRemoveSync ( buildDir ) )
10411049
10421050 fs . mkdirSync ( buildDir )
10431051 fs . mkdirSync ( path . join ( buildDir , 'd' ) )
@@ -1063,11 +1071,11 @@ describe('lib/main', function () {
10631071 } )
10641072
10651073 it ( 'cleans the temporary directory before running `_archivePrebuilt`' , function ( ) {
1066- _timeout ( { this : this , sec : 30 } ) // give it time to zip
1074+ _timeout ( { this : this , sec : 180 } ) // give it time to zip
10671075 const buildDir = '.build_' + Date . now ( )
10681076 const codeDir = lambda . _codeDirectory ( )
10691077 const tmpFile = path . join ( codeDir , 'deleteme' )
1070- after ( ( ) => fs . removeSync ( buildDir ) )
1078+ after ( ( ) => forceRemoveSync ( buildDir ) )
10711079
10721080 fs . mkdirSync ( codeDir , { recursive : true } )
10731081 fs . writeFileSync ( tmpFile , '...' )
@@ -1085,7 +1093,7 @@ describe('lib/main', function () {
10851093 const testZipFile = path . join ( os . tmpdir ( ) , 'node-lambda-test.zip' )
10861094 let bufferExpected = null
10871095 before ( function ( ) {
1088- _timeout ( { this : this , sec : 30 } ) // give it time to zip
1096+ _timeout ( { this : this , sec : 180 } ) // give it time to zip
10891097
10901098 return lambda . _zip ( program , codeDirectory ) . then ( ( data ) => {
10911099 bufferExpected = data
@@ -1130,7 +1138,7 @@ describe('lib/main', function () {
11301138 deployZipfile : filePath ,
11311139 sourceDirectory : sourceDirectoryForTest
11321140 }
1133- _timeout ( { this : this , sec : 30 } ) // give it time to zip
1141+ _timeout ( { this : this , sec : 180 } ) // give it time to zip
11341142 return lambda . _archive ( _program ) . then ( ( data ) => {
11351143 // same test as "installs and zips with an index.js file and node_modules/dotenv"
11361144 const archive = new Zip ( data )
@@ -1642,7 +1650,7 @@ describe('lib/main', function () {
16421650
16431651 describe ( 'Lambda.prototype.deploy()' , ( ) => {
16441652 it ( 'simple test with mock' , function ( ) {
1645- _timeout ( { this : this , sec : 30 } ) // give it time to zip
1653+ _timeout ( { this : this , sec : 180 } ) // give it time to zip
16461654 return lambda . deploy ( { ...program , sourceDirectory : sourceDirectoryForTest } ) . then ( ( result ) => {
16471655 assert . isUndefined ( result )
16481656 } )
@@ -1654,10 +1662,9 @@ describe('lib/main', function () {
16541662 return lambda . _updateTags (
16551663 awsLambda ,
16561664 'arn:aws:lambda:eu-central-1:1234567:function:test' ,
1657- { tagKey : 'tagValue' } ) . then ( ( result ) => {
1658- assert . deepEqual (
1659- result , { }
1660- )
1665+ { tagKey : 'tagValue' }
1666+ ) . then ( ( result ) => {
1667+ assert . deepEqual ( result , { } )
16611668 } )
16621669 } )
16631670 } )
0 commit comments