Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / walkdir / test / pauseresume.js
diff --git a/legacy-libs/walkdir/test/pauseresume.js b/legacy-libs/walkdir/test/pauseresume.js
new file mode 100644 (file)
index 0000000..29d3d60
--- /dev/null
@@ -0,0 +1,36 @@
+var test = require('tape'),
+walk  = require('../walkdir.js');
+
+test('should be able to pause walk',function(t){
+
+  var paths = [];
+  var paused = false;
+  var em = walk('./',function(path){
+    if(!paused){
+      em.pause();
+      paused = 1;
+      setTimeout(function(){
+        t.equals(paths.length,1,'while paused should not emit any more paths');
+        em.resume();
+      },300);
+    } else if(paused == 1){
+      em.pause();
+      paused = 2;
+      setTimeout(function(){
+        t.equals(paths.length,2,'while paused should not emit any more paths');
+        em.resume();
+      },300);
+    }
+
+    paths.push(path);
+
+  });
+
+  em.on('end',function(){
+    console.log('end, and i found ',paths.length,'paths');
+    t.ok(paths.length > 1,'should have more paths before end');
+    t.end();
+  });
+
+});
+