node/test/pummel/test-watch-file.js
cjihrig dd9aefde69
test: use const for all require() calls
PR-URL: https://github.com/nodejs/node/pull/10550
Reviewed-By: Rich Trott <rtrott@gmail.com>
2017-01-30 12:08:31 -05:00

30 lines
568 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const f = path.join(common.fixturesDir, 'x.txt');
let changes = 0;
function watchFile() {
fs.watchFile(f, (curr, prev) => {
changes++;
assert.notDeepStrictEqual(curr.mtime, prev.mtime);
fs.unwatchFile(f);
watchFile();
fs.unwatchFile(f);
});
}
watchFile();
const fd = fs.openSync(f, 'w+');
fs.writeSync(fd, 'xyz\n');
fs.closeSync(fd);
process.on('exit', function() {
assert.ok(changes > 0);
});