Skip to content

Commit 0041417

Browse files
author
Fabian Jakobs
committed
Merge pull request #27 from houli/node012testfix
Fix failing tests on node 0.12 and above
2 parents 98312a3 + 18993e9 commit 0041417

File tree

2 files changed

+45
-42
lines changed

2 files changed

+45
-42
lines changed

.travis.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
language: node_js
22
node_js:
3-
- 0.4
4-
- 0.6
3+
- 0.10
4+
- 0.12
5+
- 4.0
6+
- 4.1

test/fs.test.js

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@ var async = require("../index")
22
var assert = require("assert")
33
var Path = require("path")
44
var fs = require("fs")
5+
var Exists = fs.exists || Path.exists
56

67
var testDir = "assets_TEST"
78

89
var Test = {
9-
10+
1011
setUp: function(next) {
1112
this.$dir = process.cwd()
1213
process.chdir(__dirname)
1314
async.rmtree(__dirname + "/assets_TEST", function() {
1415
async.copytree(__dirname + "/assets", testDir, next)
1516
})
1617
},
17-
18+
1819
tearDown: function(next) {
1920
process.chdir(this.$dir)
2021
async.rmtree(__dirname + "/assets_TEST", next)
2122
},
22-
23+
2324
"test stat": function(next) {
2425
async.files([testDir + "/1.txt"])
2526
.stat()
@@ -29,12 +30,12 @@ var Test = {
2930
next()
3031
})
3132
},
32-
33+
3334
"test unlink existing file should remove the file": function(next) {
3435
async.files([testDir + "/3.txt"])
3536
.unlink()
3637
.end(function(err, file) {
37-
Path.exists(file.path, function(exists) {
38+
Exists(file.path, function(exists) {
3839
assert.ok(!exists)
3940
next()
4041
})
@@ -45,25 +46,25 @@ var Test = {
4546
async.files([testDir + "/emptydir"])
4647
.rmdir()
4748
.end(function(err, file) {
48-
Path.exists(file.path, function(exists) {
49+
Exists(file.path, function(exists) {
4950
assert.ok(!exists)
5051
next()
5152
})
52-
})
53+
})
5354
},
54-
55+
5556
"test rmdir non empty dir should fail": function(next) {
5657
async.files([testDir + "/nonemptydir"])
5758
.rmdir()
5859
.end(function(err, file) {
5960
assert.ok(err)
60-
Path.exists(file.path, function(exists) {
61+
Exists(file.path, function(exists) {
6162
assert.ok(exists)
6263
next()
6364
})
6465
})
6566
},
66-
67+
6768
"test rmdir non existing dir should fail": function(next) {
6869
async.files([testDir + "/foobar"])
6970
.rmdir()
@@ -72,7 +73,7 @@ var Test = {
7273
next()
7374
})
7475
},
75-
76+
7677
"test read file": function(next) {
7778
async.files([testDir + "/1.txt"])
7879
.readFile()
@@ -82,7 +83,7 @@ var Test = {
8283
next()
8384
})
8485
},
85-
86+
8687
"test open/close file": function(next) {
8788
async.files([testDir + "/1.txt"])
8889
.open()
@@ -97,10 +98,10 @@ var Test = {
9798
})
9899
.end(function(err) {
99100
assert.ok(!err)
100-
next()
101+
next()
101102
})
102103
},
103-
104+
104105
"test chmod": function(next) {
105106
async.files([testDir + "/1.txt"])
106107
.chmod(0600)
@@ -122,32 +123,32 @@ var Test = {
122123
})
123124
.end(function(err) {
124125
assert.ok(!err)
125-
next()
126+
next()
126127
})
127128
},
128-
129+
129130
"test mkdir/rmdir": function(next) {
130131
async.files([testDir + "/newdir"])
131132
.mkdir(0755)
132133
.each(function(file, next) {
133-
Path.exists(file.path, function(exists) {
134+
Exists(file.path, function(exists) {
134135
assert.ok(exists)
135136
next()
136137
})
137138
})
138139
.rmdir()
139140
.each(function(file, next) {
140-
Path.exists(file.path, function(exists) {
141+
Exists(file.path, function(exists) {
141142
assert.ok(!exists)
142143
next()
143144
})
144145
})
145146
.end(function(err) {
146147
assert.ok(!err)
147-
next()
148+
next()
148149
})
149150
},
150-
151+
151152
"test write file with data from argument": function(next) {
152153
async.files([testDir + "/4.txt"])
153154
.writeFile("4")
@@ -158,7 +159,7 @@ var Test = {
158159
next()
159160
})
160161
},
161-
162+
162163
"test write file with data from stream": function(next) {
163164
async.files([testDir + "/5.txt"])
164165
.each(function(file) {
@@ -223,7 +224,7 @@ var Test = {
223224
next()
224225
})
225226
},
226-
227+
227228
"test glob with * in file name": function(next) {
228229
async.glob(testDir + "/*.txt")
229230
.get("path")
@@ -235,7 +236,7 @@ var Test = {
235236
next()
236237
})
237238
},
238-
239+
239240
"test glob with ? in file name": function(next) {
240241
async.glob(testDir + "/?.txt")
241242
.get("path")
@@ -247,7 +248,7 @@ var Test = {
247248
next()
248249
})
249250
},
250-
251+
251252
"test glob with only file magic": function(next) {
252253
process.chdir(testDir)
253254
async.glob("*.txt")
@@ -260,35 +261,35 @@ var Test = {
260261
next()
261262
})
262263
},
263-
264+
264265
"test glob without magic for not existing file should return empty list": function(next) {
265266
async.glob(testDir + "/notexisting/juhu.txt")
266267
.toArray(function(err, values) {
267268
assert.equal(values.length, 0)
268269
next()
269270
})
270271
},
271-
272+
272273
"test glob with non existing file name should return empty list" : function(next) {
273274
async.glob(testDir + "/notexisting/*.txt")
274275
.toArray(function(err, values) {
275276
assert.equal(values.length, 0)
276277
next()
277-
})
278+
})
278279
},
279-
280+
280281
"test glob with * in path": function(next) {
281282
async.glob(testDir + "/dir*/*.txt")
282283
.get("path")
283284
.toArray(function(err, values) {
284285
var expected = [
285-
testDir + "/dir1/1.txt",
286-
testDir + "/dir2/2.txt",
286+
testDir + "/dir1/1.txt",
287+
testDir + "/dir2/2.txt",
287288
testDir + "/dir11/11.txt"
288289
]
289290
assert.equal(JSON.stringify(values.sort()), JSON.stringify(expected.sort()))
290291
next()
291-
})
292+
})
292293
},
293294

294295
"test glob with ? in path": function(next) {
@@ -301,33 +302,33 @@ var Test = {
301302
]
302303
assert.equal(JSON.stringify(values.sort()), JSON.stringify(expected.sort()))
303304
next()
304-
})
305+
})
305306
},
306-
307+
307308
"test glob with * in path and ? name": function(next) {
308309
async.glob(testDir + "/dir*/?.txt")
309310
.get("path")
310311
.toArray(function(err, values) {
311312
var expected = [
312-
testDir + "/dir1/1.txt",
313+
testDir + "/dir1/1.txt",
313314
testDir + "/dir2/2.txt"
314315
]
315316
assert.equal(JSON.stringify(values.sort()), JSON.stringify(expected.sort()))
316317
next()
317-
})
318-
},
319-
318+
})
319+
},
320+
320321
"test copytree should deal with recursive symlinks": function(next) {
321322
async.copytree(testDir + "/symlink-dir", testDir + "/symlink-dir-copy", function (err) {
322323
assert.equal(err, null);
323-
324+
324325
fs.lstat(testDir + "/symlink-dir-copy/dir/symlink-dir", function (err, stat) {
325326
assert.equal(err, null);
326327
assert.equal(stat.isSymbolicLink(), true);
327328
next();
328329
});
329-
});
330-
},
330+
});
331+
},
331332
}
332333

333334
module.exports = require("../lib/test").testcase(Test, "fs")

0 commit comments

Comments
 (0)