2010-12-03 09:03:18 +08:00
|
|
|
common = require('../common');
|
2010-07-16 02:47:25 +08:00
|
|
|
assert = common.assert
|
2009-11-17 21:07:48 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
var fs = require('fs');
|
|
|
|
var path = require('path');
|
2009-11-17 21:07:48 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
var f = path.join(common.fixturesDir, 'x.txt');
|
|
|
|
var f2 = path.join(common.fixturesDir, 'x2.txt');
|
2009-11-17 21:07:48 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
console.log('watching for changes of ' + f);
|
2009-11-17 21:52:18 +08:00
|
|
|
|
2009-11-17 21:07:48 +08:00
|
|
|
var changes = 0;
|
2010-03-30 21:27:23 +08:00
|
|
|
function watchFile () {
|
2010-12-03 09:03:18 +08:00
|
|
|
fs.watchFile(f, function(curr, prev) {
|
|
|
|
console.log(f + ' change');
|
2010-03-30 21:27:23 +08:00
|
|
|
changes++;
|
|
|
|
assert.ok(curr.mtime != prev.mtime);
|
|
|
|
fs.unwatchFile(f);
|
|
|
|
watchFile();
|
|
|
|
fs.unwatchFile(f);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
watchFile();
|
2009-11-17 21:07:48 +08:00
|
|
|
|
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
var fd = fs.openSync(f, 'w+');
|
2010-02-17 15:06:26 +08:00
|
|
|
fs.writeSync(fd, 'xyz\n');
|
|
|
|
fs.closeSync(fd);
|
2009-11-17 21:07:48 +08:00
|
|
|
|
2010-12-03 09:03:18 +08:00
|
|
|
process.addListener('exit', function() {
|
2010-02-18 06:30:50 +08:00
|
|
|
assert.ok(changes > 0);
|
2009-11-17 21:07:48 +08:00
|
|
|
});
|