1 var test = require('tape'),
2 walkdir = require('../walkdir.js');
9 'dir/foo/a/b/z':'file',
10 'dir/foo/a/b/c':'dir',
11 'dir/foo/a/b/c/w':'file'
14 test('async events',function(t){
20 var emitter = walkdir(__dirname+'/dir/foo',function(path){
21 //console.log('path: ',path);
22 paths.push(path.replace(__dirname+'/',''));
25 emitter.on('directory',function(path,stat){
26 dirs.push(path.replace(__dirname+'/',''));
29 emitter.on('file',function(path,stat){
30 //console.log('file: ',path);
31 files.push(path.replace(__dirname+'/',''));
34 emitter.on('end',function(){
36 files.forEach(function(v,k){
37 t.equals(expectedPaths[v],'file','path from file event should be file');
40 var expected = Object.keys(expectedPaths);
42 t.ok(expected.length == paths.length, 'expected and emitted paths should have the same length');
44 expected.forEach(function(v,k){
45 if(expectedPaths[v] == 'file') {
46 t.ok(files.indexOf(v) > -1,'should have file in files array');
50 dirs.forEach(function(v,k){
51 t.equals(expectedPaths[v],'dir','path from dir event should be dir '+v);
54 expected.forEach(function(v,k){
55 if(expectedPaths[v] == 'dir') {
56 t.ok(dirs.indexOf(v) > -1,'should have dir in dirs array');
60 expected.forEach(function(v,k){
61 t.ok(paths.indexOf(v) !== -1,'should have found all expected paths '+v);