0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 23:43:09 +01:00
nodejs/test/pummel/test-watch-file.js
Rich Trott 5eb0ca7d1a test: fix assertion in test-watch-file.js
Because it is comparing two Date objects, an assertion in
test/pummel/test-watch-file.js would never fire even if the two objects
represented the same time. Use `assert.notDeepStrictEqual()` so that the
assertion fires if different Date objects represent the same time.

PR-URL: https://github.com/nodejs/node/pull/8129
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-08-18 15:15:56 -07:00

34 lines
639 B
JavaScript

'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var f = path.join(common.fixturesDir, 'x.txt');
console.log('watching for changes of ' + f);
var changes = 0;
function watchFile() {
fs.watchFile(f, function(curr, prev) {
console.log(f + ' change');
changes++;
assert.notDeepStrictEqual(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.on('exit', function() {
assert.ok(changes > 0);
});