Added async readdir
This commit is contained in:
parent
b91834d796
commit
b8ae7be2f7
3 changed files with 121 additions and 16 deletions
|
|
@ -4,29 +4,53 @@ var wrench = require('../lib/wrench');
|
|||
var path = require('path');
|
||||
var _und = require("underscore");
|
||||
|
||||
|
||||
function checkResult(test, files) {
|
||||
var check = [
|
||||
'bar.txt',
|
||||
'foo',
|
||||
'foo/bar',
|
||||
'foo/dolor.md',
|
||||
'foo/lorem.txt',
|
||||
'foo/bar/ipsum.js'
|
||||
];
|
||||
|
||||
test.equals(files.length, check.length, 'number of paths is correct');
|
||||
|
||||
_und.each(check, function(it) {
|
||||
test.ok(_und.include(files, it), 'path ' + it + ' should be returned');
|
||||
});
|
||||
|
||||
test.done();
|
||||
}
|
||||
|
||||
module.exports = testCase({
|
||||
test_readdirSyncRecursive: function(test) {
|
||||
var dir = __dirname + '/readdir';
|
||||
|
||||
test.equals(path.existsSync(dir), true, 'Folders should exist');
|
||||
|
||||
var check = [
|
||||
'bar.txt',
|
||||
'foo',
|
||||
'foo/bar',
|
||||
'foo/dolor.md',
|
||||
'foo/lorem.txt',
|
||||
'foo/bar/ipsum.js'
|
||||
];
|
||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
||||
|
||||
var files = wrench.readdirSyncRecursive(dir);
|
||||
|
||||
test.equals(files.length, check.length, 'number of paths is correct');
|
||||
for (var filename in files) {
|
||||
test.ok(_und.include(check, files[filename]));
|
||||
}
|
||||
checkResult(test, files);
|
||||
},
|
||||
|
||||
test.done();
|
||||
test_readdirRecursive: function(test) {
|
||||
var dir = __dirname + '/readdir';
|
||||
|
||||
test.ok(path.existsSync(dir), 'Folders should exist');
|
||||
|
||||
var allFiles = [];
|
||||
|
||||
wrench.readdirRecursive(dir, function(e, files) {
|
||||
if (e) throw e;
|
||||
|
||||
if (files) {
|
||||
allFiles = allFiles.concat(files);
|
||||
} else {
|
||||
checkResult(test, allFiles);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Reference in a new issue