test_monitor.js 692 B

12345678910111213141516171819202122232425262728293031
  1. var watch = require('../main')
  2. , assert = require('assert')
  3. , path = require('path')
  4. , fs = require('fs')
  5. , target = path.join(__dirname, "d/t")
  6. ;
  7. function clearFile() {
  8. fs.writeFileSync(target, '')
  9. }
  10. clearFile()
  11. // test if changed event is fired correctly
  12. watch.createMonitor(__dirname, { interval: 150 },
  13. function (monitor) {
  14. monitor.once('changed', function (f) {
  15. assert.equal(f, target);
  16. clearFile();
  17. process.exit(0)
  18. })
  19. fs.writeFile(target, 'Test Write\n', function (err) {
  20. if (err) throw err;
  21. setTimeout(function () {
  22. // should have got the other assert done by now
  23. assert.ok(false);
  24. }, 300);
  25. })
  26. });