HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //proc/1233/cwd/home/arjun/projects/buyercall/node_modules/watch/test/test_monitor.js
var watch = require('../main')
  , assert = require('assert')
  , path = require('path')
  , fs = require('fs')
  , target = path.join(__dirname, "d/t")
  ;

function clearFile() {
  fs.writeFileSync(target, '')
}

clearFile()

// test if changed event is fired correctly
watch.createMonitor(__dirname, { interval: 150 },
  function (monitor) {
    monitor.once('changed', function (f) {
      assert.equal(f, target);
      clearFile();
      process.exit(0)
    })

    fs.writeFile(target, 'Test Write\n', function (err) {
      if (err) throw err;

      setTimeout(function () {
        // should have got the other assert done by now
        assert.ok(false);
      }, 300);
    })
});