Permalink
Browse files

failing test for optional callbacks

  • Loading branch information...
1 parent 29070fd commit 8f3a995c9d96fff972f7aa2cf56776aef08f31f2 @substack substack committed Jul 9, 2011
Showing with 35 additions and 18 deletions.
  1. +18 −15 index.js
  2. +14 −0 test/cb.js
  3. +2 −2 test/foo.js
  4. +1 −1 test/module.js
View
@@ -64,22 +64,25 @@ function find (base, cb) {
return em;
};
-exports.findSync = function findSync (dir) {
- if (!fs.statSync(dir).isDirectory()) return [dir];
+exports.findSync = function findSync (dir, cb) {
+ var rootStat = fs.statSync(dir);
+ if (!rootStat.isDirectory()) {
+ if (cb) cb(dir, rootStat);
+ return [dir];
+ }
- return fs.readdirSync(dir)
- .reduce(function (files, file) {
- var p = dir + '/' + file;
- var stat = fs.statSync(p);
- files.push(p);
-
- if (stat.isDirectory()) {
- files.push.apply(files, findSync(p));
- }
-
- return files;
- }, [])
- ;
+ return fs.readdirSync(dir).reduce(function (files, file) {
+ var p = dir + '/' + file;
+ var stat = fs.statSync(p);
+ if (cb) cb(file, stat);
+ files.push(p);
+
+ if (stat.isDirectory()) {
+ files.push.apply(files, findSync(p, cb));
+ }
+
+ return files;
+ }, []);
};
exports.find.sync = exports.findSync;
View
@@ -0,0 +1,14 @@
+var assert = require('assert');
+var find = require('../');
+
+exports.cbSync = function () {
+ var files = [];
+ var dirs = [];
+ find.sync(__dirname + '/foo', function (file, stat) {
+ if (stat.isDirectory()) dirs.push(file)
+ else files.push(file)
+ });
+
+ assert.deepEqual(dirs, [ 'a', 'a/b', 'a/b/c' ]);
+ assert.deepEqual(files, [ 'x', 'a/y', 'a/b/z', 'a/b/c/w' ]);
+};
View
@@ -1,6 +1,6 @@
var assert = require('assert');
-var find = require('findit').find;
-var findSync = require('findit').findSync;
+var find = require('../').find;
+var findSync = require('../').findSync;
exports.foo = function () {
var to = setTimeout(function () {
View
@@ -1,5 +1,5 @@
var assert = require('assert');
-var find = require('findit');
+var find = require('../');
exports.module = function () {
assert.eql(find.findSync, find.find.sync);

0 comments on commit 8f3a995

Please sign in to comment.