0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/pummel/test-watch-file.js
sivaprasanna a799854ce9 test: refactor test-watch-file.js
* use const and let instead of var
* use arrow function
* removed console.log statements

PR-URL: https://github.com/nodejs/node/pull/10679
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2017-01-09 23:21:38 -08:00

31 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);
});