@@ -21,7 +21,9 @@ class TestData {
21
21
* @return {string } full path
22
22
*/
23
23
getFullPath ( pathFromDataFolder : string ) : string {
24
- return path . join ( __dirname , '..' , dataFolderName , pathFromDataFolder ) ;
24
+ const fullPath = path . join ( __dirname , '..' , dataFolderName , pathFromDataFolder ) ;
25
+ logger . info ( `Full path from data folder: ${ fullPath } ` ) ;
26
+ return fullPath ;
25
27
}
26
28
27
29
/**
@@ -56,19 +58,27 @@ class TestData {
56
58
*/
57
59
cleanUpDownloadsData ( ) {
58
60
const downloadsPath = this . getFullPath ( `/${ downloadsFolderName } ` ) ;
59
- return new Promise ( ( resolve ) => {
61
+ return new Promise ( ( resolve , reject ) => {
60
62
logger . info ( 'Running Downloads Clean UP!' ) ;
61
- if ( fs . existsSync ( downloadsPath ) ) {
62
- fs . readdirSync ( downloadsPath ) . forEach ( function ( file , index ) {
63
- const curPath = downloadsPath + '/' + file ;
64
- if ( fs . lstatSync ( curPath ) . isDirectory ( ) ) {
65
- this . deleteFolderRecursive ( curPath ) ;
66
- } else {
67
- fs . unlinkSync ( curPath ) ;
68
- }
69
- } ) ;
70
- resolve ( ) ;
63
+ try {
64
+ if ( fs . existsSync ( downloadsPath ) ) {
65
+ logger . info ( 'Downloads folder Exists' ) ;
66
+ fs . readdirSync ( downloadsPath ) . forEach ( function ( file , index ) {
67
+ logger . info ( `Processing ${ file } ` ) ;
68
+ const curPath = path . join ( downloadsPath , file ) ;
69
+ if ( fs . lstatSync ( curPath ) . isDirectory ( ) ) {
70
+ logger . info ( `Removing directory '${ file } '` ) ;
71
+ this . deleteFolderRecursive ( curPath ) ;
72
+ } else {
73
+ logger . info ( `Removing file '${ file } '` ) ;
74
+ fs . unlinkSync ( curPath ) ;
75
+ }
76
+ } ) ;
77
+ }
78
+ } catch ( error ) {
79
+ reject ( `Was not able to clean up the downloads folder: ${ error . message } ` ) ;
71
80
}
81
+ resolve ( ) ;
72
82
} ) ;
73
83
}
74
84
0 commit comments