test_watchTree.js 697 B

1234567891011121314151617181920212223
  1. var fs = require('fs')
  2. , watch = require('../main')
  3. , assert = require('assert')
  4. ;
  5. //
  6. // Demonstrate that the function of 'filter' is semantically inconsistent with
  7. // usual convention, that returning true means 'keep this'.
  8. //
  9. function isDirOrQ(f, stat) { return stat.isDirectory() || f === 'Q'; }
  10. watch.watchTree(__dirname, { filter: isDirOrQ }, function (f, curr, prev) {
  11. if (typeof f == 'object' && prev === null && curr === null) {
  12. Object.keys(f).forEach(function(name) {
  13. var stat = f[name];
  14. assert(isDirOrQ(name, stat));
  15. });
  16. // If the process never exits then `unwatchTree` failed to unwatch all
  17. // the files.
  18. watch.unwatchTree(__dirname);
  19. }
  20. });