@@ -2,24 +2,25 @@ var async = require("../index")
2
2
var assert = require ( "assert" )
3
3
var Path = require ( "path" )
4
4
var fs = require ( "fs" )
5
+ var Exists = fs . exists || Path . exists
5
6
6
7
var testDir = "assets_TEST"
7
8
8
9
var Test = {
9
-
10
+
10
11
setUp : function ( next ) {
11
12
this . $dir = process . cwd ( )
12
13
process . chdir ( __dirname )
13
14
async . rmtree ( __dirname + "/assets_TEST" , function ( ) {
14
15
async . copytree ( __dirname + "/assets" , testDir , next )
15
16
} )
16
17
} ,
17
-
18
+
18
19
tearDown : function ( next ) {
19
20
process . chdir ( this . $dir )
20
21
async . rmtree ( __dirname + "/assets_TEST" , next )
21
22
} ,
22
-
23
+
23
24
"test stat" : function ( next ) {
24
25
async . files ( [ testDir + "/1.txt" ] )
25
26
. stat ( )
@@ -29,12 +30,12 @@ var Test = {
29
30
next ( )
30
31
} )
31
32
} ,
32
-
33
+
33
34
"test unlink existing file should remove the file" : function ( next ) {
34
35
async . files ( [ testDir + "/3.txt" ] )
35
36
. unlink ( )
36
37
. end ( function ( err , file ) {
37
- Path . exists ( file . path , function ( exists ) {
38
+ Exists ( file . path , function ( exists ) {
38
39
assert . ok ( ! exists )
39
40
next ( )
40
41
} )
@@ -45,25 +46,25 @@ var Test = {
45
46
async . files ( [ testDir + "/emptydir" ] )
46
47
. rmdir ( )
47
48
. end ( function ( err , file ) {
48
- Path . exists ( file . path , function ( exists ) {
49
+ Exists ( file . path , function ( exists ) {
49
50
assert . ok ( ! exists )
50
51
next ( )
51
52
} )
52
- } )
53
+ } )
53
54
} ,
54
-
55
+
55
56
"test rmdir non empty dir should fail" : function ( next ) {
56
57
async . files ( [ testDir + "/nonemptydir" ] )
57
58
. rmdir ( )
58
59
. end ( function ( err , file ) {
59
60
assert . ok ( err )
60
- Path . exists ( file . path , function ( exists ) {
61
+ Exists ( file . path , function ( exists ) {
61
62
assert . ok ( exists )
62
63
next ( )
63
64
} )
64
65
} )
65
66
} ,
66
-
67
+
67
68
"test rmdir non existing dir should fail" : function ( next ) {
68
69
async . files ( [ testDir + "/foobar" ] )
69
70
. rmdir ( )
@@ -72,7 +73,7 @@ var Test = {
72
73
next ( )
73
74
} )
74
75
} ,
75
-
76
+
76
77
"test read file" : function ( next ) {
77
78
async . files ( [ testDir + "/1.txt" ] )
78
79
. readFile ( )
@@ -82,7 +83,7 @@ var Test = {
82
83
next ( )
83
84
} )
84
85
} ,
85
-
86
+
86
87
"test open/close file" : function ( next ) {
87
88
async . files ( [ testDir + "/1.txt" ] )
88
89
. open ( )
@@ -97,10 +98,10 @@ var Test = {
97
98
} )
98
99
. end ( function ( err ) {
99
100
assert . ok ( ! err )
100
- next ( )
101
+ next ( )
101
102
} )
102
103
} ,
103
-
104
+
104
105
"test chmod" : function ( next ) {
105
106
async . files ( [ testDir + "/1.txt" ] )
106
107
. chmod ( 0600 )
@@ -122,32 +123,32 @@ var Test = {
122
123
} )
123
124
. end ( function ( err ) {
124
125
assert . ok ( ! err )
125
- next ( )
126
+ next ( )
126
127
} )
127
128
} ,
128
-
129
+
129
130
"test mkdir/rmdir" : function ( next ) {
130
131
async . files ( [ testDir + "/newdir" ] )
131
132
. mkdir ( 0755 )
132
133
. each ( function ( file , next ) {
133
- Path . exists ( file . path , function ( exists ) {
134
+ Exists ( file . path , function ( exists ) {
134
135
assert . ok ( exists )
135
136
next ( )
136
137
} )
137
138
} )
138
139
. rmdir ( )
139
140
. each ( function ( file , next ) {
140
- Path . exists ( file . path , function ( exists ) {
141
+ Exists ( file . path , function ( exists ) {
141
142
assert . ok ( ! exists )
142
143
next ( )
143
144
} )
144
145
} )
145
146
. end ( function ( err ) {
146
147
assert . ok ( ! err )
147
- next ( )
148
+ next ( )
148
149
} )
149
150
} ,
150
-
151
+
151
152
"test write file with data from argument" : function ( next ) {
152
153
async . files ( [ testDir + "/4.txt" ] )
153
154
. writeFile ( "4" )
@@ -158,7 +159,7 @@ var Test = {
158
159
next ( )
159
160
} )
160
161
} ,
161
-
162
+
162
163
"test write file with data from stream" : function ( next ) {
163
164
async . files ( [ testDir + "/5.txt" ] )
164
165
. each ( function ( file ) {
@@ -223,7 +224,7 @@ var Test = {
223
224
next ( )
224
225
} )
225
226
} ,
226
-
227
+
227
228
"test glob with * in file name" : function ( next ) {
228
229
async . glob ( testDir + "/*.txt" )
229
230
. get ( "path" )
@@ -235,7 +236,7 @@ var Test = {
235
236
next ( )
236
237
} )
237
238
} ,
238
-
239
+
239
240
"test glob with ? in file name" : function ( next ) {
240
241
async . glob ( testDir + "/?.txt" )
241
242
. get ( "path" )
@@ -247,7 +248,7 @@ var Test = {
247
248
next ( )
248
249
} )
249
250
} ,
250
-
251
+
251
252
"test glob with only file magic" : function ( next ) {
252
253
process . chdir ( testDir )
253
254
async . glob ( "*.txt" )
@@ -260,35 +261,35 @@ var Test = {
260
261
next ( )
261
262
} )
262
263
} ,
263
-
264
+
264
265
"test glob without magic for not existing file should return empty list" : function ( next ) {
265
266
async . glob ( testDir + "/notexisting/juhu.txt" )
266
267
. toArray ( function ( err , values ) {
267
268
assert . equal ( values . length , 0 )
268
269
next ( )
269
270
} )
270
271
} ,
271
-
272
+
272
273
"test glob with non existing file name should return empty list" : function ( next ) {
273
274
async . glob ( testDir + "/notexisting/*.txt" )
274
275
. toArray ( function ( err , values ) {
275
276
assert . equal ( values . length , 0 )
276
277
next ( )
277
- } )
278
+ } )
278
279
} ,
279
-
280
+
280
281
"test glob with * in path" : function ( next ) {
281
282
async . glob ( testDir + "/dir*/*.txt" )
282
283
. get ( "path" )
283
284
. toArray ( function ( err , values ) {
284
285
var expected = [
285
- testDir + "/dir1/1.txt" ,
286
- testDir + "/dir2/2.txt" ,
286
+ testDir + "/dir1/1.txt" ,
287
+ testDir + "/dir2/2.txt" ,
287
288
testDir + "/dir11/11.txt"
288
289
]
289
290
assert . equal ( JSON . stringify ( values . sort ( ) ) , JSON . stringify ( expected . sort ( ) ) )
290
291
next ( )
291
- } )
292
+ } )
292
293
} ,
293
294
294
295
"test glob with ? in path" : function ( next ) {
@@ -301,33 +302,33 @@ var Test = {
301
302
]
302
303
assert . equal ( JSON . stringify ( values . sort ( ) ) , JSON . stringify ( expected . sort ( ) ) )
303
304
next ( )
304
- } )
305
+ } )
305
306
} ,
306
-
307
+
307
308
"test glob with * in path and ? name" : function ( next ) {
308
309
async . glob ( testDir + "/dir*/?.txt" )
309
310
. get ( "path" )
310
311
. toArray ( function ( err , values ) {
311
312
var expected = [
312
- testDir + "/dir1/1.txt" ,
313
+ testDir + "/dir1/1.txt" ,
313
314
testDir + "/dir2/2.txt"
314
315
]
315
316
assert . equal ( JSON . stringify ( values . sort ( ) ) , JSON . stringify ( expected . sort ( ) ) )
316
317
next ( )
317
- } )
318
- } ,
319
-
318
+ } )
319
+ } ,
320
+
320
321
"test copytree should deal with recursive symlinks" : function ( next ) {
321
322
async . copytree ( testDir + "/symlink-dir" , testDir + "/symlink-dir-copy" , function ( err ) {
322
323
assert . equal ( err , null ) ;
323
-
324
+
324
325
fs . lstat ( testDir + "/symlink-dir-copy/dir/symlink-dir" , function ( err , stat ) {
325
326
assert . equal ( err , null ) ;
326
327
assert . equal ( stat . isSymbolicLink ( ) , true ) ;
327
328
next ( ) ;
328
329
} ) ;
329
- } ) ;
330
- } ,
330
+ } ) ;
331
+ } ,
331
332
}
332
333
333
334
module . exports = require ( "../lib/test" ) . testcase ( Test , "fs" )
0 commit comments