Sha256: 0df61e6f45f2f1a7c5409ff396bb7bf18a4bab4d9beae034db7c7d5ed970880a

Contents?: true

Size: 1.59 KB

Versions: 21

Compression:

Stored size: 1.59 KB

Contents

var test = require('tape'),
walkdir = require('../walkdir.js');

var expectedPaths = {
'dir/foo/x':'file',
'dir/foo/a':'dir',
'dir/foo/a/y':'file',
'dir/foo/a/b':'dir',
'dir/foo/a/b/z':'file',
'dir/foo/a/b/c':'dir',
'dir/foo/a/b/c/w':'file'
};

test('async events',function(t){
  var paths = [],
  files = [],
  dirs = [];


  var emitter = walkdir(__dirname+'/dir/foo',function(path){
    //console.log('path: ',path);
    paths.push(path.replace(__dirname+'/',''));
  });

  emitter.on('directory',function(path,stat){
    dirs.push(path.replace(__dirname+'/',''));
  });

  emitter.on('file',function(path,stat){
    //console.log('file: ',path); 
    files.push(path.replace(__dirname+'/',''));
  });

  emitter.on('end',function(){

     files.forEach(function(v,k){
       t.equals(expectedPaths[v],'file','path from file event should be file');  
     });

     var expected = Object.keys(expectedPaths);

     t.ok(expected.length == paths.length, 'expected and emitted paths should have the same length');

     expected.forEach(function(v,k){
       if(expectedPaths[v] == 'file') {
          t.ok(files.indexOf(v) > -1,'should have file in files array');
       }
     });

     dirs.forEach(function(v,k){
       t.equals(expectedPaths[v],'dir','path from dir event should be dir '+v);  
     });

     expected.forEach(function(v,k){
       if(expectedPaths[v] == 'dir') {
          t.ok(dirs.indexOf(v) > -1,'should have dir in dirs array');
       }
     });

     expected.forEach(function(v,k){
       t.ok(paths.indexOf(v) !== -1,'should have found all expected paths '+v);
     });

     t.end();
  });
});

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
ela-4.1.6 node_modules/walkdir/test/async.js
ela-4.1.5 node_modules/walkdir/test/async.js
ela-4.1.4 node_modules/walkdir/test/async.js
ela-4.1.3 node_modules/walkdir/test/async.js
ela-4.1.2 node_modules/walkdir/test/async.js
ela-4.1.1 node_modules/walkdir/test/async.js
ela-4.1.0 node_modules/walkdir/test/async.js
ela-4.0.0 node_modules/walkdir/test/async.js
ela-3.4.3 node_modules/walkdir/test/async.js
ela-3.4.2 node_modules/walkdir/test/async.js
ela-3.4.0 node_modules/walkdir/test/async.js
ela-3.3.1 node_modules/walkdir/test/async.js
ela-3.3.0 node_modules/walkdir/test/async.js
ela-3.2.0 node_modules/walkdir/test/async.js
ela-3.1.1 node_modules/walkdir/test/async.js
ela-3.1.0 node_modules/walkdir/test/async.js
ela-3.0.0 node_modules/walkdir/test/async.js
ela-2.0.0 node_modules/walkdir/test/async.js
ela-1.1.0 node_modules/walkdir/test/async.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/walkdir/test/async.js