@@ -28,6 +28,87 @@ describe("adm-zip.js - methods handling local files", () => {
28
28
// clean up folder content
29
29
afterEach ( ( done ) => rimraf ( destination , done ) ) ;
30
30
31
+ describe ( ".deleteFile()" , ( ) => {
32
+ const ultrazip = [
33
+ "./attributes_test/asd/New Text Document.txt" ,
34
+ "./attributes_test/blank file.txt" ,
35
+ "./attributes_test/New folder/hidden.txt" ,
36
+ "./attributes_test/New folder/hidden_readonly.txt" ,
37
+ "./attributes_test/New folder/readonly.txt" ,
38
+ "./utes_test/New folder/somefile.txt"
39
+ ] . map ( wrapList ) ;
40
+
41
+ // Issue 523 - deletes additional files
42
+ it ( "zip.deleteFile() - delete folder with subfolders" , ( ) => {
43
+ const content = "test" ;
44
+ const comment = "comment" ;
45
+ const zip1 = new Zip ( { noSort : true } ) ;
46
+ zip1 . addFile ( "test/" ) ;
47
+ zip1 . addFile ( "test/path1/" ) ;
48
+ zip1 . addFile ( "test/path1/file1.txt" , content , comment ) ;
49
+ zip1 . addFile ( "test/path1/folder1/" ) ;
50
+ zip1 . addFile ( "test/path1/folder1/file2.txt" , content , comment ) ;
51
+ zip1 . addFile ( "test/path2/" ) ;
52
+ zip1 . addFile ( "test/path2/file1.txt" , content , comment ) ;
53
+ zip1 . addFile ( "test/path2/folder1/" ) ;
54
+ zip1 . addFile ( "test/path2/folder1/file2.txt" , content , comment ) ;
55
+
56
+ zip1 . deleteFile ( "test/path1/" ) ;
57
+
58
+ const zipEntries = zip1 . getEntries ( ) . map ( ( child ) => child . entryName ) ;
59
+
60
+ expect ( zipEntries ) . to . deep . equal ( [ "test/" , "test/path2/" , "test/path2/file1.txt" , "test/path2/folder1/" , "test/path2/folder1/file2.txt" ] ) ;
61
+ } ) ;
62
+
63
+ it ( "zip.deleteFile() - delete folder" , ( ) => {
64
+ const content = "test" ;
65
+ const comment = "comment" ;
66
+ const zip1 = new Zip ( { noSort : true } ) ;
67
+ zip1 . addFile ( "test/" ) ;
68
+ zip1 . addFile ( "test/path1/" ) ;
69
+ zip1 . addFile ( "test/path1/file1.txt" , content , comment ) ;
70
+ zip1 . addFile ( "test/path1/folder1/" ) ;
71
+ zip1 . addFile ( "test/path1/folder1/file2.txt" , content , comment ) ;
72
+ zip1 . addFile ( "test/path2/" ) ;
73
+ zip1 . addFile ( "test/path2/file1.txt" , content , comment ) ;
74
+ zip1 . addFile ( "test/path2/folder1/" ) ;
75
+ zip1 . addFile ( "test/path2/folder1/file2.txt" , content , comment ) ;
76
+
77
+ zip1 . deleteFile ( "test/path1/" , false ) ;
78
+
79
+ const zipEntries = zip1 . getEntries ( ) . map ( ( child ) => child . entryName ) ;
80
+
81
+ expect ( zipEntries ) . to . deep . equal ( [
82
+ "test/" ,
83
+ "test/path1/file1.txt" ,
84
+ "test/path1/folder1/" ,
85
+ "test/path1/folder1/file2.txt" ,
86
+ "test/path2/" ,
87
+ "test/path2/file1.txt" ,
88
+ "test/path2/folder1/" ,
89
+ "test/path2/folder1/file2.txt"
90
+ ] ) ;
91
+ } ) ;
92
+
93
+ it ( "zip.deleteFile() - delete files" , ( ) => {
94
+ const content = "test" ;
95
+ const comment = "comment" ;
96
+ const zip1 = new Zip ( { noSort : true } ) ;
97
+ zip1 . addFile ( "test/" ) ;
98
+ zip1 . addFile ( "test/path1/" ) ;
99
+ zip1 . addFile ( "test/path1/file1.txt" , content , comment ) ;
100
+ zip1 . addFile ( "test/path1/folder1/" ) ;
101
+ zip1 . addFile ( "test/path1/folder1/file2.txt" , content , comment ) ;
102
+
103
+ zip1 . deleteFile ( "test/path1/file1.txt" , false ) ;
104
+ zip1 . deleteFile ( "test/path1/folder1/file2.txt" , false ) ;
105
+
106
+ const zipEntries = zip1 . getEntries ( ) . map ( ( child ) => child . entryName ) ;
107
+
108
+ expect ( zipEntries ) . to . deep . equal ( [ "test/" , "test/path1/" , "test/path1/folder1/" ] ) ;
109
+ } ) ;
110
+ } ) ;
111
+
31
112
describe ( ".extractAllTo() - sync" , ( ) => {
32
113
const ultrazip = [
33
114
"./attributes_test/asd/New Text Document.txt" ,
0 commit comments