RyanZim
8 years ago
11 changed files with 2 additions and 227 deletions
@ -1,55 +0,0 @@ |
|||||
var assert = require('assert') |
|
||||
var path = require('path') |
|
||||
|
|
||||
var fse = require('../../') |
|
||||
|
|
||||
/* global describe, it */ |
|
||||
var fixturesDir = path.join(__dirname, 'fixtures') |
|
||||
|
|
||||
describe('walk-sync', function () { |
|
||||
it('should return an error if the source dir does not exist', function (done) { |
|
||||
try { |
|
||||
fse.walkSync('dirDoesNotExist/') |
|
||||
} catch (err) { |
|
||||
assert.equal(err.code, 'ENOENT') |
|
||||
} finally { |
|
||||
done() |
|
||||
} |
|
||||
}) |
|
||||
|
|
||||
it('should return an error if the source is not a dir', function (done) { |
|
||||
try { |
|
||||
fse.walkSync(path.join(fixturesDir, 'dir1/file1_2')) |
|
||||
} catch (err) { |
|
||||
assert.equal(err.code, 'ENOTDIR') |
|
||||
} finally { |
|
||||
done() |
|
||||
} |
|
||||
}) |
|
||||
|
|
||||
it('should return all items of a dir containing path and stats data successfully', function (done) { |
|
||||
var items = fse.walkSync(fixturesDir) |
|
||||
var files = ['dir1/file1_2', 'dir2/dir2_1/file2_1_1', 'file1'] |
|
||||
files = files.map(function (item) { |
|
||||
return path.join(fixturesDir, item) |
|
||||
}) |
|
||||
var dirs = ['dir1', 'dir2', 'dir2/dir2_1'] |
|
||||
dirs = dirs.map(function (item) { |
|
||||
return path.join(fixturesDir, item) |
|
||||
}) |
|
||||
var expectedItems = [ |
|
||||
{path: dirs[0], stats: fse.lstatSync(dirs[0])}, |
|
||||
{path: files[0], stats: fse.lstatSync(files[0])}, |
|
||||
{path: dirs[1], stats: fse.lstatSync(dirs[1])}, |
|
||||
{path: dirs[2], stats: fse.lstatSync(dirs[2])}, |
|
||||
{path: files[1], stats: fse.lstatSync(files[1])}, |
|
||||
{path: files[2], stats: fse.lstatSync(files[2])} |
|
||||
] |
|
||||
items.forEach(function (elem, i) { |
|
||||
assert.deepEqual(elem, expectedItems[i]) |
|
||||
assert.strictEqual(elem.path, expectedItems[i].path) |
|
||||
assert.deepEqual(elem.stats, expectedItems[i].stats) |
|
||||
}) |
|
||||
done() |
|
||||
}) |
|
||||
}) |
|
@ -1,22 +0,0 @@ |
|||||
var fs = require('graceful-fs') |
|
||||
var path = require('path') |
|
||||
|
|
||||
var walkSync = function (dir, list) { |
|
||||
var files = fs.readdirSync(path.resolve(dir)) |
|
||||
list = list || [] |
|
||||
files.forEach(function (file) { |
|
||||
var nestedPath = path.join(dir, file) |
|
||||
var stat = fs.lstatSync(nestedPath) |
|
||||
if (stat.isDirectory()) { |
|
||||
list.push({path: nestedPath, stats: stat}) |
|
||||
list = walkSync(nestedPath, list) |
|
||||
} else { |
|
||||
list.push({path: nestedPath, stats: stat}) |
|
||||
} |
|
||||
}) |
|
||||
return list |
|
||||
} |
|
||||
|
|
||||
module.exports = { |
|
||||
walkSync: walkSync |
|
||||
} |
|
@ -1,7 +0,0 @@ |
|||||
[ |
|
||||
"a/b/c/d.txt", |
|
||||
"a/e.jpg", |
|
||||
"h/i/j/k.txt", |
|
||||
"h/i/l.txt", |
|
||||
"h/i/m.jpg" |
|
||||
] |
|
@ -1,73 +0,0 @@ |
|||||
var assert = require('assert') |
|
||||
var path = require('path') |
|
||||
var os = require('os') |
|
||||
var fse = require('../../') |
|
||||
var fixtures = require('./fixtures') |
|
||||
|
|
||||
/* global afterEach, beforeEach, describe, it */ |
|
||||
// trinity: mocha
|
|
||||
|
|
||||
describe('walk()', function () { |
|
||||
var TEST_DIR |
|
||||
|
|
||||
beforeEach(function (done) { |
|
||||
TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'walk') |
|
||||
fse.emptyDir(TEST_DIR, function (err) { |
|
||||
if (err) return done(err) |
|
||||
fixtures.forEach(function (f) { |
|
||||
f = path.join(TEST_DIR, f) |
|
||||
fse.outputFileSync(f, path.basename(f, path.extname(f))) |
|
||||
}) |
|
||||
done() |
|
||||
}) |
|
||||
}) |
|
||||
|
|
||||
afterEach(function (done) { |
|
||||
fse.remove(TEST_DIR, done) |
|
||||
}) |
|
||||
|
|
||||
it('should work w/ streams 1', function (done) { |
|
||||
var items = [] |
|
||||
fse.walk(TEST_DIR) |
|
||||
.on('data', function (item) { |
|
||||
assert.strictEqual(typeof item.stats, 'object') // verify that property is there
|
|
||||
items.push(item.path) |
|
||||
}) |
|
||||
.on('end', function () { |
|
||||
items.sort() |
|
||||
var expected = ['a', 'a/b', 'a/b/c', 'a/b/c/d.txt', 'a/e.jpg', 'h', 'h/i', 'h/i/j', |
|
||||
'h/i/j/k.txt', 'h/i/l.txt', 'h/i/m.jpg'] |
|
||||
expected = expected.map(function (item) { |
|
||||
return path.join(path.join(TEST_DIR, item)) |
|
||||
}) |
|
||||
expected.unshift(TEST_DIR) |
|
||||
|
|
||||
assert.deepEqual(items, expected) |
|
||||
done() |
|
||||
}) |
|
||||
}) |
|
||||
|
|
||||
it('should work w/ streams 2/3', function (done) { |
|
||||
var items = [] |
|
||||
fse.walk(TEST_DIR) |
|
||||
.on('readable', function () { |
|
||||
var item |
|
||||
while ((item = this.read())) { |
|
||||
assert.strictEqual(typeof item.stats, 'object') // verify that property is there
|
|
||||
items.push(item.path) |
|
||||
} |
|
||||
}) |
|
||||
.on('end', function () { |
|
||||
items.sort() |
|
||||
var expected = ['a', 'a/b', 'a/b/c', 'a/b/c/d.txt', 'a/e.jpg', 'h', 'h/i', 'h/i/j', |
|
||||
'h/i/j/k.txt', 'h/i/l.txt', 'h/i/m.jpg'] |
|
||||
expected = expected.map(function (item) { |
|
||||
return path.join(path.join(TEST_DIR, item)) |
|
||||
}) |
|
||||
expected.unshift(TEST_DIR) |
|
||||
|
|
||||
assert.deepEqual(items, expected) |
|
||||
done() |
|
||||
}) |
|
||||
}) |
|
||||
}) |
|
@ -1,5 +0,0 @@ |
|||||
var klaw = require('klaw') |
|
||||
|
|
||||
module.exports = { |
|
||||
walk: klaw |
|
||||
} |
|
Loading…
Reference in new issue