From de98e0b232509d5f40c135d540a70e415272ff85 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 3 May 2017 15:35:00 +0200 Subject: node_modules --- node_modules/walkdir/test/async.js | 66 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 node_modules/walkdir/test/async.js (limited to 'node_modules/walkdir/test/async.js') diff --git a/node_modules/walkdir/test/async.js b/node_modules/walkdir/test/async.js new file mode 100644 index 000000000..ef02ab487 --- /dev/null +++ b/node_modules/walkdir/test/async.js @@ -0,0 +1,66 @@ +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(); + }); +}); -- cgit v1.2.3