node/test/pummel/test-watch-file.js

34 lines
660 B
JavaScript
Raw Normal View History

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