1
+ const { expect} = require ( 'chai' ) ;
2
+ const Attr = require ( "../util" ) . FileAttr ;
3
+ const Zip = require ( "../adm-zip" ) ;
4
+ const pth = require ( "path" ) ;
5
+ const fs = require ( "fs" ) ;
6
+ const rimraf = require ( "rimraf" )
7
+
8
+ describe ( 'adm-zip' , ( ) => {
9
+
10
+ const destination = './test/xxx'
11
+
12
+ beforeEach ( done => {
13
+ rimraf ( destination , err => {
14
+ if ( err ) return done ( err )
15
+ console . log ( 'Cleared directory: ' + destination )
16
+ return done ( )
17
+ } )
18
+ } )
19
+
20
+ it ( 'zip.extractAllTo()' , ( ) => {
21
+ const zip = new Zip ( './test/assets/ultra.zip' ) ;
22
+ zip . extractAllTo ( destination ) ;
23
+ const files = walk ( destination )
24
+
25
+ expect ( files . sort ( ) ) . to . deep . equal ( [
26
+ "./test/xxx/attributes_test/asd/New Text Document.txt" ,
27
+ "./test/xxx/attributes_test/blank file.txt" ,
28
+ "./test/xxx/attributes_test/New folder/hidden.txt" ,
29
+ "./test/xxx/attributes_test/New folder/hidden_readonly.txt" ,
30
+ "./test/xxx/attributes_test/New folder/readonly.txt" ,
31
+ "./test/xxx/utes_test/New folder/somefile.txt"
32
+ ] . sort ( ) ) ;
33
+ } )
34
+
35
+ it ( 'zip.extractEntryTo(entry, destination, false, true)' , ( ) => {
36
+ const destination = './test/xxx'
37
+ const zip = new Zip ( './test/assets/ultra.zip' ) ;
38
+ var zipEntries = zip . getEntries ( ) ;
39
+ zipEntries . forEach ( e => zip . extractEntryTo ( e , destination , false , true ) ) ;
40
+
41
+ const files = walk ( destination )
42
+ expect ( files . sort ( ) ) . to . deep . equal ( [
43
+ "./test/xxx/blank file.txt" ,
44
+ "./test/xxx/hidden.txt" ,
45
+ "./test/xxx/hidden_readonly.txt" ,
46
+ "./test/xxx/New Text Document.txt" ,
47
+ "./test/xxx/readonly.txt" ,
48
+ "./test/xxx/somefile.txt"
49
+ ] . sort ( ) ) ;
50
+ } )
51
+
52
+ it ( 'zip.extractEntryTo(entry, destination, true, true)' , ( ) => {
53
+ const destination = './test/xxx'
54
+ const zip = new Zip ( './test/assets/ultra.zip' ) ;
55
+ var zipEntries = zip . getEntries ( ) ;
56
+ zipEntries . forEach ( e => zip . extractEntryTo ( e , destination , true , true ) ) ;
57
+
58
+ const files = walk ( destination )
59
+ expect ( files . sort ( ) ) . to . deep . equal ( [
60
+ "./test/xxx/attributes_test/asd/New Text Document.txt" ,
61
+ "./test/xxx/attributes_test/blank file.txt" ,
62
+ "./test/xxx/attributes_test/New folder/hidden.txt" ,
63
+ "./test/xxx/attributes_test/New folder/hidden_readonly.txt" ,
64
+ "./test/xxx/attributes_test/New folder/readonly.txt" ,
65
+ "./test/xxx/utes_test/New folder/somefile.txt"
66
+ ] . sort ( ) ) ;
67
+ } )
68
+
69
+ it ( 'passes issue-237-Twizzeld test case' , ( ) => {
70
+ const zip = new Zip ( './test/assets/issue-237-Twizzeld.zip' ) ;
71
+ const zipEntries = zip . getEntries ( ) ;
72
+ zipEntries . forEach ( function ( zipEntry ) {
73
+ if ( ! zipEntry . isDirectory ) {
74
+ zip . extractEntryTo ( zipEntry , './' , false , true ) ;
75
+ // This should create text.txt on the desktop.
76
+ // It will actually create two, but the first is overwritten by the second.
77
+ }
78
+ } ) ;
79
+ let text = fs . readFileSync ( './text.txt' ) . toString ( )
80
+ expect ( text ) . to . equal ( 'ride em cowboy!' )
81
+ fs . unlinkSync ( './text.txt' )
82
+ } )
83
+ } )
84
+
85
+ function walk ( dir ) {
86
+ let results = [ ] ;
87
+ const list = fs . readdirSync ( dir ) ;
88
+ list . forEach ( function ( file ) {
89
+ file = dir + '/' + file ;
90
+ const stat = fs . statSync ( file ) ;
91
+ if ( stat && stat . isDirectory ( ) ) {
92
+ /* Recurse into a subdirectory */
93
+ results = results . concat ( walk ( file ) ) ;
94
+ } else {
95
+ /* Is a file */
96
+ results . push ( file ) ;
97
+ }
98
+ } ) ;
99
+ return results ;
100
+ }
101
+
102
+ function walkD ( dir ) {
103
+ let results = [ ] ;
104
+ const list = fs . readdirSync ( dir ) ;
105
+ list . forEach ( function ( file ) {
106
+ file = dir + '/' + file ;
107
+ const stat = fs . statSync ( file ) ;
108
+ if ( stat && stat . isDirectory ( ) ) {
109
+ /* Recurse into a subdirectory */
110
+ results = results . concat ( walk ( file ) ) ;
111
+ results . push ( file ) ;
112
+ }
113
+ } ) ;
114
+ return results ;
115
+ }
0 commit comments